Rev 1547 | Rev 1555 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1547 | Rev 1552 | ||
---|---|---|---|
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 | 29 | ||
30 | #include <kbd.h> |
30 | #include <kbd.h> |
31 | #include <fb.h> |
31 | #include <fb.h> |
32 | #include <ipc/ipc.h> |
32 | #include <ipc/ipc.h> |
33 | #include <ipc/fb.h> |
33 | #include <ipc/fb.h> |
34 | #include <ipc/services.h> |
34 | #include <ipc/services.h> |
35 | #include <errno.h> |
35 | #include <errno.h> |
36 | #include <key_buffer.h> |
36 | #include <key_buffer.h> |
37 | #include <console.h> |
37 | #include <console.h> |
38 | #include <unistd.h> |
38 | #include <unistd.h> |
39 | #include <async.h> |
39 | #include <async.h> |
40 | #include <libadt/fifo.h> |
40 | #include <libadt/fifo.h> |
41 | #include <screenbuffer.h> |
41 | #include <screenbuffer.h> |
42 | #include <sys/mman.h> |
42 | #include <sys/mman.h> |
43 | 43 | ||
44 | #include "gcons.h" |
44 | #include "gcons.h" |
45 | 45 | ||
46 | #define MAX_KEYREQUESTS_BUFFERED 32 |
46 | #define MAX_KEYREQUESTS_BUFFERED 32 |
47 | 47 | ||
48 | #define NAME "CONSOLE" |
48 | #define NAME "CONSOLE" |
49 | 49 | ||
50 | /** Index of currently used virtual console. |
50 | /** Index of currently used virtual console. |
51 | */ |
51 | */ |
52 | int active_console = 0; |
52 | int active_console = 0; |
53 | 53 | ||
54 | /** Information about framebuffer |
54 | /** Information about framebuffer |
55 | */ |
55 | */ |
56 | struct { |
56 | struct { |
57 | int phone; /**< Framebuffer phone */ |
57 | int phone; /**< Framebuffer phone */ |
58 | ipcarg_t rows; /**< Framebuffer rows */ |
58 | ipcarg_t rows; /**< Framebuffer rows */ |
59 | ipcarg_t cols; /**< Framebuffer columns */ |
59 | ipcarg_t cols; /**< Framebuffer columns */ |
60 | } fb_info; |
60 | } fb_info; |
61 | 61 | ||
62 | 62 | ||
63 | typedef struct { |
63 | typedef struct { |
64 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
64 | keybuffer_t keybuffer; /**< Buffer for incoming keys. */ |
65 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); /**< Buffer for unsatisfied request for keys. */ |
65 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); /**< Buffer for unsatisfied request for keys. */ |
66 | int keyrequest_counter; /**< Number of requests in buffer. */ |
66 | int keyrequest_counter; /**< Number of requests in buffer. */ |
67 | int client_phone; /**< Phone to connected client. */ |
67 | int client_phone; /**< Phone to connected client. */ |
68 | int used; /**< 1 if this virtual console is connected to some client.*/ |
68 | int used; /**< 1 if this virtual console is connected to some client.*/ |
69 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen contents and related settings. */ |
69 | screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen contents and related settings. */ |
70 | } connection_t; |
70 | } connection_t; |
71 | 71 | ||
72 | connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual consoles */ |
72 | static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual consoles */ |
73 | keyfield_t *interbuffer = NULL; /**< Pointer to memory shared with framebufer used for faster virt. console switching */ |
73 | static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared with framebufer used for faster virt. console switching */ |
- | 74 | ||
- | 75 | static int kernel_pixmap = -1; /**< Number of fb pixmap, where kernel console is stored */ |
|
74 | 76 | ||
75 | 77 | ||
76 | /** Find unused virtual console. |
78 | /** Find unused virtual console. |
77 | * |
79 | * |
78 | */ |
80 | */ |
79 | static int find_free_connection() |
81 | static int find_free_connection() |
80 | { |
82 | { |
81 | int i = 0; |
83 | int i = 0; |
82 | 84 | ||
83 | while (i < CONSOLE_COUNT) { |
85 | while (i < CONSOLE_COUNT) { |
84 | if (connections[i].used == 0) |
86 | if (connections[i].used == 0) |
85 | return i; |
87 | return i; |
86 | ++i; |
88 | ++i; |
87 | } |
89 | } |
88 | return CONSOLE_COUNT; |
90 | return CONSOLE_COUNT; |
89 | } |
91 | } |
90 | 92 | ||
91 | /** Find index of virtual console used by client with given phone. |
93 | /** Find index of virtual console used by client with given phone. |
92 | * |
94 | * |
93 | */ |
95 | */ |
94 | static int find_connection(int client_phone) |
96 | static int find_connection(int client_phone) |
95 | { |
97 | { |
96 | int i = 0; |
98 | int i = 0; |
97 | 99 | ||
98 | while (i < CONSOLE_COUNT) { |
100 | while (i < CONSOLE_COUNT) { |
99 | if (connections[i].client_phone == client_phone) |
101 | if (connections[i].client_phone == client_phone) |
100 | return i; |
102 | return i; |
101 | ++i; |
103 | ++i; |
102 | } |
104 | } |
103 | return CONSOLE_COUNT; |
105 | return CONSOLE_COUNT; |
104 | } |
106 | } |
105 | 107 | ||
- | 108 | static void clrscr(void) |
|
- | 109 | { |
|
- | 110 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
|
- | 111 | } |
|
- | 112 | ||
- | 113 | static void curs_visibility(int v) |
|
- | 114 | { |
|
- | 115 | send_call(fb_info.phone, FB_CURSOR_VISIBILITY, v); |
|
- | 116 | } |
|
- | 117 | ||
- | 118 | static void curs_goto(int row, int col) |
|
- | 119 | { |
|
- | 120 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, row, col); |
|
- | 121 | ||
- | 122 | } |
|
- | 123 | ||
- | 124 | static void set_style(style_t *style) |
|
- | 125 | { |
|
- | 126 | nsend_call_2(fb_info.phone, FB_SET_STYLE, style->fg_color, style->bg_color); |
|
- | 127 | } |
|
- | 128 | ||
- | 129 | static void set_style_col(int fgcolor, int bgcolor) |
|
- | 130 | { |
|
- | 131 | nsend_call_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor); |
|
- | 132 | } |
|
- | 133 | ||
- | 134 | static void prtchr(char c, int row, int col) |
|
- | 135 | { |
|
- | 136 | nsend_call_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
|
- | 137 | ||
- | 138 | } |
|
- | 139 | ||
106 | /** Check key and process special keys. |
140 | /** Check key and process special keys. |
107 | * |
141 | * |
108 | * */ |
142 | * */ |
109 | static void write_char(int console, char key) |
143 | static void write_char(int console, char key) |
110 | { |
144 | { |
111 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
145 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
112 | 146 | ||
113 | switch (key) { |
147 | switch (key) { |
114 | case '\n': |
148 | case '\n': |
115 | scr->position_y += 1; |
149 | scr->position_y += 1; |
116 | scr->position_x = 0; |
150 | scr->position_x = 0; |
117 | break; |
151 | break; |
118 | case '\r': |
152 | case '\r': |
119 | break; |
153 | break; |
120 | case '\t': |
154 | case '\t': |
121 | scr->position_x += 8; |
155 | scr->position_x += 8; |
122 | scr->position_x -= scr->position_x % 8; |
156 | scr->position_x -= scr->position_x % 8; |
123 | break; |
157 | break; |
124 | case '\b': |
158 | case '\b': |
125 | if (scr->position_x == 0) |
159 | if (scr->position_x == 0) |
126 | break; |
160 | break; |
127 | 161 | ||
128 | scr->position_x--; |
162 | scr->position_x--; |
129 | 163 | ||
130 | if (console == active_console) { |
164 | if (console == active_console) |
131 | nsend_call_3(fb_info.phone, FB_PUTCHAR, ' ', scr->position_y, scr->position_x); |
165 | prtchr(' ', scr->position_y, scr->position_x); |
132 | } |
- | |
133 | 166 | ||
134 | screenbuffer_putchar(scr, ' '); |
167 | screenbuffer_putchar(scr, ' '); |
135 | 168 | ||
136 | break; |
169 | break; |
137 | default: |
170 | default: |
138 | if (console == active_console) { |
171 | if (console == active_console) |
139 | nsend_call_3(fb_info.phone, FB_PUTCHAR, key, scr->position_y, scr->position_x); |
172 | prtchr(key, scr->position_y, scr->position_x); |
140 | } |
- | |
141 | 173 | ||
142 | screenbuffer_putchar(scr, key); |
174 | screenbuffer_putchar(scr, key); |
143 | scr->position_x++; |
175 | scr->position_x++; |
144 | } |
176 | } |
145 | 177 | ||
146 | scr->position_y += (scr->position_x >= scr->size_x); |
178 | scr->position_y += (scr->position_x >= scr->size_x); |
147 | 179 | ||
148 | if (scr->position_y >= scr->size_y) { |
180 | if (scr->position_y >= scr->size_y) { |
149 | scr->position_y = scr->size_y - 1; |
181 | scr->position_y = scr->size_y - 1; |
150 | screenbuffer_clear_line(scr, scr->top_line++); |
182 | screenbuffer_clear_line(scr, scr->top_line++); |
151 | if (console == active_console) |
183 | if (console == active_console) |
152 | nsend_call(fb_info.phone, FB_SCROLL, 1); |
184 | nsend_call(fb_info.phone, FB_SCROLL, 1); |
153 | } |
185 | } |
154 | 186 | ||
155 | scr->position_x = scr->position_x % scr->size_x; |
187 | scr->position_x = scr->position_x % scr->size_x; |
156 | 188 | ||
157 | if (console == active_console) |
189 | if (console == active_console) |
- | 190 | curs_goto(scr->position_y, scr->position_x); |
|
- | 191 | ||
- | 192 | } |
|
- | 193 | ||
- | 194 | /** Save current screen to pixmap, draw old pixmap |
|
- | 195 | * |
|
- | 196 | * @param oldpixmap Old pixmap |
|
- | 197 | * @return ID of pixmap of current screen |
|
- | 198 | */ |
|
- | 199 | static int switch_screens(int oldpixmap) |
|
- | 200 | { |
|
- | 201 | int newpmap; |
|
- | 202 | ||
- | 203 | /* Save screen */ |
|
- | 204 | newpmap = sync_send(fb_info.phone, FB_VP2PIXMAP, 0, NULL); |
|
- | 205 | if (newpmap < 0) |
|
- | 206 | return -1; |
|
- | 207 | ||
- | 208 | if (oldpixmap != -1) { |
|
- | 209 | /* Show old screen */ |
|
158 | send_call_2(fb_info.phone, FB_CURSOR_GOTO, scr->position_y, scr->position_x); |
210 | nsend_call_2(fb_info.phone, FB_VP_DRAW_PIXMAP, 0, oldpixmap); |
- | 211 | /* Drop old pixmap */ |
|
- | 212 | nsend_call(fb_info.phone, FB_DROP_PIXMAP, oldpixmap); |
|
- | 213 | } |
|
159 | 214 | ||
- | 215 | return newpmap; |
|
160 | } |
216 | } |
161 | 217 | ||
- | 218 | /** Switch to new console */ |
|
- | 219 | static void change_console(int newcons) |
|
- | 220 | { |
|
- | 221 | connection_t *conn; |
|
- | 222 | static int console_pixmap = -1; |
|
- | 223 | int i, j; |
|
- | 224 | char c; |
|
- | 225 | ||
- | 226 | if (newcons == active_console) |
|
- | 227 | return; |
|
- | 228 | ||
- | 229 | if (newcons == -1) { |
|
- | 230 | if (active_console == -1) |
|
- | 231 | return; |
|
- | 232 | active_console = -1; |
|
- | 233 | curs_visibility(0); |
|
- | 234 | ||
- | 235 | if (kernel_pixmap == -1) { |
|
- | 236 | /* store/restore unsupported */ |
|
- | 237 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
|
- | 238 | clrscr(); |
|
- | 239 | } else { |
|
- | 240 | gcons_in_kernel(); |
|
- | 241 | console_pixmap = switch_screens(kernel_pixmap); |
|
- | 242 | kernel_pixmap = -1; |
|
- | 243 | } |
|
- | 244 | ||
- | 245 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
|
- | 246 | return; |
|
- | 247 | } |
|
- | 248 | ||
- | 249 | if (console_pixmap != -1) { |
|
- | 250 | kernel_pixmap = switch_screens(console_pixmap); |
|
- | 251 | console_pixmap = -1; |
|
- | 252 | } |
|
- | 253 | ||
- | 254 | active_console = newcons; |
|
- | 255 | gcons_change_console(newcons); |
|
- | 256 | conn = &connections[active_console]; |
|
- | 257 | ||
- | 258 | curs_visibility(0); |
|
- | 259 | if (interbuffer) { |
|
- | 260 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
|
- | 261 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
|
- | 262 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j); |
|
- | 263 | ||
- | 264 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL); |
|
- | 265 | } else { |
|
- | 266 | clrscr(); |
|
- | 267 | ||
- | 268 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
|
- | 269 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
|
- | 270 | c = get_field_at(&(conn->screenbuffer),i, j)->character; |
|
- | 271 | if (c && c != ' ') |
|
- | 272 | prtchr(c, j, i); |
|
- | 273 | } |
|
- | 274 | ||
- | 275 | } |
|
- | 276 | curs_goto(conn->screenbuffer.position_y, conn->screenbuffer.position_x); |
|
- | 277 | set_style(&conn->screenbuffer.style); |
|
- | 278 | curs_visibility(1); |
|
- | 279 | } |
|
162 | 280 | ||
163 | /** Handler for keyboard */ |
281 | /** Handler for keyboard */ |
164 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
282 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
165 | { |
283 | { |
166 | ipc_callid_t callid; |
284 | ipc_callid_t callid; |
167 | ipc_call_t call; |
285 | ipc_call_t call; |
168 | int retval; |
286 | int retval; |
169 | int i, j; |
- | |
170 | char c,d; |
287 | char c; |
171 | connection_t *conn; |
288 | connection_t *conn; |
172 | 289 | ||
173 | /* Ignore parameters, the connection is alread opened */ |
290 | /* Ignore parameters, the connection is alread opened */ |
174 | while (1) { |
291 | while (1) { |
175 | callid = async_get_call(&call); |
292 | callid = async_get_call(&call); |
176 | switch (IPC_GET_METHOD(call)) { |
293 | switch (IPC_GET_METHOD(call)) { |
177 | case IPC_M_PHONE_HUNGUP: |
294 | case IPC_M_PHONE_HUNGUP: |
178 | ipc_answer_fast(callid,0,0,0); |
295 | ipc_answer_fast(callid,0,0,0); |
179 | /* TODO: Handle hangup */ |
296 | /* TODO: Handle hangup */ |
180 | return; |
297 | return; |
181 | case KBD_PUSHCHAR: |
298 | case KBD_PUSHCHAR: |
182 | /* got key from keyboard driver */ |
299 | /* got key from keyboard driver */ |
183 | 300 | ||
184 | retval = 0; |
301 | retval = 0; |
185 | c = IPC_GET_ARG1(call); |
302 | c = IPC_GET_ARG1(call); |
186 | /* switch to another virtual console */ |
303 | /* switch to another virtual console */ |
187 | 304 | ||
188 | conn = &connections[active_console]; |
305 | conn = &connections[active_console]; |
189 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
306 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
190 | if ((c >= '0') && (c < '0' + CONSOLE_COUNT)) { |
307 | if ((c >= '0') && (c < '0' + CONSOLE_COUNT)) { |
191 | if (c == '0') { |
308 | if (c == '0') |
192 | /* switch to kernel console*/ |
- | |
193 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 0); |
- | |
194 | nsend_call_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); |
- | |
195 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
- | |
196 | /* FIXME: restore kernel console */ |
- | |
197 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
- | |
198 | break; |
- | |
199 | - | ||
200 | } else { |
- | |
201 | c = c - '1'; |
- | |
202 | if (c == active_console) |
- | |
203 | break; |
- | |
204 | active_console = c; |
- | |
205 | gcons_change_console(c); |
309 | change_console(-1); |
206 | - | ||
207 | } |
- | |
208 | - | ||
209 | conn = &connections[active_console]; |
- | |
210 | - | ||
211 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 0); |
- | |
212 | - | ||
213 | if (interbuffer) { |
- | |
214 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
- | |
215 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
- | |
216 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j); |
- | |
217 | - | ||
218 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL); |
- | |
219 | } else { |
310 | else |
220 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
- | |
221 | - | ||
222 | - | ||
223 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
- | |
224 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
- | |
225 | d = get_field_at(&(conn->screenbuffer),i, j)->character; |
- | |
226 | if (d && d != ' ') |
311 | change_console(c - '1'); |
227 | nsend_call_3(fb_info.phone, FB_PUTCHAR, d, j, i); |
- | |
228 | } |
- | |
229 | - | ||
230 | } |
- | |
231 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, conn->screenbuffer.position_y, conn->screenbuffer.position_x); |
- | |
232 | nsend_call_2(fb_info.phone, FB_SET_STYLE, conn->screenbuffer.style.fg_color, \ |
- | |
233 | conn->screenbuffer.style.bg_color); |
- | |
234 | send_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
- | |
235 | - | ||
236 | break; |
312 | break; |
237 | } |
313 | } |
238 | 314 | ||
239 | /* if client is awaiting key, send it */ |
315 | /* if client is awaiting key, send it */ |
240 | if (conn->keyrequest_counter > 0) { |
316 | if (conn->keyrequest_counter > 0) { |
241 | conn->keyrequest_counter--; |
317 | conn->keyrequest_counter--; |
242 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0); |
318 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0); |
243 | break; |
319 | break; |
244 | } |
320 | } |
245 | 321 | ||
246 | /*FIXME: else store key to its buffer */ |
322 | /*FIXME: else store key to its buffer */ |
247 | keybuffer_push(&conn->keybuffer, c); |
323 | keybuffer_push(&conn->keybuffer, c); |
248 | 324 | ||
249 | break; |
325 | break; |
250 | default: |
326 | default: |
251 | retval = ENOENT; |
327 | retval = ENOENT; |
252 | } |
328 | } |
253 | ipc_answer_fast(callid, retval, 0, 0); |
329 | ipc_answer_fast(callid, retval, 0, 0); |
254 | } |
330 | } |
255 | } |
331 | } |
256 | 332 | ||
257 | /** Default thread for new connections */ |
333 | /** Default thread for new connections */ |
258 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
334 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
259 | { |
335 | { |
260 | ipc_callid_t callid; |
336 | ipc_callid_t callid; |
261 | ipc_call_t call; |
337 | ipc_call_t call; |
262 | int consnum; |
338 | int consnum; |
263 | ipcarg_t arg1, arg2; |
339 | ipcarg_t arg1, arg2; |
264 | 340 | ||
265 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
341 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
266 | ipc_answer_fast(iid,ELIMIT,0,0); |
342 | ipc_answer_fast(iid,ELIMIT,0,0); |
267 | return; |
343 | return; |
268 | } |
344 | } |
269 | 345 | ||
270 | connections[consnum].used = 1; |
346 | connections[consnum].used = 1; |
271 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
347 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
272 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
348 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
273 | 349 | ||
274 | /* Accept the connection */ |
350 | /* Accept the connection */ |
275 | ipc_answer_fast(iid,0,0,0); |
351 | ipc_answer_fast(iid,0,0,0); |
276 | 352 | ||
277 | while (1) { |
353 | while (1) { |
278 | callid = async_get_call(&call); |
354 | callid = async_get_call(&call); |
279 | arg1 = arg2 = 0; |
355 | arg1 = arg2 = 0; |
280 | switch (IPC_GET_METHOD(call)) { |
356 | switch (IPC_GET_METHOD(call)) { |
281 | case IPC_M_PHONE_HUNGUP: |
357 | case IPC_M_PHONE_HUNGUP: |
282 | /* TODO */ |
358 | /* TODO */ |
283 | ipc_answer_fast(callid, 0,0,0); |
359 | ipc_answer_fast(callid, 0,0,0); |
284 | return; |
360 | return; |
285 | case CONSOLE_PUTCHAR: |
361 | case CONSOLE_PUTCHAR: |
286 | write_char(consnum, IPC_GET_ARG1(call)); |
362 | write_char(consnum, IPC_GET_ARG1(call)); |
287 | gcons_notify_char(consnum); |
363 | gcons_notify_char(consnum); |
288 | break; |
364 | break; |
289 | case CONSOLE_CLEAR: |
365 | case CONSOLE_CLEAR: |
290 | /* Send message to fb */ |
366 | /* Send message to fb */ |
291 | if (consnum == active_console) { |
367 | if (consnum == active_console) { |
292 | send_call(fb_info.phone, FB_CLEAR, 0); |
368 | send_call(fb_info.phone, FB_CLEAR, 0); |
293 | } |
369 | } |
294 | 370 | ||
295 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
371 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
296 | 372 | ||
297 | break; |
373 | break; |
298 | case CONSOLE_GOTO: |
374 | case CONSOLE_GOTO: |
299 | 375 | ||
300 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
376 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG2(call), IPC_GET_ARG1(call)); |
301 | 377 | ||
302 | break; |
378 | break; |
303 | 379 | ||
304 | case CONSOLE_GETSIZE: |
380 | case CONSOLE_GETSIZE: |
305 | arg1 = fb_info.rows; |
381 | arg1 = fb_info.rows; |
306 | arg2 = fb_info.cols; |
382 | arg2 = fb_info.cols; |
307 | break; |
383 | break; |
308 | case CONSOLE_FLUSH: |
384 | case CONSOLE_FLUSH: |
309 | sync_send_2(fb_info.phone, FB_FLUSH, 0, 0, NULL, NULL); |
385 | sync_send_2(fb_info.phone, FB_FLUSH, 0, 0, NULL, NULL); |
310 | break; |
386 | break; |
311 | case CONSOLE_SET_STYLE: |
387 | case CONSOLE_SET_STYLE: |
312 | 388 | ||
313 | arg1 = IPC_GET_ARG1(call); |
389 | arg1 = IPC_GET_ARG1(call); |
314 | arg2 = IPC_GET_ARG2(call); |
390 | arg2 = IPC_GET_ARG2(call); |
315 | screenbuffer_set_style(&(connections[consnum].screenbuffer),arg1, arg2); |
391 | screenbuffer_set_style(&(connections[consnum].screenbuffer),arg1, arg2); |
316 | if (consnum == active_console) |
392 | if (consnum == active_console) |
317 | nsend_call_2(fb_info.phone, FB_SET_STYLE, arg1, arg2); |
393 | set_style_col(arg1, arg2); |
318 | 394 | ||
319 | break; |
395 | break; |
320 | case CONSOLE_GETCHAR: |
396 | case CONSOLE_GETCHAR: |
321 | if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
397 | if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
322 | /* buffer is empty -> store request */ |
398 | /* buffer is empty -> store request */ |
323 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) { |
399 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) { |
324 | fifo_push(connections[consnum].keyrequests, callid); |
400 | fifo_push(connections[consnum].keyrequests, callid); |
325 | connections[consnum].keyrequest_counter++; |
401 | connections[consnum].keyrequest_counter++; |
326 | } else { |
402 | } else { |
327 | /* no key available and too many requests => fail */ |
403 | /* no key available and too many requests => fail */ |
328 | ipc_answer_fast(callid, ELIMIT, 0, 0); |
404 | ipc_answer_fast(callid, ELIMIT, 0, 0); |
329 | } |
405 | } |
330 | continue; |
406 | continue; |
331 | }; |
407 | }; |
332 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
408 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
333 | 409 | ||
334 | break; |
410 | break; |
335 | } |
411 | } |
336 | ipc_answer_fast(callid, 0, arg1, arg2); |
412 | ipc_answer_fast(callid, 0, arg1, arg2); |
337 | } |
413 | } |
338 | } |
414 | } |
339 | 415 | ||
340 | int main(int argc, char *argv[]) |
416 | int main(int argc, char *argv[]) |
341 | { |
417 | { |
342 | ipcarg_t phonehash; |
418 | ipcarg_t phonehash; |
343 | int kbd_phone, fb_phone; |
419 | int kbd_phone, fb_phone; |
344 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
420 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
345 | int i; |
421 | int i; |
346 | 422 | ||
347 | async_set_client_connection(client_connection); |
423 | async_set_client_connection(client_connection); |
348 | 424 | ||
349 | /* Connect to keyboard driver */ |
425 | /* Connect to keyboard driver */ |
350 | 426 | ||
351 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
427 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
352 | usleep(10000); |
428 | usleep(10000); |
353 | }; |
429 | }; |
354 | 430 | ||
355 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
431 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
356 | return -1; |
432 | return -1; |
357 | }; |
433 | }; |
358 | 434 | ||
359 | /* Connect to framebuffer driver */ |
435 | /* Connect to framebuffer driver */ |
360 | 436 | ||
361 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
437 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
362 | usleep(10000); |
438 | usleep(10000); |
363 | } |
439 | } |
- | 440 | ||
- | 441 | /* Save old kernel screen */ |
|
- | 442 | kernel_pixmap = switch_screens(-1); |
|
364 | 443 | ||
365 | /* Initialize gcons */ |
444 | /* Initialize gcons */ |
366 | gcons_init(fb_info.phone); |
445 | gcons_init(fb_info.phone); |
367 | /* Synchronize, the gcons can have something in queue */ |
446 | /* Synchronize, the gcons can have something in queue */ |
368 | sync_send_2(fb_info.phone, FB_GET_CSIZE, 0, 0, NULL, NULL); |
447 | sync_send_2(fb_info.phone, FB_GET_CSIZE, 0, 0, NULL, NULL); |
369 | 448 | ||
370 | 449 | ||
371 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
450 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
372 | nsend_call_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); |
451 | set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); |
373 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
452 | clrscr(); |
374 | 453 | ||
375 | /* Init virtual consoles */ |
454 | /* Init virtual consoles */ |
376 | for (i = 0; i < CONSOLE_COUNT; i++) { |
455 | for (i = 0; i < CONSOLE_COUNT; i++) { |
377 | connections[i].used = 0; |
456 | connections[i].used = 0; |
378 | keybuffer_init(&(connections[i].keybuffer)); |
457 | keybuffer_init(&(connections[i].keybuffer)); |
379 | 458 | ||
380 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
459 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
381 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
460 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
382 | connections[i].keyrequest_counter = 0; |
461 | connections[i].keyrequest_counter = 0; |
383 | 462 | ||
384 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
463 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
385 | /*FIXME: handle error */ |
464 | /*FIXME: handle error */ |
386 | return -1; |
465 | return -1; |
387 | } |
466 | } |
388 | } |
467 | } |
389 | 468 | ||
390 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) { |
469 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) { |
391 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ, NULL, NULL, NULL) != 0) { |
470 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ, NULL, NULL, NULL) != 0) { |
392 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
471 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
393 | interbuffer = NULL; |
472 | interbuffer = NULL; |
394 | } |
473 | } |
395 | } |
474 | } |
396 | 475 | ||
397 | /* FIXME: save kernel console screen */ |
- | |
398 | - | ||
399 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
476 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
400 | 477 | ||
401 | sync_send_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0, NULL, NULL); |
478 | sync_send_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0, NULL, NULL); |
402 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
479 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
403 | 480 | ||
404 | /* Register at NS */ |
481 | /* Register at NS */ |
405 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
482 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
406 | return -1; |
483 | return -1; |
407 | }; |
484 | }; |
408 | 485 | ||
409 | async_manager(); |
486 | async_manager(); |
410 | 487 | ||
411 | return 0; |
488 | return 0; |
412 | } |
489 | } |
413 | 490 | ||
414 | 491 |