Rev 4420 | Rev 4537 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4420 | Rev 4439 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Josef Cejka |
2 | * Copyright (c) 2006 Josef Cejka |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup console |
29 | /** @addtogroup console |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
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 <kbd.h> |
38 | #include <kbd.h> |
39 | #include <kbd/keycode.h> |
39 | #include <kbd/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 <key_buffer.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> |
48 | #include <screenbuffer.h> |
49 | #include <sys/mman.h> |
49 | #include <sys/mman.h> |
50 | #include <stdio.h> |
50 | #include <stdio.h> |
51 | #include <string.h> |
51 | #include <string.h> |
52 | #include <sysinfo.h> |
52 | #include <sysinfo.h> |
53 | #include <event.h> |
53 | #include <event.h> |
54 | 54 | ||
55 | #include "console.h" |
55 | #include "console.h" |
56 | #include "gcons.h" |
56 | #include "gcons.h" |
57 | 57 | ||
58 | #define MAX_KEYREQUESTS_BUFFERED 32 |
58 | #define NAME "console" |
59 | 59 | ||
- | 60 | #define MAX_KEYREQUESTS_BUFFERED 32 |
|
- | 61 | ||
- | 62 | /** Size of cwrite_buf. */ |
|
60 | #define NAME "console" |
63 | #define CWRITE_BUF_SIZE 256 |
61 | 64 | ||
62 | /** Index of currently used virtual console. |
65 | /** Index of currently used virtual console. |
63 | */ |
66 | */ |
64 | int active_console = 0; |
67 | int active_console = 0; |
65 | int prev_console = 0; |
68 | int prev_console = 0; |
66 | 69 | ||
67 | /** Phone to the keyboard driver. */ |
70 | /** Phone to the keyboard driver. */ |
68 | static int kbd_phone; |
71 | static int kbd_phone; |
69 | 72 | ||
70 | /** Information about framebuffer */ |
73 | /** Information about framebuffer */ |
71 | struct { |
74 | struct { |
72 | int phone; /**< Framebuffer phone */ |
75 | int phone; /**< Framebuffer phone */ |
73 | ipcarg_t rows; /**< Framebuffer rows */ |
76 | ipcarg_t rows; /**< Framebuffer rows */ |
74 | ipcarg_t cols; /**< Framebuffer columns */ |
77 | ipcarg_t cols; /**< Framebuffer columns */ |
75 | } fb_info; |
78 | } fb_info; |
76 | 79 | ||
77 | typedef struct { |
80 | typedef struct { |
78 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
81 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
- | 82 | ||
79 | /** Buffer for unsatisfied request for keys. */ |
83 | /** Buffer for unsatisfied request for keys. */ |
80 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t, |
84 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t, |
81 | MAX_KEYREQUESTS_BUFFERED); |
85 | MAX_KEYREQUESTS_BUFFERED); |
- | 86 | ||
82 | int keyrequest_counter; /**< Number of requests in buffer. */ |
87 | int keyrequest_counter; /**< Number of requests in buffer. */ |
83 | int client_phone; /**< Phone to connected client. */ |
88 | int client_phone; /**< Phone to connected client. */ |
84 | int used; /**< 1 if this virtual console is |
89 | int used; /**< 1 if this virtual console is |
85 | * connected to some client.*/ |
90 | connected to some client. */ |
86 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen |
91 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen |
87 | * contents and related settings. */ |
92 | contents and related settings. */ |
88 | } connection_t; |
93 | } connection_t; |
89 | 94 | ||
90 | static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual |
- | |
91 | * consoles */ |
95 | /** Array of data for virtual consoles */ |
92 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared |
96 | static connection_t connections[CONSOLE_COUNT]; |
- | 97 | ||
93 | * with framebufer used for |
98 | /** Pointer to memory shared with framebufer used for |
94 | * faster virtual console |
99 | faster virtual console switching */ |
95 | * switching */ |
100 | static keyfield_t *interbuffer = NULL; |
96 | 101 | ||
97 | /** Information on row-span yet unsent to FB driver. */ |
102 | /** Information on row-span yet unsent to FB driver. */ |
98 | struct { |
103 | struct { |
99 | int row; /**< Row where the span lies. */ |
104 | int row; /**< Row where the span lies. */ |
100 | int col; /**< Leftmost column of the span. */ |
105 | int col; /**< Leftmost column of the span. */ |
101 | int n; /**< Width of the span. */ |
106 | int cnt; /**< Width of the span. */ |
102 | } fb_pending; |
107 | } fb_pending; |
103 | 108 | ||
104 | /** Size of cwrite_buf. */ |
- | |
105 | #define CWRITE_BUF_SIZE 256 |
- | |
106 | - | ||
107 | /** Buffer for receiving data via the CONSOLE_WRITE call from the client. */ |
109 | /** Buffer for receiving data via the CONSOLE_WRITE call from the client. */ |
108 | static char cwrite_buf[CWRITE_BUF_SIZE]; |
110 | static char cwrite_buf[CWRITE_BUF_SIZE]; |
109 | 111 | ||
110 | static void fb_putchar(wchar_t c, int row, int col); |
- | |
111 | - | ||
112 | - | ||
113 | /** Find unused virtual console. |
112 | /** Find unused virtual console. |
114 | * |
113 | * |
115 | */ |
114 | */ |
116 | static int find_free_connection(void) |
115 | static int find_free_connection(void) |
117 | { |
116 | { |
118 | int i; |
117 | int i; |
119 | 118 | ||
120 | for (i = 0; i < CONSOLE_COUNT; i++) { |
119 | for (i = 0; i < CONSOLE_COUNT; i++) { |
121 | if (!connections[i].used) |
120 | if (!connections[i].used) |
122 | return i; |
121 | return i; |
123 | } |
122 | } |
- | 123 | ||
124 | return -1; |
124 | return -1; |
125 | } |
125 | } |
126 | 126 | ||
127 | static void clrscr(void) |
127 | static void clrscr(void) |
128 | { |
128 | { |
129 | async_msg_0(fb_info.phone, FB_CLEAR); |
129 | async_msg_0(fb_info.phone, FB_CLEAR); |
130 | } |
130 | } |
131 | 131 | ||
132 | static void curs_visibility(bool visible) |
132 | static void curs_visibility(bool visible) |
133 | { |
133 | { |
134 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
134 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
135 | } |
135 | } |
136 | 136 | ||
137 | static void curs_hide_sync(void) |
137 | static void curs_hide_sync(void) |
138 | { |
138 | { |
139 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
139 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
140 | } |
140 | } |
141 | 141 | ||
142 | static void curs_goto(int row, int col) |
142 | static void curs_goto(int row, int col) |
143 | { |
143 | { |
144 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
144 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
145 | } |
145 | } |
146 | 146 | ||
147 | static void screen_yield(void) |
147 | static void screen_yield(void) |
148 | { |
148 | { |
149 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD); |
149 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD); |
150 | } |
150 | } |
151 | 151 | ||
152 | static void screen_reclaim(void) |
152 | static void screen_reclaim(void) |
153 | { |
153 | { |
154 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_RECLAIM); |
154 | ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_RECLAIM); |
155 | } |
155 | } |
156 | 156 | ||
157 | static void kbd_yield(void) |
157 | static void kbd_yield(void) |
158 | { |
158 | { |
159 | ipc_call_sync_0_0(kbd_phone, KBD_YIELD); |
159 | ipc_call_sync_0_0(kbd_phone, KBD_YIELD); |
160 | } |
160 | } |
161 | 161 | ||
162 | static void kbd_reclaim(void) |
162 | static void kbd_reclaim(void) |
163 | { |
163 | { |
164 | ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM); |
164 | ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM); |
165 | } |
165 | } |
166 | 166 | ||
167 | static void set_style(int style) |
167 | static void set_style(int style) |
168 | { |
168 | { |
169 | async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
169 | async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
170 | } |
170 | } |
171 | 171 | ||
172 | static void set_color(int fgcolor, int bgcolor, int flags) |
172 | static void set_color(int fgcolor, int bgcolor, int flags) |
173 | { |
173 | { |
174 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
174 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
175 | } |
175 | } |
176 | 176 | ||
177 | static void set_rgb_color(int fgcolor, int bgcolor) |
177 | static void set_rgb_color(int fgcolor, int bgcolor) |
178 | { |
178 | { |
179 | async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); |
179 | async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); |
180 | } |
180 | } |
181 | 181 | ||
182 | static void set_attrs(attrs_t *attrs) |
182 | static void set_attrs(attrs_t *attrs) |
183 | { |
183 | { |
184 | switch (attrs->t) { |
184 | switch (attrs->t) { |
185 | case at_style: |
185 | case at_style: |
186 | set_style(attrs->a.s.style); |
186 | set_style(attrs->a.s.style); |
187 | break; |
187 | break; |
188 | - | ||
189 | case at_idx: |
188 | case at_idx: |
190 | set_color(attrs->a.i.fg_color, attrs->a.i.bg_color, |
189 | set_color(attrs->a.i.fg_color, attrs->a.i.bg_color, |
191 | attrs->a.i.flags); |
190 | attrs->a.i.flags); |
192 | break; |
191 | break; |
193 | - | ||
194 | case at_rgb: |
192 | case at_rgb: |
195 | set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color); |
193 | set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color); |
196 | break; |
194 | break; |
197 | } |
195 | } |
198 | } |
196 | } |
199 | 197 | ||
200 | /** Send an area of screenbuffer to the FB driver. */ |
198 | /** Send an area of screenbuffer to the FB driver. */ |
201 | static void fb_update_area(connection_t *conn, int x, int y, int w, int h) |
199 | static void fb_update_area(connection_t *conn, int x, int y, int w, int h) |
202 | { |
200 | { |
203 | int i, j; |
201 | int i; |
204 | int rc; |
202 | int j; |
205 | attrs_t *attrs; |
203 | attrs_t *attrs; |
206 | keyfield_t *field; |
204 | keyfield_t *field; |
207 | 205 | ||
208 | if (interbuffer) { |
206 | if (interbuffer) { |
209 | for (j = 0; j < h; j++) { |
207 | for (j = 0; j < h; j++) { |
210 | for (i = 0; i < w; i++) { |
208 | for (i = 0; i < w; i++) { |
211 | interbuffer[i + j * w] = |
209 | interbuffer[i + j * w] = |
212 | *get_field_at(&conn->screenbuffer, |
210 | *get_field_at(&conn->screenbuffer, x + i, y + j); |
213 | x + i, y + j); |
- | |
214 | } |
211 | } |
215 | } |
212 | } |
216 | 213 | ||
217 | rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
214 | async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
218 | x, y, w, h); |
215 | x, y, w, h); |
219 | } else { |
- | |
220 | rc = ENOTSUP; |
- | |
221 | } |
- | |
222 | - | ||
223 | if (rc != 0) { |
- | |
224 | /* |
- | |
225 | attrs = &conn->screenbuffer.attrs; |
- | |
226 | - | ||
227 | for (j = 0; j < h; j++) { |
- | |
228 | for (i = 0; i < w; i++) { |
- | |
229 | field = get_field_at(&conn->screenbuffer, |
- | |
230 | x + i, y + j); |
- | |
231 | if (!attrs_same(*attrs, field->attrs)) |
- | |
232 | set_attrs(&field->attrs); |
- | |
233 | attrs = &field->attrs; |
- | |
234 | - | ||
235 | fb_putchar(field->character, y + j, x + i); |
- | |
236 | } |
- | |
237 | }*/ |
- | |
238 | } |
216 | } |
239 | } |
217 | } |
240 | 218 | ||
241 | /** Flush pending cells to FB. */ |
219 | /** Flush pending cells to FB. */ |
242 | static void fb_pending_flush(void) |
220 | static void fb_pending_flush(void) |
243 | { |
221 | { |
244 | screenbuffer_t *scr; |
222 | screenbuffer_t *scr |
245 | - | ||
246 | scr = &(connections[active_console].screenbuffer); |
223 | = &(connections[active_console].screenbuffer); |
247 | 224 | ||
248 | if (fb_pending.n > 0) { |
225 | if (fb_pending.cnt > 0) { |
249 | fb_update_area(&connections[active_console], fb_pending.col, |
226 | fb_update_area(&connections[active_console], fb_pending.col, |
250 | fb_pending.row, fb_pending.n, 1); |
227 | fb_pending.row, fb_pending.cnt, 1); |
251 | fb_pending.n = 0; |
228 | fb_pending.cnt = 0; |
252 | } |
229 | } |
253 | } |
230 | } |
254 | 231 | ||
255 | /** Mark a character cell as changed. |
232 | /** Mark a character cell as changed. |
256 | * |
233 | * |
257 | * This adds the cell to the pending rowspan if possible. Otherwise |
234 | * This adds the cell to the pending rowspan if possible. Otherwise |
258 | * the old span is flushed first. |
235 | * the old span is flushed first. |
- | 236 | * |
|
259 | */ |
237 | */ |
260 | static void cell_mark_changed(int row, int col) |
238 | static void cell_mark_changed(int row, int col) |
261 | { |
239 | { |
262 | if (fb_pending.n != 0) { |
240 | if (fb_pending.cnt != 0) { |
263 | if (row != fb_pending.row || |
241 | if ((row != fb_pending.row) |
264 | col != fb_pending.col + fb_pending.n) { |
242 | || (col != fb_pending.col + fb_pending.cnt)) { |
265 | fb_pending_flush(); |
243 | fb_pending_flush(); |
266 | } |
244 | } |
267 | } |
245 | } |
268 | 246 | ||
269 | if (fb_pending.n == 0) { |
247 | if (fb_pending.cnt == 0) { |
270 | fb_pending.row = row; |
248 | fb_pending.row = row; |
271 | fb_pending.col = col; |
249 | fb_pending.col = col; |
272 | } |
250 | } |
273 | 251 | ||
274 | ++fb_pending.n; |
252 | fb_pending.cnt++; |
275 | } |
253 | } |
276 | 254 | ||
277 | - | ||
278 | /** Print a character to the active VC with buffering. */ |
255 | /** Print a character to the active VC with buffering. */ |
279 | static void fb_putchar(wchar_t c, int row, int col) |
256 | static void fb_putchar(wchar_t c, int row, int col) |
280 | { |
257 | { |
281 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
258 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
282 | } |
259 | } |
283 | 260 | ||
284 | /** Process a character from the client (TTY emulation). */ |
261 | /** Process a character from the client (TTY emulation). */ |
285 | static void write_char(int console, wchar_t ch) |
262 | static void write_char(int console, wchar_t ch) |
286 | { |
263 | { |
287 | bool flush_cursor = false; |
264 | bool flush_cursor = false; |
288 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
265 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
289 | 266 | ||
290 | switch (ch) { |
267 | switch (ch) { |
291 | case '\n': |
268 | case '\n': |
292 | fb_pending_flush(); |
269 | fb_pending_flush(); |
293 | flush_cursor = true; |
270 | flush_cursor = true; |
294 | scr->position_y++; |
271 | scr->position_y++; |
295 | scr->position_x = 0; |
272 | scr->position_x = 0; |
296 | break; |
273 | break; |
297 | case '\r': |
274 | case '\r': |
298 | break; |
275 | break; |
299 | case '\t': |
276 | case '\t': |
300 | scr->position_x += 8; |
277 | scr->position_x += 8; |
301 | scr->position_x -= scr->position_x % 8; |
278 | scr->position_x -= scr->position_x % 8; |
302 | break; |
279 | break; |
303 | case '\b': |
280 | case '\b': |
304 | if (scr->position_x == 0) |
281 | if (scr->position_x == 0) |
305 | break; |
282 | break; |
306 | scr->position_x--; |
283 | scr->position_x--; |
307 | if (console == active_console) |
284 | if (console == active_console) |
308 | cell_mark_changed(scr->position_y, scr->position_x); |
285 | cell_mark_changed(scr->position_y, scr->position_x); |
309 | screenbuffer_putchar(scr, ' '); |
286 | screenbuffer_putchar(scr, ' '); |
310 | break; |
287 | break; |
311 | default: |
288 | default: |
312 | if (console == active_console) |
289 | if (console == active_console) |
313 | cell_mark_changed(scr->position_y, scr->position_x); |
290 | cell_mark_changed(scr->position_y, scr->position_x); |
314 | 291 | ||
315 | screenbuffer_putchar(scr, ch); |
292 | screenbuffer_putchar(scr, ch); |
316 | scr->position_x++; |
293 | scr->position_x++; |
317 | } |
294 | } |
318 | 295 | ||
319 | if (scr->position_x >= scr->size_x) { |
296 | if (scr->position_x >= scr->size_x) { |
320 | flush_cursor = true; |
297 | flush_cursor = true; |
321 | scr->position_y++; |
298 | scr->position_y++; |
322 | } |
299 | } |
323 | 300 | ||
324 | if (scr->position_y >= scr->size_y) { |
301 | if (scr->position_y >= scr->size_y) { |
325 | fb_pending_flush(); |
302 | fb_pending_flush(); |
326 | scr->position_y = scr->size_y - 1; |
303 | scr->position_y = scr->size_y - 1; |
327 | screenbuffer_clear_line(scr, scr->top_line); |
304 | screenbuffer_clear_line(scr, scr->top_line); |
328 | scr->top_line = (scr->top_line + 1) % scr->size_y; |
305 | scr->top_line = (scr->top_line + 1) % scr->size_y; |
329 | if (console == active_console) |
306 | if (console == active_console) |
330 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
307 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
331 | } |
308 | } |
332 | 309 | ||
333 | scr->position_x = scr->position_x % scr->size_x; |
310 | scr->position_x = scr->position_x % scr->size_x; |
334 | 311 | ||
335 | if (console == active_console && flush_cursor) |
312 | if (console == active_console && flush_cursor) |
336 | curs_goto(scr->position_y, scr->position_x); |
313 | curs_goto(scr->position_y, scr->position_x); |
337 | } |
314 | } |
338 | 315 | ||
339 | /** Switch to new console */ |
316 | /** Switch to new console */ |
340 | static void change_console(int newcons) |
317 | static void change_console(int newcons) |
341 | { |
318 | { |
342 | connection_t *conn; |
319 | connection_t *conn; |
- | 320 | int i; |
|
- | 321 | int j; |
|
343 | int i, j, rc; |
322 | int rc; |
344 | keyfield_t *field; |
323 | keyfield_t *field; |
345 | attrs_t *attrs; |
324 | attrs_t *attrs; |
346 | 325 | ||
347 | if (newcons == active_console) |
326 | if (newcons == active_console) |
348 | return; |
327 | return; |
349 | 328 | ||
350 | fb_pending_flush(); |
329 | fb_pending_flush(); |
351 | 330 | ||
352 | if (newcons == KERNEL_CONSOLE) { |
331 | if (newcons == KERNEL_CONSOLE) { |
353 | async_serialize_start(); |
332 | async_serialize_start(); |
354 | curs_hide_sync(); |
333 | curs_hide_sync(); |
355 | gcons_in_kernel(); |
334 | gcons_in_kernel(); |
356 | screen_yield(); |
335 | screen_yield(); |
357 | kbd_yield(); |
336 | kbd_yield(); |
358 | async_serialize_end(); |
337 | async_serialize_end(); |
359 | 338 | ||
360 | 339 | ||
361 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { |
340 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { |
362 | prev_console = active_console; |
341 | prev_console = active_console; |
363 | active_console = KERNEL_CONSOLE; |
342 | active_console = KERNEL_CONSOLE; |
364 | } else |
343 | } else |
365 | newcons = active_console; |
344 | newcons = active_console; |
366 | } |
345 | } |
367 | 346 | ||
368 | if (newcons != KERNEL_CONSOLE) { |
347 | if (newcons != KERNEL_CONSOLE) { |
369 | async_serialize_start(); |
348 | async_serialize_start(); |
370 | 349 | ||
371 | if (active_console == KERNEL_CONSOLE) { |
350 | if (active_console == KERNEL_CONSOLE) { |
372 | screen_reclaim(); |
351 | screen_reclaim(); |
373 | kbd_reclaim(); |
352 | kbd_reclaim(); |
374 | gcons_redraw_console(); |
353 | gcons_redraw_console(); |
375 | } |
354 | } |
376 | 355 | ||
377 | active_console = newcons; |
356 | active_console = newcons; |
378 | gcons_change_console(newcons); |
357 | gcons_change_console(newcons); |
379 | conn = &connections[active_console]; |
358 | conn = &connections[active_console]; |
380 | 359 | ||
381 | set_attrs(&conn->screenbuffer.attrs); |
360 | set_attrs(&conn->screenbuffer.attrs); |
382 | curs_visibility(false); |
361 | curs_visibility(false); |
383 | if (interbuffer) { |
362 | if (interbuffer) { |
384 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
363 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
385 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
364 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
386 | unsigned int size_x; |
365 | unsigned int size_x; |
387 | 366 | ||
388 | size_x = conn->screenbuffer.size_x; |
367 | size_x = conn->screenbuffer.size_x; |
389 | interbuffer[j * size_x + i] = |
368 | interbuffer[j * size_x + i] = |
390 | *get_field_at(&conn->screenbuffer, i, j); |
369 | *get_field_at(&conn->screenbuffer, i, j); |
391 | } |
370 | } |
392 | } |
371 | } |
393 | /* This call can preempt, but we are already at the end */ |
372 | /* This call can preempt, but we are already at the end */ |
394 | rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
373 | rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
395 | 0, 0, conn->screenbuffer.size_x, |
374 | 0, 0, conn->screenbuffer.size_x, |
396 | conn->screenbuffer.size_y); |
375 | conn->screenbuffer.size_y); |
397 | } |
376 | } |
398 | 377 | ||
399 | if ((!interbuffer) || (rc != 0)) { |
378 | if ((!interbuffer) || (rc != 0)) { |
400 | set_attrs(&conn->screenbuffer.attrs); |
379 | set_attrs(&conn->screenbuffer.attrs); |
401 | clrscr(); |
380 | clrscr(); |
402 | attrs = &conn->screenbuffer.attrs; |
381 | attrs = &conn->screenbuffer.attrs; |
403 | 382 | ||
404 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
383 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
405 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
384 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
406 | field = get_field_at(&conn->screenbuffer, i, j); |
385 | field = get_field_at(&conn->screenbuffer, i, j); |
407 | if (!attrs_same(*attrs, field->attrs)) |
386 | if (!attrs_same(*attrs, field->attrs)) |
408 | set_attrs(&field->attrs); |
387 | set_attrs(&field->attrs); |
409 | attrs = &field->attrs; |
388 | attrs = &field->attrs; |
410 | if ((field->character == ' ') && |
389 | if ((field->character == ' ') && |
411 | (attrs_same(field->attrs, |
- | |
412 | conn->screenbuffer.attrs))) |
390 | (attrs_same(field->attrs, conn->screenbuffer.attrs))) |
413 | continue; |
391 | continue; |
414 | 392 | ||
415 | fb_putchar(field->character, j, i); |
393 | fb_putchar(field->character, j, i); |
416 | } |
394 | } |
417 | } |
395 | } |
418 | 396 | ||
419 | curs_goto(conn->screenbuffer.position_y, |
397 | curs_goto(conn->screenbuffer.position_y, |
420 | conn->screenbuffer.position_x); |
398 | conn->screenbuffer.position_x); |
421 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
399 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
422 | 400 | ||
423 | async_serialize_end(); |
401 | async_serialize_end(); |
424 | } |
402 | } |
425 | } |
403 | } |
426 | 404 | ||
427 | /** Handler for keyboard */ |
405 | /** Handler for keyboard */ |
428 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
406 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
429 | { |
407 | { |
430 | ipc_callid_t callid; |
408 | ipc_callid_t callid; |
431 | ipc_call_t call; |
409 | ipc_call_t call; |
432 | int retval; |
410 | int retval; |
433 | kbd_event_t ev; |
411 | kbd_event_t ev; |
434 | connection_t *conn; |
412 | connection_t *conn; |
435 | int newcon; |
413 | int newcon; |
436 | 414 | ||
437 | /* Ignore parameters, the connection is alread opened */ |
415 | /* Ignore parameters, the connection is alread opened */ |
438 | while (1) { |
416 | while (true) { |
439 | callid = async_get_call(&call); |
417 | callid = async_get_call(&call); |
440 | switch (IPC_GET_METHOD(call)) { |
418 | switch (IPC_GET_METHOD(call)) { |
441 | case IPC_M_PHONE_HUNGUP: |
419 | case IPC_M_PHONE_HUNGUP: |
442 | /* TODO: Handle hangup */ |
420 | /* TODO: Handle hangup */ |
443 | return; |
421 | return; |
444 | case KBD_MS_LEFT: |
422 | case KBD_MS_LEFT: |
445 | newcon = gcons_mouse_btn(IPC_GET_ARG1(call)); |
423 | newcon = gcons_mouse_btn(IPC_GET_ARG1(call)); |
446 | if (newcon != -1) |
424 | if (newcon != -1) |
447 | change_console(newcon); |
425 | change_console(newcon); |
448 | retval = 0; |
426 | retval = 0; |
449 | break; |
427 | break; |
450 | case KBD_MS_MOVE: |
428 | case KBD_MS_MOVE: |
451 | gcons_mouse_move(IPC_GET_ARG1(call), |
429 | gcons_mouse_move(IPC_GET_ARG1(call), |
452 | IPC_GET_ARG2(call)); |
430 | IPC_GET_ARG2(call)); |
453 | retval = 0; |
431 | retval = 0; |
454 | break; |
432 | break; |
455 | case KBD_EVENT: |
433 | case KBD_EVENT: |
456 | /* Got event from keyboard driver. */ |
434 | /* Got event from keyboard driver. */ |
457 | retval = 0; |
435 | retval = 0; |
458 | ev.type = IPC_GET_ARG1(call); |
436 | ev.type = IPC_GET_ARG1(call); |
459 | ev.key = IPC_GET_ARG2(call); |
437 | ev.key = IPC_GET_ARG2(call); |
460 | ev.mods = IPC_GET_ARG3(call); |
438 | ev.mods = IPC_GET_ARG3(call); |
461 | ev.c = IPC_GET_ARG4(call); |
439 | ev.c = IPC_GET_ARG4(call); |
462 | 440 | ||
463 | /* switch to another virtual console */ |
441 | /* Switch to another virtual console */ |
464 | - | ||
465 | conn = &connections[active_console]; |
442 | conn = &connections[active_console]; |
466 | 443 | ||
467 | if ((ev.key >= KC_F1) && (ev.key < KC_F1 + |
444 | if ((ev.key >= KC_F1) && (ev.key < KC_F1 + |
468 | CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) { |
445 | CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) { |
469 | if (ev.key == KC_F12) |
446 | if (ev.key == KC_F12) |
470 | change_console(KERNEL_CONSOLE); |
447 | change_console(KERNEL_CONSOLE); |
471 | else |
448 | else |
472 | change_console(ev.key - KC_F1); |
449 | change_console(ev.key - KC_F1); |
473 | break; |
450 | break; |
474 | } |
451 | } |
475 | 452 | ||
476 | /* if client is awaiting key, send it */ |
453 | /* If client is awaiting key, send it */ |
477 | if (conn->keyrequest_counter > 0) { |
454 | if (conn->keyrequest_counter > 0) { |
478 | conn->keyrequest_counter--; |
455 | conn->keyrequest_counter--; |
479 | ipc_answer_4(fifo_pop(conn->keyrequests), EOK, |
456 | ipc_answer_4(fifo_pop(conn->keyrequests), EOK, |
480 | ev.type, ev.key, ev.mods, ev.c); |
457 | ev.type, ev.key, ev.mods, ev.c); |
481 | break; |
458 | break; |
482 | } |
459 | } |
483 | 460 | ||
484 | keybuffer_push(&conn->keybuffer, &ev); |
461 | keybuffer_push(&conn->keybuffer, &ev); |
485 | retval = 0; |
462 | retval = 0; |
486 | 463 | ||
487 | break; |
464 | break; |
488 | default: |
465 | default: |
489 | retval = ENOENT; |
466 | retval = ENOENT; |
490 | } |
467 | } |
491 | ipc_answer_0(callid, retval); |
468 | ipc_answer_0(callid, retval); |
492 | } |
469 | } |
493 | } |
470 | } |
494 | 471 | ||
495 | /** Handle CONSOLE_WRITE call. */ |
472 | /** Handle CONSOLE_WRITE call. */ |
496 | static void cons_write(int consnum, ipc_callid_t rid, ipc_call_t *request) |
473 | static void cons_write(int consnum, ipc_callid_t rid, ipc_call_t *request) |
497 | { |
474 | { |
498 | ipc_callid_t callid; |
475 | ipc_callid_t callid; |
499 | size_t size; |
476 | size_t size; |
500 | wchar_t ch; |
477 | wchar_t ch; |
501 | size_t off; |
478 | size_t off; |
502 | 479 | ||
503 | if (!ipc_data_write_receive(&callid, &size)) { |
480 | if (!ipc_data_write_receive(&callid, &size)) { |
504 | ipc_answer_0(callid, EINVAL); |
481 | ipc_answer_0(callid, EINVAL); |
505 | ipc_answer_0(rid, EINVAL); |
482 | ipc_answer_0(rid, EINVAL); |
506 | return; |
483 | return; |
507 | } |
484 | } |
508 | 485 | ||
509 | if (size > CWRITE_BUF_SIZE) |
486 | if (size > CWRITE_BUF_SIZE) |
510 | size = CWRITE_BUF_SIZE; |
487 | size = CWRITE_BUF_SIZE; |
511 | 488 | ||
512 | (void) ipc_data_write_finalize(callid, cwrite_buf, size); |
489 | (void) ipc_data_write_finalize(callid, cwrite_buf, size); |
513 | 490 | ||
514 | async_serialize_start(); |
491 | async_serialize_start(); |
515 | 492 | ||
516 | off = 0; |
493 | off = 0; |
517 | while (off < size) { |
494 | while (off < size) { |
518 | ch = str_decode(cwrite_buf, &off, size); |
495 | ch = str_decode(cwrite_buf, &off, size); |
519 | write_char(consnum, ch); |
496 | write_char(consnum, ch); |
520 | } |
497 | } |
521 | 498 | ||
522 | async_serialize_end(); |
499 | async_serialize_end(); |
523 | 500 | ||
524 | gcons_notify_char(consnum); |
501 | gcons_notify_char(consnum); |
525 | ipc_answer_1(rid, EOK, size); |
502 | ipc_answer_1(rid, EOK, size); |
526 | } |
503 | } |
527 | 504 | ||
528 | /** Default thread for new connections */ |
505 | /** Default thread for new connections */ |
529 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
506 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
530 | { |
507 | { |
531 | ipc_callid_t callid; |
508 | ipc_callid_t callid; |
532 | ipc_call_t call; |
509 | ipc_call_t call; |
533 | int consnum; |
510 | int consnum; |
534 | ipcarg_t arg1, arg2, arg3, arg4; |
511 | ipcarg_t arg1, arg2, arg3, arg4; |
535 | connection_t *conn; |
512 | connection_t *conn; |
536 | screenbuffer_t *scr; |
513 | screenbuffer_t *scr; |
537 | 514 | ||
538 | if ((consnum = find_free_connection()) == -1) { |
515 | if ((consnum = find_free_connection()) == -1) { |
539 | ipc_answer_0(iid, ELIMIT); |
516 | ipc_answer_0(iid, ELIMIT); |
540 | return; |
517 | return; |
541 | } |
518 | } |
542 | conn = &connections[consnum]; |
519 | conn = &connections[consnum]; |
543 | conn->used = 1; |
520 | conn->used = 1; |
544 | 521 | ||
545 | async_serialize_start(); |
522 | async_serialize_start(); |
546 | gcons_notify_connect(consnum); |
523 | gcons_notify_connect(consnum); |
547 | conn->client_phone = IPC_GET_ARG5(*icall); |
524 | conn->client_phone = IPC_GET_ARG5(*icall); |
548 | screenbuffer_clear(&conn->screenbuffer); |
525 | screenbuffer_clear(&conn->screenbuffer); |
549 | if (consnum == active_console) |
526 | if (consnum == active_console) |
550 | clrscr(); |
527 | clrscr(); |
551 | 528 | ||
552 | /* Accept the connection */ |
529 | /* Accept the connection */ |
553 | ipc_answer_0(iid, EOK); |
530 | ipc_answer_0(iid, EOK); |
554 | 531 | ||
555 | while (1) { |
532 | while (true) { |
556 | async_serialize_end(); |
533 | async_serialize_end(); |
557 | callid = async_get_call(&call); |
534 | callid = async_get_call(&call); |
558 | async_serialize_start(); |
535 | async_serialize_start(); |
559 | 536 | ||
560 | arg1 = 0; |
537 | arg1 = 0; |
561 | arg2 = 0; |
538 | arg2 = 0; |
562 | arg3 = 0; |
539 | arg3 = 0; |
563 | arg4 = 0; |
540 | arg4 = 0; |
564 | 541 | ||
565 | switch (IPC_GET_METHOD(call)) { |
542 | switch (IPC_GET_METHOD(call)) { |
566 | case IPC_M_PHONE_HUNGUP: |
543 | case IPC_M_PHONE_HUNGUP: |
567 | gcons_notify_disconnect(consnum); |
544 | gcons_notify_disconnect(consnum); |
568 | 545 | ||
569 | /* Answer all pending requests */ |
546 | /* Answer all pending requests */ |
570 | while (conn->keyrequest_counter > 0) { |
547 | while (conn->keyrequest_counter > 0) { |
571 | conn->keyrequest_counter--; |
548 | conn->keyrequest_counter--; |
572 | ipc_answer_0(fifo_pop(conn->keyrequests), |
549 | ipc_answer_0(fifo_pop(conn->keyrequests), |
573 | ENOENT); |
550 | ENOENT); |
574 | break; |
551 | break; |
575 | } |
552 | } |
576 | conn->used = 0; |
553 | conn->used = 0; |
577 | return; |
554 | return; |
578 | case CONSOLE_PUTCHAR: |
555 | case CONSOLE_PUTCHAR: |
579 | write_char(consnum, IPC_GET_ARG1(call)); |
556 | write_char(consnum, IPC_GET_ARG1(call)); |
580 | gcons_notify_char(consnum); |
557 | gcons_notify_char(consnum); |
581 | break; |
558 | break; |
582 | case CONSOLE_WRITE: |
559 | case CONSOLE_WRITE: |
583 | async_serialize_end(); |
560 | async_serialize_end(); |
584 | cons_write(consnum, callid, &call); |
561 | cons_write(consnum, callid, &call); |
585 | async_serialize_start(); |
562 | async_serialize_start(); |
586 | continue; |
563 | continue; |
587 | case CONSOLE_CLEAR: |
564 | case CONSOLE_CLEAR: |
588 | /* Send message to fb */ |
565 | /* Send message to fb */ |
589 | if (consnum == active_console) { |
566 | if (consnum == active_console) { |
590 | async_msg_0(fb_info.phone, FB_CLEAR); |
567 | async_msg_0(fb_info.phone, FB_CLEAR); |
591 | } |
568 | } |
592 | 569 | ||
593 | screenbuffer_clear(&conn->screenbuffer); |
570 | screenbuffer_clear(&conn->screenbuffer); |
594 | 571 | ||
595 | break; |
572 | break; |
596 | case CONSOLE_GOTO: |
573 | case CONSOLE_GOTO: |
597 | screenbuffer_goto(&conn->screenbuffer, |
574 | screenbuffer_goto(&conn->screenbuffer, |
598 | IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
575 | IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
599 | if (consnum == active_console) |
576 | if (consnum == active_console) |
600 | curs_goto(IPC_GET_ARG1(call), |
577 | curs_goto(IPC_GET_ARG1(call), |
601 | IPC_GET_ARG2(call)); |
578 | IPC_GET_ARG2(call)); |
602 | break; |
579 | break; |
603 | case CONSOLE_GETSIZE: |
580 | case CONSOLE_GETSIZE: |
604 | arg1 = fb_info.rows; |
581 | arg1 = fb_info.rows; |
605 | arg2 = fb_info.cols; |
582 | arg2 = fb_info.cols; |
606 | break; |
583 | break; |
607 | case CONSOLE_FLUSH: |
584 | case CONSOLE_FLUSH: |
608 | fb_pending_flush(); |
585 | fb_pending_flush(); |
609 | if (consnum == active_console) { |
586 | if (consnum == active_console) { |
610 | async_req_0_0(fb_info.phone, FB_FLUSH); |
587 | async_req_0_0(fb_info.phone, FB_FLUSH); |
611 | 588 | ||
612 | scr = &(connections[consnum].screenbuffer); |
589 | scr = &(connections[consnum].screenbuffer); |
613 | curs_goto(scr->position_y, scr->position_x); |
590 | curs_goto(scr->position_y, scr->position_x); |
614 | } |
591 | } |
615 | break; |
592 | break; |
616 | case CONSOLE_SET_STYLE: |
593 | case CONSOLE_SET_STYLE: |
617 | fb_pending_flush(); |
594 | fb_pending_flush(); |
618 | arg1 = IPC_GET_ARG1(call); |
595 | arg1 = IPC_GET_ARG1(call); |
619 | screenbuffer_set_style(&conn->screenbuffer, arg1); |
596 | screenbuffer_set_style(&conn->screenbuffer, arg1); |
620 | if (consnum == active_console) |
597 | if (consnum == active_console) |
621 | set_style(arg1); |
598 | set_style(arg1); |
622 | break; |
599 | break; |
623 | case CONSOLE_SET_COLOR: |
600 | case CONSOLE_SET_COLOR: |
624 | fb_pending_flush(); |
601 | fb_pending_flush(); |
625 | arg1 = IPC_GET_ARG1(call); |
602 | arg1 = IPC_GET_ARG1(call); |
626 | arg2 = IPC_GET_ARG2(call); |
603 | arg2 = IPC_GET_ARG2(call); |
627 | arg3 = IPC_GET_ARG3(call); |
604 | arg3 = IPC_GET_ARG3(call); |
628 | screenbuffer_set_color(&conn->screenbuffer, arg1, |
605 | screenbuffer_set_color(&conn->screenbuffer, arg1, |
629 | arg2, arg3); |
606 | arg2, arg3); |
630 | if (consnum == active_console) |
607 | if (consnum == active_console) |
631 | set_color(arg1, arg2, arg3); |
608 | set_color(arg1, arg2, arg3); |
632 | break; |
609 | break; |
633 | case CONSOLE_SET_RGB_COLOR: |
610 | case CONSOLE_SET_RGB_COLOR: |
634 | fb_pending_flush(); |
611 | fb_pending_flush(); |
635 | arg1 = IPC_GET_ARG1(call); |
612 | arg1 = IPC_GET_ARG1(call); |
636 | arg2 = IPC_GET_ARG2(call); |
613 | arg2 = IPC_GET_ARG2(call); |
637 | screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
614 | screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
638 | arg2); |
615 | arg2); |
639 | if (consnum == active_console) |
616 | if (consnum == active_console) |
640 | set_rgb_color(arg1, arg2); |
617 | set_rgb_color(arg1, arg2); |
641 | break; |
618 | break; |
642 | case CONSOLE_CURSOR_VISIBILITY: |
619 | case CONSOLE_CURSOR_VISIBILITY: |
643 | fb_pending_flush(); |
620 | fb_pending_flush(); |
644 | arg1 = IPC_GET_ARG1(call); |
621 | arg1 = IPC_GET_ARG1(call); |
645 | conn->screenbuffer.is_cursor_visible = arg1; |
622 | conn->screenbuffer.is_cursor_visible = arg1; |
646 | if (consnum == active_console) |
623 | if (consnum == active_console) |
647 | curs_visibility(arg1); |
624 | curs_visibility(arg1); |
648 | break; |
625 | break; |
649 | case CONSOLE_GETKEY: |
626 | case CONSOLE_GETKEY: |
650 | if (keybuffer_empty(&conn->keybuffer)) { |
627 | if (keybuffer_empty(&conn->keybuffer)) { |
651 | /* buffer is empty -> store request */ |
628 | /* buffer is empty -> store request */ |
652 | if (conn->keyrequest_counter < |
629 | if (conn->keyrequest_counter < |
653 | MAX_KEYREQUESTS_BUFFERED) { |
630 | MAX_KEYREQUESTS_BUFFERED) { |
654 | fifo_push(conn->keyrequests, callid); |
631 | fifo_push(conn->keyrequests, callid); |
655 | conn->keyrequest_counter++; |
632 | conn->keyrequest_counter++; |
656 | } else { |
633 | } else { |
657 | /* |
634 | /* |
658 | * No key available and too many |
635 | * No key available and too many |
659 | * requests => fail. |
636 | * requests => fail. |
660 | */ |
637 | */ |
661 | ipc_answer_0(callid, ELIMIT); |
638 | ipc_answer_0(callid, ELIMIT); |
662 | } |
639 | } |
663 | continue; |
640 | continue; |
664 | } |
641 | } |
665 | kbd_event_t ev; |
642 | kbd_event_t ev; |
666 | keybuffer_pop(&conn->keybuffer, &ev); |
643 | keybuffer_pop(&conn->keybuffer, &ev); |
667 | arg1 = ev.type; |
644 | arg1 = ev.type; |
668 | arg2 = ev.key; |
645 | arg2 = ev.key; |
669 | arg3 = ev.mods; |
646 | arg3 = ev.mods; |
670 | arg4 = ev.c; |
647 | arg4 = ev.c; |
671 | break; |
648 | break; |
672 | case CONSOLE_KCON_ENABLE: |
649 | case CONSOLE_KCON_ENABLE: |
673 | change_console(KERNEL_CONSOLE); |
650 | change_console(KERNEL_CONSOLE); |
674 | break; |
651 | break; |
675 | } |
652 | } |
676 | ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4); |
653 | ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4); |
677 | } |
654 | } |
678 | } |
655 | } |
679 | 656 | ||
680 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
657 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
681 | { |
658 | { |
682 | change_console(prev_console); |
659 | change_console(prev_console); |
683 | } |
660 | } |
684 | 661 | ||
685 | int main(int argc, char *argv[]) |
662 | int main(int argc, char *argv[]) |
686 | { |
663 | { |
687 | printf(NAME ": HelenOS Console service\n"); |
664 | printf(NAME ": HelenOS Console service\n"); |
688 | 665 | ||
689 | ipcarg_t phonehash; |
666 | ipcarg_t phonehash; |
690 | size_t ib_size; |
667 | size_t ib_size; |
691 | int i; |
668 | int i; |
692 | 669 | ||
693 | async_set_client_connection(client_connection); |
670 | async_set_client_connection(client_connection); |
694 | 671 | ||
695 | /* Connect to keyboard driver */ |
672 | /* Connect to keyboard driver */ |
696 | kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
673 | kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
697 | if (kbd_phone < 0) { |
674 | if (kbd_phone < 0) { |
698 | printf(NAME ": Failed to connect to keyboard service\n"); |
675 | printf(NAME ": Failed to connect to keyboard service\n"); |
699 | return -1; |
676 | return -1; |
700 | } |
677 | } |
701 | 678 | ||
702 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { |
679 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { |
703 | printf(NAME ": Failed to create callback from keyboard service\n"); |
680 | printf(NAME ": Failed to create callback from keyboard service\n"); |
704 | return -1; |
681 | return -1; |
705 | } |
682 | } |
706 | 683 | ||
707 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
684 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
708 | 685 | ||
709 | /* Connect to framebuffer driver */ |
686 | /* Connect to framebuffer driver */ |
710 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0); |
687 | fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0); |
711 | if (fb_info.phone < 0) { |
688 | if (fb_info.phone < 0) { |
712 | printf(NAME ": Failed to connect to video service\n"); |
689 | printf(NAME ": Failed to connect to video service\n"); |
713 | return -1; |
690 | return -1; |
714 | } |
691 | } |
715 | 692 | ||
716 | /* Disable kernel output to the console */ |
693 | /* Disable kernel output to the console */ |
717 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE); |
694 | __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE); |
718 | 695 | ||
719 | /* Initialize gcons */ |
696 | /* Initialize gcons */ |
720 | gcons_init(fb_info.phone); |
697 | gcons_init(fb_info.phone); |
721 | /* Synchronize, the gcons can have something in queue */ |
698 | /* Synchronize, the gcons can have something in queue */ |
722 | async_req_0_0(fb_info.phone, FB_FLUSH); |
699 | async_req_0_0(fb_info.phone, FB_FLUSH); |
723 | 700 | ||
724 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
701 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
725 | &fb_info.cols); |
702 | &fb_info.cols); |
726 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
703 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
727 | clrscr(); |
704 | clrscr(); |
728 | 705 | ||
729 | /* Init virtual consoles */ |
706 | /* Init virtual consoles */ |
730 | for (i = 0; i < CONSOLE_COUNT; i++) { |
707 | for (i = 0; i < CONSOLE_COUNT; i++) { |
731 | connections[i].used = 0; |
708 | connections[i].used = 0; |
732 | keybuffer_init(&connections[i].keybuffer); |
709 | keybuffer_init(&connections[i].keybuffer); |
733 | 710 | ||
734 | connections[i].keyrequests.head = 0; |
711 | connections[i].keyrequests.head = 0; |
735 | connections[i].keyrequests.tail = 0; |
712 | connections[i].keyrequests.tail = 0; |
736 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
713 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
737 | connections[i].keyrequest_counter = 0; |
714 | connections[i].keyrequest_counter = 0; |
738 | 715 | ||
739 | if (screenbuffer_init(&connections[i].screenbuffer, |
716 | if (screenbuffer_init(&connections[i].screenbuffer, |
740 | fb_info.cols, fb_info.rows) == NULL) { |
717 | fb_info.cols, fb_info.rows) == NULL) { |
741 | /* FIXME: handle error */ |
718 | /* FIXME: handle error */ |
742 | return -1; |
719 | return -1; |
743 | } |
720 | } |
744 | } |
721 | } |
745 | connections[KERNEL_CONSOLE].used = 1; |
722 | connections[KERNEL_CONSOLE].used = 1; |
746 | 723 | ||
747 | /* Set up shared memory buffer. */ |
724 | /* Set up shared memory buffer. */ |
748 | ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; |
725 | ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; |
749 | interbuffer = as_get_mappable_page(ib_size); |
726 | interbuffer = as_get_mappable_page(ib_size); |
750 | 727 | ||
751 | fb_pending.n = 0; |
728 | fb_pending.cnt = 0; |
752 | 729 | ||
753 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ | |
730 | if (as_area_create(interbuffer, ib_size, AS_AREA_READ | |
754 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) { |
731 | AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) { |
755 | interbuffer = NULL; |
732 | interbuffer = NULL; |
756 | } |
733 | } |
757 | 734 | ||
758 | if (interbuffer) { |
735 | if (interbuffer) { |
759 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
736 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
760 | AS_AREA_READ) != EOK) { |
737 | AS_AREA_READ) != EOK) { |
761 | as_area_destroy(interbuffer); |
738 | as_area_destroy(interbuffer); |
762 | interbuffer = NULL; |
739 | interbuffer = NULL; |
763 | } |
740 | } |
764 | } |
741 | } |
765 | 742 | ||
766 | curs_goto(0, 0); |
743 | curs_goto(0, 0); |
767 | curs_visibility( |
744 | curs_visibility( |
768 | connections[active_console].screenbuffer.is_cursor_visible); |
745 | connections[active_console].screenbuffer.is_cursor_visible); |
769 | 746 | ||
770 | /* Register at NS */ |
747 | /* Register at NS */ |
771 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
748 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
772 | return -1; |
749 | return -1; |
773 | 750 | ||
774 | /* Receive kernel notifications */ |
751 | /* Receive kernel notifications */ |
775 | if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) |
752 | if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) |
776 | printf(NAME ": Error registering kconsole notifications\n"); |
753 | printf(NAME ": Error registering kconsole notifications\n"); |
777 | 754 | ||
778 | async_set_interrupt_received(interrupt_received); |
755 | async_set_interrupt_received(interrupt_received); |
779 | 756 | ||
780 | // FIXME: avoid connectiong to itself, keep using klog |
757 | // FIXME: avoid connectiong to itself, keep using klog |
781 | // printf(NAME ": Accepting connections\n"); |
758 | // printf(NAME ": Accepting connections\n"); |
782 | async_manager(); |
759 | async_manager(); |
783 | 760 | ||
784 | return 0; |
761 | return 0; |
785 | } |
762 | } |
786 | 763 | ||
787 | /** @} |
764 | /** @} |
788 | */ |
765 | */ |
789 | 766 |