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