Rev 4337 | Rev 4339 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4337 | Rev 4338 | ||
---|---|---|---|
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 <keys.h> |
38 | #include <keys.h> |
39 | #include <ipc/fb.h> |
39 | #include <ipc/fb.h> |
40 | #include <ipc/services.h> |
40 | #include <ipc/services.h> |
41 | #include <errno.h> |
41 | #include <errno.h> |
42 | #include <key_buffer.h> |
42 | #include <key_buffer.h> |
43 | #include <console.h> |
43 | #include <ipc/console.h> |
44 | #include <unistd.h> |
44 | #include <unistd.h> |
45 | #include <async.h> |
45 | #include <async.h> |
46 | #include <libadt/fifo.h> |
46 | #include <libadt/fifo.h> |
47 | #include <screenbuffer.h> |
47 | #include <screenbuffer.h> |
48 | #include <sys/mman.h> |
48 | #include <sys/mman.h> |
49 | #include <stdio.h> |
49 | #include <stdio.h> |
- | 50 | #include <sysinfo.h> |
|
50 | 51 | ||
- | 52 | #include "console.h" |
|
51 | #include "gcons.h" |
53 | #include "gcons.h" |
52 | 54 | ||
53 | #define MAX_KEYREQUESTS_BUFFERED 32 |
55 | #define MAX_KEYREQUESTS_BUFFERED 32 |
54 | 56 | ||
55 | #define NAME "console" |
57 | #define NAME "console" |
56 | 58 | ||
57 | /** Index of currently used virtual console. |
59 | /** Index of currently used virtual console. |
58 | */ |
60 | */ |
59 | int active_console = 0; |
61 | int active_console = 0; |
- | 62 | int prev_console = 0; |
|
60 | 63 | ||
61 | /** Information about framebuffer |
64 | /** Information about framebuffer |
62 | */ |
65 | */ |
63 | struct { |
66 | struct { |
64 | int phone; /**< Framebuffer phone */ |
67 | int phone; /**< Framebuffer phone */ |
65 | ipcarg_t rows; /**< Framebuffer rows */ |
68 | ipcarg_t rows; /**< Framebuffer rows */ |
66 | ipcarg_t cols; /**< Framebuffer columns */ |
69 | ipcarg_t cols; /**< Framebuffer columns */ |
67 | } fb_info; |
70 | } fb_info; |
68 | 71 | ||
69 | typedef struct { |
72 | typedef struct { |
70 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
73 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
71 | /** Buffer for unsatisfied request for keys. */ |
74 | /** Buffer for unsatisfied request for keys. */ |
72 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t, |
75 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t, |
73 | MAX_KEYREQUESTS_BUFFERED); |
76 | MAX_KEYREQUESTS_BUFFERED); |
74 | int keyrequest_counter; /**< Number of requests in buffer. */ |
77 | int keyrequest_counter; /**< Number of requests in buffer. */ |
75 | int client_phone; /**< Phone to connected client. */ |
78 | int client_phone; /**< Phone to connected client. */ |
76 | int used; /**< 1 if this virtual console is |
79 | int used; /**< 1 if this virtual console is |
77 | * connected to some client.*/ |
80 | * connected to some client.*/ |
78 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen |
81 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen |
79 | * contents and related settings. */ |
82 | * contents and related settings. */ |
80 | } connection_t; |
83 | } connection_t; |
81 | 84 | ||
82 | static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual |
85 | static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual |
83 | * consoles */ |
86 | * consoles */ |
84 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared |
87 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared |
85 | * with framebufer used for |
88 | * with framebufer used for |
86 | * faster virtual console |
89 | * faster virtual console |
87 | * switching */ |
90 | * switching */ |
88 | 91 | ||
89 | 92 | ||
90 | /** Find unused virtual console. |
93 | /** Find unused virtual console. |
91 | * |
94 | * |
92 | */ |
95 | */ |
93 | static int find_free_connection(void) |
96 | static int find_free_connection(void) |
94 | { |
97 | { |
95 | int i; |
98 | int i; |
96 | 99 | ||
97 | for (i = 0; i < CONSOLE_COUNT; i++) { |
100 | for (i = 0; i < CONSOLE_COUNT; i++) { |
98 | if (!connections[i].used) |
101 | if (!connections[i].used) |
99 | return i; |
102 | return i; |
100 | } |
103 | } |
101 | return -1; |
104 | return -1; |
102 | } |
105 | } |
103 | 106 | ||
104 | static void clrscr(void) |
107 | static void clrscr(void) |
105 | { |
108 | { |
106 | async_msg_0(fb_info.phone, FB_CLEAR); |
109 | async_msg_0(fb_info.phone, FB_CLEAR); |
107 | } |
110 | } |
108 | 111 | ||
109 | static void curs_visibility(bool visible) |
112 | static void curs_visibility(bool visible) |
110 | { |
113 | { |
111 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
114 | async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); |
112 | } |
115 | } |
113 | 116 | ||
114 | static void curs_hide_sync(void) |
117 | static void curs_hide_sync(void) |
115 | { |
118 | { |
116 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
119 | ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); |
117 | } |
120 | } |
118 | 121 | ||
119 | static void curs_goto(int row, int col) |
122 | static void curs_goto(int row, int col) |
120 | { |
123 | { |
121 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
124 | async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
122 | } |
125 | } |
123 | 126 | ||
124 | static void set_style(style_t *style) |
127 | static void set_style(int style) |
125 | { |
128 | { |
126 | async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color, |
129 | async_msg_1(fb_info.phone, FB_SET_STYLE, style); |
127 | style->bg_color); |
- | |
128 | } |
130 | } |
129 | 131 | ||
130 | static void set_style_col(int fgcolor, int bgcolor) |
132 | static void set_color(int fgcolor, int bgcolor, int flags) |
131 | { |
133 | { |
- | 134 | async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags); |
|
- | 135 | } |
|
- | 136 | ||
- | 137 | static void set_rgb_color(int fgcolor, int bgcolor) |
|
- | 138 | { |
|
132 | async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor); |
139 | async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor); |
- | 140 | } |
|
- | 141 | ||
- | 142 | static void set_attrs(attrs_t *attrs) |
|
- | 143 | { |
|
- | 144 | switch (attrs->t) { |
|
- | 145 | case at_style: |
|
- | 146 | set_style(attrs->a.s.style); |
|
- | 147 | break; |
|
- | 148 | ||
- | 149 | case at_idx: |
|
- | 150 | set_color(attrs->a.i.fg_color, attrs->a.i.bg_color, |
|
- | 151 | attrs->a.i.flags); |
|
- | 152 | break; |
|
- | 153 | ||
- | 154 | case at_rgb: |
|
- | 155 | set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color); |
|
- | 156 | break; |
|
- | 157 | } |
|
133 | } |
158 | } |
134 | 159 | ||
135 | static void prtchr(char c, int row, int col) |
160 | static void prtchr(char c, int row, int col) |
136 | { |
161 | { |
137 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
162 | async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
138 | } |
163 | } |
139 | 164 | ||
140 | /** Check key and process special keys. |
165 | /** Check key and process special keys. |
141 | * |
166 | * |
142 | * |
167 | * |
143 | */ |
168 | */ |
144 | static void write_char(int console, char key) |
169 | static void write_char(int console, char key) |
145 | { |
170 | { |
146 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
171 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
147 | 172 | ||
148 | switch (key) { |
173 | switch (key) { |
149 | case '\n': |
174 | case '\n': |
150 | scr->position_y++; |
175 | scr->position_y++; |
151 | scr->position_x = 0; |
176 | scr->position_x = 0; |
152 | break; |
177 | break; |
153 | case '\r': |
178 | case '\r': |
154 | break; |
179 | break; |
155 | case '\t': |
180 | case '\t': |
156 | scr->position_x += 8; |
181 | scr->position_x += 8; |
157 | scr->position_x -= scr->position_x % 8; |
182 | scr->position_x -= scr->position_x % 8; |
158 | break; |
183 | break; |
159 | case '\b': |
184 | case '\b': |
160 | if (scr->position_x == 0) |
185 | if (scr->position_x == 0) |
161 | break; |
186 | break; |
162 | scr->position_x--; |
187 | scr->position_x--; |
163 | if (console == active_console) |
188 | if (console == active_console) |
164 | prtchr(' ', scr->position_y, scr->position_x); |
189 | prtchr(' ', scr->position_y, scr->position_x); |
165 | screenbuffer_putchar(scr, ' '); |
190 | screenbuffer_putchar(scr, ' '); |
166 | break; |
191 | break; |
167 | default: |
192 | default: |
168 | if (console == active_console) |
193 | if (console == active_console) |
169 | prtchr(key, scr->position_y, scr->position_x); |
194 | prtchr(key, scr->position_y, scr->position_x); |
170 | 195 | ||
171 | screenbuffer_putchar(scr, key); |
196 | screenbuffer_putchar(scr, key); |
172 | scr->position_x++; |
197 | scr->position_x++; |
173 | } |
198 | } |
174 | 199 | ||
175 | scr->position_y += (scr->position_x >= scr->size_x); |
200 | scr->position_y += (scr->position_x >= scr->size_x); |
176 | 201 | ||
177 | if (scr->position_y >= scr->size_y) { |
202 | if (scr->position_y >= scr->size_y) { |
178 | scr->position_y = scr->size_y - 1; |
203 | scr->position_y = scr->size_y - 1; |
179 | screenbuffer_clear_line(scr, scr->top_line); |
204 | screenbuffer_clear_line(scr, scr->top_line); |
180 | scr->top_line = (scr->top_line + 1) % scr->size_y; |
205 | scr->top_line = (scr->top_line + 1) % scr->size_y; |
181 | if (console == active_console) |
206 | if (console == active_console) |
182 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
207 | async_msg_1(fb_info.phone, FB_SCROLL, 1); |
183 | } |
208 | } |
184 | 209 | ||
185 | scr->position_x = scr->position_x % scr->size_x; |
210 | scr->position_x = scr->position_x % scr->size_x; |
186 | 211 | ||
187 | if (console == active_console) |
212 | if (console == active_console) |
188 | curs_goto(scr->position_y, scr->position_x); |
213 | curs_goto(scr->position_y, scr->position_x); |
189 | 214 | ||
190 | } |
215 | } |
191 | 216 | ||
192 | /** Switch to new console */ |
217 | /** Switch to new console */ |
193 | static void change_console(int newcons) |
218 | static void change_console(int newcons) |
194 | { |
219 | { |
195 | connection_t *conn; |
220 | connection_t *conn; |
196 | int i, j, rc; |
221 | int i, j, rc; |
197 | keyfield_t *field; |
222 | keyfield_t *field; |
198 | style_t *style; |
223 | attrs_t *attrs; |
199 | 224 | ||
200 | if (newcons == active_console) |
225 | if (newcons == active_console) |
201 | return; |
226 | return; |
202 | 227 | ||
203 | if (newcons == KERNEL_CONSOLE) { |
228 | if (newcons == KERNEL_CONSOLE) { |
204 | async_serialize_start(); |
229 | async_serialize_start(); |
205 | curs_hide_sync(); |
230 | curs_hide_sync(); |
206 | gcons_in_kernel(); |
231 | gcons_in_kernel(); |
207 | async_serialize_end(); |
232 | async_serialize_end(); |
208 | 233 | ||
209 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) |
234 | if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) { |
- | 235 | prev_console = active_console; |
|
210 | active_console = KERNEL_CONSOLE; |
236 | active_console = KERNEL_CONSOLE; |
211 | else |
237 | } else |
212 | newcons = active_console; |
238 | newcons = active_console; |
213 | } |
239 | } |
214 | 240 | ||
215 | if (newcons != KERNEL_CONSOLE) { |
241 | if (newcons != KERNEL_CONSOLE) { |
216 | async_serialize_start(); |
242 | async_serialize_start(); |
217 | 243 | ||
218 | if (active_console == KERNEL_CONSOLE) |
244 | if (active_console == KERNEL_CONSOLE) |
219 | gcons_redraw_console(); |
245 | gcons_redraw_console(); |
220 | 246 | ||
221 | active_console = newcons; |
247 | active_console = newcons; |
222 | gcons_change_console(newcons); |
248 | gcons_change_console(newcons); |
223 | conn = &connections[active_console]; |
249 | conn = &connections[active_console]; |
224 | 250 | ||
225 | set_style(&conn->screenbuffer.style); |
251 | set_attrs(&conn->screenbuffer.attrs); |
226 | curs_visibility(false); |
252 | curs_visibility(false); |
227 | if (interbuffer) { |
253 | if (interbuffer) { |
228 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
254 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
229 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
255 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
230 | unsigned int size_x; |
256 | unsigned int size_x; |
231 | 257 | ||
232 | size_x = conn->screenbuffer.size_x; |
258 | size_x = conn->screenbuffer.size_x; |
233 | interbuffer[i + j * size_x] = |
259 | interbuffer[i + j * size_x] = |
234 | *get_field_at(&conn->screenbuffer, i, j); |
260 | *get_field_at(&conn->screenbuffer, i, j); |
235 | } |
261 | } |
236 | /* This call can preempt, but we are already at the end */ |
262 | /* This call can preempt, but we are already at the end */ |
237 | rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); |
263 | rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); |
238 | } |
264 | } |
239 | 265 | ||
240 | if ((!interbuffer) || (rc != 0)) { |
266 | if ((!interbuffer) || (rc != 0)) { |
241 | set_style(&conn->screenbuffer.style); |
267 | set_attrs(&conn->screenbuffer.attrs); |
242 | clrscr(); |
268 | clrscr(); |
243 | style = &conn->screenbuffer.style; |
269 | attrs = &conn->screenbuffer.attrs; |
244 | 270 | ||
245 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
271 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
246 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
272 | for (i = 0; i < conn->screenbuffer.size_x; i++) { |
247 | field = get_field_at(&conn->screenbuffer, i, j); |
273 | field = get_field_at(&conn->screenbuffer, i, j); |
248 | if (!style_same(*style, field->style)) |
274 | if (!attrs_same(*attrs, field->attrs)) |
249 | set_style(&field->style); |
275 | set_attrs(&field->attrs); |
250 | style = &field->style; |
276 | attrs = &field->attrs; |
251 | if ((field->character == ' ') && |
277 | if ((field->character == ' ') && |
252 | (style_same(field->style, |
278 | (attrs_same(field->attrs, |
253 | conn->screenbuffer.style))) |
279 | conn->screenbuffer.attrs))) |
254 | continue; |
280 | continue; |
255 | 281 | ||
256 | prtchr(field->character, j, i); |
282 | prtchr(field->character, j, i); |
257 | } |
283 | } |
258 | } |
284 | } |
259 | 285 | ||
260 | curs_goto(conn->screenbuffer.position_y, |
286 | curs_goto(conn->screenbuffer.position_y, |
261 | conn->screenbuffer.position_x); |
287 | conn->screenbuffer.position_x); |
262 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
288 | curs_visibility(conn->screenbuffer.is_cursor_visible); |
263 | 289 | ||
264 | async_serialize_end(); |
290 | async_serialize_end(); |
265 | } |
291 | } |
266 | } |
292 | } |
267 | 293 | ||
268 | /** Handler for keyboard */ |
294 | /** Handler for keyboard */ |
269 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
295 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
270 | { |
296 | { |
271 | ipc_callid_t callid; |
297 | ipc_callid_t callid; |
272 | ipc_call_t call; |
298 | ipc_call_t call; |
273 | int retval; |
299 | int retval; |
274 | int c; |
300 | int c; |
275 | connection_t *conn; |
301 | connection_t *conn; |
276 | int newcon; |
302 | int newcon; |
277 | 303 | ||
278 | /* Ignore parameters, the connection is alread opened */ |
304 | /* Ignore parameters, the connection is alread opened */ |
279 | while (1) { |
305 | while (1) { |
280 | callid = async_get_call(&call); |
306 | callid = async_get_call(&call); |
281 | switch (IPC_GET_METHOD(call)) { |
307 | switch (IPC_GET_METHOD(call)) { |
282 | case IPC_M_PHONE_HUNGUP: |
308 | case IPC_M_PHONE_HUNGUP: |
283 | /* TODO: Handle hangup */ |
309 | /* TODO: Handle hangup */ |
284 | return; |
310 | return; |
285 | case KBD_MS_LEFT: |
311 | case KBD_MS_LEFT: |
286 | newcon = gcons_mouse_btn(IPC_GET_ARG1(call)); |
312 | newcon = gcons_mouse_btn(IPC_GET_ARG1(call)); |
287 | if (newcon != -1) |
313 | if (newcon != -1) |
288 | change_console(newcon); |
314 | change_console(newcon); |
289 | retval = 0; |
315 | retval = 0; |
290 | break; |
316 | break; |
291 | case KBD_MS_MOVE: |
317 | case KBD_MS_MOVE: |
292 | gcons_mouse_move(IPC_GET_ARG1(call), |
318 | gcons_mouse_move(IPC_GET_ARG1(call), |
293 | IPC_GET_ARG2(call)); |
319 | IPC_GET_ARG2(call)); |
294 | retval = 0; |
320 | retval = 0; |
295 | break; |
321 | break; |
296 | case KBD_PUSHCHAR: |
322 | case KBD_PUSHCHAR: |
297 | /* got key from keyboard driver */ |
323 | /* got key from keyboard driver */ |
298 | retval = 0; |
324 | retval = 0; |
299 | c = IPC_GET_ARG1(call); |
325 | c = IPC_GET_ARG1(call); |
300 | /* switch to another virtual console */ |
326 | /* switch to another virtual console */ |
301 | 327 | ||
302 | conn = &connections[active_console]; |
328 | conn = &connections[active_console]; |
303 | /* |
329 | /* |
304 | * if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + |
330 | * if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + |
305 | * CONSOLE_COUNT)) { |
331 | * CONSOLE_COUNT)) { |
306 | */ |
332 | */ |
307 | if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) { |
333 | if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) { |
308 | if (c == 0x112) |
334 | if (c == 0x112) |
309 | change_console(KERNEL_CONSOLE); |
335 | change_console(KERNEL_CONSOLE); |
310 | else |
336 | else |
311 | change_console(c - 0x101); |
337 | change_console(c - 0x101); |
312 | break; |
338 | break; |
313 | } |
339 | } |
314 | 340 | ||
315 | /* if client is awaiting key, send it */ |
341 | /* if client is awaiting key, send it */ |
316 | if (conn->keyrequest_counter > 0) { |
342 | if (conn->keyrequest_counter > 0) { |
317 | conn->keyrequest_counter--; |
343 | conn->keyrequest_counter--; |
318 | ipc_answer_1(fifo_pop(conn->keyrequests), EOK, |
344 | ipc_answer_1(fifo_pop(conn->keyrequests), EOK, |
319 | c); |
345 | c); |
320 | break; |
346 | break; |
321 | } |
347 | } |
322 | 348 | ||
323 | keybuffer_push(&conn->keybuffer, c); |
349 | keybuffer_push(&conn->keybuffer, c); |
324 | retval = 0; |
350 | retval = 0; |
325 | 351 | ||
326 | break; |
352 | break; |
327 | default: |
353 | default: |
328 | retval = ENOENT; |
354 | retval = ENOENT; |
329 | } |
355 | } |
330 | ipc_answer_0(callid, retval); |
356 | ipc_answer_0(callid, retval); |
331 | } |
357 | } |
332 | } |
358 | } |
333 | 359 | ||
334 | /** Default thread for new connections */ |
360 | /** Default thread for new connections */ |
335 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
361 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
336 | { |
362 | { |
337 | ipc_callid_t callid; |
363 | ipc_callid_t callid; |
338 | ipc_call_t call; |
364 | ipc_call_t call; |
339 | int consnum; |
365 | int consnum; |
340 | ipcarg_t arg1, arg2; |
366 | ipcarg_t arg1, arg2, arg3; |
341 | connection_t *conn; |
367 | connection_t *conn; |
342 | 368 | ||
343 | if ((consnum = find_free_connection()) == -1) { |
369 | if ((consnum = find_free_connection()) == -1) { |
344 | ipc_answer_0(iid, ELIMIT); |
370 | ipc_answer_0(iid, ELIMIT); |
345 | return; |
371 | return; |
346 | } |
372 | } |
347 | conn = &connections[consnum]; |
373 | conn = &connections[consnum]; |
348 | conn->used = 1; |
374 | conn->used = 1; |
349 | 375 | ||
350 | async_serialize_start(); |
376 | async_serialize_start(); |
351 | gcons_notify_connect(consnum); |
377 | gcons_notify_connect(consnum); |
352 | conn->client_phone = IPC_GET_ARG5(*icall); |
378 | conn->client_phone = IPC_GET_ARG5(*icall); |
353 | screenbuffer_clear(&conn->screenbuffer); |
379 | screenbuffer_clear(&conn->screenbuffer); |
354 | 380 | ||
355 | /* Accept the connection */ |
381 | /* Accept the connection */ |
356 | ipc_answer_0(iid, EOK); |
382 | ipc_answer_0(iid, EOK); |
357 | 383 | ||
358 | while (1) { |
384 | while (1) { |
359 | async_serialize_end(); |
385 | async_serialize_end(); |
360 | callid = async_get_call(&call); |
386 | callid = async_get_call(&call); |
361 | async_serialize_start(); |
387 | async_serialize_start(); |
362 | 388 | ||
363 | arg1 = 0; |
389 | arg1 = 0; |
364 | arg2 = 0; |
390 | arg2 = 0; |
365 | switch (IPC_GET_METHOD(call)) { |
391 | switch (IPC_GET_METHOD(call)) { |
366 | case IPC_M_PHONE_HUNGUP: |
392 | case IPC_M_PHONE_HUNGUP: |
367 | gcons_notify_disconnect(consnum); |
393 | gcons_notify_disconnect(consnum); |
368 | 394 | ||
369 | /* Answer all pending requests */ |
395 | /* Answer all pending requests */ |
370 | while (conn->keyrequest_counter > 0) { |
396 | while (conn->keyrequest_counter > 0) { |
371 | conn->keyrequest_counter--; |
397 | conn->keyrequest_counter--; |
372 | ipc_answer_0(fifo_pop(conn->keyrequests), |
398 | ipc_answer_0(fifo_pop(conn->keyrequests), |
373 | ENOENT); |
399 | ENOENT); |
374 | break; |
400 | break; |
375 | } |
401 | } |
376 | conn->used = 0; |
402 | conn->used = 0; |
377 | return; |
403 | return; |
378 | case CONSOLE_PUTCHAR: |
404 | case CONSOLE_PUTCHAR: |
379 | write_char(consnum, IPC_GET_ARG1(call)); |
405 | write_char(consnum, IPC_GET_ARG1(call)); |
380 | gcons_notify_char(consnum); |
406 | gcons_notify_char(consnum); |
381 | break; |
407 | break; |
382 | case CONSOLE_CLEAR: |
408 | case CONSOLE_CLEAR: |
383 | /* Send message to fb */ |
409 | /* Send message to fb */ |
384 | if (consnum == active_console) { |
410 | if (consnum == active_console) { |
385 | async_msg_0(fb_info.phone, FB_CLEAR); |
411 | async_msg_0(fb_info.phone, FB_CLEAR); |
386 | } |
412 | } |
387 | 413 | ||
388 | screenbuffer_clear(&conn->screenbuffer); |
414 | screenbuffer_clear(&conn->screenbuffer); |
389 | 415 | ||
390 | break; |
416 | break; |
391 | case CONSOLE_GOTO: |
417 | case CONSOLE_GOTO: |
392 | screenbuffer_goto(&conn->screenbuffer, |
418 | screenbuffer_goto(&conn->screenbuffer, |
393 | IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
419 | IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
394 | if (consnum == active_console) |
420 | if (consnum == active_console) |
395 | curs_goto(IPC_GET_ARG1(call), |
421 | curs_goto(IPC_GET_ARG1(call), |
396 | IPC_GET_ARG2(call)); |
422 | IPC_GET_ARG2(call)); |
397 | break; |
423 | break; |
398 | case CONSOLE_GETSIZE: |
424 | case CONSOLE_GETSIZE: |
399 | arg1 = fb_info.rows; |
425 | arg1 = fb_info.rows; |
400 | arg2 = fb_info.cols; |
426 | arg2 = fb_info.cols; |
401 | break; |
427 | break; |
402 | case CONSOLE_FLUSH: |
428 | case CONSOLE_FLUSH: |
403 | if (consnum == active_console) |
429 | if (consnum == active_console) |
404 | async_req_0_0(fb_info.phone, FB_FLUSH); |
430 | async_req_0_0(fb_info.phone, FB_FLUSH); |
405 | break; |
431 | break; |
406 | case CONSOLE_SET_STYLE: |
432 | case CONSOLE_SET_STYLE: |
407 | arg1 = IPC_GET_ARG1(call); |
433 | arg1 = IPC_GET_ARG1(call); |
- | 434 | screenbuffer_set_style(&conn->screenbuffer, arg1); |
|
- | 435 | if (consnum == active_console) |
|
- | 436 | set_style(arg1); |
|
- | 437 | break; |
|
- | 438 | case CONSOLE_SET_COLOR: |
|
- | 439 | arg1 = IPC_GET_ARG1(call); |
|
- | 440 | arg2 = IPC_GET_ARG2(call); |
|
- | 441 | arg3 = IPC_GET_ARG3(call); |
|
- | 442 | screenbuffer_set_color(&conn->screenbuffer, arg1, |
|
- | 443 | arg2, arg3); |
|
- | 444 | if (consnum == active_console) |
|
- | 445 | set_color(arg1, arg2, arg3); |
|
- | 446 | break; |
|
- | 447 | case CONSOLE_SET_RGB_COLOR: |
|
- | 448 | arg1 = IPC_GET_ARG1(call); |
|
408 | arg2 = IPC_GET_ARG2(call); |
449 | arg2 = IPC_GET_ARG2(call); |
409 | screenbuffer_set_style(&conn->screenbuffer, arg1, |
450 | screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
410 | arg2); |
451 | arg2); |
411 | if (consnum == active_console) |
452 | if (consnum == active_console) |
412 | set_style_col(arg1, arg2); |
453 | set_rgb_color(arg1, arg2); |
413 | break; |
454 | break; |
414 | case CONSOLE_CURSOR_VISIBILITY: |
455 | case CONSOLE_CURSOR_VISIBILITY: |
415 | arg1 = IPC_GET_ARG1(call); |
456 | arg1 = IPC_GET_ARG1(call); |
416 | conn->screenbuffer.is_cursor_visible = arg1; |
457 | conn->screenbuffer.is_cursor_visible = arg1; |
417 | if (consnum == active_console) |
458 | if (consnum == active_console) |
418 | curs_visibility(arg1); |
459 | curs_visibility(arg1); |
419 | break; |
460 | break; |
420 | case CONSOLE_GETCHAR: |
461 | case CONSOLE_GETCHAR: |
421 | if (keybuffer_empty(&conn->keybuffer)) { |
462 | if (keybuffer_empty(&conn->keybuffer)) { |
422 | /* buffer is empty -> store request */ |
463 | /* buffer is empty -> store request */ |
423 | if (conn->keyrequest_counter < |
464 | if (conn->keyrequest_counter < |
424 | MAX_KEYREQUESTS_BUFFERED) { |
465 | MAX_KEYREQUESTS_BUFFERED) { |
425 | fifo_push(conn->keyrequests, callid); |
466 | fifo_push(conn->keyrequests, callid); |
426 | conn->keyrequest_counter++; |
467 | conn->keyrequest_counter++; |
427 | } else { |
468 | } else { |
428 | /* |
469 | /* |
429 | * No key available and too many |
470 | * No key available and too many |
430 | * requests => fail. |
471 | * requests => fail. |
431 | */ |
472 | */ |
432 | ipc_answer_0(callid, ELIMIT); |
473 | ipc_answer_0(callid, ELIMIT); |
433 | } |
474 | } |
434 | continue; |
475 | continue; |
435 | } |
476 | } |
436 | int ch; |
477 | int ch; |
437 | keybuffer_pop(&conn->keybuffer, &ch); |
478 | keybuffer_pop(&conn->keybuffer, &ch); |
438 | arg1 = ch; |
479 | arg1 = ch; |
439 | break; |
480 | break; |
440 | } |
481 | } |
441 | ipc_answer_2(callid, EOK, arg1, arg2); |
482 | ipc_answer_2(callid, EOK, arg1, arg2); |
442 | } |
483 | } |
443 | } |
484 | } |
444 | 485 | ||
- | 486 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) |
|
- | 487 | { |
|
- | 488 | change_console(prev_console); |
|
- | 489 | } |
|
- | 490 | ||
445 | int main(int argc, char *argv[]) |
491 | int main(int argc, char *argv[]) |
446 | { |
492 | { |
447 | printf(NAME ": HelenOS Console service\n"); |
493 | printf(NAME ": HelenOS Console service\n"); |
448 | 494 | ||
449 | ipcarg_t phonehash; |
495 | ipcarg_t phonehash; |
450 | int kbd_phone; |
496 | int kbd_phone; |
451 | int i; |
497 | int i; |
452 | 498 | ||
453 | async_set_client_connection(client_connection); |
499 | async_set_client_connection(client_connection); |
454 | 500 | ||
455 | /* Connect to keyboard driver */ |
501 | /* Connect to keyboard driver */ |
456 | 502 | ||
457 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
503 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
458 | while (kbd_phone < 0) { |
504 | while (kbd_phone < 0) { |
459 | usleep(10000); |
505 | usleep(10000); |
460 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
506 | kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0); |
461 | } |
507 | } |
462 | 508 | ||
463 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
509 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
464 | return -1; |
510 | return -1; |
465 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
511 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
466 | 512 | ||
467 | /* Connect to framebuffer driver */ |
513 | /* Connect to framebuffer driver */ |
468 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
514 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
469 | while (fb_info.phone < 0) { |
515 | while (fb_info.phone < 0) { |
470 | usleep(10000); |
516 | usleep(10000); |
471 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
517 | fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0); |
472 | } |
518 | } |
473 | 519 | ||
474 | /* Initialize gcons */ |
520 | /* Initialize gcons */ |
475 | gcons_init(fb_info.phone); |
521 | gcons_init(fb_info.phone); |
476 | /* Synchronize, the gcons can have something in queue */ |
522 | /* Synchronize, the gcons can have something in queue */ |
477 | async_req_0_0(fb_info.phone, FB_FLUSH); |
523 | async_req_0_0(fb_info.phone, FB_FLUSH); |
478 | 524 | ||
479 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
525 | async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows, |
480 | &fb_info.cols); |
526 | &fb_info.cols); |
481 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
527 | set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
482 | clrscr(); |
528 | clrscr(); |
483 | 529 | ||
484 | /* Init virtual consoles */ |
530 | /* Init virtual consoles */ |
485 | for (i = 0; i < CONSOLE_COUNT; i++) { |
531 | for (i = 0; i < CONSOLE_COUNT; i++) { |
486 | connections[i].used = 0; |
532 | connections[i].used = 0; |
487 | keybuffer_init(&connections[i].keybuffer); |
533 | keybuffer_init(&connections[i].keybuffer); |
488 | 534 | ||
489 | connections[i].keyrequests.head = 0; |
535 | connections[i].keyrequests.head = 0; |
490 | connections[i].keyrequests.tail = 0; |
536 | connections[i].keyrequests.tail = 0; |
491 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
537 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
492 | connections[i].keyrequest_counter = 0; |
538 | connections[i].keyrequest_counter = 0; |
493 | 539 | ||
494 | if (screenbuffer_init(&connections[i].screenbuffer, |
540 | if (screenbuffer_init(&connections[i].screenbuffer, |
495 | fb_info.cols, fb_info.rows) == NULL) { |
541 | fb_info.cols, fb_info.rows) == NULL) { |
496 | /* FIXME: handle error */ |
542 | /* FIXME: handle error */ |
497 | return -1; |
543 | return -1; |
498 | } |
544 | } |
499 | } |
545 | } |
500 | connections[KERNEL_CONSOLE].used = 1; |
546 | connections[KERNEL_CONSOLE].used = 1; |
501 | 547 | ||
502 | interbuffer = mmap(NULL, |
548 | interbuffer = mmap(NULL, |
503 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows, |
549 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows, |
504 | PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); |
550 | PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); |
505 | if (!interbuffer) { |
551 | if (!interbuffer) { |
506 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
552 | if (ipc_share_out_start(fb_info.phone, interbuffer, |
507 | AS_AREA_READ) != EOK) { |
553 | AS_AREA_READ) != EOK) { |
508 | munmap(interbuffer, |
554 | munmap(interbuffer, |
509 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
555 | sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
510 | interbuffer = NULL; |
556 | interbuffer = NULL; |
511 | } |
557 | } |
512 | } |
558 | } |
513 | 559 | ||
514 | curs_goto(0, 0); |
560 | curs_goto(0, 0); |
515 | curs_visibility( |
561 | curs_visibility( |
516 | connections[active_console].screenbuffer.is_cursor_visible); |
562 | connections[active_console].screenbuffer.is_cursor_visible); |
517 | 563 | ||
518 | /* Register at NS */ |
564 | /* Register at NS */ |
519 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
565 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) |
520 | return -1; |
566 | return -1; |
521 | 567 | ||
- | 568 | /* Receive kernel notifications */ |
|
- | 569 | if (sysinfo_value("kconsole.present")) { |
|
- | 570 | int devno = sysinfo_value("kconsole.devno"); |
|
- | 571 | int inr = sysinfo_value("kconsole.inr"); |
|
- | 572 | if (ipc_register_irq(inr, devno, 0, NULL) != EOK) |
|
- | 573 | printf(NAME ": Error registering kconsole notifications\n"); |
|
- | 574 | ||
- | 575 | async_set_interrupt_received(interrupt_received); |
|
- | 576 | } |
|
- | 577 | ||
522 | // FIXME: avoid connectiong to itself, keep using klog |
578 | // FIXME: avoid connectiong to itself, keep using klog |
523 | // printf(NAME ": Accepting connections\n"); |
579 | // printf(NAME ": Accepting connections\n"); |
524 | async_manager(); |
580 | async_manager(); |
525 | 581 | ||
526 | return 0; |
582 | return 0; |
527 | } |
583 | } |
528 | 584 | ||
529 | /** @} |
585 | /** @} |
530 | */ |
586 | */ |
531 | 587 |