[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>
|
---|
[171f9a1] | 49 | #include <string.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 | {
|
---|
| 477 | ipc_callid_t callid;
|
---|
[171f9a1] | 478 | size_t size;
|
---|
[0da4e41] | 479 | if (!async_data_write_receive(&callid, &size)) {
|
---|
[d2cc7e1] | 480 | ipc_answer_0(callid, EINVAL);
|
---|
| 481 | ipc_answer_0(rid, EINVAL);
|
---|
[6568225] | 482 | return;
|
---|
[d2cc7e1] | 483 | }
|
---|
[1601f3c] | 484 |
|
---|
[424cd43] | 485 | char *buf = (char *) malloc(size);
|
---|
| 486 | if (buf == NULL) {
|
---|
| 487 | ipc_answer_0(callid, ENOMEM);
|
---|
| 488 | ipc_answer_0(rid, ENOMEM);
|
---|
| 489 | return;
|
---|
| 490 | }
|
---|
[1601f3c] | 491 |
|
---|
[0da4e41] | 492 | (void) async_data_write_finalize(callid, buf, size);
|
---|
[1601f3c] | 493 |
|
---|
[6568225] | 494 | async_serialize_start();
|
---|
[1601f3c] | 495 |
|
---|
[424cd43] | 496 | size_t off = 0;
|
---|
[171f9a1] | 497 | while (off < size) {
|
---|
[424cd43] | 498 | wchar_t ch = str_decode(buf, &off, size);
|
---|
| 499 | write_char(cons, ch);
|
---|
[d2cc7e1] | 500 | }
|
---|
[1601f3c] | 501 |
|
---|
[6568225] | 502 | async_serialize_end();
|
---|
[1601f3c] | 503 |
|
---|
[424cd43] | 504 | gcons_notify_char(cons->index);
|
---|
[171f9a1] | 505 | ipc_answer_1(rid, EOK, size);
|
---|
[424cd43] | 506 |
|
---|
| 507 | free(buf);
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
|
---|
| 511 | {
|
---|
| 512 | ipc_callid_t callid;
|
---|
| 513 | size_t size;
|
---|
[0da4e41] | 514 | if (!async_data_read_receive(&callid, &size)) {
|
---|
[424cd43] | 515 | ipc_answer_0(callid, EINVAL);
|
---|
| 516 | ipc_answer_0(rid, EINVAL);
|
---|
| 517 | return;
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | char *buf = (char *) malloc(size);
|
---|
| 521 | if (buf == NULL) {
|
---|
| 522 | ipc_answer_0(callid, ENOMEM);
|
---|
| 523 | ipc_answer_0(rid, ENOMEM);
|
---|
| 524 | return;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | size_t pos = 0;
|
---|
| 528 | console_event_t ev;
|
---|
[953769f] | 529 | fibril_mutex_lock(&input_mutex);
|
---|
[af65b72] | 530 | recheck:
|
---|
[424cd43] | 531 | while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
|
---|
| 532 | if (ev.type == KEY_PRESS) {
|
---|
| 533 | buf[pos] = ev.c;
|
---|
| 534 | pos++;
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | if (pos == size) {
|
---|
[0da4e41] | 539 | (void) async_data_read_finalize(callid, buf, size);
|
---|
[424cd43] | 540 | ipc_answer_1(rid, EOK, size);
|
---|
| 541 | free(buf);
|
---|
| 542 | } else {
|
---|
[af65b72] | 543 | fibril_condvar_wait(&input_cv, &input_mutex);
|
---|
| 544 | goto recheck;
|
---|
[424cd43] | 545 | }
|
---|
[953769f] | 546 | fibril_mutex_unlock(&input_mutex);
|
---|
[424cd43] | 547 | }
|
---|
| 548 |
|
---|
| 549 | static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
|
---|
| 550 | {
|
---|
| 551 | console_event_t ev;
|
---|
[953769f] | 552 |
|
---|
| 553 | fibril_mutex_lock(&input_mutex);
|
---|
[af65b72] | 554 | recheck:
|
---|
[424cd43] | 555 | if (keybuffer_pop(&cons->keybuffer, &ev)) {
|
---|
| 556 | ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
|
---|
| 557 | } else {
|
---|
[af65b72] | 558 | fibril_condvar_wait(&input_cv, &input_mutex);
|
---|
| 559 | goto recheck;
|
---|
[424cd43] | 560 | }
|
---|
[953769f] | 561 | fibril_mutex_unlock(&input_mutex);
|
---|
[d2cc7e1] | 562 | }
|
---|
| 563 |
|
---|
[eaf34f7] | 564 | /** Default thread for new connections */
|
---|
[b1f51f0] | 565 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[eaf34f7] | 566 | {
|
---|
[424cd43] | 567 | console_t *cons = NULL;
|
---|
[3ad953c] | 568 |
|
---|
[424cd43] | 569 | size_t i;
|
---|
| 570 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
| 571 | if (i == KERNEL_CONSOLE)
|
---|
| 572 | continue;
|
---|
| 573 |
|
---|
| 574 | if (consoles[i].dev_handle == (dev_handle_t) IPC_GET_ARG1(*icall)) {
|
---|
| 575 | cons = &consoles[i];
|
---|
| 576 | break;
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | if (cons == NULL) {
|
---|
| 581 | ipc_answer_0(iid, ENOENT);
|
---|
[eaf34f7] | 582 | return;
|
---|
| 583 | }
|
---|
[424cd43] | 584 |
|
---|
| 585 | ipc_callid_t callid;
|
---|
| 586 | ipc_call_t call;
|
---|
| 587 | ipcarg_t arg1;
|
---|
| 588 | ipcarg_t arg2;
|
---|
| 589 | ipcarg_t arg3;
|
---|
[50cfa6c] | 590 |
|
---|
| 591 | int cons_ccap;
|
---|
| 592 | int rc;
|
---|
[a7d2d78] | 593 |
|
---|
[085bd54] | 594 | async_serialize_start();
|
---|
[424cd43] | 595 | if (cons->refcount == 0)
|
---|
| 596 | gcons_notify_connect(cons->index);
|
---|
| 597 |
|
---|
| 598 | cons->refcount++;
|
---|
[10569b1] | 599 |
|
---|
[eaf34f7] | 600 | /* Accept the connection */
|
---|
[b74959bd] | 601 | ipc_answer_0(iid, EOK);
|
---|
[3ad953c] | 602 |
|
---|
[1601f3c] | 603 | while (true) {
|
---|
[085bd54] | 604 | async_serialize_end();
|
---|
[eaf34f7] | 605 | callid = async_get_call(&call);
|
---|
[085bd54] | 606 | async_serialize_start();
|
---|
[3ad953c] | 607 |
|
---|
[96858e8] | 608 | arg1 = 0;
|
---|
| 609 | arg2 = 0;
|
---|
[fa09449] | 610 | arg3 = 0;
|
---|
[1601f3c] | 611 |
|
---|
[eaf34f7] | 612 | switch (IPC_GET_METHOD(call)) {
|
---|
| 613 | case IPC_M_PHONE_HUNGUP:
|
---|
[424cd43] | 614 | cons->refcount--;
|
---|
| 615 | if (cons->refcount == 0)
|
---|
| 616 | gcons_notify_disconnect(cons->index);
|
---|
[eaf34f7] | 617 | return;
|
---|
[4198f9c3] | 618 | case VFS_OUT_READ:
|
---|
[424cd43] | 619 | async_serialize_end();
|
---|
| 620 | cons_read(cons, callid, &call);
|
---|
| 621 | async_serialize_start();
|
---|
| 622 | continue;
|
---|
[4198f9c3] | 623 | case VFS_OUT_WRITE:
|
---|
[6568225] | 624 | async_serialize_end();
|
---|
[424cd43] | 625 | cons_write(cons, callid, &call);
|
---|
[6568225] | 626 | async_serialize_start();
|
---|
[d2cc7e1] | 627 | continue;
|
---|
[4198f9c3] | 628 | case VFS_OUT_SYNC:
|
---|
[424cd43] | 629 | fb_pending_flush();
|
---|
| 630 | if (cons == active_console) {
|
---|
| 631 | async_req_0_0(fb_info.phone, FB_FLUSH);
|
---|
| 632 |
|
---|
| 633 | curs_goto(cons->scr.position_x, cons->scr.position_y);
|
---|
| 634 | }
|
---|
| 635 | break;
|
---|
[ad123964] | 636 | case CONSOLE_CLEAR:
|
---|
[3993b3d] | 637 | /* Send message to fb */
|
---|
[424cd43] | 638 | if (cons == active_console)
|
---|
| 639 | async_msg_0(fb_info.phone, FB_CLEAR);
|
---|
[3993b3d] | 640 |
|
---|
[424cd43] | 641 | screenbuffer_clear(&cons->scr);
|
---|
[3993b3d] | 642 |
|
---|
[eaf34f7] | 643 | break;
|
---|
[ad123964] | 644 | case CONSOLE_GOTO:
|
---|
[424cd43] | 645 | screenbuffer_goto(&cons->scr,
|
---|
| 646 | IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
| 647 | if (cons == active_console)
|
---|
[00bb6965] | 648 | curs_goto(IPC_GET_ARG1(call),
|
---|
[01f5e17] | 649 | IPC_GET_ARG2(call));
|
---|
[ad123964] | 650 | break;
|
---|
[19528516] | 651 | case CONSOLE_GET_POS:
|
---|
| 652 | arg1 = cons->scr.position_x;
|
---|
| 653 | arg2 = cons->scr.position_y;
|
---|
| 654 | break;
|
---|
[424cd43] | 655 | case CONSOLE_GET_SIZE:
|
---|
| 656 | arg1 = fb_info.cols;
|
---|
| 657 | arg2 = fb_info.rows;
|
---|
[a9bd960c] | 658 | break;
|
---|
[50cfa6c] | 659 | case CONSOLE_GET_COLOR_CAP:
|
---|
| 660 | rc = ccap_fb_to_con(fb_info.color_cap, &cons_ccap);
|
---|
| 661 | if (rc != EOK) {
|
---|
| 662 | ipc_answer_0(callid, rc);
|
---|
| 663 | continue;
|
---|
| 664 | }
|
---|
| 665 | arg1 = cons_ccap;
|
---|
| 666 | break;
|
---|
[a9bd960c] | 667 | case CONSOLE_SET_STYLE:
|
---|
[dc033a1] | 668 | fb_pending_flush();
|
---|
[9805cde] | 669 | arg1 = IPC_GET_ARG1(call);
|
---|
[424cd43] | 670 | screenbuffer_set_style(&cons->scr, arg1);
|
---|
| 671 | if (cons == active_console)
|
---|
[9805cde] | 672 | set_style(arg1);
|
---|
| 673 | break;
|
---|
| 674 | case CONSOLE_SET_COLOR:
|
---|
[dc033a1] | 675 | fb_pending_flush();
|
---|
[9805cde] | 676 | arg1 = IPC_GET_ARG1(call);
|
---|
| 677 | arg2 = IPC_GET_ARG2(call);
|
---|
| 678 | arg3 = IPC_GET_ARG3(call);
|
---|
[424cd43] | 679 | screenbuffer_set_color(&cons->scr, arg1, arg2, arg3);
|
---|
| 680 | if (cons == active_console)
|
---|
[9805cde] | 681 | set_color(arg1, arg2, arg3);
|
---|
| 682 | break;
|
---|
| 683 | case CONSOLE_SET_RGB_COLOR:
|
---|
[dc033a1] | 684 | fb_pending_flush();
|
---|
[a9bd960c] | 685 | arg1 = IPC_GET_ARG1(call);
|
---|
| 686 | arg2 = IPC_GET_ARG2(call);
|
---|
[424cd43] | 687 | screenbuffer_set_rgb_color(&cons->scr, arg1, arg2);
|
---|
| 688 | if (cons == active_console)
|
---|
[9805cde] | 689 | set_rgb_color(arg1, arg2);
|
---|
[0c6984e] | 690 | break;
|
---|
[a8b2b5b2] | 691 | case CONSOLE_CURSOR_VISIBILITY:
|
---|
[dc033a1] | 692 | fb_pending_flush();
|
---|
[a8b2b5b2] | 693 | arg1 = IPC_GET_ARG1(call);
|
---|
[424cd43] | 694 | cons->scr.is_cursor_visible = arg1;
|
---|
| 695 | if (cons == active_console)
|
---|
[a8b2b5b2] | 696 | curs_visibility(arg1);
|
---|
| 697 | break;
|
---|
[424cd43] | 698 | case CONSOLE_GET_EVENT:
|
---|
| 699 | async_serialize_end();
|
---|
| 700 | cons_get_event(cons, callid, &call);
|
---|
| 701 | async_serialize_start();
|
---|
| 702 | continue;
|
---|
[3fe00ee] | 703 | case CONSOLE_KCON_ENABLE:
|
---|
[424cd43] | 704 | change_console(kernel_console);
|
---|
[3fe00ee] | 705 | break;
|
---|
[eaf34f7] | 706 | }
|
---|
[424cd43] | 707 | ipc_answer_3(callid, EOK, arg1, arg2, arg3);
|
---|
[eaf34f7] | 708 | }
|
---|
| 709 | }
|
---|
| 710 |
|
---|
[3ad953c] | 711 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
|
---|
| 712 | {
|
---|
| 713 | change_console(prev_console);
|
---|
| 714 | }
|
---|
| 715 |
|
---|
[47a350f] | 716 | static bool console_init(char *input)
|
---|
[eaf34f7] | 717 | {
|
---|
[47a350f] | 718 | /* Connect to input device */
|
---|
| 719 | int input_fd = open(input, O_RDONLY);
|
---|
| 720 | if (input_fd < 0) {
|
---|
| 721 | printf(NAME ": Failed opening %s\n", input);
|
---|
| 722 | return false;
|
---|
| 723 | }
|
---|
[9f51afc] | 724 |
|
---|
[47a350f] | 725 | kbd_phone = fd_phone(input_fd);
|
---|
[4904de8] | 726 | if (kbd_phone < 0) {
|
---|
[47a350f] | 727 | printf(NAME ": Failed to connect to input device\n");
|
---|
[424cd43] | 728 | return false;
|
---|
[00bb6965] | 729 | }
|
---|
[9f51afc] | 730 |
|
---|
[47a350f] | 731 | /* NB: The callback connection is slotted for removal */
|
---|
[424cd43] | 732 | ipcarg_t phonehash;
|
---|
[4904de8] | 733 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
|
---|
[47a350f] | 734 | printf(NAME ": Failed to create callback from input device\n");
|
---|
[424cd43] | 735 | return false;
|
---|
[4904de8] | 736 | }
|
---|
[9f51afc] | 737 |
|
---|
[290c0db] | 738 | async_new_connection(phonehash, 0, NULL, keyboard_events);
|
---|
[953769f] | 739 |
|
---|
[9f51afc] | 740 | /* Connect to mouse device */
|
---|
| 741 | mouse_phone = -1;
|
---|
| 742 | int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
|
---|
| 743 |
|
---|
| 744 | if (mouse_fd < 0) {
|
---|
| 745 | printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
|
---|
| 746 | goto skip_mouse;
|
---|
| 747 | }
|
---|
| 748 |
|
---|
| 749 | mouse_phone = fd_phone(mouse_fd);
|
---|
| 750 | if (mouse_phone < 0) {
|
---|
| 751 | printf(NAME ": Failed to connect to mouse device\n");
|
---|
| 752 | goto skip_mouse;
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
|
---|
| 756 | printf(NAME ": Failed to create callback from mouse device\n");
|
---|
| 757 | mouse_phone = -1;
|
---|
| 758 | goto skip_mouse;
|
---|
| 759 | }
|
---|
| 760 |
|
---|
| 761 | async_new_connection(phonehash, 0, NULL, mouse_events);
|
---|
| 762 | skip_mouse:
|
---|
| 763 |
|
---|
[51c1b003] | 764 | /* Connect to framebuffer driver */
|
---|
[4904de8] | 765 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
|
---|
| 766 | if (fb_info.phone < 0) {
|
---|
| 767 | printf(NAME ": Failed to connect to video service\n");
|
---|
| 768 | return -1;
|
---|
[3993b3d] | 769 | }
|
---|
[9f51afc] | 770 |
|
---|
[424cd43] | 771 | /* Register driver */
|
---|
| 772 | int rc = devmap_driver_register(NAME, client_connection);
|
---|
| 773 | if (rc < 0) {
|
---|
| 774 | printf(NAME ": Unable to register driver (%d)\n", rc);
|
---|
| 775 | return false;
|
---|
| 776 | }
|
---|
[516ff92] | 777 |
|
---|
[e1c4849] | 778 | /* Initialize gcons */
|
---|
| 779 | gcons_init(fb_info.phone);
|
---|
[3993b3d] | 780 |
|
---|
[424cd43] | 781 | /* Synchronize, the gcons could put something in queue */
|
---|
[47a350f] | 782 | ipcarg_t color_cap;
|
---|
[424cd43] | 783 | async_req_0_0(fb_info.phone, FB_FLUSH);
|
---|
| 784 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
|
---|
[50cfa6c] | 785 | async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap);
|
---|
| 786 | fb_info.color_cap = color_cap;
|
---|
[1601f3c] | 787 |
|
---|
[7447572] | 788 | /* Set up shared memory buffer. */
|
---|
[424cd43] | 789 | size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
|
---|
[7447572] | 790 | interbuffer = as_get_mappable_page(ib_size);
|
---|
[1601f3c] | 791 |
|
---|
[7447572] | 792 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
|
---|
[424cd43] | 793 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer)
|
---|
[7447572] | 794 | interbuffer = NULL;
|
---|
[1601f3c] | 795 |
|
---|
[7447572] | 796 | if (interbuffer) {
|
---|
[0da4e41] | 797 | if (async_share_out_start(fb_info.phone, interbuffer,
|
---|
[27d293a] | 798 | AS_AREA_READ) != EOK) {
|
---|
[7447572] | 799 | as_area_destroy(interbuffer);
|
---|
[390a678] | 800 | interbuffer = NULL;
|
---|
| 801 | }
|
---|
| 802 | }
|
---|
[3ad953c] | 803 |
|
---|
[424cd43] | 804 | fb_pending.cnt = 0;
|
---|
[3ad953c] | 805 |
|
---|
[424cd43] | 806 | /* Inititalize consoles */
|
---|
| 807 | size_t i;
|
---|
| 808 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
| 809 | if (i != KERNEL_CONSOLE) {
|
---|
| 810 | if (screenbuffer_init(&consoles[i].scr,
|
---|
| 811 | fb_info.cols, fb_info.rows) == NULL) {
|
---|
| 812 | printf(NAME ": Unable to allocate screen buffer %u\n", i);
|
---|
| 813 | return false;
|
---|
| 814 | }
|
---|
| 815 | screenbuffer_clear(&consoles[i].scr);
|
---|
| 816 | keybuffer_init(&consoles[i].keybuffer);
|
---|
| 817 | consoles[i].index = i;
|
---|
| 818 | consoles[i].refcount = 0;
|
---|
| 819 |
|
---|
[1313ee9] | 820 | char vc[DEVMAP_NAME_MAXLEN + 1];
|
---|
| 821 | snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%u", NAMESPACE, i);
|
---|
[424cd43] | 822 |
|
---|
| 823 | if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) {
|
---|
| 824 | devmap_hangup_phone(DEVMAP_DRIVER);
|
---|
| 825 | printf(NAME ": Unable to register device %s\n", vc);
|
---|
| 826 | return false;
|
---|
| 827 | }
|
---|
| 828 | }
|
---|
| 829 | }
|
---|
| 830 |
|
---|
[1035437] | 831 | /* Disable kernel output to the console */
|
---|
| 832 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
|
---|
| 833 |
|
---|
[424cd43] | 834 | /* Initialize the screen */
|
---|
[953769f] | 835 | async_serialize_start();
|
---|
[1035437] | 836 | gcons_redraw_console();
|
---|
[424cd43] | 837 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
|
---|
| 838 | screen_clear();
|
---|
| 839 | curs_goto(0, 0);
|
---|
| 840 | curs_visibility(active_console->scr.is_cursor_visible);
|
---|
[953769f] | 841 | async_serialize_end();
|
---|
[51c1b003] | 842 |
|
---|
[3ad953c] | 843 | /* Receive kernel notifications */
|
---|
[05641a9e] | 844 | if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
|
---|
| 845 | printf(NAME ": Error registering kconsole notifications\n");
|
---|
[1601f3c] | 846 |
|
---|
[05641a9e] | 847 | async_set_interrupt_received(interrupt_received);
|
---|
[3ad953c] | 848 |
|
---|
[424cd43] | 849 | return true;
|
---|
| 850 | }
|
---|
| 851 |
|
---|
[47a350f] | 852 | static void usage(void)
|
---|
| 853 | {
|
---|
| 854 | printf("Usage: console <input>\n");
|
---|
| 855 | }
|
---|
| 856 |
|
---|
[424cd43] | 857 | int main(int argc, char *argv[])
|
---|
| 858 | {
|
---|
[47a350f] | 859 | if (argc < 2) {
|
---|
| 860 | usage();
|
---|
| 861 | return -1;
|
---|
| 862 | }
|
---|
| 863 |
|
---|
[424cd43] | 864 | printf(NAME ": HelenOS Console service\n");
|
---|
| 865 |
|
---|
[47a350f] | 866 | if (!console_init(argv[1]))
|
---|
[424cd43] | 867 | return -1;
|
---|
| 868 |
|
---|
| 869 | printf(NAME ": Accepting connections\n");
|
---|
[eaf34f7] | 870 | async_manager();
|
---|
[3ad953c] | 871 |
|
---|
| 872 | return 0;
|
---|
[51c1b003] | 873 | }
|
---|
[516ff92] | 874 |
|
---|
[ce5bcb4] | 875 | /** @}
|
---|
| 876 | */
|
---|