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