[51c1b003] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Josef Cejka
|
---|
[51c1b003] | 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 | */
|
---|
[ce5bcb4] | 28 |
|
---|
[231a60a] | 29 | /** @addtogroup console
|
---|
[1601f3c] | 30 | * @{
|
---|
[ce5bcb4] | 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[3209923] | 35 | #include <libc.h>
|
---|
[51c1b003] | 36 | #include <ipc/ipc.h>
|
---|
[e795203] | 37 | #include <ipc/kbd.h>
|
---|
[424cd43] | 38 | #include <io/keycode.h>
|
---|
[9f51afc] | 39 | #include <ipc/mouse.h>
|
---|
[79460ae] | 40 | #include <ipc/fb.h>
|
---|
[51c1b003] | 41 | #include <ipc/services.h>
|
---|
| 42 | #include <errno.h>
|
---|
[d3e6935] | 43 | #include <ipc/console.h>
|
---|
[eaf34f7] | 44 | #include <unistd.h>
|
---|
| 45 | #include <async.h>
|
---|
[d9c8c81] | 46 | #include <adt/fifo.h>
|
---|
[2def788] | 47 | #include <sys/mman.h>
|
---|
[271b540] | 48 | #include <stdio.h>
|
---|
[19f857a] | 49 | #include <str.h>
|
---|
[3ad953c] | 50 | #include <sysinfo.h>
|
---|
[05641a9e] | 51 | #include <event.h>
|
---|
[424cd43] | 52 | #include <devmap.h>
|
---|
[47a350f] | 53 | #include <fcntl.h>
|
---|
| 54 | #include <vfs/vfs.h>
|
---|
[1e4cada] | 55 | #include <fibril_synch.h>
|
---|
[79460ae] | 56 |
|
---|
[9805cde] | 57 | #include "console.h"
|
---|
[e1c4849] | 58 | #include "gcons.h"
|
---|
[cc1f8d4] | 59 | #include "keybuffer.h"
|
---|
[424cd43] | 60 | #include "screenbuffer.h"
|
---|
[e1c4849] | 61 |
|
---|
[1313ee9] | 62 | #define NAME "console"
|
---|
| 63 | #define NAMESPACE "term"
|
---|
[eaf34f7] | 64 |
|
---|
[ccd1a14] | 65 | /** Phone to the keyboard driver. */
|
---|
| 66 | static int kbd_phone;
|
---|
| 67 |
|
---|
[9f51afc] | 68 | /** Phone to the mouse driver. */
|
---|
| 69 | static int mouse_phone;
|
---|
| 70 |
|
---|
[dc033a1] | 71 | /** Information about framebuffer */
|
---|
[3993b3d] | 72 | struct {
|
---|
[1601f3c] | 73 | int phone; /**< Framebuffer phone */
|
---|
| 74 | ipcarg_t cols; /**< Framebuffer columns */
|
---|
[424cd43] | 75 | ipcarg_t rows; /**< Framebuffer rows */
|
---|
[1313ee9] | 76 | int color_cap; /**< Color capabilities (FB_CCAP_xxx) */
|
---|
[3993b3d] | 77 | } fb_info;
|
---|
| 78 |
|
---|
[79460ae] | 79 | typedef struct {
|
---|
[424cd43] | 80 | size_t index; /**< Console index */
|
---|
| 81 | size_t refcount; /**< Connection reference count */
|
---|
| 82 | dev_handle_t dev_handle; /**< Device handle */
|
---|
| 83 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */
|
---|
| 84 | screenbuffer_t scr; /**< Screenbuffer for saving screen
|
---|
| 85 | contents and related settings. */
|
---|
| 86 | } console_t;
|
---|
[79460ae] | 87 |
|
---|
[1601f3c] | 88 | /** Array of data for virtual consoles */
|
---|
[424cd43] | 89 | static console_t consoles[CONSOLE_COUNT];
|
---|
| 90 |
|
---|
| 91 | static console_t *active_console = &consoles[0];
|
---|
| 92 | static console_t *prev_console = &consoles[0];
|
---|
| 93 | static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
|
---|
[1601f3c] | 94 |
|
---|
| 95 | /** Pointer to memory shared with framebufer used for
|
---|
| 96 | faster virtual console switching */
|
---|
| 97 | static keyfield_t *interbuffer = NULL;
|
---|
[d2cc7e1] | 98 |
|
---|
[dc033a1] | 99 | /** Information on row-span yet unsent to FB driver. */
|
---|
| 100 | struct {
|
---|
[424cd43] | 101 | size_t col; /**< Leftmost column of the span. */
|
---|
| 102 | size_t row; /**< Row where the span lies. */
|
---|
| 103 | size_t cnt; /**< Width of the span. */
|
---|
[dc033a1] | 104 | } fb_pending;
|
---|
[d2cc7e1] | 105 |
|
---|
[953769f] | 106 | static FIBRIL_MUTEX_INITIALIZE(input_mutex);
|
---|
| 107 | static FIBRIL_CONDVAR_INITIALIZE(input_cv);
|
---|
[429acb9] | 108 |
|
---|
[8c6337d] | 109 | static void curs_visibility(bool visible)
|
---|
[429acb9] | 110 | {
|
---|
[8c6337d] | 111 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | static void curs_hide_sync(void)
|
---|
| 115 | {
|
---|
| 116 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
|
---|
[429acb9] | 117 | }
|
---|
| 118 |
|
---|
[424cd43] | 119 | static void curs_goto(size_t x, size_t y)
|
---|
[429acb9] | 120 | {
|
---|
[424cd43] | 121 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | static void screen_clear(void)
|
---|
| 125 | {
|
---|
| 126 | async_msg_0(fb_info.phone, FB_CLEAR);
|
---|
[429acb9] | 127 | }
|
---|
| 128 |
|
---|
[ebfabf6] | 129 | static void screen_yield(void)
|
---|
[10270a8] | 130 | {
|
---|
[ebfabf6] | 131 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD);
|
---|
[10270a8] | 132 | }
|
---|
| 133 |
|
---|
[ebfabf6] | 134 | static void screen_reclaim(void)
|
---|
[10270a8] | 135 | {
|
---|
[ebfabf6] | 136 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
|
---|
[10270a8] | 137 | }
|
---|
| 138 |
|
---|
[ccd1a14] | 139 | static void kbd_yield(void)
|
---|
| 140 | {
|
---|
| 141 | ipc_call_sync_0_0(kbd_phone, KBD_YIELD);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | static void kbd_reclaim(void)
|
---|
| 145 | {
|
---|
| 146 | ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[9805cde] | 149 | static void set_style(int style)
|
---|
[429acb9] | 150 | {
|
---|
[424cd43] | 151 | async_msg_1(fb_info.phone, FB_SET_STYLE, style);
|
---|
[429acb9] | 152 | }
|
---|
| 153 |
|
---|
[9805cde] | 154 | static void set_color(int fgcolor, int bgcolor, int flags)
|
---|
[429acb9] | 155 | {
|
---|
[9805cde] | 156 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | static void set_rgb_color(int fgcolor, int bgcolor)
|
---|
| 160 | {
|
---|
| 161 | async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | static void set_attrs(attrs_t *attrs)
|
---|
| 165 | {
|
---|
| 166 | switch (attrs->t) {
|
---|
| 167 | case at_style:
|
---|
| 168 | set_style(attrs->a.s.style);
|
---|
| 169 | break;
|
---|
| 170 | case at_idx:
|
---|
| 171 | set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
|
---|
| 172 | attrs->a.i.flags);
|
---|
| 173 | break;
|
---|
| 174 | case at_rgb:
|
---|
| 175 | set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
|
---|
| 176 | break;
|
---|
| 177 | }
|
---|
[429acb9] | 178 | }
|
---|
| 179 |
|
---|
[a405563] | 180 | static int ccap_fb_to_con(int ccap_fb, int *ccap_con)
|
---|
[50cfa6c] | 181 | {
|
---|
| 182 | switch (ccap_fb) {
|
---|
| 183 | case FB_CCAP_NONE: *ccap_con = CONSOLE_CCAP_NONE; break;
|
---|
| 184 | case FB_CCAP_STYLE: *ccap_con = CONSOLE_CCAP_STYLE; break;
|
---|
| 185 | case FB_CCAP_INDEXED: *ccap_con = CONSOLE_CCAP_INDEXED; break;
|
---|
| 186 | case FB_CCAP_RGB: *ccap_con = CONSOLE_CCAP_RGB; break;
|
---|
| 187 | default: return EINVAL;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | return EOK;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[dc033a1] | 193 | /** Send an area of screenbuffer to the FB driver. */
|
---|
[424cd43] | 194 | static void fb_update_area(console_t *cons, ipcarg_t x0, ipcarg_t y0, ipcarg_t width, ipcarg_t height)
|
---|
[d2cc7e1] | 195 | {
|
---|
[dc033a1] | 196 | if (interbuffer) {
|
---|
[424cd43] | 197 | ipcarg_t x;
|
---|
| 198 | ipcarg_t y;
|
---|
| 199 |
|
---|
| 200 | for (y = 0; y < height; y++) {
|
---|
| 201 | for (x = 0; x < width; x++) {
|
---|
| 202 | interbuffer[y * width + x] =
|
---|
| 203 | *get_field_at(&cons->scr, x0 + x, y0 + y);
|
---|
[dc033a1] | 204 | }
|
---|
| 205 | }
|
---|
[1601f3c] | 206 |
|
---|
| 207 | async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
|
---|
[424cd43] | 208 | x0, y0, width, height);
|
---|
[dc033a1] | 209 | }
|
---|
[d2cc7e1] | 210 | }
|
---|
| 211 |
|
---|
[dc033a1] | 212 | /** Flush pending cells to FB. */
|
---|
| 213 | static void fb_pending_flush(void)
|
---|
[d2cc7e1] | 214 | {
|
---|
[1601f3c] | 215 | if (fb_pending.cnt > 0) {
|
---|
[424cd43] | 216 | fb_update_area(active_console, fb_pending.col,
|
---|
[1601f3c] | 217 | fb_pending.row, fb_pending.cnt, 1);
|
---|
| 218 | fb_pending.cnt = 0;
|
---|
[d2cc7e1] | 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[dc033a1] | 222 | /** Mark a character cell as changed.
|
---|
| 223 | *
|
---|
| 224 | * This adds the cell to the pending rowspan if possible. Otherwise
|
---|
| 225 | * the old span is flushed first.
|
---|
[1601f3c] | 226 | *
|
---|
[dc033a1] | 227 | */
|
---|
[424cd43] | 228 | static void cell_mark_changed(size_t col, size_t row)
|
---|
[429acb9] | 229 | {
|
---|
[1601f3c] | 230 | if (fb_pending.cnt != 0) {
|
---|
[424cd43] | 231 | if ((col != fb_pending.col + fb_pending.cnt)
|
---|
| 232 | || (row != fb_pending.row)) {
|
---|
[dc033a1] | 233 | fb_pending_flush();
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
[1601f3c] | 236 |
|
---|
| 237 | if (fb_pending.cnt == 0) {
|
---|
[dc033a1] | 238 | fb_pending.col = col;
|
---|
[424cd43] | 239 | fb_pending.row = row;
|
---|
[d2cc7e1] | 240 | }
|
---|
[1601f3c] | 241 |
|
---|
| 242 | fb_pending.cnt++;
|
---|
[429acb9] | 243 | }
|
---|
| 244 |
|
---|
[dc033a1] | 245 | /** Print a character to the active VC with buffering. */
|
---|
[424cd43] | 246 | static void fb_putchar(wchar_t c, ipcarg_t col, ipcarg_t row)
|
---|
[dc033a1] | 247 | {
|
---|
[424cd43] | 248 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
|
---|
[dc033a1] | 249 | }
|
---|
| 250 |
|
---|
| 251 | /** Process a character from the client (TTY emulation). */
|
---|
[424cd43] | 252 | static void write_char(console_t *cons, wchar_t ch)
|
---|
[10569b1] | 253 | {
|
---|
[0ed2e0e] | 254 | bool flush_cursor = false;
|
---|
| 255 |
|
---|
[7ce3cb2] | 256 | switch (ch) {
|
---|
[00bb6965] | 257 | case '\n':
|
---|
[dc033a1] | 258 | fb_pending_flush();
|
---|
[0ed2e0e] | 259 | flush_cursor = true;
|
---|
[424cd43] | 260 | cons->scr.position_y++;
|
---|
| 261 | cons->scr.position_x = 0;
|
---|
[00bb6965] | 262 | break;
|
---|
| 263 | case '\r':
|
---|
| 264 | break;
|
---|
| 265 | case '\t':
|
---|
[424cd43] | 266 | cons->scr.position_x += 8;
|
---|
| 267 | cons->scr.position_x -= cons->scr.position_x % 8;
|
---|
[00bb6965] | 268 | break;
|
---|
| 269 | case '\b':
|
---|
[424cd43] | 270 | if (cons->scr.position_x == 0)
|
---|
[10569b1] | 271 | break;
|
---|
[424cd43] | 272 | cons->scr.position_x--;
|
---|
| 273 | if (cons == active_console)
|
---|
| 274 | cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
|
---|
| 275 | screenbuffer_putchar(&cons->scr, ' ');
|
---|
[00bb6965] | 276 | break;
|
---|
[1601f3c] | 277 | default:
|
---|
[424cd43] | 278 | if (cons == active_console)
|
---|
| 279 | cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
|
---|
[1601f3c] | 280 |
|
---|
[424cd43] | 281 | screenbuffer_putchar(&cons->scr, ch);
|
---|
| 282 | cons->scr.position_x++;
|
---|
[10569b1] | 283 | }
|
---|
[1601f3c] | 284 |
|
---|
[0ed2e0e] | 285 | if (cons->scr.position_x >= cons->scr.size_x) {
|
---|
| 286 | flush_cursor = true;
|
---|
[424cd43] | 287 | cons->scr.position_y++;
|
---|
[0ed2e0e] | 288 | }
|
---|
[10569b1] | 289 |
|
---|
[424cd43] | 290 | if (cons->scr.position_y >= cons->scr.size_y) {
|
---|
[dc033a1] | 291 | fb_pending_flush();
|
---|
[424cd43] | 292 | cons->scr.position_y = cons->scr.size_y - 1;
|
---|
| 293 | screenbuffer_clear_line(&cons->scr, cons->scr.top_line);
|
---|
| 294 | cons->scr.top_line = (cons->scr.top_line + 1) % cons->scr.size_y;
|
---|
| 295 |
|
---|
| 296 | if (cons == active_console)
|
---|
[0cc4313] | 297 | async_msg_1(fb_info.phone, FB_SCROLL, 1);
|
---|
[10569b1] | 298 | }
|
---|
[0ed2e0e] | 299 |
|
---|
| 300 | if (cons == active_console && flush_cursor)
|
---|
| 301 | curs_goto(cons->scr.position_x, cons->scr.position_y);
|
---|
[424cd43] | 302 | cons->scr.position_x = cons->scr.position_x % cons->scr.size_x;
|
---|
[10569b1] | 303 | }
|
---|
| 304 |
|
---|
[429acb9] | 305 | /** Switch to new console */
|
---|
[424cd43] | 306 | static void change_console(console_t *cons)
|
---|
[429acb9] | 307 | {
|
---|
[424cd43] | 308 | if (cons == active_console)
|
---|
[429acb9] | 309 | return;
|
---|
[1601f3c] | 310 |
|
---|
[dc033a1] | 311 | fb_pending_flush();
|
---|
[1601f3c] | 312 |
|
---|
[424cd43] | 313 | if (cons == kernel_console) {
|
---|
[1f83244] | 314 | async_serialize_start();
|
---|
[8c6337d] | 315 | curs_hide_sync();
|
---|
[76fca31] | 316 | gcons_in_kernel();
|
---|
[ebfabf6] | 317 | screen_yield();
|
---|
[ccd1a14] | 318 | kbd_yield();
|
---|
[1f83244] | 319 | async_serialize_end();
|
---|
[1601f3c] | 320 |
|
---|
[3ad953c] | 321 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
|
---|
| 322 | prev_console = active_console;
|
---|
[424cd43] | 323 | active_console = kernel_console;
|
---|
[3ad953c] | 324 | } else
|
---|
[424cd43] | 325 | cons = active_console;
|
---|
[01f5e17] | 326 | }
|
---|
[6d5005c] | 327 |
|
---|
[424cd43] | 328 | if (cons != kernel_console) {
|
---|
| 329 | size_t x;
|
---|
| 330 | size_t y;
|
---|
| 331 | int rc = 0;
|
---|
| 332 |
|
---|
[76fca31] | 333 | async_serialize_start();
|
---|
| 334 |
|
---|
[424cd43] | 335 | if (active_console == kernel_console) {
|
---|
[ebfabf6] | 336 | screen_reclaim();
|
---|
[ccd1a14] | 337 | kbd_reclaim();
|
---|
[76fca31] | 338 | gcons_redraw_console();
|
---|
[10270a8] | 339 | }
|
---|
[76fca31] | 340 |
|
---|
[424cd43] | 341 | active_console = cons;
|
---|
| 342 | gcons_change_console(cons->index);
|
---|
[76fca31] | 343 |
|
---|
[424cd43] | 344 | set_attrs(&cons->scr.attrs);
|
---|
[8c6337d] | 345 | curs_visibility(false);
|
---|
[76fca31] | 346 | if (interbuffer) {
|
---|
[424cd43] | 347 | for (y = 0; y < cons->scr.size_y; y++) {
|
---|
| 348 | for (x = 0; x < cons->scr.size_x; x++) {
|
---|
| 349 | interbuffer[y * cons->scr.size_x + x] =
|
---|
| 350 | *get_field_at(&cons->scr, x, y);
|
---|
[76fca31] | 351 | }
|
---|
[dc033a1] | 352 | }
|
---|
[424cd43] | 353 |
|
---|
[76fca31] | 354 | /* This call can preempt, but we are already at the end */
|
---|
[dc033a1] | 355 | rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
|
---|
[424cd43] | 356 | 0, 0, cons->scr.size_x,
|
---|
| 357 | cons->scr.size_y);
|
---|
[76fca31] | 358 | }
|
---|
| 359 |
|
---|
| 360 | if ((!interbuffer) || (rc != 0)) {
|
---|
[424cd43] | 361 | set_attrs(&cons->scr.attrs);
|
---|
| 362 | screen_clear();
|
---|
[76fca31] | 363 |
|
---|
[424cd43] | 364 | for (y = 0; y < cons->scr.size_y; y++)
|
---|
| 365 | for (x = 0; x < cons->scr.size_x; x++) {
|
---|
| 366 | keyfield_t *field = get_field_at(&cons->scr, x, y);
|
---|
| 367 |
|
---|
| 368 | if (!attrs_same(cons->scr.attrs, field->attrs))
|
---|
[9805cde] | 369 | set_attrs(&field->attrs);
|
---|
[424cd43] | 370 |
|
---|
| 371 | cons->scr.attrs = field->attrs;
|
---|
[76fca31] | 372 | if ((field->character == ' ') &&
|
---|
[424cd43] | 373 | (attrs_same(field->attrs, cons->scr.attrs)))
|
---|
[76fca31] | 374 | continue;
|
---|
[1601f3c] | 375 |
|
---|
[424cd43] | 376 | fb_putchar(field->character, x, y);
|
---|
[76fca31] | 377 | }
|
---|
| 378 | }
|
---|
| 379 |
|
---|
[424cd43] | 380 | curs_goto(cons->scr.position_x, cons->scr.position_y);
|
---|
| 381 | curs_visibility(cons->scr.is_cursor_visible);
|
---|
[76fca31] | 382 |
|
---|
| 383 | async_serialize_end();
|
---|
[429acb9] | 384 | }
|
---|
| 385 | }
|
---|
[10569b1] | 386 |
|
---|
[e87e18f] | 387 | /** Handler for keyboard */
|
---|
[eaf34f7] | 388 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[51c1b003] | 389 | {
|
---|
[424cd43] | 390 | /* Ignore parameters, the connection is already opened */
|
---|
[1601f3c] | 391 | while (true) {
|
---|
[424cd43] | 392 |
|
---|
| 393 | ipc_call_t call;
|
---|
| 394 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 395 |
|
---|
| 396 | int retval;
|
---|
| 397 | console_event_t ev;
|
---|
| 398 |
|
---|
[eaf34f7] | 399 | switch (IPC_GET_METHOD(call)) {
|
---|
| 400 | case IPC_M_PHONE_HUNGUP:
|
---|
| 401 | /* TODO: Handle hangup */
|
---|
| 402 | return;
|
---|
[fa09449] | 403 | case KBD_EVENT:
|
---|
| 404 | /* Got event from keyboard driver. */
|
---|
[eaf34f7] | 405 | retval = 0;
|
---|
[fa09449] | 406 | ev.type = IPC_GET_ARG1(call);
|
---|
| 407 | ev.key = IPC_GET_ARG2(call);
|
---|
| 408 | ev.mods = IPC_GET_ARG3(call);
|
---|
| 409 | ev.c = IPC_GET_ARG4(call);
|
---|
| 410 |
|
---|
[f89979b] | 411 | if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
|
---|
[0175246] | 412 | CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
|
---|
[424cd43] | 413 | if (ev.key == KC_F1 + KERNEL_CONSOLE)
|
---|
| 414 | change_console(kernel_console);
|
---|
[429acb9] | 415 | else
|
---|
[424cd43] | 416 | change_console(&consoles[ev.key - KC_F1]);
|
---|
[eaf34f7] | 417 | break;
|
---|
| 418 | }
|
---|
[cf28036c] | 419 |
|
---|
[953769f] | 420 | fibril_mutex_lock(&input_mutex);
|
---|
[424cd43] | 421 | keybuffer_push(&active_console->keybuffer, &ev);
|
---|
[af65b72] | 422 | fibril_condvar_broadcast(&input_cv);
|
---|
[953769f] | 423 | fibril_mutex_unlock(&input_mutex);
|
---|
[eaf34f7] | 424 | break;
|
---|
| 425 | default:
|
---|
[1029d3d3] | 426 | retval = ENOENT;
|
---|
[085bd54] | 427 | }
|
---|
[b74959bd] | 428 | ipc_answer_0(callid, retval);
|
---|
[eaf34f7] | 429 | }
|
---|
| 430 | }
|
---|
| 431 |
|
---|
[9f51afc] | 432 | /** Handler for mouse events */
|
---|
| 433 | static void mouse_events(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 434 | {
|
---|
| 435 | int button, press;
|
---|
| 436 | int dx, dy;
|
---|
| 437 | int newcon;
|
---|
| 438 |
|
---|
| 439 | /* Ignore parameters, the connection is already opened */
|
---|
| 440 | while (true) {
|
---|
| 441 |
|
---|
| 442 | ipc_call_t call;
|
---|
| 443 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 444 |
|
---|
| 445 | int retval;
|
---|
| 446 |
|
---|
| 447 | switch (IPC_GET_METHOD(call)) {
|
---|
| 448 | case IPC_M_PHONE_HUNGUP:
|
---|
| 449 | /* TODO: Handle hangup */
|
---|
| 450 | return;
|
---|
| 451 | case MEVENT_BUTTON:
|
---|
| 452 | button = IPC_GET_ARG1(call);
|
---|
| 453 | press = IPC_GET_ARG2(call);
|
---|
| 454 | if (button == 1) {
|
---|
| 455 | newcon = gcons_mouse_btn(press);
|
---|
| 456 | if (newcon != -1)
|
---|
| 457 | change_console(&consoles[newcon]);
|
---|
| 458 | }
|
---|
| 459 | retval = 0;
|
---|
| 460 | break;
|
---|
| 461 | case MEVENT_MOVE:
|
---|
| 462 | dx = IPC_GET_ARG1(call);
|
---|
| 463 | dy = IPC_GET_ARG2(call);
|
---|
| 464 | gcons_mouse_move(dx, dy);
|
---|
| 465 | retval = 0;
|
---|
| 466 | break;
|
---|
| 467 | default:
|
---|
| 468 | retval = ENOENT;
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | ipc_answer_0(callid, retval);
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 |
|
---|
[424cd43] | 475 | static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
|
---|
[d2cc7e1] | 476 | {
|
---|
[472c09d] | 477 | void *buf;
|
---|
[171f9a1] | 478 | size_t size;
|
---|
[eda925a] | 479 | int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
|
---|
[1601f3c] | 480 |
|
---|
[472c09d] | 481 | if (rc != EOK) {
|
---|
| 482 | ipc_answer_0(rid, rc);
|
---|
[424cd43] | 483 | return;
|
---|
| 484 | }
|
---|
[1601f3c] | 485 |
|
---|
[6568225] | 486 | async_serialize_start();
|
---|
[1601f3c] | 487 |
|
---|
[424cd43] | 488 | size_t off = 0;
|
---|
[171f9a1] | 489 | while (off < size) {
|
---|
[424cd43] | 490 | wchar_t ch = str_decode(buf, &off, size);
|
---|
| 491 | write_char(cons, ch);
|
---|
[d2cc7e1] | 492 | }
|
---|
[1601f3c] | 493 |
|
---|
[6568225] | 494 | async_serialize_end();
|
---|
[1601f3c] | 495 |
|
---|
[424cd43] | 496 | gcons_notify_char(cons->index);
|
---|
[171f9a1] | 497 | ipc_answer_1(rid, EOK, size);
|
---|
[424cd43] | 498 |
|
---|
| 499 | free(buf);
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
|
---|
| 503 | {
|
---|
| 504 | ipc_callid_t callid;
|
---|
| 505 | size_t size;
|
---|
[0da4e41] | 506 | if (!async_data_read_receive(&callid, &size)) {
|
---|
[424cd43] | 507 | ipc_answer_0(callid, EINVAL);
|
---|
| 508 | ipc_answer_0(rid, EINVAL);
|
---|
| 509 | return;
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | char *buf = (char *) malloc(size);
|
---|
| 513 | if (buf == NULL) {
|
---|
| 514 | ipc_answer_0(callid, ENOMEM);
|
---|
| 515 | ipc_answer_0(rid, ENOMEM);
|
---|
| 516 | return;
|
---|
| 517 | }
|
---|
| 518 |
|
---|
| 519 | size_t pos = 0;
|
---|
| 520 | console_event_t ev;
|
---|
[953769f] | 521 | fibril_mutex_lock(&input_mutex);
|
---|
[af65b72] | 522 | recheck:
|
---|
[424cd43] | 523 | while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
|
---|
| 524 | if (ev.type == KEY_PRESS) {
|
---|
| 525 | buf[pos] = ev.c;
|
---|
| 526 | pos++;
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | if (pos == size) {
|
---|
[0da4e41] | 531 | (void) async_data_read_finalize(callid, buf, size);
|
---|
[424cd43] | 532 | ipc_answer_1(rid, EOK, size);
|
---|
| 533 | free(buf);
|
---|
| 534 | } else {
|
---|
[af65b72] | 535 | fibril_condvar_wait(&input_cv, &input_mutex);
|
---|
| 536 | goto recheck;
|
---|
[424cd43] | 537 | }
|
---|
[953769f] | 538 | fibril_mutex_unlock(&input_mutex);
|
---|
[424cd43] | 539 | }
|
---|
| 540 |
|
---|
| 541 | static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
|
---|
| 542 | {
|
---|
| 543 | console_event_t ev;
|
---|
[953769f] | 544 |
|
---|
| 545 | fibril_mutex_lock(&input_mutex);
|
---|
[af65b72] | 546 | recheck:
|
---|
[424cd43] | 547 | if (keybuffer_pop(&cons->keybuffer, &ev)) {
|
---|
| 548 | ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
|
---|
| 549 | } else {
|
---|
[af65b72] | 550 | fibril_condvar_wait(&input_cv, &input_mutex);
|
---|
| 551 | goto recheck;
|
---|
[424cd43] | 552 | }
|
---|
[953769f] | 553 | fibril_mutex_unlock(&input_mutex);
|
---|
[d2cc7e1] | 554 | }
|
---|
| 555 |
|
---|
[eaf34f7] | 556 | /** Default thread for new connections */
|
---|
[b1f51f0] | 557 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[eaf34f7] | 558 | {
|
---|
[424cd43] | 559 | console_t *cons = NULL;
|
---|
[3ad953c] | 560 |
|
---|
[424cd43] | 561 | size_t i;
|
---|
| 562 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
| 563 | if (i == KERNEL_CONSOLE)
|
---|
| 564 | continue;
|
---|
| 565 |
|
---|
| 566 | if (consoles[i].dev_handle == (dev_handle_t) IPC_GET_ARG1(*icall)) {
|
---|
| 567 | cons = &consoles[i];
|
---|
| 568 | break;
|
---|
| 569 | }
|
---|
| 570 | }
|
---|
| 571 |
|
---|
| 572 | if (cons == NULL) {
|
---|
| 573 | ipc_answer_0(iid, ENOENT);
|
---|
[eaf34f7] | 574 | return;
|
---|
| 575 | }
|
---|
[424cd43] | 576 |
|
---|
| 577 | ipc_callid_t callid;
|
---|
| 578 | ipc_call_t call;
|
---|
| 579 | ipcarg_t arg1;
|
---|
| 580 | ipcarg_t arg2;
|
---|
| 581 | ipcarg_t arg3;
|
---|
[50cfa6c] | 582 |
|
---|
| 583 | int cons_ccap;
|
---|
| 584 | int rc;
|
---|
[a7d2d78] | 585 |
|
---|
[085bd54] | 586 | async_serialize_start();
|
---|
[424cd43] | 587 | if (cons->refcount == 0)
|
---|
| 588 | gcons_notify_connect(cons->index);
|
---|
| 589 |
|
---|
| 590 | cons->refcount++;
|
---|
[10569b1] | 591 |
|
---|
[eaf34f7] | 592 | /* Accept the connection */
|
---|
[b74959bd] | 593 | ipc_answer_0(iid, EOK);
|
---|
[3ad953c] | 594 |
|
---|
[1601f3c] | 595 | while (true) {
|
---|
[085bd54] | 596 | async_serialize_end();
|
---|
[eaf34f7] | 597 | callid = async_get_call(&call);
|
---|
[085bd54] | 598 | async_serialize_start();
|
---|
[3ad953c] | 599 |
|
---|
[96858e8] | 600 | arg1 = 0;
|
---|
| 601 | arg2 = 0;
|
---|
[fa09449] | 602 | arg3 = 0;
|
---|
[1601f3c] | 603 |
|
---|
[eaf34f7] | 604 | switch (IPC_GET_METHOD(call)) {
|
---|
| 605 | case IPC_M_PHONE_HUNGUP:
|
---|
[424cd43] | 606 | cons->refcount--;
|
---|
| 607 | if (cons->refcount == 0)
|
---|
| 608 | gcons_notify_disconnect(cons->index);
|
---|
[eaf34f7] | 609 | return;
|
---|
[4198f9c3] | 610 | case VFS_OUT_READ:
|
---|
[424cd43] | 611 | async_serialize_end();
|
---|
| 612 | cons_read(cons, callid, &call);
|
---|
| 613 | async_serialize_start();
|
---|
| 614 | continue;
|
---|
[4198f9c3] | 615 | case VFS_OUT_WRITE:
|
---|
[6568225] | 616 | async_serialize_end();
|
---|
[424cd43] | 617 | cons_write(cons, callid, &call);
|
---|
[6568225] | 618 | async_serialize_start();
|
---|
[d2cc7e1] | 619 | continue;
|
---|
[4198f9c3] | 620 | case VFS_OUT_SYNC:
|
---|
[424cd43] | 621 | fb_pending_flush();
|
---|
| 622 | if (cons == active_console) {
|
---|
| 623 | async_req_0_0(fb_info.phone, FB_FLUSH);
|
---|
| 624 |
|
---|
| 625 | curs_goto(cons->scr.position_x, cons->scr.position_y);
|
---|
| 626 | }
|
---|
| 627 | break;
|
---|
[ad123964] | 628 | case CONSOLE_CLEAR:
|
---|
[3993b3d] | 629 | /* Send message to fb */
|
---|
[424cd43] | 630 | if (cons == active_console)
|
---|
| 631 | async_msg_0(fb_info.phone, FB_CLEAR);
|
---|
[3993b3d] | 632 |
|
---|
[424cd43] | 633 | screenbuffer_clear(&cons->scr);
|
---|
[3993b3d] | 634 |
|
---|
[eaf34f7] | 635 | break;
|
---|
[ad123964] | 636 | case CONSOLE_GOTO:
|
---|
[424cd43] | 637 | screenbuffer_goto(&cons->scr,
|
---|
| 638 | IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
| 639 | if (cons == active_console)
|
---|
[00bb6965] | 640 | curs_goto(IPC_GET_ARG1(call),
|
---|
[01f5e17] | 641 | IPC_GET_ARG2(call));
|
---|
[ad123964] | 642 | break;
|
---|
[19528516] | 643 | case CONSOLE_GET_POS:
|
---|
| 644 | arg1 = cons->scr.position_x;
|
---|
| 645 | arg2 = cons->scr.position_y;
|
---|
| 646 | break;
|
---|
[424cd43] | 647 | case CONSOLE_GET_SIZE:
|
---|
| 648 | arg1 = fb_info.cols;
|
---|
| 649 | arg2 = fb_info.rows;
|
---|
[a9bd960c] | 650 | break;
|
---|
[50cfa6c] | 651 | case CONSOLE_GET_COLOR_CAP:
|
---|
| 652 | rc = ccap_fb_to_con(fb_info.color_cap, &cons_ccap);
|
---|
| 653 | if (rc != EOK) {
|
---|
| 654 | ipc_answer_0(callid, rc);
|
---|
| 655 | continue;
|
---|
| 656 | }
|
---|
| 657 | arg1 = cons_ccap;
|
---|
| 658 | break;
|
---|
[a9bd960c] | 659 | case CONSOLE_SET_STYLE:
|
---|
[dc033a1] | 660 | fb_pending_flush();
|
---|
[9805cde] | 661 | arg1 = IPC_GET_ARG1(call);
|
---|
[424cd43] | 662 | screenbuffer_set_style(&cons->scr, arg1);
|
---|
| 663 | if (cons == active_console)
|
---|
[9805cde] | 664 | set_style(arg1);
|
---|
| 665 | break;
|
---|
| 666 | case CONSOLE_SET_COLOR:
|
---|
[dc033a1] | 667 | fb_pending_flush();
|
---|
[9805cde] | 668 | arg1 = IPC_GET_ARG1(call);
|
---|
| 669 | arg2 = IPC_GET_ARG2(call);
|
---|
| 670 | arg3 = IPC_GET_ARG3(call);
|
---|
[424cd43] | 671 | screenbuffer_set_color(&cons->scr, arg1, arg2, arg3);
|
---|
| 672 | if (cons == active_console)
|
---|
[9805cde] | 673 | set_color(arg1, arg2, arg3);
|
---|
| 674 | break;
|
---|
| 675 | case CONSOLE_SET_RGB_COLOR:
|
---|
[dc033a1] | 676 | fb_pending_flush();
|
---|
[a9bd960c] | 677 | arg1 = IPC_GET_ARG1(call);
|
---|
| 678 | arg2 = IPC_GET_ARG2(call);
|
---|
[424cd43] | 679 | screenbuffer_set_rgb_color(&cons->scr, arg1, arg2);
|
---|
| 680 | if (cons == active_console)
|
---|
[9805cde] | 681 | set_rgb_color(arg1, arg2);
|
---|
[0c6984e] | 682 | break;
|
---|
[a8b2b5b2] | 683 | case CONSOLE_CURSOR_VISIBILITY:
|
---|
[dc033a1] | 684 | fb_pending_flush();
|
---|
[a8b2b5b2] | 685 | arg1 = IPC_GET_ARG1(call);
|
---|
[424cd43] | 686 | cons->scr.is_cursor_visible = arg1;
|
---|
| 687 | if (cons == active_console)
|
---|
[a8b2b5b2] | 688 | curs_visibility(arg1);
|
---|
| 689 | break;
|
---|
[424cd43] | 690 | case CONSOLE_GET_EVENT:
|
---|
| 691 | async_serialize_end();
|
---|
| 692 | cons_get_event(cons, callid, &call);
|
---|
| 693 | async_serialize_start();
|
---|
| 694 | continue;
|
---|
[3fe00ee] | 695 | case CONSOLE_KCON_ENABLE:
|
---|
[424cd43] | 696 | change_console(kernel_console);
|
---|
[3fe00ee] | 697 | break;
|
---|
[eaf34f7] | 698 | }
|
---|
[424cd43] | 699 | ipc_answer_3(callid, EOK, arg1, arg2, arg3);
|
---|
[eaf34f7] | 700 | }
|
---|
| 701 | }
|
---|
| 702 |
|
---|
[3ad953c] | 703 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
|
---|
| 704 | {
|
---|
| 705 | change_console(prev_console);
|
---|
| 706 | }
|
---|
| 707 |
|
---|
[47a350f] | 708 | static bool console_init(char *input)
|
---|
[eaf34f7] | 709 | {
|
---|
[47a350f] | 710 | /* Connect to input device */
|
---|
| 711 | int input_fd = open(input, O_RDONLY);
|
---|
| 712 | if (input_fd < 0) {
|
---|
| 713 | printf(NAME ": Failed opening %s\n", input);
|
---|
| 714 | return false;
|
---|
| 715 | }
|
---|
[9f51afc] | 716 |
|
---|
[47a350f] | 717 | kbd_phone = fd_phone(input_fd);
|
---|
[4904de8] | 718 | if (kbd_phone < 0) {
|
---|
[47a350f] | 719 | printf(NAME ": Failed to connect to input device\n");
|
---|
[424cd43] | 720 | return false;
|
---|
[00bb6965] | 721 | }
|
---|
[9f51afc] | 722 |
|
---|
[47a350f] | 723 | /* NB: The callback connection is slotted for removal */
|
---|
[424cd43] | 724 | ipcarg_t phonehash;
|
---|
[4904de8] | 725 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
|
---|
[47a350f] | 726 | printf(NAME ": Failed to create callback from input device\n");
|
---|
[424cd43] | 727 | return false;
|
---|
[4904de8] | 728 | }
|
---|
[9f51afc] | 729 |
|
---|
[290c0db] | 730 | async_new_connection(phonehash, 0, NULL, keyboard_events);
|
---|
[953769f] | 731 |
|
---|
[9f51afc] | 732 | /* Connect to mouse device */
|
---|
| 733 | mouse_phone = -1;
|
---|
| 734 | int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
|
---|
| 735 |
|
---|
| 736 | if (mouse_fd < 0) {
|
---|
| 737 | printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
|
---|
| 738 | goto skip_mouse;
|
---|
| 739 | }
|
---|
| 740 |
|
---|
| 741 | mouse_phone = fd_phone(mouse_fd);
|
---|
| 742 | if (mouse_phone < 0) {
|
---|
| 743 | printf(NAME ": Failed to connect to mouse device\n");
|
---|
| 744 | goto skip_mouse;
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
|
---|
| 748 | printf(NAME ": Failed to create callback from mouse device\n");
|
---|
| 749 | mouse_phone = -1;
|
---|
| 750 | goto skip_mouse;
|
---|
| 751 | }
|
---|
| 752 |
|
---|
| 753 | async_new_connection(phonehash, 0, NULL, mouse_events);
|
---|
| 754 | skip_mouse:
|
---|
| 755 |
|
---|
[51c1b003] | 756 | /* Connect to framebuffer driver */
|
---|
[4904de8] | 757 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
|
---|
| 758 | if (fb_info.phone < 0) {
|
---|
| 759 | printf(NAME ": Failed to connect to video service\n");
|
---|
| 760 | return -1;
|
---|
[3993b3d] | 761 | }
|
---|
[9f51afc] | 762 |
|
---|
[424cd43] | 763 | /* Register driver */
|
---|
| 764 | int rc = devmap_driver_register(NAME, client_connection);
|
---|
| 765 | if (rc < 0) {
|
---|
| 766 | printf(NAME ": Unable to register driver (%d)\n", rc);
|
---|
| 767 | return false;
|
---|
| 768 | }
|
---|
[516ff92] | 769 |
|
---|
[e1c4849] | 770 | /* Initialize gcons */
|
---|
| 771 | gcons_init(fb_info.phone);
|
---|
[3993b3d] | 772 |
|
---|
[424cd43] | 773 | /* Synchronize, the gcons could put something in queue */
|
---|
[47a350f] | 774 | ipcarg_t color_cap;
|
---|
[424cd43] | 775 | async_req_0_0(fb_info.phone, FB_FLUSH);
|
---|
| 776 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
|
---|
[50cfa6c] | 777 | async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap);
|
---|
| 778 | fb_info.color_cap = color_cap;
|
---|
[1601f3c] | 779 |
|
---|
[7447572] | 780 | /* Set up shared memory buffer. */
|
---|
[424cd43] | 781 | size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
|
---|
[7447572] | 782 | interbuffer = as_get_mappable_page(ib_size);
|
---|
[1601f3c] | 783 |
|
---|
[7447572] | 784 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
|
---|
[424cd43] | 785 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer)
|
---|
[7447572] | 786 | interbuffer = NULL;
|
---|
[1601f3c] | 787 |
|
---|
[7447572] | 788 | if (interbuffer) {
|
---|
[0da4e41] | 789 | if (async_share_out_start(fb_info.phone, interbuffer,
|
---|
[27d293a] | 790 | AS_AREA_READ) != EOK) {
|
---|
[7447572] | 791 | as_area_destroy(interbuffer);
|
---|
[390a678] | 792 | interbuffer = NULL;
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
[3ad953c] | 795 |
|
---|
[424cd43] | 796 | fb_pending.cnt = 0;
|
---|
[3ad953c] | 797 |
|
---|
[424cd43] | 798 | /* Inititalize consoles */
|
---|
| 799 | size_t i;
|
---|
| 800 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
| 801 | if (i != KERNEL_CONSOLE) {
|
---|
| 802 | if (screenbuffer_init(&consoles[i].scr,
|
---|
| 803 | fb_info.cols, fb_info.rows) == NULL) {
|
---|
| 804 | printf(NAME ": Unable to allocate screen buffer %u\n", i);
|
---|
| 805 | return false;
|
---|
| 806 | }
|
---|
| 807 | screenbuffer_clear(&consoles[i].scr);
|
---|
| 808 | keybuffer_init(&consoles[i].keybuffer);
|
---|
| 809 | consoles[i].index = i;
|
---|
| 810 | consoles[i].refcount = 0;
|
---|
| 811 |
|
---|
[1313ee9] | 812 | char vc[DEVMAP_NAME_MAXLEN + 1];
|
---|
| 813 | snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%u", NAMESPACE, i);
|
---|
[424cd43] | 814 |
|
---|
| 815 | if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) {
|
---|
| 816 | devmap_hangup_phone(DEVMAP_DRIVER);
|
---|
| 817 | printf(NAME ": Unable to register device %s\n", vc);
|
---|
| 818 | return false;
|
---|
| 819 | }
|
---|
| 820 | }
|
---|
| 821 | }
|
---|
| 822 |
|
---|
[1035437] | 823 | /* Disable kernel output to the console */
|
---|
| 824 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
|
---|
| 825 |
|
---|
[424cd43] | 826 | /* Initialize the screen */
|
---|
[953769f] | 827 | async_serialize_start();
|
---|
[1035437] | 828 | gcons_redraw_console();
|
---|
[424cd43] | 829 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
|
---|
| 830 | screen_clear();
|
---|
| 831 | curs_goto(0, 0);
|
---|
| 832 | curs_visibility(active_console->scr.is_cursor_visible);
|
---|
[953769f] | 833 | async_serialize_end();
|
---|
[51c1b003] | 834 |
|
---|
[3ad953c] | 835 | /* Receive kernel notifications */
|
---|
[05641a9e] | 836 | if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
|
---|
| 837 | printf(NAME ": Error registering kconsole notifications\n");
|
---|
[1601f3c] | 838 |
|
---|
[05641a9e] | 839 | async_set_interrupt_received(interrupt_received);
|
---|
[3ad953c] | 840 |
|
---|
[424cd43] | 841 | return true;
|
---|
| 842 | }
|
---|
| 843 |
|
---|
[47a350f] | 844 | static void usage(void)
|
---|
| 845 | {
|
---|
| 846 | printf("Usage: console <input>\n");
|
---|
| 847 | }
|
---|
| 848 |
|
---|
[424cd43] | 849 | int main(int argc, char *argv[])
|
---|
| 850 | {
|
---|
[47a350f] | 851 | if (argc < 2) {
|
---|
| 852 | usage();
|
---|
| 853 | return -1;
|
---|
| 854 | }
|
---|
| 855 |
|
---|
[424cd43] | 856 | printf(NAME ": HelenOS Console service\n");
|
---|
| 857 |
|
---|
[47a350f] | 858 | if (!console_init(argv[1]))
|
---|
[424cd43] | 859 | return -1;
|
---|
| 860 |
|
---|
| 861 | printf(NAME ": Accepting connections\n");
|
---|
[eaf34f7] | 862 | async_manager();
|
---|
[3ad953c] | 863 |
|
---|
| 864 | return 0;
|
---|
[51c1b003] | 865 | }
|
---|
[516ff92] | 866 |
|
---|
[ce5bcb4] | 867 | /** @}
|
---|
| 868 | */
|
---|