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