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