[51c1b003] | 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 |
|
---|
| 30 | #include <kbd.h>
|
---|
[79460ae] | 31 | #include <fb.h>
|
---|
[51c1b003] | 32 | #include <ipc/ipc.h>
|
---|
[79460ae] | 33 | #include <ipc/fb.h>
|
---|
[51c1b003] | 34 | #include <ipc/services.h>
|
---|
| 35 | #include <errno.h>
|
---|
[79460ae] | 36 | #include <key_buffer.h>
|
---|
| 37 | #include <console.h>
|
---|
[eaf34f7] | 38 | #include <unistd.h>
|
---|
| 39 | #include <async.h>
|
---|
[cf28036c] | 40 | #include <libadt/fifo.h>
|
---|
[3993b3d] | 41 | #include <screenbuffer.h>
|
---|
[390a678] | 42 | #include <sys/mman.h>
|
---|
[79460ae] | 43 |
|
---|
[e1c4849] | 44 | #include "gcons.h"
|
---|
| 45 |
|
---|
[cf28036c] | 46 | #define MAX_KEYREQUESTS_BUFFERED 32
|
---|
[51c1b003] | 47 |
|
---|
| 48 | #define NAME "CONSOLE"
|
---|
| 49 |
|
---|
[e87e18f] | 50 | /** Index of currently used virtual console.
|
---|
| 51 | */
|
---|
[390a678] | 52 | int active_console = 0;
|
---|
[eaf34f7] | 53 |
|
---|
[e87e18f] | 54 | /** Information about framebuffer
|
---|
| 55 | */
|
---|
[3993b3d] | 56 | struct {
|
---|
| 57 | int phone; /**< Framebuffer phone */
|
---|
[bb51e9a8] | 58 | ipcarg_t rows; /**< Framebuffer rows */
|
---|
| 59 | ipcarg_t cols; /**< Framebuffer columns */
|
---|
[3993b3d] | 60 | } fb_info;
|
---|
| 61 |
|
---|
[e87e18f] | 62 |
|
---|
[79460ae] | 63 | typedef struct {
|
---|
[e87e18f] | 64 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */
|
---|
| 65 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); /**< Buffer for unsatisfied request for keys. */
|
---|
| 66 | int keyrequest_counter; /**< Number of requests in buffer. */
|
---|
| 67 | int client_phone; /**< Phone to connected client. */
|
---|
| 68 | int used; /**< 1 if this virtual console is connected to some client.*/
|
---|
| 69 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen contents and related settings. */
|
---|
[79460ae] | 70 | } connection_t;
|
---|
| 71 |
|
---|
[429acb9] | 72 | static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual consoles */
|
---|
| 73 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared with framebufer used for faster virt. console switching */
|
---|
| 74 |
|
---|
| 75 | static int kernel_pixmap = -1; /**< Number of fb pixmap, where kernel console is stored */
|
---|
[bb51e9a8] | 76 |
|
---|
| 77 |
|
---|
[e87e18f] | 78 | /** Find unused virtual console.
|
---|
| 79 | *
|
---|
| 80 | */
|
---|
[79460ae] | 81 | static int find_free_connection()
|
---|
| 82 | {
|
---|
| 83 | int i = 0;
|
---|
| 84 |
|
---|
| 85 | while (i < CONSOLE_COUNT) {
|
---|
| 86 | if (connections[i].used == 0)
|
---|
| 87 | return i;
|
---|
| 88 | ++i;
|
---|
| 89 | }
|
---|
| 90 | return CONSOLE_COUNT;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[e87e18f] | 93 | /** Find index of virtual console used by client with given phone.
|
---|
| 94 | *
|
---|
| 95 | */
|
---|
[79460ae] | 96 | static int find_connection(int client_phone)
|
---|
| 97 | {
|
---|
| 98 | int i = 0;
|
---|
| 99 |
|
---|
| 100 | while (i < CONSOLE_COUNT) {
|
---|
| 101 | if (connections[i].client_phone == client_phone)
|
---|
| 102 | return i;
|
---|
| 103 | ++i;
|
---|
| 104 | }
|
---|
| 105 | return CONSOLE_COUNT;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[429acb9] | 108 | static void clrscr(void)
|
---|
| 109 | {
|
---|
| 110 | nsend_call(fb_info.phone, FB_CLEAR, 0);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | static void curs_visibility(int v)
|
---|
| 114 | {
|
---|
| 115 | send_call(fb_info.phone, FB_CURSOR_VISIBILITY, v);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | static void curs_goto(int row, int col)
|
---|
| 119 | {
|
---|
| 120 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
|
---|
| 121 |
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | static void set_style(style_t *style)
|
---|
| 125 | {
|
---|
| 126 | nsend_call_2(fb_info.phone, FB_SET_STYLE, style->fg_color, style->bg_color);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | static void set_style_col(int fgcolor, int bgcolor)
|
---|
| 130 | {
|
---|
| 131 | nsend_call_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | static void prtchr(char c, int row, int col)
|
---|
| 135 | {
|
---|
| 136 | nsend_call_3(fb_info.phone, FB_PUTCHAR, c, row, col);
|
---|
| 137 |
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[10569b1] | 140 | /** Check key and process special keys.
|
---|
| 141 | *
|
---|
| 142 | * */
|
---|
| 143 | static void write_char(int console, char key)
|
---|
| 144 | {
|
---|
| 145 | screenbuffer_t *scr = &(connections[console].screenbuffer);
|
---|
| 146 |
|
---|
| 147 | switch (key) {
|
---|
| 148 | case '\n':
|
---|
| 149 | scr->position_y += 1;
|
---|
| 150 | scr->position_x = 0;
|
---|
| 151 | break;
|
---|
| 152 | case '\r':
|
---|
| 153 | break;
|
---|
| 154 | case '\t':
|
---|
| 155 | scr->position_x += 8;
|
---|
| 156 | scr->position_x -= scr->position_x % 8;
|
---|
| 157 | break;
|
---|
| 158 | case '\b':
|
---|
| 159 | if (scr->position_x == 0)
|
---|
| 160 | break;
|
---|
| 161 |
|
---|
| 162 | scr->position_x--;
|
---|
| 163 |
|
---|
[429acb9] | 164 | if (console == active_console)
|
---|
| 165 | prtchr(' ', scr->position_y, scr->position_x);
|
---|
[10569b1] | 166 |
|
---|
| 167 | screenbuffer_putchar(scr, ' ');
|
---|
| 168 |
|
---|
| 169 | break;
|
---|
| 170 | default:
|
---|
[429acb9] | 171 | if (console == active_console)
|
---|
| 172 | prtchr(key, scr->position_y, scr->position_x);
|
---|
[10569b1] | 173 |
|
---|
| 174 | screenbuffer_putchar(scr, key);
|
---|
| 175 | scr->position_x++;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | scr->position_y += (scr->position_x >= scr->size_x);
|
---|
| 179 |
|
---|
| 180 | if (scr->position_y >= scr->size_y) {
|
---|
| 181 | scr->position_y = scr->size_y - 1;
|
---|
| 182 | screenbuffer_clear_line(scr, scr->top_line++);
|
---|
[b1f51f0] | 183 | if (console == active_console)
|
---|
| 184 | nsend_call(fb_info.phone, FB_SCROLL, 1);
|
---|
[10569b1] | 185 | }
|
---|
| 186 |
|
---|
| 187 | scr->position_x = scr->position_x % scr->size_x;
|
---|
[bd929cfb] | 188 |
|
---|
[429acb9] | 189 | if (console == active_console)
|
---|
| 190 | curs_goto(scr->position_y, scr->position_x);
|
---|
[10569b1] | 191 |
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[429acb9] | 194 | /** Save current screen to pixmap, draw old pixmap
|
---|
| 195 | *
|
---|
| 196 | * @param oldpixmap Old pixmap
|
---|
| 197 | * @return ID of pixmap of current screen
|
---|
| 198 | */
|
---|
| 199 | static int switch_screens(int oldpixmap)
|
---|
| 200 | {
|
---|
| 201 | int newpmap;
|
---|
| 202 |
|
---|
| 203 | /* Save screen */
|
---|
| 204 | newpmap = sync_send(fb_info.phone, FB_VP2PIXMAP, 0, NULL);
|
---|
| 205 | if (newpmap < 0)
|
---|
| 206 | return -1;
|
---|
| 207 |
|
---|
| 208 | if (oldpixmap != -1) {
|
---|
| 209 | /* Show old screen */
|
---|
| 210 | nsend_call_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap);
|
---|
| 211 | /* Drop old pixmap */
|
---|
| 212 | nsend_call(fb_info.phone, FB_DROP_PIXMAP, oldpixmap);
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | return newpmap;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | /** Switch to new console */
|
---|
| 219 | static void change_console(int newcons)
|
---|
| 220 | {
|
---|
| 221 | connection_t *conn;
|
---|
| 222 | static int console_pixmap = -1;
|
---|
| 223 | int i, j;
|
---|
| 224 | char c;
|
---|
| 225 |
|
---|
| 226 | if (newcons == active_console)
|
---|
| 227 | return;
|
---|
| 228 |
|
---|
[a7d2d78] | 229 | if (newcons == KERNEL_CONSOLE) {
|
---|
| 230 | if (active_console == KERNEL_CONSOLE)
|
---|
[429acb9] | 231 | return;
|
---|
[a7d2d78] | 232 | active_console = KERNEL_CONSOLE;
|
---|
[429acb9] | 233 | curs_visibility(0);
|
---|
| 234 |
|
---|
| 235 | if (kernel_pixmap == -1) {
|
---|
| 236 | /* store/restore unsupported */
|
---|
| 237 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
|
---|
| 238 | clrscr();
|
---|
| 239 | } else {
|
---|
| 240 | gcons_in_kernel();
|
---|
| 241 | console_pixmap = switch_screens(kernel_pixmap);
|
---|
| 242 | kernel_pixmap = -1;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
|
---|
| 246 | return;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | if (console_pixmap != -1) {
|
---|
| 250 | kernel_pixmap = switch_screens(console_pixmap);
|
---|
| 251 | console_pixmap = -1;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | active_console = newcons;
|
---|
| 255 | gcons_change_console(newcons);
|
---|
| 256 | conn = &connections[active_console];
|
---|
| 257 |
|
---|
[7bc1e74] | 258 | set_style(&conn->screenbuffer.style);
|
---|
| 259 | curs_goto(conn->screenbuffer.position_y, conn->screenbuffer.position_x);
|
---|
[429acb9] | 260 | if (interbuffer) {
|
---|
| 261 | for (i = 0; i < conn->screenbuffer.size_x; i++)
|
---|
| 262 | for (j = 0; j < conn->screenbuffer.size_y; j++)
|
---|
| 263 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j);
|
---|
[7bc1e74] | 264 | /* This call can preempt, but we are already at the end */
|
---|
[429acb9] | 265 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL);
|
---|
| 266 | } else {
|
---|
[7bc1e74] | 267 | curs_visibility(0);
|
---|
[429acb9] | 268 | clrscr();
|
---|
| 269 |
|
---|
| 270 | for (i = 0; i < conn->screenbuffer.size_x; i++)
|
---|
| 271 | for (j = 0; j < conn->screenbuffer.size_y; j++) {
|
---|
| 272 | c = get_field_at(&(conn->screenbuffer),i, j)->character;
|
---|
| 273 | if (c && c != ' ')
|
---|
| 274 | prtchr(c, j, i);
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[7bc1e74] | 277 | curs_visibility(1);
|
---|
[429acb9] | 278 | }
|
---|
| 279 | }
|
---|
[10569b1] | 280 |
|
---|
[e87e18f] | 281 | /** Handler for keyboard */
|
---|
[eaf34f7] | 282 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[51c1b003] | 283 | {
|
---|
[eaf34f7] | 284 | ipc_callid_t callid;
|
---|
[51c1b003] | 285 | ipc_call_t call;
|
---|
[eaf34f7] | 286 | int retval;
|
---|
[dd641e3] | 287 | int c;
|
---|
[c1d2c9d] | 288 | connection_t *conn;
|
---|
[bb51e9a8] | 289 |
|
---|
[eaf34f7] | 290 | /* Ignore parameters, the connection is alread opened */
|
---|
| 291 | while (1) {
|
---|
| 292 | callid = async_get_call(&call);
|
---|
| 293 | switch (IPC_GET_METHOD(call)) {
|
---|
| 294 | case IPC_M_PHONE_HUNGUP:
|
---|
| 295 | ipc_answer_fast(callid,0,0,0);
|
---|
| 296 | /* TODO: Handle hangup */
|
---|
| 297 | return;
|
---|
| 298 | case KBD_PUSHCHAR:
|
---|
| 299 | /* got key from keyboard driver */
|
---|
[b27a97bb] | 300 |
|
---|
[eaf34f7] | 301 | retval = 0;
|
---|
[a805c24] | 302 | c = IPC_GET_ARG1(call);
|
---|
[eaf34f7] | 303 | /* switch to another virtual console */
|
---|
[cf28036c] | 304 |
|
---|
[c1d2c9d] | 305 | conn = &connections[active_console];
|
---|
[da0c91e7] | 306 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) {
|
---|
[dd641e3] | 307 | if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) {
|
---|
| 308 | if (c == 0x112)
|
---|
[a7d2d78] | 309 | change_console(KERNEL_CONSOLE);
|
---|
[429acb9] | 310 | else
|
---|
[dd641e3] | 311 | change_console(c - 0x101);
|
---|
[eaf34f7] | 312 | break;
|
---|
| 313 | }
|
---|
[cf28036c] | 314 |
|
---|
| 315 | /* if client is awaiting key, send it */
|
---|
[c1d2c9d] | 316 | if (conn->keyrequest_counter > 0) {
|
---|
| 317 | conn->keyrequest_counter--;
|
---|
| 318 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0);
|
---|
[cf28036c] | 319 | break;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | /*FIXME: else store key to its buffer */
|
---|
[c1d2c9d] | 323 | keybuffer_push(&conn->keybuffer, c);
|
---|
[ad123964] | 324 |
|
---|
[eaf34f7] | 325 | break;
|
---|
| 326 | default:
|
---|
[1029d3d3] | 327 | retval = ENOENT;
|
---|
[eaf34f7] | 328 | }
|
---|
[1029d3d3] | 329 | ipc_answer_fast(callid, retval, 0, 0);
|
---|
[eaf34f7] | 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | /** Default thread for new connections */
|
---|
[b1f51f0] | 334 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
[eaf34f7] | 335 | {
|
---|
[51c1b003] | 336 | ipc_callid_t callid;
|
---|
[eaf34f7] | 337 | ipc_call_t call;
|
---|
| 338 | int consnum;
|
---|
[3756912] | 339 | ipcarg_t arg1, arg2;
|
---|
[eaf34f7] | 340 |
|
---|
| 341 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) {
|
---|
| 342 | ipc_answer_fast(iid,ELIMIT,0,0);
|
---|
| 343 | return;
|
---|
| 344 | }
|
---|
[a7d2d78] | 345 |
|
---|
| 346 | gcons_notify_connect(consnum);
|
---|
[eaf34f7] | 347 | connections[consnum].used = 1;
|
---|
| 348 | connections[consnum].client_phone = IPC_GET_ARG3(call);
|
---|
[3993b3d] | 349 | screenbuffer_clear(&(connections[consnum].screenbuffer));
|
---|
[10569b1] | 350 |
|
---|
[eaf34f7] | 351 | /* Accept the connection */
|
---|
| 352 | ipc_answer_fast(iid,0,0,0);
|
---|
| 353 |
|
---|
| 354 | while (1) {
|
---|
| 355 | callid = async_get_call(&call);
|
---|
[3756912] | 356 | arg1 = arg2 = 0;
|
---|
[eaf34f7] | 357 | switch (IPC_GET_METHOD(call)) {
|
---|
| 358 | case IPC_M_PHONE_HUNGUP:
|
---|
| 359 | /* TODO */
|
---|
| 360 | ipc_answer_fast(callid, 0,0,0);
|
---|
| 361 | return;
|
---|
| 362 | case CONSOLE_PUTCHAR:
|
---|
[10569b1] | 363 | write_char(consnum, IPC_GET_ARG1(call));
|
---|
[d6cc453] | 364 | gcons_notify_char(consnum);
|
---|
[ad123964] | 365 | break;
|
---|
| 366 | case CONSOLE_CLEAR:
|
---|
[3993b3d] | 367 | /* Send message to fb */
|
---|
| 368 | if (consnum == active_console) {
|
---|
[b1f51f0] | 369 | send_call(fb_info.phone, FB_CLEAR, 0);
|
---|
[3993b3d] | 370 | }
|
---|
| 371 |
|
---|
| 372 | screenbuffer_clear(&(connections[consnum].screenbuffer));
|
---|
| 373 |
|
---|
[eaf34f7] | 374 | break;
|
---|
[ad123964] | 375 | case CONSOLE_GOTO:
|
---|
[3993b3d] | 376 |
|
---|
[d6cc453] | 377 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG2(call), IPC_GET_ARG1(call));
|
---|
[7bc1e74] | 378 | curs_goto(IPC_GET_ARG1(call),IPC_GET_ARG2(call));
|
---|
[3993b3d] | 379 |
|
---|
[ad123964] | 380 | break;
|
---|
[0c6984e] | 381 |
|
---|
[3756912] | 382 | case CONSOLE_GETSIZE:
|
---|
[d6cc453] | 383 | arg1 = fb_info.rows;
|
---|
| 384 | arg2 = fb_info.cols;
|
---|
[3756912] | 385 | break;
|
---|
[0c6984e] | 386 | case CONSOLE_FLUSH:
|
---|
| 387 | sync_send_2(fb_info.phone, FB_FLUSH, 0, 0, NULL, NULL);
|
---|
[a9bd960c] | 388 | break;
|
---|
| 389 | case CONSOLE_SET_STYLE:
|
---|
| 390 |
|
---|
| 391 | arg1 = IPC_GET_ARG1(call);
|
---|
| 392 | arg2 = IPC_GET_ARG2(call);
|
---|
[59ed572] | 393 | screenbuffer_set_style(&(connections[consnum].screenbuffer),arg1, arg2);
|
---|
[a9bd960c] | 394 | if (consnum == active_console)
|
---|
[429acb9] | 395 | set_style_col(arg1, arg2);
|
---|
[a9bd960c] | 396 |
|
---|
[0c6984e] | 397 | break;
|
---|
[eaf34f7] | 398 | case CONSOLE_GETCHAR:
|
---|
[cf28036c] | 399 | if (keybuffer_empty(&(connections[consnum].keybuffer))) {
|
---|
| 400 | /* buffer is empty -> store request */
|
---|
| 401 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) {
|
---|
| 402 | fifo_push(connections[consnum].keyrequests, callid);
|
---|
| 403 | connections[consnum].keyrequest_counter++;
|
---|
| 404 | } else {
|
---|
| 405 | /* no key available and too many requests => fail */
|
---|
| 406 | ipc_answer_fast(callid, ELIMIT, 0, 0);
|
---|
| 407 | }
|
---|
| 408 | continue;
|
---|
[eaf34f7] | 409 | };
|
---|
[ad123964] | 410 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1);
|
---|
[b27a97bb] | 411 |
|
---|
[eaf34f7] | 412 | break;
|
---|
| 413 | }
|
---|
[3756912] | 414 | ipc_answer_fast(callid, 0, arg1, arg2);
|
---|
[eaf34f7] | 415 | }
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | int main(int argc, char *argv[])
|
---|
| 419 | {
|
---|
| 420 | ipcarg_t phonehash;
|
---|
[79460ae] | 421 | int kbd_phone, fb_phone;
|
---|
[51c1b003] | 422 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
|
---|
[79460ae] | 423 | int i;
|
---|
[da0c91e7] | 424 |
|
---|
| 425 | async_set_client_connection(client_connection);
|
---|
[51c1b003] | 426 |
|
---|
| 427 | /* Connect to keyboard driver */
|
---|
| 428 |
|
---|
[79460ae] | 429 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
|
---|
[eaf34f7] | 430 | usleep(10000);
|
---|
[51c1b003] | 431 | };
|
---|
| 432 |
|
---|
[eaf34f7] | 433 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) {
|
---|
[51c1b003] | 434 | return -1;
|
---|
| 435 | };
|
---|
| 436 |
|
---|
| 437 | /* Connect to framebuffer driver */
|
---|
| 438 |
|
---|
[3993b3d] | 439 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
|
---|
| 440 | usleep(10000);
|
---|
| 441 | }
|
---|
[429acb9] | 442 |
|
---|
| 443 | /* Save old kernel screen */
|
---|
| 444 | kernel_pixmap = switch_screens(-1);
|
---|
[e1c4849] | 445 |
|
---|
| 446 | /* Initialize gcons */
|
---|
| 447 | gcons_init(fb_info.phone);
|
---|
| 448 | /* Synchronize, the gcons can have something in queue */
|
---|
| 449 | sync_send_2(fb_info.phone, FB_GET_CSIZE, 0, 0, NULL, NULL);
|
---|
| 450 |
|
---|
[3993b3d] | 451 |
|
---|
| 452 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols));
|
---|
[429acb9] | 453 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
|
---|
| 454 | clrscr();
|
---|
[3993b3d] | 455 |
|
---|
| 456 | /* Init virtual consoles */
|
---|
[79460ae] | 457 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
| 458 | connections[i].used = 0;
|
---|
| 459 | keybuffer_init(&(connections[i].keybuffer));
|
---|
[cf28036c] | 460 |
|
---|
| 461 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0;
|
---|
| 462 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
|
---|
| 463 | connections[i].keyrequest_counter = 0;
|
---|
[3993b3d] | 464 |
|
---|
| 465 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) {
|
---|
| 466 | /*FIXME: handle error */
|
---|
| 467 | return -1;
|
---|
| 468 | }
|
---|
[79460ae] | 469 | }
|
---|
[51c1b003] | 470 |
|
---|
[390a678] | 471 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) {
|
---|
[90f5d64] | 472 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ, NULL, NULL, NULL) != 0) {
|
---|
[390a678] | 473 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows);
|
---|
| 474 | interbuffer = NULL;
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
[a805c24] | 477 |
|
---|
[bb51e9a8] | 478 | async_new_connection(phonehash, 0, NULL, keyboard_events);
|
---|
| 479 |
|
---|
[e1c4849] | 480 | sync_send_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0, NULL, NULL);
|
---|
[a805c24] | 481 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1);
|
---|
[10569b1] | 482 |
|
---|
[b1f51f0] | 483 | /* Register at NS */
|
---|
[eaf34f7] | 484 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) {
|
---|
[51c1b003] | 485 | return -1;
|
---|
| 486 | };
|
---|
| 487 |
|
---|
[eaf34f7] | 488 | async_manager();
|
---|
[51c1b003] | 489 |
|
---|
| 490 | return 0;
|
---|
| 491 | }
|
---|
[a805c24] | 492 |
|
---|