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