Rev 4421 | Rev 4493 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4421 | Rev 4456 | ||
---|---|---|---|
Line 34... | Line 34... | ||
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 <kbd.h> |
38 | #include <kbd.h> |
39 | #include <kbd/keycode.h> |
39 | #include <io/keycode.h> |
40 | #include <ipc/fb.h> |
40 | #include <ipc/fb.h> |
41 | #include <ipc/services.h> |
41 | #include <ipc/services.h> |
42 | #include <errno.h> |
42 | #include <errno.h> |
43 | #include <key_buffer.h> |
43 | #include <keybuffer.h> |
44 | #include <ipc/console.h> |
44 | #include <ipc/console.h> |
45 | #include <unistd.h> |
45 | #include <unistd.h> |
46 | #include <async.h> |
46 | #include <async.h> |
47 | #include <libadt/fifo.h> |
47 | #include <libadt/fifo.h> |
48 | #include <screenbuffer.h> |
- | |
49 | #include <sys/mman.h> |
48 | #include <sys/mman.h> |
50 | #include <stdio.h> |
49 | #include <stdio.h> |
51 | #include <string.h> |
50 | #include <string.h> |
52 | #include <sysinfo.h> |
51 | #include <sysinfo.h> |
53 | #include <event.h> |
52 | #include <event.h> |
- | 53 | #include <devmap.h> |
|
54 | 54 | ||
55 | #include "console.h" |
55 | #include "console.h" |
56 | #include "gcons.h" |
56 | #include "gcons.h" |
- | 57 | #include "screenbuffer.h" |
|
57 | 58 | ||
58 | #define NAME "console" |
59 | #define NAME "console" |
59 | 60 | ||
60 | #define MAX_KEYREQUESTS_BUFFERED 32 |
61 | #define MAX_DEVICE_NAME 32 |
61 | - | ||
62 | /** Size of cwrite_buf. */ |
- | |
63 | #define CWRITE_BUF_SIZE 256 |
- | |
64 | - | ||
65 | /** Index of currently used virtual console. |
- | |
66 | */ |
- | |
67 | int active_console = 0; |
- | |
68 | int prev_console = 0; |
- | |
69 | 62 | ||
70 | /** Phone to the keyboard driver. */ |
63 | /** Phone to the keyboard driver. */ |
71 | static int kbd_phone; |
64 | static int kbd_phone; |
72 | 65 | ||
73 | /** Information about framebuffer */ |
66 | /** Information about framebuffer */ |
74 | struct { |
67 | struct { |
75 | int phone; /**< Framebuffer phone */ |
68 | int phone; /**< Framebuffer phone */ |
76 | ipcarg_t rows; /**< Framebuffer rows */ |
- | |
77 | ipcarg_t cols; /**< Framebuffer columns */ |
69 | ipcarg_t cols; /**< Framebuffer columns */ |
- | 70 | ipcarg_t rows; /**< Framebuffer rows */ |
|
78 | } fb_info; |
71 | } fb_info; |
79 | 72 | ||
80 | typedef struct { |
73 | typedef struct { |
81 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
74 | size_t index; /**< Console index */ |
82 | - | ||
83 | /** Buffer for unsatisfied request for keys. */ |
- | |
84 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t, |
- | |
85 | MAX_KEYREQUESTS_BUFFERED); |
- | |
86 | - | ||
87 | int keyrequest_counter; /**< Number of requests in buffer. */ |
- | |
88 | int client_phone; /**< Phone to connected client. */ |
75 | size_t refcount; /**< Connection reference count */ |
89 | int used; /**< 1 if this virtual console is |
76 | dev_handle_t dev_handle; /**< Device handle */ |
90 | connected to some client. */ |
77 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
91 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen |
78 | screenbuffer_t scr; /**< Screenbuffer for saving screen |
92 | contents and related settings. */ |
79 | contents and related settings. */ |
93 | } connection_t; |
80 | } console_t; |
94 | 81 | ||
95 | /** Array of data for virtual consoles */ |
82 | /** Array of data for virtual consoles */ |
96 | static connection_t connections[CONSOLE_COUNT]; |
83 | static console_t consoles[CONSOLE_COUNT]; |
- | 84 | ||
- | 85 | static console_t *active_console = &consoles[0]; |
|
- | 86 | static console_t *prev_console = &consoles[0]; |
|
- | 87 | static console_t *kernel_console = &consoles[KERNEL_CONSOLE]; |
|
97 | 88 | ||
98 | /** Pointer to memory shared with framebufer used for |
89 | /** Pointer to memory shared with framebufer used for |
99 | faster virtual console switching */ |
90 | faster virtual console switching */ |
100 | static keyfield_t *interbuffer = NULL; |
91 | static keyfield_t *interbuffer = NULL; |
101 | 92 | ||
102 | /** Information on row-span yet unsent to FB driver. */ |
93 | /** Information on row-span yet unsent to FB driver. */ |
103 | struct { |
94 | struct { |
104 | int row; /**< Row where the span lies. */ |
95 | size_t col; /**< Leftmost column of the span. */ |
105 | int col; /**< Leftmost column of the span. */ |
96 | size_t row; /**< Row where the span lies. */ |
106 | int cnt; /**< Width of the span. */ |
97 | size_t cnt; /**< Width of the span. */ |
107 | } fb_pending; |
98 | } fb_pending; |
108 | 99 | ||
- | 100 | /** Pending input structure. */ |
|
- | 101 | typedef struct { |
|
- | 102 | link_t link; |
|
- | 103 | console_t *cons; /**< Console waiting for input */ |
|
- | 104 | ipc_callid_t rid; /**< Call ID waiting for input */ |
|
- | 105 | ipc_callid_t callid; /**< Call ID waiting for IPC_DATA_READ */ |
|
- | 106 | ||
109 | /** Buffer for receiving data via the CONSOLE_WRITE call from the client. */ |
107 | size_t pos; /**< Position of the last stored data */ |
110 | static char cwrite_buf[CWRITE_BUF_SIZE]; |
108 | size_t size; /**< Size of ther buffer */ |
- | 109 | char *data; /**< Already stored data */ |
|
- | 110 | } pending_input_t; |
|
111 | 111 | ||
112 | /** Find unused virtual console. |
112 | LIST_INITIALIZE(pending_input); |
113 | * |
113 | |
114 | */ |
114 | /** Process pending input requests */ |
115 | static int find_free_connection(void) |
115 | static void process_pending_input(void) |
116 | { |
116 | { |
117 | int i; |
117 | async_serialize_start(); |
118 | 118 | ||
- | 119 | link_t *cur; |
|
- | 120 | ||
- | 121 | loop: |
|
- | 122 | for (cur = pending_input.next; cur != &pending_input; cur = cur->next) { |
|
- | 123 | pending_input_t *pr = list_get_instance(cur, pending_input_t, link); |
|
- | 124 | ||
- | 125 | console_event_t ev; |
|
- | 126 | if (keybuffer_pop(&pr->cons->keybuffer, &ev)) { |
|
- | 127 | ||
119 | for (i = 0; i < CONSOLE_COUNT; i++) { |
128 | if (pr->data != NULL) { |
120 | if (!connections[i].used) |
129 | if (ev.type == KEY_PRESS) { |
- | 130 | pr->data[pr->pos] = ev.c; |
|
- | 131 | pr->pos++; |
|
- | 132 | } |
|
- | 133 | } else { |
|
- | 134 | ipc_answer_4(pr->rid, EOK, ev.type, ev.key, ev.mods, ev.c); |
|
- | 135 | ||
- | 136 | list_remove(cur); |
|
- | 137 | free(pr); |
|
- | 138 | ||
- | 139 | goto loop; |
|
- | 140 | } |
|
- | 141 | } |
|
- | 142 | ||
- | 143 | if ((pr->data != NULL) && (pr->pos == pr->size)) { |
|
- | 144 | (void) ipc_data_read_finalize(pr->callid, pr->data, pr->size); |
|
- | 145 | ipc_answer_1(pr->rid, EOK, pr->size); |
|
- | 146 | ||
- | 147 | free(pr->data); |
|
- | 148 | list_remove(cur); |
|
121 | return i; |
149 | free(pr); |
- | 150 | ||
- | 151 | goto loop; |
|
- | 152 | } |
|
122 | } |
153 | } |
123 | 154 | ||
124 | return -1; |
- | |
125 | } |
- | |
126 | - | ||
127 | static void clrscr(void) |
- | |
128 | { |
- | |
129 | async_msg_0(fb_info.phone, FB_CLEAR); |
155 | async_serialize_end(); |
130 | } |
156 | } |
131 | 157 | ||
132 | static void curs_visibility(bool visible) |
158 | static void curs_visibility(bool visible) |
133 | { |
159 | { |
134 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
160 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
Line 137... | Line 163... | ||
137 | static void curs_hide_sync(void) |
163 | static void curs_hide_sync(void) |
138 | { |
164 | { |
139 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
165 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
140 | } |
166 | } |
141 | 167 | ||
142 | static void curs_goto(int row, int col) |
168 | static void curs_goto(size_t x, size_t y) |
143 | { |
169 | { |
144 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
170 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y); |
- | 171 | } |
|
- | 172 | ||
- | 173 | static void screen_clear(void) |
|
- | 174 | { |
|
- | 175 | async_msg_0(fb_info.phone, FB_CLEAR); |
|
145 | } |
176 | } |
146 | 177 | ||
147 | static void screen_yield(void) |
178 | static void screen_yield(void) |
148 | { |
179 | { |
149 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD); |
180 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD); |
Line 164... | Line 195... | ||
164 | ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM); |
195 | ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM); |
165 | } |
196 | } |
166 | 197 | ||
167 | static void set_style(int style) |
198 | static void set_style(int style) |
168 | { |
199 | { |
169 | async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
200 | async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
170 | } |
201 | } |
171 | 202 | ||
172 | static void set_color(int fgcolor, int bgcolor, int flags) |
203 | static void set_color(int fgcolor, int bgcolor, int flags) |
173 | { |
204 | { |
174 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
205 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
Line 194... | Line 225... | ||
194 | break; |
225 | break; |
195 | } |
226 | } |
196 | } |
227 | } |
197 | 228 | ||
198 | /** Send an area of screenbuffer to the FB driver. */ |
229 | /** Send an area of screenbuffer to the FB driver. */ |
199 | static void fb_update_area(connection_t *conn, int x, int y, int w, int h) |
230 | static void fb_update_area(console_t *cons, ipcarg_t x0, ipcarg_t y0, ipcarg_t width, ipcarg_t height) |
200 | { |
231 | { |
201 | int i; |
- | |
202 | int j; |
- | |
203 | attrs_t *attrs; |
- | |
204 | keyfield_t *field; |
- | |
205 | - | ||
206 | if (interbuffer) { |
232 | if (interbuffer) { |
- | 233 | ipcarg_t x; |
|
- | 234 | ipcarg_t y; |
|
- | 235 | ||
207 | for (j = 0; j < h; j++) { |
236 | for (y = 0; y < height; y++) { |
208 | for (i = 0; i < w; i++) { |
237 | for (x = 0; x < width; x++) { |
209 | interbuffer[i + j * w] = |
238 | interbuffer[y * width + x] = |
210 | *get_field_at(&conn->screenbuffer, x + i, y + j); |
239 | *get_field_at(&cons->scr, x0 + x, y0 + y); |
211 | } |
240 | } |
212 | } |
241 | } |
213 | 242 | ||
214 | async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
243 | async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
215 | x, y, w, h); |
244 | x0, y0, width, height); |
216 | } |
245 | } |
217 | } |
246 | } |
218 | 247 | ||
219 | /** Flush pending cells to FB. */ |
248 | /** Flush pending cells to FB. */ |
220 | static void fb_pending_flush(void) |
249 | static void fb_pending_flush(void) |
221 | { |
250 | { |
222 | screenbuffer_t *scr |
- | |
223 | = &(connections[active_console].screenbuffer); |
- | |
224 | - | ||
225 | if (fb_pending.cnt > 0) { |
251 | if (fb_pending.cnt > 0) { |
226 | fb_update_area(&connections[active_console], fb_pending.col, |
252 | fb_update_area(active_console, fb_pending.col, |
227 | fb_pending.row, fb_pending.cnt, 1); |
253 | fb_pending.row, fb_pending.cnt, 1); |
228 | fb_pending.cnt = 0; |
254 | fb_pending.cnt = 0; |
229 | } |
255 | } |
230 | } |
256 | } |
231 | 257 | ||
Line 233... | Line 259... | ||
233 | * |
259 | * |
234 | * This adds the cell to the pending rowspan if possible. Otherwise |
260 | * This adds the cell to the pending rowspan if possible. Otherwise |
235 | * the old span is flushed first. |
261 | * the old span is flushed first. |
236 | * |
262 | * |
237 | */ |
263 | */ |
238 | static void cell_mark_changed(int row, int col) |
264 | static void cell_mark_changed(size_t col, size_t row) |
239 | { |
265 | { |
240 | if (fb_pending.cnt != 0) { |
266 | if (fb_pending.cnt != 0) { |
241 | if ((row != fb_pending.row) |
267 | if ((col != fb_pending.col + fb_pending.cnt) |
242 | || (col != fb_pending.col + fb_pending.cnt)) { |
268 | || (row != fb_pending.row)) { |
243 | fb_pending_flush(); |
269 | fb_pending_flush(); |
244 | } |
270 | } |
245 | } |
271 | } |
246 | 272 | ||
247 | if (fb_pending.cnt == 0) { |
273 | if (fb_pending.cnt == 0) { |
248 | fb_pending.row = row; |
- | |
249 | fb_pending.col = col; |
274 | fb_pending.col = col; |
- | 275 | fb_pending.row = row; |
|
250 | } |
276 | } |
251 | 277 | ||
252 | fb_pending.cnt++; |
278 | fb_pending.cnt++; |
253 | } |
279 | } |
254 | 280 | ||
255 | /** Print a character to the active VC with buffering. */ |
281 | /** Print a character to the active VC with buffering. */ |
256 | static void fb_putchar(wchar_t c, int row, int col) |
282 | static void fb_putchar(wchar_t c, ipcarg_t col, ipcarg_t row) |
257 | { |
283 | { |
258 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
284 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row); |
259 | } |
285 | } |
260 | 286 | ||
261 | /** Process a character from the client (TTY emulation). */ |
287 | /** Process a character from the client (TTY emulation). */ |
262 | static void write_char(int console, wchar_t ch) |
288 | static void write_char(console_t *cons, wchar_t ch) |
263 | { |
289 | { |
264 | bool flush_cursor = false; |
- | |
265 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
- | |
266 | - | ||
267 | switch (ch) { |
290 | switch (ch) { |
268 | case '\n': |
291 | case '\n': |
269 | fb_pending_flush(); |
292 | fb_pending_flush(); |
270 | flush_cursor = true; |
- | |
271 | scr->position_y++; |
293 | cons->scr.position_y++; |
272 | scr->position_x = 0; |
294 | cons->scr.position_x = 0; |
273 | break; |
295 | break; |
274 | case '\r': |
296 | case '\r': |
275 | break; |
297 | break; |
276 | case '\t': |
298 | case '\t': |
277 | scr->position_x += 8; |
299 | cons->scr.position_x += 8; |
278 | scr->position_x -= scr->position_x % 8; |
300 | cons->scr.position_x -= cons->scr.position_x % 8; |
279 | break; |
301 | break; |
280 | case '\b': |
302 | case '\b': |
281 | if (scr->position_x == 0) |
303 | if (cons->scr.position_x == 0) |
282 | break; |
304 | break; |
283 | scr->position_x--; |
305 | cons->scr.position_x--; |
284 | if (console == active_console) |
306 | if (cons == active_console) |
285 | cell_mark_changed(scr->position_y, scr->position_x); |
307 | cell_mark_changed(cons->scr.position_x, cons->scr.position_y); |
286 | screenbuffer_putchar(scr, ' '); |
308 | screenbuffer_putchar(&cons->scr, ' '); |
287 | break; |
309 | break; |
288 | default: |
310 | default: |
289 | if (console == active_console) |
311 | if (cons == active_console) |
290 | cell_mark_changed(scr->position_y, scr->position_x); |
312 | cell_mark_changed(cons->scr.position_x, cons->scr.position_y); |
291 | 313 | ||
292 | screenbuffer_putchar(scr, ch); |
314 | screenbuffer_putchar(&cons->scr, ch); |
293 | scr->position_x++; |
315 | cons->scr.position_x++; |
294 | } |
316 | } |
295 | 317 | ||
296 | if (scr->position_x >= scr->size_x) { |
318 | if (cons->scr.position_x >= cons->scr.size_x) |
297 | flush_cursor = true; |
- | |
298 | scr->position_y++; |
319 | cons->scr.position_y++; |
299 | } |
- | |
300 | 320 | ||
301 | if (scr->position_y >= scr->size_y) { |
321 | if (cons->scr.position_y >= cons->scr.size_y) { |
302 | fb_pending_flush(); |
322 | fb_pending_flush(); |
303 | scr->position_y = scr->size_y - 1; |
323 | cons->scr.position_y = cons->scr.size_y - 1; |
304 | screenbuffer_clear_line(scr, scr->top_line); |
324 | screenbuffer_clear_line(&cons->scr, cons->scr.top_line); |
305 | scr->top_line = (scr->top_line + 1) % scr->size_y; |
325 | cons->scr.top_line = (cons->scr.top_line + 1) % cons->scr.size_y; |
- | 326 | ||
306 | if (console == active_console) |
327 | if (cons == active_console) |
307 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
328 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
308 | } |
329 | } |
309 | 330 | ||
310 | scr->position_x = scr->position_x % scr->size_x; |
331 | cons->scr.position_x = cons->scr.position_x % cons->scr.size_x; |
311 | - | ||
312 | if (console == active_console && flush_cursor) |
- | |
313 | curs_goto(scr->position_y, scr->position_x); |
- | |
314 | } |
332 | } |
315 | 333 | ||
316 | /** Switch to new console */ |
334 | /** Switch to new console */ |
317 | static void change_console(int newcons) |
335 | static void change_console(console_t *cons) |
318 | { |
336 | { |
319 | connection_t *conn; |
- | |
320 | int i; |
- | |
321 | int j; |
- | |
322 | int rc; |
- | |
323 | keyfield_t *field; |
- | |
324 | attrs_t *attrs; |
- | |
325 | - | ||
326 | if (newcons == active_console) |
337 | if (cons == active_console) |
327 | return; |
338 | return; |
328 | 339 | ||
329 | fb_pending_flush(); |
340 | fb_pending_flush(); |
330 | 341 | ||
331 | if (newcons == KERNEL_CONSOLE) { |
342 | if (cons == kernel_console) { |
332 | async_serialize_start(); |
343 | async_serialize_start(); |
333 | curs_hide_sync(); |
344 | curs_hide_sync(); |
334 | gcons_in_kernel(); |
345 | gcons_in_kernel(); |
335 | screen_yield(); |
346 | screen_yield(); |
336 | kbd_yield(); |
347 | kbd_yield(); |
337 | async_serialize_end(); |
348 | async_serialize_end(); |
338 | 349 | ||
339 | - | ||
340 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { |
350 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { |
341 | prev_console = active_console; |
351 | prev_console = active_console; |
342 | active_console = KERNEL_CONSOLE; |
352 | active_console = kernel_console; |
343 | } else |
353 | } else |
344 | newcons = active_console; |
354 | cons = active_console; |
345 | } |
355 | } |
346 | 356 | ||
347 | if (newcons != KERNEL_CONSOLE) { |
357 | if (cons != kernel_console) { |
- | 358 | size_t x; |
|
- | 359 | size_t y; |
|
- | 360 | int rc = 0; |
|
- | 361 | ||
348 | async_serialize_start(); |
362 | async_serialize_start(); |
349 | 363 | ||
350 | if (active_console == KERNEL_CONSOLE) { |
364 | if (active_console == kernel_console) { |
351 | screen_reclaim(); |
365 | screen_reclaim(); |
352 | kbd_reclaim(); |
366 | kbd_reclaim(); |
353 | gcons_redraw_console(); |
367 | gcons_redraw_console(); |
354 | } |
368 | } |
355 | 369 | ||
356 | active_console = newcons; |
370 | active_console = cons; |
357 | gcons_change_console(newcons); |
371 | gcons_change_console(cons->index); |
358 | conn = &connections[active_console]; |
- | |
359 | 372 | ||
360 | set_attrs(&conn->screenbuffer.attrs); |
373 | set_attrs(&cons->scr.attrs); |
361 | curs_visibility(false); |
374 | curs_visibility(false); |
362 | if (interbuffer) { |
375 | if (interbuffer) { |
363 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
376 | for (y = 0; y < cons->scr.size_y; y++) { |
364 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
377 | for (x = 0; x < cons->scr.size_x; x++) { |
365 | unsigned int size_x; |
- | |
366 | - | ||
367 | size_x = conn->screenbuffer.size_x; |
- | |
368 | interbuffer[j * size_x + i] = |
378 | interbuffer[y * cons->scr.size_x + x] = |
369 | *get_field_at(&conn->screenbuffer, i, j); |
379 | *get_field_at(&cons->scr, x, y); |
370 | } |
380 | } |
371 | } |
381 | } |
- | 382 | ||
372 | /* This call can preempt, but we are already at the end */ |
383 | /* This call can preempt, but we are already at the end */ |
373 | rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
384 | rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
374 | 0, 0, conn->screenbuffer.size_x, |
385 | 0, 0, cons->scr.size_x, |
375 | conn->screenbuffer.size_y); |
386 | cons->scr.size_y); |
376 | } |
387 | } |
377 | 388 | ||
378 | if ((!interbuffer) || (rc != 0)) { |
389 | if ((!interbuffer) || (rc != 0)) { |
379 | set_attrs(&conn->screenbuffer.attrs); |
390 | set_attrs(&cons->scr.attrs); |
380 | clrscr(); |
391 | screen_clear(); |
381 | attrs = &conn->screenbuffer.attrs; |
- | |
382 | 392 | ||
383 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
393 | for (y = 0; y < cons->scr.size_y; y++) |
384 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
394 | for (x = 0; x < cons->scr.size_x; x++) { |
385 | field = get_field_at(&conn->screenbuffer, i, j); |
395 | keyfield_t *field = get_field_at(&cons->scr, x, y); |
- | 396 | ||
386 | if (!attrs_same(*attrs, field->attrs)) |
397 | if (!attrs_same(cons->scr.attrs, field->attrs)) |
387 | set_attrs(&field->attrs); |
398 | set_attrs(&field->attrs); |
- | 399 | ||
388 | attrs = &field->attrs; |
400 | cons->scr.attrs = field->attrs; |
389 | if ((field->character == ' ') && |
401 | if ((field->character == ' ') && |
390 | (attrs_same(field->attrs, conn->screenbuffer.attrs))) |
402 | (attrs_same(field->attrs, cons->scr.attrs))) |
391 | continue; |
403 | continue; |
392 | 404 | ||
393 | fb_putchar(field->character, j, i); |
405 | fb_putchar(field->character, x, y); |
394 | } |
406 | } |
395 | } |
407 | } |
396 | 408 | ||
397 | curs_goto(conn->screenbuffer.position_y, |
409 | curs_goto(cons->scr.position_x, cons->scr.position_y); |
398 | conn->screenbuffer.position_x); |
- | |
399 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
410 | curs_visibility(cons->scr.is_cursor_visible); |
400 | 411 | ||
401 | async_serialize_end(); |
412 | async_serialize_end(); |
402 | } |
413 | } |
403 | } |
414 | } |
404 | 415 | ||
405 | /** Handler for keyboard */ |
416 | /** Handler for keyboard */ |
406 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
417 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
407 | { |
418 | { |
408 | ipc_callid_t callid; |
- | |
409 | ipc_call_t call; |
- | |
410 | int retval; |
- | |
411 | kbd_event_t ev; |
- | |
412 | connection_t *conn; |
- | |
413 | int newcon; |
- | |
414 | - | ||
415 | /* Ignore parameters, the connection is alread opened */ |
419 | /* Ignore parameters, the connection is already opened */ |
416 | while (true) { |
420 | while (true) { |
- | 421 | ||
- | 422 | ipc_call_t call; |
|
417 | callid = async_get_call(&call); |
423 | ipc_callid_t callid = async_get_call(&call); |
- | 424 | ||
- | 425 | int retval; |
|
- | 426 | console_event_t ev; |
|
- | 427 | ||
418 | switch (IPC_GET_METHOD(call)) { |
428 | switch (IPC_GET_METHOD(call)) { |
419 | case IPC_M_PHONE_HUNGUP: |
429 | case IPC_M_PHONE_HUNGUP: |
420 | /* TODO: Handle hangup */ |
430 | /* TODO: Handle hangup */ |
421 | return; |
431 | return; |
422 | case KBD_MS_LEFT: |
- | |
423 | newcon = gcons_mouse_btn(IPC_GET_ARG1(call)); |
- | |
424 | if (newcon != -1) |
- | |
425 | change_console(newcon); |
- | |
426 | retval = 0; |
- | |
427 | break; |
- | |
428 | case KBD_MS_MOVE: |
- | |
429 | gcons_mouse_move(IPC_GET_ARG1(call), |
- | |
430 | IPC_GET_ARG2(call)); |
- | |
431 | retval = 0; |
- | |
432 | break; |
- | |
433 | case KBD_EVENT: |
432 | case KBD_EVENT: |
434 | /* Got event from keyboard driver. */ |
433 | /* Got event from keyboard driver. */ |
435 | retval = 0; |
434 | retval = 0; |
436 | ev.type = IPC_GET_ARG1(call); |
435 | ev.type = IPC_GET_ARG1(call); |
437 | ev.key = IPC_GET_ARG2(call); |
436 | ev.key = IPC_GET_ARG2(call); |
438 | ev.mods = IPC_GET_ARG3(call); |
437 | ev.mods = IPC_GET_ARG3(call); |
439 | ev.c = IPC_GET_ARG4(call); |
438 | ev.c = IPC_GET_ARG4(call); |
440 | 439 | ||
441 | /* Switch to another virtual console */ |
- | |
442 | conn = &connections[active_console]; |
- | |
443 | - | ||
444 | if ((ev.key >= KC_F1) && (ev.key < KC_F1 + |
440 | if ((ev.key >= KC_F1) && (ev.key < KC_F1 + |
445 | CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) { |
441 | CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) { |
446 | if (ev.key == KC_F12) |
442 | if (ev.key == KC_F1 + KERNEL_CONSOLE) |
447 | change_console(KERNEL_CONSOLE); |
443 | change_console(kernel_console); |
448 | else |
444 | else |
449 | change_console(ev.key - KC_F1); |
445 | change_console(&consoles[ev.key - KC_F1]); |
450 | break; |
446 | break; |
451 | } |
447 | } |
452 | 448 | ||
453 | /* If client is awaiting key, send it */ |
- | |
454 | if (conn->keyrequest_counter > 0) { |
- | |
455 | conn->keyrequest_counter--; |
- | |
456 | ipc_answer_4(fifo_pop(conn->keyrequests), EOK, |
- | |
457 | ev.type, ev.key, ev.mods, ev.c); |
- | |
458 | break; |
- | |
459 | } |
- | |
460 | - | ||
461 | keybuffer_push(&conn->keybuffer, &ev); |
449 | keybuffer_push(&active_console->keybuffer, &ev); |
462 | retval = 0; |
- | |
463 | - | ||
464 | break; |
450 | break; |
465 | default: |
451 | default: |
466 | retval = ENOENT; |
452 | retval = ENOENT; |
467 | } |
453 | } |
468 | ipc_answer_0(callid, retval); |
454 | ipc_answer_0(callid, retval); |
469 | } |
455 | } |
470 | } |
456 | } |
471 | 457 | ||
472 | /** Handle CONSOLE_WRITE call. */ |
- | |
473 | static void cons_write(int consnum, ipc_callid_t rid, ipc_call_t *request) |
458 | static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request) |
474 | { |
459 | { |
475 | ipc_callid_t callid; |
460 | ipc_callid_t callid; |
476 | size_t size; |
461 | size_t size; |
477 | wchar_t ch; |
- | |
478 | size_t off; |
- | |
479 | - | ||
480 | if (!ipc_data_write_receive(&callid, &size)) { |
462 | if (!ipc_data_write_receive(&callid, &size)) { |
481 | ipc_answer_0(callid, EINVAL); |
463 | ipc_answer_0(callid, EINVAL); |
482 | ipc_answer_0(rid, EINVAL); |
464 | ipc_answer_0(rid, EINVAL); |
483 | return; |
465 | return; |
484 | } |
466 | } |
485 | 467 | ||
- | 468 | char *buf = (char *) malloc(size); |
|
486 | if (size > CWRITE_BUF_SIZE) |
469 | if (buf == NULL) { |
- | 470 | ipc_answer_0(callid, ENOMEM); |
|
487 | size = CWRITE_BUF_SIZE; |
471 | ipc_answer_0(rid, ENOMEM); |
- | 472 | return; |
|
- | 473 | } |
|
488 | 474 | ||
489 | (void) ipc_data_write_finalize(callid, cwrite_buf, size); |
475 | (void) ipc_data_write_finalize(callid, buf, size); |
490 | 476 | ||
491 | async_serialize_start(); |
477 | async_serialize_start(); |
492 | 478 | ||
493 | off = 0; |
479 | size_t off = 0; |
494 | while (off < size) { |
480 | while (off < size) { |
495 | ch = str_decode(cwrite_buf, &off, size); |
481 | wchar_t ch = str_decode(buf, &off, size); |
496 | write_char(consnum, ch); |
482 | write_char(cons, ch); |
497 | } |
483 | } |
498 | 484 | ||
- | 485 | if (cons == active_console) |
|
- | 486 | curs_goto(cons->scr.position_x, cons->scr.position_y); |
|
- | 487 | ||
499 | async_serialize_end(); |
488 | async_serialize_end(); |
500 | 489 | ||
501 | gcons_notify_char(consnum); |
490 | gcons_notify_char(cons->index); |
502 | ipc_answer_1(rid, EOK, size); |
491 | ipc_answer_1(rid, EOK, size); |
- | 492 | ||
- | 493 | free(buf); |
|
- | 494 | } |
|
- | 495 | ||
- | 496 | static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request) |
|
- | 497 | { |
|
- | 498 | ipc_callid_t callid; |
|
- | 499 | size_t size; |
|
- | 500 | if (!ipc_data_read_receive(&callid, &size)) { |
|
- | 501 | ipc_answer_0(callid, EINVAL); |
|
- | 502 | ipc_answer_0(rid, EINVAL); |
|
- | 503 | return; |
|
- | 504 | } |
|
- | 505 | ||
- | 506 | char *buf = (char *) malloc(size); |
|
- | 507 | if (buf == NULL) { |
|
- | 508 | ipc_answer_0(callid, ENOMEM); |
|
- | 509 | ipc_answer_0(rid, ENOMEM); |
|
- | 510 | return; |
|
- | 511 | } |
|
- | 512 | ||
- | 513 | async_serialize_start(); |
|
- | 514 | ||
- | 515 | size_t pos = 0; |
|
- | 516 | console_event_t ev; |
|
- | 517 | while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) { |
|
- | 518 | if (ev.type == KEY_PRESS) { |
|
- | 519 | buf[pos] = ev.c; |
|
- | 520 | pos++; |
|
- | 521 | } |
|
- | 522 | } |
|
- | 523 | ||
- | 524 | if (pos == size) { |
|
- | 525 | (void) ipc_data_read_finalize(callid, buf, size); |
|
- | 526 | ipc_answer_1(rid, EOK, size); |
|
- | 527 | free(buf); |
|
- | 528 | } else { |
|
- | 529 | pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t)); |
|
- | 530 | if (!pr) { |
|
- | 531 | ipc_answer_0(rid, ENOMEM); |
|
- | 532 | free(buf); |
|
- | 533 | async_serialize_end(); |
|
- | 534 | return; |
|
- | 535 | } |
|
- | 536 | ||
- | 537 | pr->cons = cons; |
|
- | 538 | pr->rid = rid; |
|
- | 539 | pr->callid = callid; |
|
- | 540 | pr->pos = pos; |
|
- | 541 | pr->size = size; |
|
- | 542 | pr->data = buf; |
|
- | 543 | list_append(&pr->link, &pending_input); |
|
- | 544 | } |
|
- | 545 | ||
- | 546 | async_serialize_end(); |
|
- | 547 | } |
|
- | 548 | ||
- | 549 | static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request) |
|
- | 550 | { |
|
- | 551 | async_serialize_start(); |
|
- | 552 | ||
- | 553 | console_event_t ev; |
|
- | 554 | if (keybuffer_pop(&cons->keybuffer, &ev)) { |
|
- | 555 | ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c); |
|
- | 556 | } else { |
|
- | 557 | pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t)); |
|
- | 558 | if (!pr) { |
|
- | 559 | ipc_answer_0(rid, ENOMEM); |
|
- | 560 | async_serialize_end(); |
|
- | 561 | return; |
|
- | 562 | } |
|
- | 563 | ||
- | 564 | pr->cons = cons; |
|
- | 565 | pr->rid = rid; |
|
- | 566 | pr->callid = 0; |
|
- | 567 | pr->data = NULL; |
|
- | 568 | list_append(&pr->link, &pending_input); |
|
- | 569 | } |
|
- | 570 | ||
- | 571 | async_serialize_end(); |
|
503 | } |
572 | } |
504 | 573 | ||
505 | /** Default thread for new connections */ |
574 | /** Default thread for new connections */ |
506 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
575 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
507 | { |
576 | { |
508 | ipc_callid_t callid; |
- | |
509 | ipc_call_t call; |
- | |
510 | int consnum; |
- | |
511 | ipcarg_t arg1, arg2, arg3, arg4; |
- | |
512 | connection_t *conn; |
577 | console_t *cons = NULL; |
513 | screenbuffer_t *scr; |
- | |
514 | 578 | ||
- | 579 | size_t i; |
|
- | 580 | for (i = 0; i < CONSOLE_COUNT; i++) { |
|
- | 581 | if (i == KERNEL_CONSOLE) |
|
- | 582 | continue; |
|
- | 583 | ||
515 | if ((consnum = find_free_connection()) == -1) { |
584 | if (consoles[i].dev_handle == (dev_handle_t) IPC_GET_ARG1(*icall)) { |
- | 585 | cons = &consoles[i]; |
|
- | 586 | break; |
|
- | 587 | } |
|
- | 588 | } |
|
- | 589 | ||
- | 590 | if (cons == NULL) { |
|
516 | ipc_answer_0(iid, ELIMIT); |
591 | ipc_answer_0(iid, ENOENT); |
517 | return; |
592 | return; |
518 | } |
593 | } |
- | 594 | ||
519 | conn = &connections[consnum]; |
595 | ipc_callid_t callid; |
- | 596 | ipc_call_t call; |
|
520 | conn->used = 1; |
597 | ipcarg_t arg1; |
- | 598 | ipcarg_t arg2; |
|
- | 599 | ipcarg_t arg3; |
|
521 | 600 | ||
522 | async_serialize_start(); |
601 | async_serialize_start(); |
523 | gcons_notify_connect(consnum); |
602 | if (cons->refcount == 0) |
524 | conn->client_phone = IPC_GET_ARG5(*icall); |
- | |
525 | screenbuffer_clear(&conn->screenbuffer); |
603 | gcons_notify_connect(cons->index); |
526 | if (consnum == active_console) |
- | |
- | 604 | ||
527 | clrscr(); |
605 | cons->refcount++; |
528 | 606 | ||
529 | /* Accept the connection */ |
607 | /* Accept the connection */ |
530 | ipc_answer_0(iid, EOK); |
608 | ipc_answer_0(iid, EOK); |
531 | 609 | ||
532 | while (true) { |
610 | while (true) { |
Line 535... | Line 613... | ||
535 | async_serialize_start(); |
613 | async_serialize_start(); |
536 | 614 | ||
537 | arg1 = 0; |
615 | arg1 = 0; |
538 | arg2 = 0; |
616 | arg2 = 0; |
539 | arg3 = 0; |
617 | arg3 = 0; |
540 | arg4 = 0; |
- | |
541 | 618 | ||
542 | switch (IPC_GET_METHOD(call)) { |
619 | switch (IPC_GET_METHOD(call)) { |
543 | case IPC_M_PHONE_HUNGUP: |
620 | case IPC_M_PHONE_HUNGUP: |
544 | gcons_notify_disconnect(consnum); |
621 | cons->refcount--; |
545 | - | ||
546 | /* Answer all pending requests */ |
- | |
547 | while (conn->keyrequest_counter > 0) { |
622 | if (cons->refcount == 0) |
548 | conn->keyrequest_counter--; |
623 | gcons_notify_disconnect(cons->index); |
549 | ipc_answer_0(fifo_pop(conn->keyrequests), |
- | |
550 | ENOENT); |
- | |
551 | break; |
- | |
552 | } |
- | |
553 | conn->used = 0; |
- | |
554 | return; |
624 | return; |
555 | case CONSOLE_PUTCHAR: |
625 | case VFS_READ: |
- | 626 | async_serialize_end(); |
|
556 | write_char(consnum, IPC_GET_ARG1(call)); |
627 | cons_read(cons, callid, &call); |
557 | gcons_notify_char(consnum); |
628 | async_serialize_start(); |
558 | break; |
629 | continue; |
559 | case CONSOLE_WRITE: |
630 | case VFS_WRITE: |
560 | async_serialize_end(); |
631 | async_serialize_end(); |
561 | cons_write(consnum, callid, &call); |
632 | cons_write(cons, callid, &call); |
562 | async_serialize_start(); |
633 | async_serialize_start(); |
563 | continue; |
634 | continue; |
- | 635 | case VFS_SYNC: |
|
- | 636 | fb_pending_flush(); |
|
- | 637 | if (cons == active_console) { |
|
- | 638 | async_req_0_0(fb_info.phone, FB_FLUSH); |
|
- | 639 | ||
- | 640 | curs_goto(cons->scr.position_x, cons->scr.position_y); |
|
- | 641 | } |
|
- | 642 | break; |
|
564 | case CONSOLE_CLEAR: |
643 | case CONSOLE_CLEAR: |
565 | /* Send message to fb */ |
644 | /* Send message to fb */ |
566 | if (consnum == active_console) { |
645 | if (cons == active_console) |
567 | async_msg_0(fb_info.phone, FB_CLEAR); |
646 | async_msg_0(fb_info.phone, FB_CLEAR); |
568 | } |
- | |
569 | 647 | ||
570 | screenbuffer_clear(&conn->screenbuffer); |
648 | screenbuffer_clear(&cons->scr); |
571 | 649 | ||
572 | break; |
650 | break; |
573 | case CONSOLE_GOTO: |
651 | case CONSOLE_GOTO: |
574 | screenbuffer_goto(&conn->screenbuffer, |
652 | screenbuffer_goto(&cons->scr, |
575 | IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
653 | IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
576 | if (consnum == active_console) |
654 | if (cons == active_console) |
577 | curs_goto(IPC_GET_ARG1(call), |
655 | curs_goto(IPC_GET_ARG1(call), |
578 | IPC_GET_ARG2(call)); |
656 | IPC_GET_ARG2(call)); |
579 | break; |
657 | break; |
580 | case CONSOLE_GETSIZE: |
658 | case CONSOLE_GET_SIZE: |
581 | arg1 = fb_info.rows; |
659 | arg1 = fb_info.cols; |
582 | arg2 = fb_info.cols; |
660 | arg2 = fb_info.rows; |
583 | break; |
- | |
584 | case CONSOLE_FLUSH: |
- | |
585 | fb_pending_flush(); |
- | |
586 | if (consnum == active_console) { |
- | |
587 | async_req_0_0(fb_info.phone, FB_FLUSH); |
- | |
588 | - | ||
589 | scr = &(connections[consnum].screenbuffer); |
- | |
590 | curs_goto(scr->position_y, scr->position_x); |
- | |
591 | } |
- | |
592 | break; |
661 | break; |
593 | case CONSOLE_SET_STYLE: |
662 | case CONSOLE_SET_STYLE: |
594 | fb_pending_flush(); |
663 | fb_pending_flush(); |
595 | arg1 = IPC_GET_ARG1(call); |
664 | arg1 = IPC_GET_ARG1(call); |
596 | screenbuffer_set_style(&conn->screenbuffer, arg1); |
665 | screenbuffer_set_style(&cons->scr, arg1); |
597 | if (consnum == active_console) |
666 | if (cons == active_console) |
598 | set_style(arg1); |
667 | set_style(arg1); |
599 | break; |
668 | break; |
600 | case CONSOLE_SET_COLOR: |
669 | case CONSOLE_SET_COLOR: |
601 | fb_pending_flush(); |
670 | fb_pending_flush(); |
602 | arg1 = IPC_GET_ARG1(call); |
671 | arg1 = IPC_GET_ARG1(call); |
603 | arg2 = IPC_GET_ARG2(call); |
672 | arg2 = IPC_GET_ARG2(call); |
604 | arg3 = IPC_GET_ARG3(call); |
673 | arg3 = IPC_GET_ARG3(call); |
605 | screenbuffer_set_color(&conn->screenbuffer, arg1, |
674 | screenbuffer_set_color(&cons->scr, arg1, arg2, arg3); |
606 | arg2, arg3); |
- | |
607 | if (consnum == active_console) |
675 | if (cons == active_console) |
608 | set_color(arg1, arg2, arg3); |
676 | set_color(arg1, arg2, arg3); |
609 | break; |
677 | break; |
610 | case CONSOLE_SET_RGB_COLOR: |
678 | case CONSOLE_SET_RGB_COLOR: |
611 | fb_pending_flush(); |
679 | fb_pending_flush(); |
612 | arg1 = IPC_GET_ARG1(call); |
680 | arg1 = IPC_GET_ARG1(call); |
613 | arg2 = IPC_GET_ARG2(call); |
681 | arg2 = IPC_GET_ARG2(call); |
614 | screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
682 | screenbuffer_set_rgb_color(&cons->scr, arg1, arg2); |
615 | arg2); |
- | |
616 | if (consnum == active_console) |
683 | if (cons == active_console) |
617 | set_rgb_color(arg1, arg2); |
684 | set_rgb_color(arg1, arg2); |
618 | break; |
685 | break; |
619 | case CONSOLE_CURSOR_VISIBILITY: |
686 | case CONSOLE_CURSOR_VISIBILITY: |
620 | fb_pending_flush(); |
687 | fb_pending_flush(); |
621 | arg1 = IPC_GET_ARG1(call); |
688 | arg1 = IPC_GET_ARG1(call); |
622 | conn->screenbuffer.is_cursor_visible = arg1; |
689 | cons->scr.is_cursor_visible = arg1; |
623 | if (consnum == active_console) |
690 | if (cons == active_console) |
624 | curs_visibility(arg1); |
691 | curs_visibility(arg1); |
625 | break; |
692 | break; |
626 | case CONSOLE_GETKEY: |
693 | case CONSOLE_GET_EVENT: |
627 | if (keybuffer_empty(&conn->keybuffer)) { |
- | |
628 | /* buffer is empty -> store request */ |
- | |
629 | if (conn->keyrequest_counter < |
694 | async_serialize_end(); |
630 | MAX_KEYREQUESTS_BUFFERED) { |
- | |
631 | fifo_push(conn->keyrequests, callid); |
695 | cons_get_event(cons, callid, &call); |
632 | conn->keyrequest_counter++; |
- | |
633 | } else { |
- | |
634 | /* |
- | |
635 | * No key available and too many |
- | |
636 | * requests => fail. |
- | |
637 | */ |
- | |
638 | ipc_answer_0(callid, ELIMIT); |
696 | async_serialize_start(); |
639 | } |
- | |
640 | continue; |
697 | continue; |
641 | } |
- | |
642 | kbd_event_t ev; |
- | |
643 | keybuffer_pop(&conn->keybuffer, &ev); |
- | |
644 | arg1 = ev.type; |
- | |
645 | arg2 = ev.key; |
- | |
646 | arg3 = ev.mods; |
- | |
647 | arg4 = ev.c; |
- | |
648 | break; |
- | |
649 | case CONSOLE_KCON_ENABLE: |
698 | case CONSOLE_KCON_ENABLE: |
650 | change_console(KERNEL_CONSOLE); |
699 | change_console(kernel_console); |
651 | break; |
700 | break; |
652 | } |
701 | } |
653 | ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4); |
702 | ipc_answer_3(callid, EOK, arg1, arg2, arg3); |
654 | } |
703 | } |
655 | } |
704 | } |
656 | 705 | ||
657 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
706 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
658 | { |
707 | { |
659 | change_console(prev_console); |
708 | change_console(prev_console); |
660 | } |
709 | } |
661 | 710 | ||
662 | int main(int argc, char *argv[]) |
711 | static bool console_init(void) |
663 | { |
712 | { |
664 | printf(NAME ": HelenOS Console service\n"); |
- | |
665 | - | ||
666 | ipcarg_t phonehash; |
- | |
667 | size_t ib_size; |
- | |
668 | int i; |
- | |
669 | - | ||
670 | async_set_client_connection(client_connection); |
- | |
671 | - | ||
672 | /* Connect to keyboard driver */ |
713 | /* Connect to keyboard driver */ |
- | 714 | ||
673 | kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
715 | kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
674 | if (kbd_phone < 0) { |
716 | if (kbd_phone < 0) { |
675 | printf(NAME ": Failed to connect to keyboard service\n"); |
717 | printf(NAME ": Failed to connect to keyboard service\n"); |
676 | return -1; |
718 | return false; |
677 | } |
719 | } |
678 | 720 | ||
- | 721 | ipcarg_t phonehash; |
|
679 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { |
722 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { |
680 | printf(NAME ": Failed to create callback from keyboard service\n"); |
723 | printf(NAME ": Failed to create callback from keyboard service\n"); |
681 | return -1; |
724 | return false; |
682 | } |
725 | } |
683 | 726 | ||
- | 727 | async_set_pending(process_pending_input); |
|
684 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
728 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
685 | 729 | ||
686 | /* Connect to framebuffer driver */ |
730 | /* Connect to framebuffer driver */ |
687 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0); |
731 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0); |
688 | if (fb_info.phone < 0) { |
732 | if (fb_info.phone < 0) { |
689 | printf(NAME ": Failed to connect to video service\n"); |
733 | printf(NAME ": Failed to connect to video service\n"); |
690 | return -1; |
734 | return -1; |
691 | } |
735 | } |
692 | 736 | ||
693 | /* Disable kernel output to the console */ |
737 | /* Register driver */ |
694 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE); |
738 | int rc = devmap_driver_register(NAME, client_connection); |
- | 739 | if (rc < 0) { |
|
- | 740 | printf(NAME ": Unable to register driver (%d)\n", rc); |
|
- | 741 | return false; |
|
- | 742 | } |
|
695 | 743 | ||
696 | /* Initialize gcons */ |
744 | /* Initialize gcons */ |
697 | gcons_init(fb_info.phone); |
745 | gcons_init(fb_info.phone); |
698 | /* Synchronize, the gcons can have something in queue */ |
- | |
699 | async_req_0_0(fb_info.phone, FB_FLUSH); |
- | |
700 | 746 | ||
701 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
747 | /* Synchronize, the gcons could put something in queue */ |
702 | &fb_info.cols); |
- | |
703 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
- | |
704 | clrscr(); |
- | |
705 | - | ||
706 | /* Init virtual consoles */ |
- | |
707 | for (i = 0; i < CONSOLE_COUNT; i++) { |
- | |
708 | connections[i].used = 0; |
- | |
709 | keybuffer_init(&connections[i].keybuffer); |
748 | async_req_0_0(fb_info.phone, FB_FLUSH); |
710 | - | ||
711 | connections[i].keyrequests.head = 0; |
- | |
712 | connections[i].keyrequests.tail = 0; |
- | |
713 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
- | |
714 | connections[i].keyrequest_counter = 0; |
- | |
715 | - | ||
716 | if (screenbuffer_init(&connections[i].screenbuffer, |
- | |
717 | fb_info.cols, fb_info.rows) == NULL) { |
749 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); |
718 | /* FIXME: handle error */ |
- | |
719 | return -1; |
- | |
720 | } |
- | |
721 | } |
- | |
722 | connections[KERNEL_CONSOLE].used = 1; |
- | |
723 | 750 | ||
724 | /* Set up shared memory buffer. */ |
751 | /* Set up shared memory buffer. */ |
725 | ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; |
752 | size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; |
726 | interbuffer = as_get_mappable_page(ib_size); |
753 | interbuffer = as_get_mappable_page(ib_size); |
727 | 754 | ||
728 | fb_pending.cnt = 0; |
- | |
729 | - | ||
730 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ | |
755 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ | |
731 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) { |
756 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) |
732 | interbuffer = NULL; |
757 | interbuffer = NULL; |
733 | } |
- | |
734 | 758 | ||
735 | if (interbuffer) { |
759 | if (interbuffer) { |
736 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
760 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
737 | AS_AREA_READ) != EOK) { |
761 | AS_AREA_READ) != EOK) { |
738 | as_area_destroy(interbuffer); |
762 | as_area_destroy(interbuffer); |
739 | interbuffer = NULL; |
763 | interbuffer = NULL; |
740 | } |
764 | } |
741 | } |
765 | } |
742 | 766 | ||
743 | curs_goto(0, 0); |
767 | fb_pending.cnt = 0; |
744 | curs_visibility( |
- | |
745 | connections[active_console].screenbuffer.is_cursor_visible); |
- | |
746 | 768 | ||
747 | /* Register at NS */ |
769 | /* Inititalize consoles */ |
- | 770 | size_t i; |
|
- | 771 | for (i = 0; i < CONSOLE_COUNT; i++) { |
|
- | 772 | if (i != KERNEL_CONSOLE) { |
|
- | 773 | if (screenbuffer_init(&consoles[i].scr, |
|
- | 774 | fb_info.cols, fb_info.rows) == NULL) { |
|
- | 775 | printf(NAME ": Unable to allocate screen buffer %u\n", i); |
|
- | 776 | return false; |
|
- | 777 | } |
|
- | 778 | screenbuffer_clear(&consoles[i].scr); |
|
- | 779 | keybuffer_init(&consoles[i].keybuffer); |
|
- | 780 | consoles[i].index = i; |
|
- | 781 | consoles[i].refcount = 0; |
|
- | 782 | ||
- | 783 | char vc[MAX_DEVICE_NAME]; |
|
- | 784 | snprintf(vc, MAX_DEVICE_NAME, "vc%u", i); |
|
- | 785 | ||
748 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
786 | if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) { |
- | 787 | devmap_hangup_phone(DEVMAP_DRIVER); |
|
- | 788 | printf(NAME ": Unable to register device %s\n", vc); |
|
749 | return -1; |
789 | return false; |
- | 790 | } |
|
- | 791 | } |
|
- | 792 | } |
|
- | 793 | ||
- | 794 | /* Initialize the screen */ |
|
- | 795 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
|
- | 796 | screen_clear(); |
|
- | 797 | curs_goto(0, 0); |
|
- | 798 | curs_visibility(active_console->scr.is_cursor_visible); |
|
750 | 799 | ||
751 | /* Receive kernel notifications */ |
800 | /* Receive kernel notifications */ |
752 | if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) |
801 | if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) |
753 | printf(NAME ": Error registering kconsole notifications\n"); |
802 | printf(NAME ": Error registering kconsole notifications\n"); |
754 | 803 | ||
755 | async_set_interrupt_received(interrupt_received); |
804 | async_set_interrupt_received(interrupt_received); |
756 | 805 | ||
- | 806 | return true; |
|
- | 807 | } |
|
- | 808 | ||
- | 809 | int main(int argc, char *argv[]) |
|
- | 810 | { |
|
- | 811 | printf(NAME ": HelenOS Console service\n"); |
|
- | 812 | ||
757 | // FIXME: avoid connectiong to itself, keep using klog |
813 | /* Disable kernel output to the console */ |
- | 814 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE); |
|
- | 815 | ||
- | 816 | if (!console_init()) { |
|
- | 817 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
|
- | 818 | return -1; |
|
- | 819 | } |
|
- | 820 | ||
758 | // printf(NAME ": Accepting connections\n"); |
821 | printf(NAME ": Accepting connections\n"); |
759 | async_manager(); |
822 | async_manager(); |
760 | 823 | ||
761 | return 0; |
824 | return 0; |
762 | } |
825 | } |
763 | 826 |