Rev 3386 | Rev 4327 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <libc.h> |
35 | #include <libc.h> |
36 | #include <fb.h> |
36 | #include <fb.h> |
37 | #include <ipc/ipc.h> |
37 | #include <ipc/ipc.h> |
38 | #include <keys.h> |
38 | #include <kbd.h> |
- | 39 | #include <kbd/keycode.h> |
|
39 | #include <ipc/fb.h> |
40 | #include <ipc/fb.h> |
40 | #include <ipc/services.h> |
41 | #include <ipc/services.h> |
41 | #include <errno.h> |
42 | #include <errno.h> |
42 | #include <key_buffer.h> |
43 | #include <key_buffer.h> |
43 | #include <console.h> |
44 | #include <ipc/console.h> |
44 | #include <unistd.h> |
45 | #include <unistd.h> |
45 | #include <async.h> |
46 | #include <async.h> |
46 | #include <libadt/fifo.h> |
47 | #include <libadt/fifo.h> |
47 | #include <screenbuffer.h> |
48 | #include <screenbuffer.h> |
48 | #include <sys/mman.h> |
49 | #include <sys/mman.h> |
49 | #include <stdio.h> |
50 | #include <stdio.h> |
- | 51 | #include <sysinfo.h> |
|
50 | 52 | ||
- | 53 | #include "console.h" |
|
51 | #include "gcons.h" |
54 | #include "gcons.h" |
52 | 55 | ||
53 | #define MAX_KEYREQUESTS_BUFFERED 32 |
56 | #define MAX_KEYREQUESTS_BUFFERED 32 |
54 | 57 | ||
55 | #define NAME "console" |
58 | #define NAME "console" |
56 | 59 | ||
57 | /** Index of currently used virtual console. |
60 | /** Index of currently used virtual console. |
58 | */ |
61 | */ |
59 | int active_console = 0; |
62 | int active_console = 0; |
- | 63 | int prev_console = 0; |
|
60 | 64 | ||
61 | /** Information about framebuffer |
65 | /** Information about framebuffer |
62 | */ |
66 | */ |
63 | struct { |
67 | struct { |
64 | int phone; /**< Framebuffer phone */ |
68 | int phone; /**< Framebuffer phone */ |
Line 84... | Line 88... | ||
84 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared |
88 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared |
85 | * with framebufer used for |
89 | * with framebufer used for |
86 | * faster virtual console |
90 | * faster virtual console |
87 | * switching */ |
91 | * switching */ |
88 | 92 | ||
89 | static int kernel_pixmap = -1; /**< Number of fb pixmap, where kernel |
- | |
90 | * console is stored */ |
- | |
91 | - | ||
92 | 93 | ||
93 | /** Find unused virtual console. |
94 | /** Find unused virtual console. |
94 | * |
95 | * |
95 | */ |
96 | */ |
96 | static int find_free_connection(void) |
97 | static int find_free_connection(void) |
Line 107... | Line 108... | ||
107 | static void clrscr(void) |
108 | static void clrscr(void) |
108 | { |
109 | { |
109 | async_msg_0(fb_info.phone, FB_CLEAR); |
110 | async_msg_0(fb_info.phone, FB_CLEAR); |
110 | } |
111 | } |
111 | 112 | ||
112 | static void curs_visibility(int v) |
113 | static void curs_visibility(bool visible) |
113 | { |
114 | { |
114 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, v); |
115 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
- | 116 | } |
|
- | 117 | ||
- | 118 | static void curs_hide_sync(void) |
|
- | 119 | { |
|
- | 120 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
|
115 | } |
121 | } |
116 | 122 | ||
117 | static void curs_goto(int row, int col) |
123 | static void curs_goto(int row, int col) |
118 | { |
124 | { |
119 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
125 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
120 | } |
126 | } |
121 | 127 | ||
122 | static void set_style(style_t *style) |
128 | static void set_style(int style) |
123 | { |
129 | { |
124 | async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color, |
130 | async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
125 | style->bg_color); |
- | |
126 | } |
131 | } |
127 | 132 | ||
128 | static void set_style_col(int fgcolor, int bgcolor) |
133 | static void set_color(int fgcolor, int bgcolor, int flags) |
129 | { |
134 | { |
- | 135 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
|
- | 136 | } |
|
- | 137 | ||
- | 138 | static void set_rgb_color(int fgcolor, int bgcolor) |
|
- | 139 | { |
|
130 | async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor); |
140 | async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); |
- | 141 | } |
|
- | 142 | ||
- | 143 | static void set_attrs(attrs_t *attrs) |
|
- | 144 | { |
|
- | 145 | switch (attrs->t) { |
|
- | 146 | case at_style: |
|
- | 147 | set_style(attrs->a.s.style); |
|
- | 148 | break; |
|
- | 149 | ||
- | 150 | case at_idx: |
|
- | 151 | set_color(attrs->a.i.fg_color, attrs->a.i.bg_color, |
|
- | 152 | attrs->a.i.flags); |
|
- | 153 | break; |
|
- | 154 | ||
- | 155 | case at_rgb: |
|
- | 156 | set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color); |
|
- | 157 | break; |
|
- | 158 | } |
|
131 | } |
159 | } |
132 | 160 | ||
133 | static void prtchr(char c, int row, int col) |
161 | static void prtchr(char c, int row, int col) |
134 | { |
162 | { |
135 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
163 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
Line 185... | Line 213... | ||
185 | if (console == active_console) |
213 | if (console == active_console) |
186 | curs_goto(scr->position_y, scr->position_x); |
214 | curs_goto(scr->position_y, scr->position_x); |
187 | 215 | ||
188 | } |
216 | } |
189 | 217 | ||
190 | /** Save current screen to pixmap, draw old pixmap |
- | |
191 | * |
- | |
192 | * @param oldpixmap Old pixmap |
- | |
193 | * @return ID of pixmap of current screen |
- | |
194 | */ |
- | |
195 | static int switch_screens(int oldpixmap) |
- | |
196 | { |
- | |
197 | int newpmap; |
- | |
198 | - | ||
199 | /* Save screen */ |
- | |
200 | newpmap = async_req_0_0(fb_info.phone, FB_VP2PIXMAP); |
- | |
201 | if (newpmap < 0) |
- | |
202 | return -1; |
- | |
203 | - | ||
204 | if (oldpixmap != -1) { |
- | |
205 | /* Show old screen */ |
- | |
206 | async_msg_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap); |
- | |
207 | /* Drop old pixmap */ |
- | |
208 | async_msg_1(fb_info.phone, FB_DROP_PIXMAP, oldpixmap); |
- | |
209 | } |
- | |
210 | - | ||
211 | return newpmap; |
- | |
212 | } |
- | |
213 | - | ||
214 | /** Switch to new console */ |
218 | /** Switch to new console */ |
215 | static void change_console(int newcons) |
219 | static void change_console(int newcons) |
216 | { |
220 | { |
217 | connection_t *conn; |
221 | connection_t *conn; |
218 | static int console_pixmap = -1; |
- | |
219 | int i, j, rc; |
222 | int i, j, rc; |
220 | keyfield_t *field; |
223 | keyfield_t *field; |
221 | style_t *style; |
224 | attrs_t *attrs; |
222 | 225 | ||
223 | if (newcons == active_console) |
226 | if (newcons == active_console) |
224 | return; |
227 | return; |
225 | 228 | ||
226 | if (newcons == KERNEL_CONSOLE) { |
229 | if (newcons == KERNEL_CONSOLE) { |
227 | if (active_console == KERNEL_CONSOLE) |
- | |
228 | return; |
- | |
229 | active_console = KERNEL_CONSOLE; |
- | |
230 | curs_visibility(0); |
- | |
231 | - | ||
232 | async_serialize_start(); |
230 | async_serialize_start(); |
233 | if (kernel_pixmap == -1) { |
- | |
234 | /* store/restore unsupported */ |
- | |
235 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
- | |
236 | clrscr(); |
231 | curs_hide_sync(); |
237 | } else { |
- | |
238 | gcons_in_kernel(); |
232 | gcons_in_kernel(); |
239 | console_pixmap = switch_screens(kernel_pixmap); |
- | |
240 | kernel_pixmap = -1; |
- | |
241 | } |
- | |
242 | async_serialize_end(); |
233 | async_serialize_end(); |
243 | 234 | ||
244 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
235 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { |
- | 236 | prev_console = active_console; |
|
- | 237 | active_console = KERNEL_CONSOLE; |
|
245 | return; |
238 | } else |
- | 239 | newcons = active_console; |
|
246 | } |
240 | } |
247 | 241 | ||
- | 242 | if (newcons != KERNEL_CONSOLE) { |
|
248 | async_serialize_start(); |
243 | async_serialize_start(); |
249 | 244 | ||
250 | if (console_pixmap != -1) { |
245 | if (active_console == KERNEL_CONSOLE) |
251 | kernel_pixmap = switch_screens(console_pixmap); |
- | |
252 | console_pixmap = -1; |
246 | gcons_redraw_console(); |
253 | } |
247 | |
254 | active_console = newcons; |
248 | active_console = newcons; |
255 | gcons_change_console(newcons); |
249 | gcons_change_console(newcons); |
256 | conn = &connections[active_console]; |
250 | conn = &connections[active_console]; |
257 | 251 | ||
258 | set_style(&conn->screenbuffer.style); |
252 | set_attrs(&conn->screenbuffer.attrs); |
259 | curs_visibility(0); |
253 | curs_visibility(false); |
260 | if (interbuffer) { |
254 | if (interbuffer) { |
261 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
255 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
262 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
256 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
263 | unsigned int size_x; |
257 | unsigned int size_x; |
264 | 258 | ||
Line 269... | Line 263... | ||
269 | /* This call can preempt, but we are already at the end */ |
263 | /* This call can preempt, but we are already at the end */ |
270 | rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); |
264 | rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); |
271 | } |
265 | } |
272 | 266 | ||
273 | if ((!interbuffer) || (rc != 0)) { |
267 | if ((!interbuffer) || (rc != 0)) { |
274 | set_style(&conn->screenbuffer.style); |
268 | set_attrs(&conn->screenbuffer.attrs); |
275 | clrscr(); |
269 | clrscr(); |
276 | style = &conn->screenbuffer.style; |
270 | attrs = &conn->screenbuffer.attrs; |
277 | 271 | ||
278 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
272 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
279 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
273 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
280 | field = get_field_at(&conn->screenbuffer, i, j); |
274 | field = get_field_at(&conn->screenbuffer, i, j); |
281 | if (!style_same(*style, field->style)) |
275 | if (!attrs_same(*attrs, field->attrs)) |
282 | set_style(&field->style); |
276 | set_attrs(&field->attrs); |
283 | style = &field->style; |
277 | attrs = &field->attrs; |
284 | if ((field->character == ' ') && |
278 | if ((field->character == ' ') && |
285 | (style_same(field->style, |
279 | (attrs_same(field->attrs, |
286 | conn->screenbuffer.style))) |
280 | conn->screenbuffer.attrs))) |
287 | continue; |
281 | continue; |
288 | 282 | ||
289 | prtchr(field->character, j, i); |
283 | prtchr(field->character, j, i); |
290 | } |
284 | } |
291 | } |
285 | } |
Line 294... | Line 288... | ||
294 | conn->screenbuffer.position_x); |
288 | conn->screenbuffer.position_x); |
295 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
289 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
296 | 290 | ||
297 | async_serialize_end(); |
291 | async_serialize_end(); |
298 | } |
292 | } |
- | 293 | } |
|
299 | 294 | ||
300 | /** Handler for keyboard */ |
295 | /** Handler for keyboard */ |
301 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
296 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
302 | { |
297 | { |
303 | ipc_callid_t callid; |
298 | ipc_callid_t callid; |
304 | ipc_call_t call; |
299 | ipc_call_t call; |
305 | int retval; |
300 | int retval; |
306 | int c; |
301 | kbd_event_t ev; |
307 | connection_t *conn; |
302 | connection_t *conn; |
308 | int newcon; |
303 | int newcon; |
309 | 304 | ||
310 | /* Ignore parameters, the connection is alread opened */ |
305 | /* Ignore parameters, the connection is alread opened */ |
311 | while (1) { |
306 | while (1) { |
Line 323... | Line 318... | ||
323 | case KBD_MS_MOVE: |
318 | case KBD_MS_MOVE: |
324 | gcons_mouse_move(IPC_GET_ARG1(call), |
319 | gcons_mouse_move(IPC_GET_ARG1(call), |
325 | IPC_GET_ARG2(call)); |
320 | IPC_GET_ARG2(call)); |
326 | retval = 0; |
321 | retval = 0; |
327 | break; |
322 | break; |
328 | case KBD_PUSHCHAR: |
323 | case KBD_EVENT: |
329 | /* got key from keyboard driver */ |
324 | /* Got event from keyboard driver. */ |
330 | - | ||
331 | retval = 0; |
325 | retval = 0; |
- | 326 | ev.type = IPC_GET_ARG1(call); |
|
- | 327 | ev.key = IPC_GET_ARG2(call); |
|
- | 328 | ev.mods = IPC_GET_ARG3(call); |
|
332 | c = IPC_GET_ARG1(call); |
329 | ev.c = IPC_GET_ARG4(call); |
- | 330 | ||
333 | /* switch to another virtual console */ |
331 | /* switch to another virtual console */ |
334 | 332 | ||
335 | conn = &connections[active_console]; |
333 | conn = &connections[active_console]; |
336 | /* |
334 | |
337 | * if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + |
335 | if ((ev.key >= KC_F1) && (ev.key < KC_F1 + |
338 | * CONSOLE_COUNT)) { |
336 | CONSOLE_COUNT)) { |
339 | */ |
- | |
340 | if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) { |
- | |
341 | if (c == 0x112) |
337 | if (ev.key == KC_F12) |
342 | change_console(KERNEL_CONSOLE); |
338 | change_console(KERNEL_CONSOLE); |
343 | else |
339 | else |
344 | change_console(c - 0x101); |
340 | change_console(ev.key - KC_F1); |
345 | break; |
341 | break; |
346 | } |
342 | } |
347 | 343 | ||
348 | /* if client is awaiting key, send it */ |
344 | /* if client is awaiting key, send it */ |
349 | if (conn->keyrequest_counter > 0) { |
345 | if (conn->keyrequest_counter > 0) { |
350 | conn->keyrequest_counter--; |
346 | conn->keyrequest_counter--; |
351 | ipc_answer_1(fifo_pop(conn->keyrequests), EOK, |
347 | ipc_answer_4(fifo_pop(conn->keyrequests), EOK, |
352 | c); |
348 | ev.type, ev.key, ev.mods, ev.c); |
353 | break; |
349 | break; |
354 | } |
350 | } |
355 | 351 | ||
356 | keybuffer_push(&conn->keybuffer, c); |
352 | keybuffer_push(&conn->keybuffer, &ev); |
357 | retval = 0; |
353 | retval = 0; |
358 | 354 | ||
359 | break; |
355 | break; |
360 | default: |
356 | default: |
361 | retval = ENOENT; |
357 | retval = ENOENT; |
Line 368... | Line 364... | ||
368 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
364 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
369 | { |
365 | { |
370 | ipc_callid_t callid; |
366 | ipc_callid_t callid; |
371 | ipc_call_t call; |
367 | ipc_call_t call; |
372 | int consnum; |
368 | int consnum; |
373 | ipcarg_t arg1, arg2; |
369 | ipcarg_t arg1, arg2, arg3, arg4; |
374 | connection_t *conn; |
370 | connection_t *conn; |
375 | 371 | ||
376 | if ((consnum = find_free_connection()) == -1) { |
372 | if ((consnum = find_free_connection()) == -1) { |
377 | ipc_answer_0(iid, ELIMIT); |
373 | ipc_answer_0(iid, ELIMIT); |
378 | return; |
374 | return; |
Line 393... | Line 389... | ||
393 | callid = async_get_call(&call); |
389 | callid = async_get_call(&call); |
394 | async_serialize_start(); |
390 | async_serialize_start(); |
395 | 391 | ||
396 | arg1 = 0; |
392 | arg1 = 0; |
397 | arg2 = 0; |
393 | arg2 = 0; |
- | 394 | arg3 = 0; |
|
- | 395 | arg4 = 0; |
|
- | 396 | ||
398 | switch (IPC_GET_METHOD(call)) { |
397 | switch (IPC_GET_METHOD(call)) { |
399 | case IPC_M_PHONE_HUNGUP: |
398 | case IPC_M_PHONE_HUNGUP: |
400 | gcons_notify_disconnect(consnum); |
399 | gcons_notify_disconnect(consnum); |
401 | 400 | ||
402 | /* Answer all pending requests */ |
401 | /* Answer all pending requests */ |
Line 436... | Line 435... | ||
436 | if (consnum == active_console) |
435 | if (consnum == active_console) |
437 | async_req_0_0(fb_info.phone, FB_FLUSH); |
436 | async_req_0_0(fb_info.phone, FB_FLUSH); |
438 | break; |
437 | break; |
439 | case CONSOLE_SET_STYLE: |
438 | case CONSOLE_SET_STYLE: |
440 | arg1 = IPC_GET_ARG1(call); |
439 | arg1 = IPC_GET_ARG1(call); |
- | 440 | screenbuffer_set_style(&conn->screenbuffer, arg1); |
|
- | 441 | if (consnum == active_console) |
|
- | 442 | set_style(arg1); |
|
- | 443 | break; |
|
- | 444 | case CONSOLE_SET_COLOR: |
|
- | 445 | arg1 = IPC_GET_ARG1(call); |
|
441 | arg2 = IPC_GET_ARG2(call); |
446 | arg2 = IPC_GET_ARG2(call); |
- | 447 | arg3 = IPC_GET_ARG3(call); |
|
442 | screenbuffer_set_style(&conn->screenbuffer, arg1, |
448 | screenbuffer_set_color(&conn->screenbuffer, arg1, |
- | 449 | arg2, arg3); |
|
- | 450 | if (consnum == active_console) |
|
- | 451 | set_color(arg1, arg2, arg3); |
|
- | 452 | break; |
|
- | 453 | case CONSOLE_SET_RGB_COLOR: |
|
- | 454 | arg1 = IPC_GET_ARG1(call); |
|
- | 455 | arg2 = IPC_GET_ARG2(call); |
|
- | 456 | screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
|
443 | arg2); |
457 | arg2); |
444 | if (consnum == active_console) |
458 | if (consnum == active_console) |
445 | set_style_col(arg1, arg2); |
459 | set_rgb_color(arg1, arg2); |
446 | break; |
460 | break; |
447 | case CONSOLE_CURSOR_VISIBILITY: |
461 | case CONSOLE_CURSOR_VISIBILITY: |
448 | arg1 = IPC_GET_ARG1(call); |
462 | arg1 = IPC_GET_ARG1(call); |
449 | conn->screenbuffer.is_cursor_visible = arg1; |
463 | conn->screenbuffer.is_cursor_visible = arg1; |
450 | if (consnum == active_console) |
464 | if (consnum == active_console) |
451 | curs_visibility(arg1); |
465 | curs_visibility(arg1); |
452 | break; |
466 | break; |
453 | case CONSOLE_GETCHAR: |
467 | case CONSOLE_GETKEY: |
454 | if (keybuffer_empty(&conn->keybuffer)) { |
468 | if (keybuffer_empty(&conn->keybuffer)) { |
455 | /* buffer is empty -> store request */ |
469 | /* buffer is empty -> store request */ |
456 | if (conn->keyrequest_counter < |
470 | if (conn->keyrequest_counter < |
457 | MAX_KEYREQUESTS_BUFFERED) { |
471 | MAX_KEYREQUESTS_BUFFERED) { |
458 | fifo_push(conn->keyrequests, callid); |
472 | fifo_push(conn->keyrequests, callid); |
Line 464... | Line 478... | ||
464 | */ |
478 | */ |
465 | ipc_answer_0(callid, ELIMIT); |
479 | ipc_answer_0(callid, ELIMIT); |
466 | } |
480 | } |
467 | continue; |
481 | continue; |
468 | } |
482 | } |
- | 483 | kbd_event_t ev; |
|
469 | keybuffer_pop(&conn->keybuffer, (int *) &arg1); |
484 | keybuffer_pop(&conn->keybuffer, &ev); |
- | 485 | arg1 = ev.type; |
|
- | 486 | arg2 = ev.key; |
|
- | 487 | arg3 = ev.mods; |
|
- | 488 | arg4 = ev.c; |
|
470 | break; |
489 | break; |
471 | } |
490 | } |
472 | ipc_answer_2(callid, EOK, arg1, arg2); |
491 | ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4); |
- | 492 | } |
|
473 | } |
493 | } |
- | 494 | ||
- | 495 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
|
- | 496 | { |
|
- | 497 | change_console(prev_console); |
|
474 | } |
498 | } |
475 | 499 | ||
476 | int main(int argc, char *argv[]) |
500 | int main(int argc, char *argv[]) |
477 | { |
501 | { |
478 | printf(NAME ": HelenOS Console service\n"); |
502 | printf(NAME ": HelenOS Console service\n"); |
479 | 503 | ||
480 | ipcarg_t phonehash; |
504 | ipcarg_t phonehash; |
481 | int kbd_phone; |
505 | int kbd_phone; |
- | 506 | size_t ib_size; |
|
482 | int i; |
507 | int i; |
483 | 508 | ||
484 | async_set_client_connection(client_connection); |
509 | async_set_client_connection(client_connection); |
485 | 510 | ||
486 | /* Connect to keyboard driver */ |
511 | /* Connect to keyboard driver */ |
487 | - | ||
488 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
512 | kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
489 | while (kbd_phone < 0) { |
513 | if (kbd_phone < 0) { |
- | 514 | printf(NAME ": Failed to connect to keyboard service\n"); |
|
490 | usleep(10000); |
515 | return -1; |
491 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
- | |
492 | } |
516 | } |
493 | 517 | ||
494 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
518 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { |
- | 519 | printf(NAME ": Failed to create callback from keyboard service\n"); |
|
495 | return -1; |
520 | return -1; |
- | 521 | } |
|
- | 522 | ||
496 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
523 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
497 | 524 | ||
498 | /* Connect to framebuffer driver */ |
525 | /* Connect to framebuffer driver */ |
499 | - | ||
500 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
526 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0); |
501 | while (fb_info.phone < 0) { |
527 | if (fb_info.phone < 0) { |
- | 528 | printf(NAME ": Failed to connect to video service\n"); |
|
502 | usleep(10000); |
529 | return -1; |
503 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
- | |
504 | } |
530 | } |
505 | 531 | ||
506 | /* Save old kernel screen */ |
532 | /* Disable kernel output to the console */ |
507 | kernel_pixmap = switch_screens(-1); |
533 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE); |
508 | 534 | ||
509 | /* Initialize gcons */ |
535 | /* Initialize gcons */ |
510 | gcons_init(fb_info.phone); |
536 | gcons_init(fb_info.phone); |
511 | /* Synchronize, the gcons can have something in queue */ |
537 | /* Synchronize, the gcons can have something in queue */ |
512 | async_req_0_0(fb_info.phone, FB_FLUSH); |
538 | async_req_0_0(fb_info.phone, FB_FLUSH); |
513 | /* Enable double buffering */ |
- | |
514 | async_msg_2(fb_info.phone, FB_VIEWPORT_DB, (sysarg_t) -1, 1); |
- | |
515 | 539 | ||
516 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
540 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
517 | &fb_info.cols); |
541 | &fb_info.cols); |
518 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
542 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
519 | clrscr(); |
543 | clrscr(); |
520 | 544 | ||
521 | /* Init virtual consoles */ |
545 | /* Init virtual consoles */ |
522 | for (i = 0; i < CONSOLE_COUNT; i++) { |
546 | for (i = 0; i < CONSOLE_COUNT; i++) { |
523 | connections[i].used = 0; |
547 | connections[i].used = 0; |
Line 534... | Line 558... | ||
534 | return -1; |
558 | return -1; |
535 | } |
559 | } |
536 | } |
560 | } |
537 | connections[KERNEL_CONSOLE].used = 1; |
561 | connections[KERNEL_CONSOLE].used = 1; |
538 | 562 | ||
539 | interbuffer = mmap(NULL, |
563 | /* Set up shared memory buffer. */ |
540 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows, |
564 | ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; |
- | 565 | interbuffer = as_get_mappable_page(ib_size); |
|
- | 566 | ||
- | 567 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ | |
|
541 | PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); |
568 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) { |
- | 569 | interbuffer = NULL; |
|
- | 570 | } |
|
- | 571 | ||
542 | if (!interbuffer) { |
572 | if (interbuffer) { |
543 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
573 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
544 | AS_AREA_READ) != EOK) { |
574 | AS_AREA_READ) != EOK) { |
545 | munmap(interbuffer, |
575 | as_area_destroy(interbuffer); |
546 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
- | |
547 | interbuffer = NULL; |
576 | interbuffer = NULL; |
548 | } |
577 | } |
549 | } |
578 | } |
550 | 579 | ||
551 | curs_goto(0, 0); |
580 | curs_goto(0, 0); |
Line 554... | Line 583... | ||
554 | 583 | ||
555 | /* Register at NS */ |
584 | /* Register at NS */ |
556 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
585 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
557 | return -1; |
586 | return -1; |
558 | 587 | ||
- | 588 | /* Receive kernel notifications */ |
|
- | 589 | // if (sysinfo_value("kconsole.present")) { |
|
- | 590 | // int inr = sysinfo_value("kconsole.inr"); |
|
- | 591 | // if (ipc_register_irq(inr, device_assign_devno(), 0, NULL) != EOK) |
|
- | 592 | // printf(NAME ": Error registering kconsole notifications\n"); |
|
- | 593 | // |
|
- | 594 | // async_set_interrupt_received(interrupt_received); |
|
- | 595 | // } |
|
- | 596 | ||
559 | // FIXME: avoid connectiong to itself, keep using klog |
597 | // FIXME: avoid connectiong to itself, keep using klog |
560 | // printf(NAME ": Accepting connections\n"); |
598 | // printf(NAME ": Accepting connections\n"); |
561 | async_manager(); |
599 | async_manager(); |
562 | 600 | ||
563 | return 0; |
601 | return 0; |