source: mainline/uspace/srv/console/console.c@ bc77bfa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bc77bfa was 19528516, checked in by jirka <jirka@…>, 16 years ago

Rewrite command-line input routine. Adds capability to seek, insert and delete (left/right arrow keys, home, end, delete).

  • Property mode set to 100644
File size: 18.9 KB
Line 
1/*
2 * Copyright (c) 2006 Josef Cejka
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup console
30 * @{
31 */
32/** @file
33 */
34
35#include <libc.h>
36#include <ipc/ipc.h>
37#include <ipc/kbd.h>
38#include <io/keycode.h>
39#include <ipc/fb.h>
40#include <ipc/services.h>
41#include <errno.h>
42#include <ipc/console.h>
43#include <unistd.h>
44#include <async.h>
45#include <adt/fifo.h>
46#include <sys/mman.h>
47#include <stdio.h>
48#include <string.h>
49#include <sysinfo.h>
50#include <event.h>
51#include <devmap.h>
52#include <fibril_sync.h>
53
54#include "console.h"
55#include "gcons.h"
56#include "keybuffer.h"
57#include "screenbuffer.h"
58
59#define NAME "console"
60
61#define MAX_DEVICE_NAME 32
62
63/** Phone to the keyboard driver. */
64static int kbd_phone;
65
66/** Information about framebuffer */
67struct {
68 int phone; /**< Framebuffer phone */
69 ipcarg_t cols; /**< Framebuffer columns */
70 ipcarg_t rows; /**< Framebuffer rows */
71 int color_cap; /**< Color capabilities (FB_CCAP_xxx) */
72} fb_info;
73
74typedef struct {
75 size_t index; /**< Console index */
76 size_t refcount; /**< Connection reference count */
77 dev_handle_t dev_handle; /**< Device handle */
78 keybuffer_t keybuffer; /**< Buffer for incoming keys. */
79 screenbuffer_t scr; /**< Screenbuffer for saving screen
80 contents and related settings. */
81} console_t;
82
83/** Array of data for virtual consoles */
84static console_t consoles[CONSOLE_COUNT];
85
86static console_t *active_console = &consoles[0];
87static console_t *prev_console = &consoles[0];
88static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
89
90/** Pointer to memory shared with framebufer used for
91 faster virtual console switching */
92static keyfield_t *interbuffer = NULL;
93
94/** Information on row-span yet unsent to FB driver. */
95struct {
96 size_t col; /**< Leftmost column of the span. */
97 size_t row; /**< Row where the span lies. */
98 size_t cnt; /**< Width of the span. */
99} fb_pending;
100
101static FIBRIL_MUTEX_INITIALIZE(input_mutex);
102static FIBRIL_CONDVAR_INITIALIZE(input_cv);
103
104static void curs_visibility(bool visible)
105{
106 async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
107}
108
109static void curs_hide_sync(void)
110{
111 ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
112}
113
114static void curs_goto(size_t x, size_t y)
115{
116 async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
117}
118
119static void screen_clear(void)
120{
121 async_msg_0(fb_info.phone, FB_CLEAR);
122}
123
124static void screen_yield(void)
125{
126 ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD);
127}
128
129static void screen_reclaim(void)
130{
131 ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
132}
133
134static void kbd_yield(void)
135{
136 ipc_call_sync_0_0(kbd_phone, KBD_YIELD);
137}
138
139static void kbd_reclaim(void)
140{
141 ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM);
142}
143
144static void set_style(int style)
145{
146 async_msg_1(fb_info.phone, FB_SET_STYLE, style);
147}
148
149static void set_color(int fgcolor, int bgcolor, int flags)
150{
151 async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
152}
153
154static void set_rgb_color(int fgcolor, int bgcolor)
155{
156 async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
157}
158
159static void set_attrs(attrs_t *attrs)
160{
161 switch (attrs->t) {
162 case at_style:
163 set_style(attrs->a.s.style);
164 break;
165 case at_idx:
166 set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
167 attrs->a.i.flags);
168 break;
169 case at_rgb:
170 set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
171 break;
172 }
173}
174
175static int ccap_fb_to_con(int ccap_fb, int *ccap_con)
176{
177 switch (ccap_fb) {
178 case FB_CCAP_NONE: *ccap_con = CONSOLE_CCAP_NONE; break;
179 case FB_CCAP_STYLE: *ccap_con = CONSOLE_CCAP_STYLE; break;
180 case FB_CCAP_INDEXED: *ccap_con = CONSOLE_CCAP_INDEXED; break;
181 case FB_CCAP_RGB: *ccap_con = CONSOLE_CCAP_RGB; break;
182 default: return EINVAL;
183 }
184
185 return EOK;
186}
187
188/** Send an area of screenbuffer to the FB driver. */
189static void fb_update_area(console_t *cons, ipcarg_t x0, ipcarg_t y0, ipcarg_t width, ipcarg_t height)
190{
191 if (interbuffer) {
192 ipcarg_t x;
193 ipcarg_t y;
194
195 for (y = 0; y < height; y++) {
196 for (x = 0; x < width; x++) {
197 interbuffer[y * width + x] =
198 *get_field_at(&cons->scr, x0 + x, y0 + y);
199 }
200 }
201
202 async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
203 x0, y0, width, height);
204 }
205}
206
207/** Flush pending cells to FB. */
208static void fb_pending_flush(void)
209{
210 if (fb_pending.cnt > 0) {
211 fb_update_area(active_console, fb_pending.col,
212 fb_pending.row, fb_pending.cnt, 1);
213 fb_pending.cnt = 0;
214 }
215}
216
217/** Mark a character cell as changed.
218 *
219 * This adds the cell to the pending rowspan if possible. Otherwise
220 * the old span is flushed first.
221 *
222 */
223static void cell_mark_changed(size_t col, size_t row)
224{
225 if (fb_pending.cnt != 0) {
226 if ((col != fb_pending.col + fb_pending.cnt)
227 || (row != fb_pending.row)) {
228 fb_pending_flush();
229 }
230 }
231
232 if (fb_pending.cnt == 0) {
233 fb_pending.col = col;
234 fb_pending.row = row;
235 }
236
237 fb_pending.cnt++;
238}
239
240/** Print a character to the active VC with buffering. */
241static void fb_putchar(wchar_t c, ipcarg_t col, ipcarg_t row)
242{
243 async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
244}
245
246/** Process a character from the client (TTY emulation). */
247static void write_char(console_t *cons, wchar_t ch)
248{
249 bool flush_cursor = false;
250
251 switch (ch) {
252 case '\n':
253 fb_pending_flush();
254 flush_cursor = true;
255 cons->scr.position_y++;
256 cons->scr.position_x = 0;
257 break;
258 case '\r':
259 break;
260 case '\t':
261 cons->scr.position_x += 8;
262 cons->scr.position_x -= cons->scr.position_x % 8;
263 break;
264 case '\b':
265 if (cons->scr.position_x == 0)
266 break;
267 cons->scr.position_x--;
268 if (cons == active_console)
269 cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
270 screenbuffer_putchar(&cons->scr, ' ');
271 break;
272 default:
273 if (cons == active_console)
274 cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
275
276 screenbuffer_putchar(&cons->scr, ch);
277 cons->scr.position_x++;
278 }
279
280 if (cons->scr.position_x >= cons->scr.size_x) {
281 flush_cursor = true;
282 cons->scr.position_y++;
283 }
284
285 if (cons->scr.position_y >= cons->scr.size_y) {
286 fb_pending_flush();
287 cons->scr.position_y = cons->scr.size_y - 1;
288 screenbuffer_clear_line(&cons->scr, cons->scr.top_line);
289 cons->scr.top_line = (cons->scr.top_line + 1) % cons->scr.size_y;
290
291 if (cons == active_console)
292 async_msg_1(fb_info.phone, FB_SCROLL, 1);
293 }
294
295 if (cons == active_console && flush_cursor)
296 curs_goto(cons->scr.position_x, cons->scr.position_y);
297 cons->scr.position_x = cons->scr.position_x % cons->scr.size_x;
298}
299
300/** Switch to new console */
301static void change_console(console_t *cons)
302{
303 if (cons == active_console)
304 return;
305
306 fb_pending_flush();
307
308 if (cons == kernel_console) {
309 async_serialize_start();
310 curs_hide_sync();
311 gcons_in_kernel();
312 screen_yield();
313 kbd_yield();
314 async_serialize_end();
315
316 if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
317 prev_console = active_console;
318 active_console = kernel_console;
319 } else
320 cons = active_console;
321 }
322
323 if (cons != kernel_console) {
324 size_t x;
325 size_t y;
326 int rc = 0;
327
328 async_serialize_start();
329
330 if (active_console == kernel_console) {
331 screen_reclaim();
332 kbd_reclaim();
333 gcons_redraw_console();
334 }
335
336 active_console = cons;
337 gcons_change_console(cons->index);
338
339 set_attrs(&cons->scr.attrs);
340 curs_visibility(false);
341 if (interbuffer) {
342 for (y = 0; y < cons->scr.size_y; y++) {
343 for (x = 0; x < cons->scr.size_x; x++) {
344 interbuffer[y * cons->scr.size_x + x] =
345 *get_field_at(&cons->scr, x, y);
346 }
347 }
348
349 /* This call can preempt, but we are already at the end */
350 rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
351 0, 0, cons->scr.size_x,
352 cons->scr.size_y);
353 }
354
355 if ((!interbuffer) || (rc != 0)) {
356 set_attrs(&cons->scr.attrs);
357 screen_clear();
358
359 for (y = 0; y < cons->scr.size_y; y++)
360 for (x = 0; x < cons->scr.size_x; x++) {
361 keyfield_t *field = get_field_at(&cons->scr, x, y);
362
363 if (!attrs_same(cons->scr.attrs, field->attrs))
364 set_attrs(&field->attrs);
365
366 cons->scr.attrs = field->attrs;
367 if ((field->character == ' ') &&
368 (attrs_same(field->attrs, cons->scr.attrs)))
369 continue;
370
371 fb_putchar(field->character, x, y);
372 }
373 }
374
375 curs_goto(cons->scr.position_x, cons->scr.position_y);
376 curs_visibility(cons->scr.is_cursor_visible);
377
378 async_serialize_end();
379 }
380}
381
382/** Handler for keyboard */
383static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
384{
385 /* Ignore parameters, the connection is already opened */
386 while (true) {
387
388 ipc_call_t call;
389 ipc_callid_t callid = async_get_call(&call);
390
391 int retval;
392 console_event_t ev;
393
394 switch (IPC_GET_METHOD(call)) {
395 case IPC_M_PHONE_HUNGUP:
396 /* TODO: Handle hangup */
397 return;
398 case KBD_EVENT:
399 /* Got event from keyboard driver. */
400 retval = 0;
401 ev.type = IPC_GET_ARG1(call);
402 ev.key = IPC_GET_ARG2(call);
403 ev.mods = IPC_GET_ARG3(call);
404 ev.c = IPC_GET_ARG4(call);
405
406 if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
407 CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
408 if (ev.key == KC_F1 + KERNEL_CONSOLE)
409 change_console(kernel_console);
410 else
411 change_console(&consoles[ev.key - KC_F1]);
412 break;
413 }
414
415 fibril_mutex_lock(&input_mutex);
416 keybuffer_push(&active_console->keybuffer, &ev);
417 fibril_condvar_broadcast(&input_cv);
418 fibril_mutex_unlock(&input_mutex);
419 break;
420 default:
421 retval = ENOENT;
422 }
423 ipc_answer_0(callid, retval);
424 }
425}
426
427static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
428{
429 ipc_callid_t callid;
430 size_t size;
431 if (!async_data_write_receive(&callid, &size)) {
432 ipc_answer_0(callid, EINVAL);
433 ipc_answer_0(rid, EINVAL);
434 return;
435 }
436
437 char *buf = (char *) malloc(size);
438 if (buf == NULL) {
439 ipc_answer_0(callid, ENOMEM);
440 ipc_answer_0(rid, ENOMEM);
441 return;
442 }
443
444 (void) async_data_write_finalize(callid, buf, size);
445
446 async_serialize_start();
447
448 size_t off = 0;
449 while (off < size) {
450 wchar_t ch = str_decode(buf, &off, size);
451 write_char(cons, ch);
452 }
453
454 async_serialize_end();
455
456 gcons_notify_char(cons->index);
457 ipc_answer_1(rid, EOK, size);
458
459 free(buf);
460}
461
462static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
463{
464 ipc_callid_t callid;
465 size_t size;
466 if (!async_data_read_receive(&callid, &size)) {
467 ipc_answer_0(callid, EINVAL);
468 ipc_answer_0(rid, EINVAL);
469 return;
470 }
471
472 char *buf = (char *) malloc(size);
473 if (buf == NULL) {
474 ipc_answer_0(callid, ENOMEM);
475 ipc_answer_0(rid, ENOMEM);
476 return;
477 }
478
479 size_t pos = 0;
480 console_event_t ev;
481 fibril_mutex_lock(&input_mutex);
482recheck:
483 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
484 if (ev.type == KEY_PRESS) {
485 buf[pos] = ev.c;
486 pos++;
487 }
488 }
489
490 if (pos == size) {
491 (void) async_data_read_finalize(callid, buf, size);
492 ipc_answer_1(rid, EOK, size);
493 free(buf);
494 } else {
495 fibril_condvar_wait(&input_cv, &input_mutex);
496 goto recheck;
497 }
498 fibril_mutex_unlock(&input_mutex);
499}
500
501static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
502{
503 console_event_t ev;
504
505 fibril_mutex_lock(&input_mutex);
506recheck:
507 if (keybuffer_pop(&cons->keybuffer, &ev)) {
508 ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
509 } else {
510 fibril_condvar_wait(&input_cv, &input_mutex);
511 goto recheck;
512 }
513 fibril_mutex_unlock(&input_mutex);
514}
515
516/** Default thread for new connections */
517static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
518{
519 console_t *cons = NULL;
520
521 size_t i;
522 for (i = 0; i < CONSOLE_COUNT; i++) {
523 if (i == KERNEL_CONSOLE)
524 continue;
525
526 if (consoles[i].dev_handle == (dev_handle_t) IPC_GET_ARG1(*icall)) {
527 cons = &consoles[i];
528 break;
529 }
530 }
531
532 if (cons == NULL) {
533 ipc_answer_0(iid, ENOENT);
534 return;
535 }
536
537 ipc_callid_t callid;
538 ipc_call_t call;
539 ipcarg_t arg1;
540 ipcarg_t arg2;
541 ipcarg_t arg3;
542
543 int cons_ccap;
544 int rc;
545
546 async_serialize_start();
547 if (cons->refcount == 0)
548 gcons_notify_connect(cons->index);
549
550 cons->refcount++;
551
552 /* Accept the connection */
553 ipc_answer_0(iid, EOK);
554
555 while (true) {
556 async_serialize_end();
557 callid = async_get_call(&call);
558 async_serialize_start();
559
560 arg1 = 0;
561 arg2 = 0;
562 arg3 = 0;
563
564 switch (IPC_GET_METHOD(call)) {
565 case IPC_M_PHONE_HUNGUP:
566 cons->refcount--;
567 if (cons->refcount == 0)
568 gcons_notify_disconnect(cons->index);
569 return;
570 case VFS_OUT_READ:
571 async_serialize_end();
572 cons_read(cons, callid, &call);
573 async_serialize_start();
574 continue;
575 case VFS_OUT_WRITE:
576 async_serialize_end();
577 cons_write(cons, callid, &call);
578 async_serialize_start();
579 continue;
580 case VFS_OUT_SYNC:
581 fb_pending_flush();
582 if (cons == active_console) {
583 async_req_0_0(fb_info.phone, FB_FLUSH);
584
585 curs_goto(cons->scr.position_x, cons->scr.position_y);
586 }
587 break;
588 case CONSOLE_CLEAR:
589 /* Send message to fb */
590 if (cons == active_console)
591 async_msg_0(fb_info.phone, FB_CLEAR);
592
593 screenbuffer_clear(&cons->scr);
594
595 break;
596 case CONSOLE_GOTO:
597 screenbuffer_goto(&cons->scr,
598 IPC_GET_ARG1(call), IPC_GET_ARG2(call));
599 if (cons == active_console)
600 curs_goto(IPC_GET_ARG1(call),
601 IPC_GET_ARG2(call));
602 break;
603 case CONSOLE_GET_POS:
604 arg1 = cons->scr.position_x;
605 arg2 = cons->scr.position_y;
606 break;
607 case CONSOLE_GET_SIZE:
608 arg1 = fb_info.cols;
609 arg2 = fb_info.rows;
610 break;
611 case CONSOLE_GET_COLOR_CAP:
612 rc = ccap_fb_to_con(fb_info.color_cap, &cons_ccap);
613 if (rc != EOK) {
614 ipc_answer_0(callid, rc);
615 continue;
616 }
617 arg1 = cons_ccap;
618 break;
619 case CONSOLE_SET_STYLE:
620 fb_pending_flush();
621 arg1 = IPC_GET_ARG1(call);
622 screenbuffer_set_style(&cons->scr, arg1);
623 if (cons == active_console)
624 set_style(arg1);
625 break;
626 case CONSOLE_SET_COLOR:
627 fb_pending_flush();
628 arg1 = IPC_GET_ARG1(call);
629 arg2 = IPC_GET_ARG2(call);
630 arg3 = IPC_GET_ARG3(call);
631 screenbuffer_set_color(&cons->scr, arg1, arg2, arg3);
632 if (cons == active_console)
633 set_color(arg1, arg2, arg3);
634 break;
635 case CONSOLE_SET_RGB_COLOR:
636 fb_pending_flush();
637 arg1 = IPC_GET_ARG1(call);
638 arg2 = IPC_GET_ARG2(call);
639 screenbuffer_set_rgb_color(&cons->scr, arg1, arg2);
640 if (cons == active_console)
641 set_rgb_color(arg1, arg2);
642 break;
643 case CONSOLE_CURSOR_VISIBILITY:
644 fb_pending_flush();
645 arg1 = IPC_GET_ARG1(call);
646 cons->scr.is_cursor_visible = arg1;
647 if (cons == active_console)
648 curs_visibility(arg1);
649 break;
650 case CONSOLE_GET_EVENT:
651 async_serialize_end();
652 cons_get_event(cons, callid, &call);
653 async_serialize_start();
654 continue;
655 case CONSOLE_KCON_ENABLE:
656 change_console(kernel_console);
657 break;
658 }
659 ipc_answer_3(callid, EOK, arg1, arg2, arg3);
660 }
661}
662
663static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
664{
665 change_console(prev_console);
666}
667
668static bool console_init(void)
669{
670 ipcarg_t color_cap;
671
672 /* Connect to keyboard driver */
673 kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
674 if (kbd_phone < 0) {
675 printf(NAME ": Failed to connect to keyboard service\n");
676 return false;
677 }
678
679 ipcarg_t phonehash;
680 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
681 printf(NAME ": Failed to create callback from keyboard service\n");
682 return false;
683 }
684
685 async_new_connection(phonehash, 0, NULL, keyboard_events);
686
687 /* Connect to framebuffer driver */
688 fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
689 if (fb_info.phone < 0) {
690 printf(NAME ": Failed to connect to video service\n");
691 return -1;
692 }
693
694 /* Register driver */
695 int rc = devmap_driver_register(NAME, client_connection);
696 if (rc < 0) {
697 printf(NAME ": Unable to register driver (%d)\n", rc);
698 return false;
699 }
700
701 /* Initialize gcons */
702 gcons_init(fb_info.phone);
703
704 /* Synchronize, the gcons could put something in queue */
705 async_req_0_0(fb_info.phone, FB_FLUSH);
706 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
707 async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap);
708 fb_info.color_cap = color_cap;
709
710 /* Set up shared memory buffer. */
711 size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
712 interbuffer = as_get_mappable_page(ib_size);
713
714 if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
715 AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer)
716 interbuffer = NULL;
717
718 if (interbuffer) {
719 if (async_share_out_start(fb_info.phone, interbuffer,
720 AS_AREA_READ) != EOK) {
721 as_area_destroy(interbuffer);
722 interbuffer = NULL;
723 }
724 }
725
726 fb_pending.cnt = 0;
727
728 /* Inititalize consoles */
729 size_t i;
730 for (i = 0; i < CONSOLE_COUNT; i++) {
731 if (i != KERNEL_CONSOLE) {
732 if (screenbuffer_init(&consoles[i].scr,
733 fb_info.cols, fb_info.rows) == NULL) {
734 printf(NAME ": Unable to allocate screen buffer %u\n", i);
735 return false;
736 }
737 screenbuffer_clear(&consoles[i].scr);
738 keybuffer_init(&consoles[i].keybuffer);
739 consoles[i].index = i;
740 consoles[i].refcount = 0;
741
742 char vc[MAX_DEVICE_NAME];
743 snprintf(vc, MAX_DEVICE_NAME, "vc%u", i);
744
745 if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) {
746 devmap_hangup_phone(DEVMAP_DRIVER);
747 printf(NAME ": Unable to register device %s\n", vc);
748 return false;
749 }
750 }
751 }
752
753 /* Disable kernel output to the console */
754 __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
755
756 /* Initialize the screen */
757 async_serialize_start();
758 gcons_redraw_console();
759 set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
760 screen_clear();
761 curs_goto(0, 0);
762 curs_visibility(active_console->scr.is_cursor_visible);
763 async_serialize_end();
764
765 /* Receive kernel notifications */
766 if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
767 printf(NAME ": Error registering kconsole notifications\n");
768
769 async_set_interrupt_received(interrupt_received);
770
771 return true;
772}
773
774int main(int argc, char *argv[])
775{
776 printf(NAME ": HelenOS Console service\n");
777
778 if (!console_init())
779 return -1;
780
781 printf(NAME ": Accepting connections\n");
782 async_manager();
783
784 return 0;
785}
786
787/** @}
788 */
Note: See TracBrowser for help on using the repository browser.