Rev 3735 | Rev 3761 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1445 | cejka | 1 | /* |
| 2071 | jermar | 2 | * Copyright (c) 2006 Josef Cejka |
| 1445 | 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 | */ |
||
| 1649 | cejka | 28 | |
| 1740 | jermar | 29 | /** @addtogroup console |
| 1649 | cejka | 30 | * @{ |
| 31 | */ |
||
| 32 | /** @file |
||
| 33 | */ |
||
| 34 | |||
| 2618 | jermar | 35 | #include <libc.h> |
| 1451 | cejka | 36 | #include <fb.h> |
| 1445 | cejka | 37 | #include <ipc/ipc.h> |
| 1694 | palkovsky | 38 | #include <keys.h> |
| 1451 | cejka | 39 | #include <ipc/fb.h> |
| 1445 | cejka | 40 | #include <ipc/services.h> |
| 41 | #include <errno.h> |
||
| 1451 | cejka | 42 | #include <key_buffer.h> |
| 43 | #include <console.h> |
||
| 3747 | svoboda | 44 | #include <ipc/console.h> |
| 1453 | palkovsky | 45 | #include <unistd.h> |
| 46 | #include <async.h> |
||
| 1481 | cejka | 47 | #include <libadt/fifo.h> |
| 1487 | cejka | 48 | #include <screenbuffer.h> |
| 1867 | jermar | 49 | #include <sys/mman.h> |
| 3084 | decky | 50 | #include <stdio.h> |
| 1445 | cejka | 51 | |
| 1522 | palkovsky | 52 | #include "gcons.h" |
| 53 | |||
| 1481 | cejka | 54 | #define MAX_KEYREQUESTS_BUFFERED 32 |
| 1451 | cejka | 55 | |
| 3084 | decky | 56 | #define NAME "console" |
| 1445 | cejka | 57 | |
| 1526 | cejka | 58 | /** Index of currently used virtual console. |
| 59 | */ |
||
| 1512 | cejka | 60 | int active_console = 0; |
| 1453 | palkovsky | 61 | |
| 1526 | cejka | 62 | /** Information about framebuffer |
| 63 | */ |
||
| 1487 | cejka | 64 | struct { |
| 65 | int phone; /**< Framebuffer phone */ |
||
| 1506 | cejka | 66 | ipcarg_t rows; /**< Framebuffer rows */ |
| 67 | ipcarg_t cols; /**< Framebuffer columns */ |
||
| 1487 | cejka | 68 | } fb_info; |
| 69 | |||
| 1451 | cejka | 70 | typedef struct { |
| 1526 | cejka | 71 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
| 2025 | jermar | 72 | /** Buffer for unsatisfied request for keys. */ |
| 73 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t, |
||
| 74 | MAX_KEYREQUESTS_BUFFERED); |
||
| 1526 | cejka | 75 | int keyrequest_counter; /**< Number of requests in buffer. */ |
| 76 | int client_phone; /**< Phone to connected client. */ |
||
| 2025 | jermar | 77 | int used; /**< 1 if this virtual console is |
| 78 | * connected to some client.*/ |
||
| 79 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen |
||
| 80 | * contents and related settings. */ |
||
| 1451 | cejka | 81 | } connection_t; |
| 82 | |||
| 2025 | jermar | 83 | static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual |
| 84 | * consoles */ |
||
| 85 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared |
||
| 86 | * with framebufer used for |
||
| 87 | * faster virtual console |
||
| 2069 | jermar | 88 | * switching */ |
| 1506 | cejka | 89 | |
| 90 | |||
| 1526 | cejka | 91 | /** Find unused virtual console. |
| 92 | * |
||
| 93 | */ |
||
| 1574 | palkovsky | 94 | static int find_free_connection(void) |
| 1451 | cejka | 95 | { |
| 2069 | jermar | 96 | int i; |
| 1451 | cejka | 97 | |
| 2069 | jermar | 98 | for (i = 0; i < CONSOLE_COUNT; i++) { |
| 1574 | palkovsky | 99 | if (!connections[i].used) |
| 1451 | cejka | 100 | return i; |
| 101 | } |
||
| 1574 | palkovsky | 102 | return -1; |
| 1451 | cejka | 103 | } |
| 104 | |||
| 1552 | palkovsky | 105 | static void clrscr(void) |
| 106 | { |
||
| 2621 | jermar | 107 | async_msg_0(fb_info.phone, FB_CLEAR); |
| 1552 | palkovsky | 108 | } |
| 109 | |||
| 3735 | decky | 110 | static void curs_visibility(bool visible) |
| 1552 | palkovsky | 111 | { |
| 3735 | decky | 112 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
| 1552 | palkovsky | 113 | } |
| 114 | |||
| 3735 | decky | 115 | static void curs_hide_sync(void) |
| 116 | { |
||
| 117 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
||
| 118 | } |
||
| 119 | |||
| 1552 | palkovsky | 120 | static void curs_goto(int row, int col) |
| 121 | { |
||
| 1610 | palkovsky | 122 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
| 1552 | palkovsky | 123 | } |
| 124 | |||
| 125 | static void set_style(style_t *style) |
||
| 126 | { |
||
| 2025 | jermar | 127 | async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color, |
| 2539 | jermar | 128 | style->bg_color); |
| 1552 | palkovsky | 129 | } |
| 130 | |||
| 131 | static void set_style_col(int fgcolor, int bgcolor) |
||
| 132 | { |
||
| 1610 | palkovsky | 133 | async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor); |
| 1552 | palkovsky | 134 | } |
| 135 | |||
| 136 | static void prtchr(char c, int row, int col) |
||
| 137 | { |
||
| 1610 | palkovsky | 138 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
| 1552 | palkovsky | 139 | } |
| 140 | |||
| 1497 | cejka | 141 | /** Check key and process special keys. |
| 142 | * |
||
| 2566 | jermar | 143 | * |
| 144 | */ |
||
| 1497 | cejka | 145 | static void write_char(int console, char key) |
| 146 | { |
||
| 147 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
||
| 148 | |||
| 149 | switch (key) { |
||
| 2025 | jermar | 150 | case '\n': |
| 2069 | jermar | 151 | scr->position_y++; |
| 152 | scr->position_x = 0; |
||
| 2025 | jermar | 153 | break; |
| 154 | case '\r': |
||
| 155 | break; |
||
| 156 | case '\t': |
||
| 157 | scr->position_x += 8; |
||
| 158 | scr->position_x -= scr->position_x % 8; |
||
| 159 | break; |
||
| 160 | case '\b': |
||
| 161 | if (scr->position_x == 0) |
||
| 1497 | cejka | 162 | break; |
| 2025 | jermar | 163 | scr->position_x--; |
| 164 | if (console == active_console) |
||
| 165 | prtchr(' ', scr->position_y, scr->position_x); |
||
| 166 | screenbuffer_putchar(scr, ' '); |
||
| 167 | break; |
||
| 168 | default: |
||
| 169 | if (console == active_console) |
||
| 170 | prtchr(key, scr->position_y, scr->position_x); |
||
| 1497 | cejka | 171 | |
| 2025 | jermar | 172 | screenbuffer_putchar(scr, key); |
| 173 | scr->position_x++; |
||
| 1497 | cejka | 174 | } |
| 175 | |||
| 176 | scr->position_y += (scr->position_x >= scr->size_x); |
||
| 177 | |||
| 178 | if (scr->position_y >= scr->size_y) { |
||
| 179 | scr->position_y = scr->size_y - 1; |
||
| 1674 | palkovsky | 180 | screenbuffer_clear_line(scr, scr->top_line); |
| 2069 | jermar | 181 | scr->top_line = (scr->top_line + 1) % scr->size_y; |
| 1518 | palkovsky | 182 | if (console == active_console) |
| 2621 | jermar | 183 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
| 1497 | cejka | 184 | } |
| 185 | |||
| 186 | scr->position_x = scr->position_x % scr->size_x; |
||
| 187 | |||
| 1552 | palkovsky | 188 | if (console == active_console) |
| 189 | curs_goto(scr->position_y, scr->position_x); |
||
| 1504 | cejka | 190 | |
| 1497 | cejka | 191 | } |
| 192 | |||
| 1552 | palkovsky | 193 | /** Switch to new console */ |
| 194 | static void change_console(int newcons) |
||
| 195 | { |
||
| 196 | connection_t *conn; |
||
| 1673 | palkovsky | 197 | int i, j, rc; |
| 1578 | cejka | 198 | keyfield_t *field; |
| 199 | style_t *style; |
||
| 3707 | decky | 200 | |
| 1552 | palkovsky | 201 | if (newcons == active_console) |
| 202 | return; |
||
| 3707 | decky | 203 | |
| 1555 | palkovsky | 204 | if (newcons == KERNEL_CONSOLE) { |
| 3707 | decky | 205 | async_serialize_start(); |
| 3735 | decky | 206 | curs_hide_sync(); |
| 3707 | decky | 207 | gcons_in_kernel(); |
| 208 | async_serialize_end(); |
||
| 209 | |||
| 210 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) |
||
| 211 | active_console = KERNEL_CONSOLE; |
||
| 212 | else |
||
| 3735 | decky | 213 | newcons = active_console; |
| 3707 | decky | 214 | } |
| 215 | |||
| 216 | if (newcons != KERNEL_CONSOLE) { |
||
| 217 | async_serialize_start(); |
||
| 218 | |||
| 1555 | palkovsky | 219 | if (active_console == KERNEL_CONSOLE) |
| 3707 | decky | 220 | gcons_redraw_console(); |
| 221 | |||
| 222 | active_console = newcons; |
||
| 223 | gcons_change_console(newcons); |
||
| 224 | conn = &connections[active_console]; |
||
| 225 | |||
| 226 | set_style(&conn->screenbuffer.style); |
||
| 3735 | decky | 227 | curs_visibility(false); |
| 3707 | decky | 228 | if (interbuffer) { |
| 229 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
||
| 230 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
||
| 231 | unsigned int size_x; |
||
| 232 | |||
| 233 | size_x = conn->screenbuffer.size_x; |
||
| 234 | interbuffer[i + j * size_x] = |
||
| 235 | *get_field_at(&conn->screenbuffer, i, j); |
||
| 236 | } |
||
| 237 | /* This call can preempt, but we are already at the end */ |
||
| 238 | rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); |
||
| 239 | } |
||
| 240 | |||
| 241 | if ((!interbuffer) || (rc != 0)) { |
||
| 242 | set_style(&conn->screenbuffer.style); |
||
| 1552 | palkovsky | 243 | clrscr(); |
| 3707 | decky | 244 | style = &conn->screenbuffer.style; |
| 245 | |||
| 246 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
||
| 247 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
||
| 248 | field = get_field_at(&conn->screenbuffer, i, j); |
||
| 249 | if (!style_same(*style, field->style)) |
||
| 250 | set_style(&field->style); |
||
| 251 | style = &field->style; |
||
| 252 | if ((field->character == ' ') && |
||
| 253 | (style_same(field->style, |
||
| 254 | conn->screenbuffer.style))) |
||
| 255 | continue; |
||
| 256 | |||
| 257 | prtchr(field->character, j, i); |
||
| 258 | } |
||
| 1552 | palkovsky | 259 | } |
| 3707 | decky | 260 | |
| 261 | curs_goto(conn->screenbuffer.position_y, |
||
| 262 | conn->screenbuffer.position_x); |
||
| 263 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
||
| 264 | |||
| 1717 | palkovsky | 265 | async_serialize_end(); |
| 1552 | palkovsky | 266 | } |
| 267 | } |
||
| 268 | |||
| 1526 | cejka | 269 | /** Handler for keyboard */ |
| 1453 | palkovsky | 270 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
| 1445 | cejka | 271 | { |
| 1453 | palkovsky | 272 | ipc_callid_t callid; |
| 1445 | cejka | 273 | ipc_call_t call; |
| 1453 | palkovsky | 274 | int retval; |
| 1560 | vana | 275 | int c; |
| 1489 | palkovsky | 276 | connection_t *conn; |
| 1717 | palkovsky | 277 | int newcon; |
| 1506 | cejka | 278 | |
| 1453 | palkovsky | 279 | /* Ignore parameters, the connection is alread opened */ |
| 280 | while (1) { |
||
| 281 | callid = async_get_call(&call); |
||
| 282 | switch (IPC_GET_METHOD(call)) { |
||
| 283 | case IPC_M_PHONE_HUNGUP: |
||
| 284 | /* TODO: Handle hangup */ |
||
| 285 | return; |
||
| 1717 | palkovsky | 286 | case KBD_MS_LEFT: |
| 287 | newcon = gcons_mouse_btn(IPC_GET_ARG1(call)); |
||
| 288 | if (newcon != -1) |
||
| 289 | change_console(newcon); |
||
| 1721 | palkovsky | 290 | retval = 0; |
| 1717 | palkovsky | 291 | break; |
| 1707 | palkovsky | 292 | case KBD_MS_MOVE: |
| 2025 | jermar | 293 | gcons_mouse_move(IPC_GET_ARG1(call), |
| 2539 | jermar | 294 | IPC_GET_ARG2(call)); |
| 1721 | palkovsky | 295 | retval = 0; |
| 1707 | palkovsky | 296 | break; |
| 1453 | palkovsky | 297 | case KBD_PUSHCHAR: |
| 298 | /* got key from keyboard driver */ |
||
| 299 | retval = 0; |
||
| 1520 | cejka | 300 | c = IPC_GET_ARG1(call); |
| 1453 | palkovsky | 301 | /* switch to another virtual console */ |
| 1481 | cejka | 302 | |
| 1489 | palkovsky | 303 | conn = &connections[active_console]; |
| 2025 | jermar | 304 | /* |
| 305 | * if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + |
||
| 306 | * CONSOLE_COUNT)) { |
||
| 307 | */ |
||
| 1560 | vana | 308 | if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) { |
| 309 | if (c == 0x112) |
||
| 1555 | palkovsky | 310 | change_console(KERNEL_CONSOLE); |
| 1552 | palkovsky | 311 | else |
| 1560 | vana | 312 | change_console(c - 0x101); |
| 1453 | palkovsky | 313 | break; |
| 314 | } |
||
| 1481 | cejka | 315 | |
| 316 | /* if client is awaiting key, send it */ |
||
| 1489 | palkovsky | 317 | if (conn->keyrequest_counter > 0) { |
| 318 | conn->keyrequest_counter--; |
||
| 2619 | jermar | 319 | ipc_answer_1(fifo_pop(conn->keyrequests), EOK, |
| 320 | c); |
||
| 1481 | cejka | 321 | break; |
| 322 | } |
||
| 323 | |||
| 1489 | palkovsky | 324 | keybuffer_push(&conn->keybuffer, c); |
| 1721 | palkovsky | 325 | retval = 0; |
| 1476 | cejka | 326 | |
| 1453 | palkovsky | 327 | break; |
| 328 | default: |
||
| 1459 | palkovsky | 329 | retval = ENOENT; |
| 1610 | palkovsky | 330 | } |
| 2619 | jermar | 331 | ipc_answer_0(callid, retval); |
| 1453 | palkovsky | 332 | } |
| 333 | } |
||
| 334 | |||
| 335 | /** Default thread for new connections */ |
||
| 1518 | palkovsky | 336 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
| 1453 | palkovsky | 337 | { |
| 1445 | cejka | 338 | ipc_callid_t callid; |
| 1453 | palkovsky | 339 | ipc_call_t call; |
| 340 | int consnum; |
||
| 1521 | cejka | 341 | ipcarg_t arg1, arg2; |
| 1592 | palkovsky | 342 | connection_t *conn; |
| 1453 | palkovsky | 343 | |
| 1574 | palkovsky | 344 | if ((consnum = find_free_connection()) == -1) { |
| 2619 | jermar | 345 | ipc_answer_0(iid, ELIMIT); |
| 1453 | palkovsky | 346 | return; |
| 347 | } |
||
| 1592 | palkovsky | 348 | conn = &connections[consnum]; |
| 1610 | palkovsky | 349 | conn->used = 1; |
| 1555 | palkovsky | 350 | |
| 1610 | palkovsky | 351 | async_serialize_start(); |
| 1555 | palkovsky | 352 | gcons_notify_connect(consnum); |
| 2637 | cejka | 353 | conn->client_phone = IPC_GET_ARG5(*icall); |
| 1592 | palkovsky | 354 | screenbuffer_clear(&conn->screenbuffer); |
| 1497 | cejka | 355 | |
| 1453 | palkovsky | 356 | /* Accept the connection */ |
| 2619 | jermar | 357 | ipc_answer_0(iid, EOK); |
| 1610 | palkovsky | 358 | |
| 1453 | palkovsky | 359 | while (1) { |
| 1610 | palkovsky | 360 | async_serialize_end(); |
| 1453 | palkovsky | 361 | callid = async_get_call(&call); |
| 1610 | palkovsky | 362 | async_serialize_start(); |
| 363 | |||
| 2566 | jermar | 364 | arg1 = 0; |
| 365 | arg2 = 0; |
||
| 1453 | palkovsky | 366 | switch (IPC_GET_METHOD(call)) { |
| 367 | case IPC_M_PHONE_HUNGUP: |
||
| 1592 | palkovsky | 368 | gcons_notify_disconnect(consnum); |
| 1610 | palkovsky | 369 | |
| 1592 | palkovsky | 370 | /* Answer all pending requests */ |
| 371 | while (conn->keyrequest_counter > 0) { |
||
| 372 | conn->keyrequest_counter--; |
||
| 2619 | jermar | 373 | ipc_answer_0(fifo_pop(conn->keyrequests), |
| 374 | ENOENT); |
||
| 1592 | palkovsky | 375 | break; |
| 376 | } |
||
| 1616 | palkovsky | 377 | conn->used = 0; |
| 1453 | palkovsky | 378 | return; |
| 379 | case CONSOLE_PUTCHAR: |
||
| 1497 | cejka | 380 | write_char(consnum, IPC_GET_ARG1(call)); |
| 1528 | palkovsky | 381 | gcons_notify_char(consnum); |
| 1453 | palkovsky | 382 | break; |
| 1476 | cejka | 383 | case CONSOLE_CLEAR: |
| 1487 | cejka | 384 | /* Send message to fb */ |
| 385 | if (consnum == active_console) { |
||
| 2621 | jermar | 386 | async_msg_0(fb_info.phone, FB_CLEAR); |
| 1487 | cejka | 387 | } |
| 388 | |||
| 1592 | palkovsky | 389 | screenbuffer_clear(&conn->screenbuffer); |
| 1487 | cejka | 390 | |
| 1476 | cejka | 391 | break; |
| 392 | case CONSOLE_GOTO: |
||
| 2025 | jermar | 393 | screenbuffer_goto(&conn->screenbuffer, |
| 2539 | jermar | 394 | IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
| 1567 | palkovsky | 395 | if (consnum == active_console) |
| 2025 | jermar | 396 | curs_goto(IPC_GET_ARG1(call), |
| 2539 | jermar | 397 | IPC_GET_ARG2(call)); |
| 1476 | cejka | 398 | break; |
| 1521 | cejka | 399 | case CONSOLE_GETSIZE: |
| 1528 | palkovsky | 400 | arg1 = fb_info.rows; |
| 401 | arg2 = fb_info.cols; |
||
| 1521 | cejka | 402 | break; |
| 1523 | cejka | 403 | case CONSOLE_FLUSH: |
| 1723 | palkovsky | 404 | if (consnum == active_console) |
| 2621 | jermar | 405 | async_req_0_0(fb_info.phone, FB_FLUSH); |
| 1523 | cejka | 406 | break; |
| 1525 | cejka | 407 | case CONSOLE_SET_STYLE: |
| 408 | arg1 = IPC_GET_ARG1(call); |
||
| 409 | arg2 = IPC_GET_ARG2(call); |
||
| 2539 | jermar | 410 | screenbuffer_set_style(&conn->screenbuffer, arg1, |
| 411 | arg2); |
||
| 1525 | cejka | 412 | if (consnum == active_console) |
| 1552 | palkovsky | 413 | set_style_col(arg1, arg2); |
| 1525 | cejka | 414 | break; |
| 1575 | cejka | 415 | case CONSOLE_CURSOR_VISIBILITY: |
| 416 | arg1 = IPC_GET_ARG1(call); |
||
| 1592 | palkovsky | 417 | conn->screenbuffer.is_cursor_visible = arg1; |
| 1575 | cejka | 418 | if (consnum == active_console) |
| 419 | curs_visibility(arg1); |
||
| 420 | break; |
||
| 1453 | palkovsky | 421 | case CONSOLE_GETCHAR: |
| 1592 | palkovsky | 422 | if (keybuffer_empty(&conn->keybuffer)) { |
| 1481 | cejka | 423 | /* buffer is empty -> store request */ |
| 2025 | jermar | 424 | if (conn->keyrequest_counter < |
| 425 | MAX_KEYREQUESTS_BUFFERED) { |
||
| 1592 | palkovsky | 426 | fifo_push(conn->keyrequests, callid); |
| 427 | conn->keyrequest_counter++; |
||
| 1481 | cejka | 428 | } else { |
| 2025 | jermar | 429 | /* |
| 430 | * No key available and too many |
||
| 431 | * requests => fail. |
||
| 432 | */ |
||
| 2619 | jermar | 433 | ipc_answer_0(callid, ELIMIT); |
| 1481 | cejka | 434 | } |
| 435 | continue; |
||
| 2025 | jermar | 436 | } |
| 3599 | jermar | 437 | int ch; |
| 438 | keybuffer_pop(&conn->keybuffer, &ch); |
||
| 439 | arg1 = ch; |
||
| 1453 | palkovsky | 440 | break; |
| 441 | } |
||
| 2619 | jermar | 442 | ipc_answer_2(callid, EOK, arg1, arg2); |
| 1453 | palkovsky | 443 | } |
| 444 | } |
||
| 445 | |||
| 446 | int main(int argc, char *argv[]) |
||
| 447 | { |
||
| 3084 | decky | 448 | printf(NAME ": HelenOS Console service\n"); |
| 449 | |||
| 1453 | palkovsky | 450 | ipcarg_t phonehash; |
| 1721 | palkovsky | 451 | int kbd_phone; |
| 1451 | cejka | 452 | int i; |
| 1490 | palkovsky | 453 | |
| 454 | async_set_client_connection(client_connection); |
||
| 1445 | cejka | 455 | |
| 456 | /* Connect to keyboard driver */ |
||
| 457 | |||
| 2635 | cejka | 458 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
| 2069 | jermar | 459 | while (kbd_phone < 0) { |
| 1453 | palkovsky | 460 | usleep(10000); |
| 2635 | cejka | 461 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
| 2025 | jermar | 462 | } |
| 1445 | cejka | 463 | |
| 2637 | cejka | 464 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
| 1445 | cejka | 465 | return -1; |
| 1689 | palkovsky | 466 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
| 467 | |||
| 1445 | cejka | 468 | /* Connect to framebuffer driver */ |
| 2635 | cejka | 469 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
| 2069 | jermar | 470 | while (fb_info.phone < 0) { |
| 1487 | cejka | 471 | usleep(10000); |
| 2635 | cejka | 472 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
| 1487 | cejka | 473 | } |
| 1552 | palkovsky | 474 | |
| 1522 | palkovsky | 475 | /* Initialize gcons */ |
| 476 | gcons_init(fb_info.phone); |
||
| 477 | /* Synchronize, the gcons can have something in queue */ |
||
| 2621 | jermar | 478 | async_req_0_0(fb_info.phone, FB_FLUSH); |
| 1487 | cejka | 479 | |
| 2621 | jermar | 480 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
| 2539 | jermar | 481 | &fb_info.cols); |
| 1552 | palkovsky | 482 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
| 483 | clrscr(); |
||
| 1487 | cejka | 484 | |
| 485 | /* Init virtual consoles */ |
||
| 1451 | cejka | 486 | for (i = 0; i < CONSOLE_COUNT; i++) { |
| 487 | connections[i].used = 0; |
||
| 2539 | jermar | 488 | keybuffer_init(&connections[i].keybuffer); |
| 1481 | cejka | 489 | |
| 2539 | jermar | 490 | connections[i].keyrequests.head = 0; |
| 491 | connections[i].keyrequests.tail = 0; |
||
| 1481 | cejka | 492 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
| 493 | connections[i].keyrequest_counter = 0; |
||
| 1487 | cejka | 494 | |
| 2539 | jermar | 495 | if (screenbuffer_init(&connections[i].screenbuffer, |
| 496 | fb_info.cols, fb_info.rows) == NULL) { |
||
| 2069 | jermar | 497 | /* FIXME: handle error */ |
| 1487 | cejka | 498 | return -1; |
| 499 | } |
||
| 1451 | cejka | 500 | } |
| 1574 | palkovsky | 501 | connections[KERNEL_CONSOLE].used = 1; |
| 1445 | cejka | 502 | |
| 2069 | jermar | 503 | interbuffer = mmap(NULL, |
| 2539 | jermar | 504 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows, |
| 505 | PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); |
||
| 2069 | jermar | 506 | if (!interbuffer) { |
| 2678 | jermar | 507 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
| 2677 | jermar | 508 | AS_AREA_READ) != EOK) { |
| 2539 | jermar | 509 | munmap(interbuffer, |
| 510 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
||
| 1512 | cejka | 511 | interbuffer = NULL; |
| 512 | } |
||
| 513 | } |
||
| 1520 | cejka | 514 | |
| 2069 | jermar | 515 | curs_goto(0, 0); |
| 2539 | jermar | 516 | curs_visibility( |
| 517 | connections[active_console].screenbuffer.is_cursor_visible); |
||
| 1497 | cejka | 518 | |
| 1518 | palkovsky | 519 | /* Register at NS */ |
| 3084 | decky | 520 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
| 1445 | cejka | 521 | return -1; |
| 522 | |||
| 3084 | decky | 523 | // FIXME: avoid connectiong to itself, keep using klog |
| 524 | // printf(NAME ": Accepting connections\n"); |
||
| 1453 | palkovsky | 525 | async_manager(); |
| 1451 | cejka | 526 | |
| 1445 | cejka | 527 | return 0; |
| 528 | } |
||
| 1649 | cejka | 529 | |
| 530 | /** @} |
||
| 531 | */ |