Rev 1518 | Rev 1521 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1518 | Rev 1520 | ||
---|---|---|---|
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 | #define MAX_KEYREQUESTS_BUFFERED 32 |
44 | #define MAX_KEYREQUESTS_BUFFERED 32 |
45 | 45 | ||
46 | #define NAME "CONSOLE" |
46 | #define NAME "CONSOLE" |
47 | 47 | ||
48 | int active_console = 0; |
48 | int active_console = 0; |
49 | 49 | ||
50 | struct { |
50 | struct { |
51 | int phone; /**< Framebuffer phone */ |
51 | int phone; /**< Framebuffer phone */ |
52 | ipcarg_t rows; /**< Framebuffer rows */ |
52 | ipcarg_t rows; /**< Framebuffer rows */ |
53 | ipcarg_t cols; /**< Framebuffer columns */ |
53 | ipcarg_t cols; /**< Framebuffer columns */ |
54 | } fb_info; |
54 | } fb_info; |
55 | 55 | ||
56 | typedef struct { |
56 | typedef struct { |
57 | keybuffer_t keybuffer; |
57 | keybuffer_t keybuffer; |
58 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); |
58 | FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); |
59 | int keyrequest_counter; |
59 | int keyrequest_counter; |
60 | int client_phone; |
60 | int client_phone; |
61 | int used; |
61 | int used; |
62 | screenbuffer_t screenbuffer; |
62 | screenbuffer_t screenbuffer; |
63 | } connection_t; |
63 | } connection_t; |
64 | 64 | ||
65 | 65 | ||
66 | 66 | ||
67 | connection_t connections[CONSOLE_COUNT]; |
67 | connection_t connections[CONSOLE_COUNT]; |
68 | keyfield_t *interbuffer = NULL; |
68 | keyfield_t *interbuffer = NULL; |
69 | 69 | ||
70 | static int find_free_connection() |
70 | static int find_free_connection() |
71 | { |
71 | { |
72 | int i = 0; |
72 | int i = 0; |
73 | 73 | ||
74 | while (i < CONSOLE_COUNT) { |
74 | while (i < CONSOLE_COUNT) { |
75 | if (connections[i].used == 0) |
75 | if (connections[i].used == 0) |
76 | return i; |
76 | return i; |
77 | ++i; |
77 | ++i; |
78 | } |
78 | } |
79 | return CONSOLE_COUNT; |
79 | return CONSOLE_COUNT; |
80 | } |
80 | } |
81 | 81 | ||
82 | 82 | ||
83 | static int find_connection(int client_phone) |
83 | static int find_connection(int client_phone) |
84 | { |
84 | { |
85 | int i = 0; |
85 | int i = 0; |
86 | 86 | ||
87 | while (i < CONSOLE_COUNT) { |
87 | while (i < CONSOLE_COUNT) { |
88 | if (connections[i].client_phone == client_phone) |
88 | if (connections[i].client_phone == client_phone) |
89 | return i; |
89 | return i; |
90 | ++i; |
90 | ++i; |
91 | } |
91 | } |
92 | return CONSOLE_COUNT; |
92 | return CONSOLE_COUNT; |
93 | } |
93 | } |
94 | 94 | ||
95 | /** Check key and process special keys. |
95 | /** Check key and process special keys. |
96 | * |
96 | * |
97 | * */ |
97 | * */ |
98 | static void write_char(int console, char key) |
98 | static void write_char(int console, char key) |
99 | { |
99 | { |
100 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
100 | screenbuffer_t *scr = &(connections[console].screenbuffer); |
101 | 101 | ||
102 | switch (key) { |
102 | switch (key) { |
103 | case '\n': |
103 | case '\n': |
104 | scr->position_y += 1; |
104 | scr->position_y += 1; |
105 | scr->position_x = 0; |
105 | scr->position_x = 0; |
106 | break; |
106 | break; |
107 | case '\r': |
107 | case '\r': |
108 | break; |
108 | break; |
109 | case '\t': |
109 | case '\t': |
110 | scr->position_x += 8; |
110 | scr->position_x += 8; |
111 | scr->position_x -= scr->position_x % 8; |
111 | scr->position_x -= scr->position_x % 8; |
112 | break; |
112 | break; |
113 | case '\b': |
113 | case '\b': |
114 | if (scr->position_x == 0) |
114 | if (scr->position_x == 0) |
115 | break; |
115 | break; |
116 | 116 | ||
117 | scr->position_x--; |
117 | scr->position_x--; |
118 | 118 | ||
119 | if (console == active_console) { |
119 | if (console == active_console) { |
120 | nsend_call_3(fb_info.phone, FB_PUTCHAR, ' ', scr->position_y, scr->position_x); |
120 | nsend_call_3(fb_info.phone, FB_PUTCHAR, ' ', scr->position_y, scr->position_x); |
121 | } |
121 | } |
122 | 122 | ||
123 | screenbuffer_putchar(scr, ' '); |
123 | screenbuffer_putchar(scr, ' '); |
124 | 124 | ||
125 | break; |
125 | break; |
126 | default: |
126 | default: |
127 | if (console == active_console) { |
127 | if (console == active_console) { |
128 | nsend_call_3(fb_info.phone, FB_PUTCHAR, key, scr->position_y, scr->position_x); |
128 | nsend_call_3(fb_info.phone, FB_PUTCHAR, key, scr->position_y, scr->position_x); |
129 | } |
129 | } |
130 | 130 | ||
131 | screenbuffer_putchar(scr, key); |
131 | screenbuffer_putchar(scr, key); |
132 | scr->position_x++; |
132 | scr->position_x++; |
133 | } |
133 | } |
134 | 134 | ||
135 | scr->position_y += (scr->position_x >= scr->size_x); |
135 | scr->position_y += (scr->position_x >= scr->size_x); |
136 | 136 | ||
137 | if (scr->position_y >= scr->size_y) { |
137 | if (scr->position_y >= scr->size_y) { |
138 | scr->position_y = scr->size_y - 1; |
138 | scr->position_y = scr->size_y - 1; |
139 | screenbuffer_clear_line(scr, scr->top_line++); |
139 | screenbuffer_clear_line(scr, scr->top_line++); |
140 | if (console == active_console) |
140 | if (console == active_console) |
141 | nsend_call(fb_info.phone, FB_SCROLL, 1); |
141 | nsend_call(fb_info.phone, FB_SCROLL, 1); |
142 | } |
142 | } |
143 | 143 | ||
144 | scr->position_x = scr->position_x % scr->size_x; |
144 | scr->position_x = scr->position_x % scr->size_x; |
145 | 145 | ||
146 | if (console == active_console) |
146 | if (console == active_console) |
147 | send_call_2(fb_info.phone, FB_CURSOR_GOTO, scr->position_y, scr->position_x); |
147 | send_call_2(fb_info.phone, FB_CURSOR_GOTO, scr->position_y, scr->position_x); |
148 | 148 | ||
149 | } |
149 | } |
150 | 150 | ||
151 | 151 | ||
152 | /* Handler for keyboard */ |
152 | /* Handler for keyboard */ |
153 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
153 | static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall) |
154 | { |
154 | { |
155 | ipc_callid_t callid; |
155 | ipc_callid_t callid; |
156 | ipc_call_t call; |
156 | ipc_call_t call; |
157 | int retval; |
157 | int retval; |
158 | int i, j; |
158 | int i, j; |
159 | char c,d; |
159 | char c,d; |
160 | connection_t *conn; |
160 | connection_t *conn; |
161 | 161 | ||
162 | /* Ignore parameters, the connection is alread opened */ |
162 | /* Ignore parameters, the connection is alread opened */ |
163 | while (1) { |
163 | while (1) { |
164 | callid = async_get_call(&call); |
164 | callid = async_get_call(&call); |
165 | switch (IPC_GET_METHOD(call)) { |
165 | switch (IPC_GET_METHOD(call)) { |
166 | case IPC_M_PHONE_HUNGUP: |
166 | case IPC_M_PHONE_HUNGUP: |
167 | ipc_answer_fast(callid,0,0,0); |
167 | ipc_answer_fast(callid,0,0,0); |
168 | /* TODO: Handle hangup */ |
168 | /* TODO: Handle hangup */ |
169 | return; |
169 | return; |
170 | case KBD_PUSHCHAR: |
170 | case KBD_PUSHCHAR: |
171 | /* got key from keyboard driver */ |
171 | /* got key from keyboard driver */ |
172 | 172 | ||
173 | retval = 0; |
173 | retval = 0; |
174 | c = IPC_GET_ARG1(call) - '0'; |
174 | c = IPC_GET_ARG1(call); |
175 | /* switch to another virtual console */ |
175 | /* switch to another virtual console */ |
176 | 176 | ||
177 | conn = &connections[active_console]; |
177 | conn = &connections[active_console]; |
178 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
178 | // if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
179 | if ((c >= 0) && (c < CONSOLE_COUNT)) { |
179 | if ((c >= '0') && (c < '0' + CONSOLE_COUNT)) { |
180 | /*FIXME: draw another console content from buffer */ |
- | |
181 | if (c == active_console) |
- | |
182 | break; |
- | |
183 | 180 | ||
184 | if (c == 0) { |
181 | if (c == '0') { |
185 | /* switch to kernel console*/ |
182 | /* switch to kernel console*/ |
- | 183 | sync_send_2(fb_info.phone, FB_CURSOR_VISIBILITY, 0, 0, NULL, NULL); |
|
- | 184 | nsend_call_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); |
|
- | 185 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
|
- | 186 | /* FIXME: restore kernel console */ |
|
186 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
187 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
- | 188 | break; |
|
187 | 189 | ||
188 | } else { |
190 | } else { |
- | 191 | c = c - '1'; |
|
- | 192 | if (c == active_console) |
|
- | 193 | break; |
|
189 | active_console = c; |
194 | active_console = c; |
190 | } |
195 | } |
191 | 196 | ||
192 | - | ||
193 | conn = &connections[active_console]; |
197 | conn = &connections[active_console]; |
194 | 198 | ||
195 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 0); |
199 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 0); |
196 | 200 | ||
197 | if (interbuffer) { |
201 | if (interbuffer) { |
198 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
202 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
199 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
203 | for (j = 0; j < conn->screenbuffer.size_y; j++) |
200 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j); |
204 | interbuffer[i + j*conn->screenbuffer.size_x] = *get_field_at(&(conn->screenbuffer),i, j); |
201 | 205 | ||
202 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL); |
206 | sync_send_2(fb_info.phone, FB_DRAW_TEXT_DATA, 0, 0, NULL, NULL); |
203 | } else { |
207 | } else { |
204 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
208 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
205 | 209 | ||
206 | 210 | ||
207 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
211 | for (i = 0; i < conn->screenbuffer.size_x; i++) |
208 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
212 | for (j = 0; j < conn->screenbuffer.size_y; j++) { |
209 | d = get_field_at(&(conn->screenbuffer),i, j)->character; |
213 | d = get_field_at(&(conn->screenbuffer),i, j)->character; |
210 | if (d && d != ' ') |
214 | if (d && d != ' ') |
211 | nsend_call_3(fb_info.phone, FB_PUTCHAR, d, j, i); |
215 | nsend_call_3(fb_info.phone, FB_PUTCHAR, d, j, i); |
212 | } |
216 | } |
213 | 217 | ||
214 | } |
218 | } |
215 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, conn->screenbuffer.position_y, conn->screenbuffer.position_x); |
219 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, conn->screenbuffer.position_y, conn->screenbuffer.position_x); |
216 | nsend_call_2(fb_info.phone, FB_SET_STYLE, conn->screenbuffer.style.fg_color, \ |
220 | nsend_call_2(fb_info.phone, FB_SET_STYLE, conn->screenbuffer.style.fg_color, \ |
217 | conn->screenbuffer.style.bg_color); |
221 | conn->screenbuffer.style.bg_color); |
218 | send_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
222 | send_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
219 | 223 | ||
220 | break; |
224 | break; |
221 | } |
225 | } |
222 | 226 | ||
223 | /* if client is awaiting key, send it */ |
227 | /* if client is awaiting key, send it */ |
224 | if (conn->keyrequest_counter > 0) { |
228 | if (conn->keyrequest_counter > 0) { |
225 | conn->keyrequest_counter--; |
229 | conn->keyrequest_counter--; |
226 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0); |
230 | ipc_answer_fast(fifo_pop(conn->keyrequests), 0, c, 0); |
227 | break; |
231 | break; |
228 | } |
232 | } |
229 | 233 | ||
230 | /*FIXME: else store key to its buffer */ |
234 | /*FIXME: else store key to its buffer */ |
231 | keybuffer_push(&conn->keybuffer, c); |
235 | keybuffer_push(&conn->keybuffer, c); |
232 | 236 | ||
233 | break; |
237 | break; |
234 | default: |
238 | default: |
235 | retval = ENOENT; |
239 | retval = ENOENT; |
236 | } |
240 | } |
237 | ipc_answer_fast(callid, retval, 0, 0); |
241 | ipc_answer_fast(callid, retval, 0, 0); |
238 | } |
242 | } |
239 | } |
243 | } |
240 | 244 | ||
241 | /** Default thread for new connections */ |
245 | /** Default thread for new connections */ |
242 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
246 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
243 | { |
247 | { |
244 | ipc_callid_t callid; |
248 | ipc_callid_t callid; |
245 | ipc_call_t call; |
249 | ipc_call_t call; |
246 | int consnum; |
250 | int consnum; |
247 | ipcarg_t arg1; |
251 | ipcarg_t arg1; |
248 | 252 | ||
249 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
253 | if ((consnum = find_free_connection()) == CONSOLE_COUNT) { |
250 | ipc_answer_fast(iid,ELIMIT,0,0); |
254 | ipc_answer_fast(iid,ELIMIT,0,0); |
251 | return; |
255 | return; |
252 | } |
256 | } |
253 | 257 | ||
254 | connections[consnum].used = 1; |
258 | connections[consnum].used = 1; |
255 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
259 | connections[consnum].client_phone = IPC_GET_ARG3(call); |
256 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
260 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
257 | 261 | ||
258 | /* Accept the connection */ |
262 | /* Accept the connection */ |
259 | ipc_answer_fast(iid,0,0,0); |
263 | ipc_answer_fast(iid,0,0,0); |
260 | 264 | ||
261 | while (1) { |
265 | while (1) { |
262 | callid = async_get_call(&call); |
266 | callid = async_get_call(&call); |
263 | switch (IPC_GET_METHOD(call)) { |
267 | switch (IPC_GET_METHOD(call)) { |
264 | case IPC_M_PHONE_HUNGUP: |
268 | case IPC_M_PHONE_HUNGUP: |
265 | /* TODO */ |
269 | /* TODO */ |
266 | ipc_answer_fast(callid, 0,0,0); |
270 | ipc_answer_fast(callid, 0,0,0); |
267 | return; |
271 | return; |
268 | case CONSOLE_PUTCHAR: |
272 | case CONSOLE_PUTCHAR: |
269 | write_char(consnum, IPC_GET_ARG1(call)); |
273 | write_char(consnum, IPC_GET_ARG1(call)); |
270 | break; |
274 | break; |
271 | case CONSOLE_CLEAR: |
275 | case CONSOLE_CLEAR: |
272 | /* Send message to fb */ |
276 | /* Send message to fb */ |
273 | if (consnum == active_console) { |
277 | if (consnum == active_console) { |
274 | send_call(fb_info.phone, FB_CLEAR, 0); |
278 | send_call(fb_info.phone, FB_CLEAR, 0); |
275 | } |
279 | } |
276 | 280 | ||
277 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
281 | screenbuffer_clear(&(connections[consnum].screenbuffer)); |
278 | 282 | ||
279 | break; |
283 | break; |
280 | case CONSOLE_GOTO: |
284 | case CONSOLE_GOTO: |
281 | 285 | ||
282 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
286 | screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
283 | 287 | ||
284 | break; |
288 | break; |
285 | 289 | ||
286 | case CONSOLE_GETCHAR: |
290 | case CONSOLE_GETCHAR: |
287 | if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
291 | if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
288 | /* buffer is empty -> store request */ |
292 | /* buffer is empty -> store request */ |
289 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) { |
293 | if (connections[consnum].keyrequest_counter < MAX_KEYREQUESTS_BUFFERED) { |
290 | fifo_push(connections[consnum].keyrequests, callid); |
294 | fifo_push(connections[consnum].keyrequests, callid); |
291 | connections[consnum].keyrequest_counter++; |
295 | connections[consnum].keyrequest_counter++; |
292 | } else { |
296 | } else { |
293 | /* no key available and too many requests => fail */ |
297 | /* no key available and too many requests => fail */ |
294 | ipc_answer_fast(callid, ELIMIT, 0, 0); |
298 | ipc_answer_fast(callid, ELIMIT, 0, 0); |
295 | } |
299 | } |
296 | continue; |
300 | continue; |
297 | }; |
301 | }; |
298 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
302 | keybuffer_pop(&(connections[consnum].keybuffer), (char *)&arg1); |
299 | 303 | ||
300 | break; |
304 | break; |
301 | } |
305 | } |
302 | ipc_answer_fast(callid, 0, arg1, 0); |
306 | ipc_answer_fast(callid, 0, arg1, 0); |
303 | } |
307 | } |
304 | } |
308 | } |
305 | 309 | ||
306 | int main(int argc, char *argv[]) |
310 | int main(int argc, char *argv[]) |
307 | { |
311 | { |
308 | ipcarg_t phonehash; |
312 | ipcarg_t phonehash; |
309 | int kbd_phone, fb_phone; |
313 | int kbd_phone, fb_phone; |
310 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
314 | ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef; |
311 | int i; |
315 | int i; |
312 | 316 | ||
313 | async_set_client_connection(client_connection); |
317 | async_set_client_connection(client_connection); |
314 | 318 | ||
315 | /* Connect to keyboard driver */ |
319 | /* Connect to keyboard driver */ |
316 | 320 | ||
317 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
321 | while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) { |
318 | usleep(10000); |
322 | usleep(10000); |
319 | }; |
323 | }; |
320 | 324 | ||
321 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
325 | if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
322 | return -1; |
326 | return -1; |
323 | }; |
327 | }; |
324 | 328 | ||
325 | /* Connect to framebuffer driver */ |
329 | /* Connect to framebuffer driver */ |
326 | 330 | ||
327 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
331 | while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
328 | usleep(10000); |
332 | usleep(10000); |
329 | } |
333 | } |
330 | 334 | ||
331 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
335 | ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
332 | nsend_call_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); |
336 | nsend_call_2(fb_info.phone, FB_SET_STYLE, DEFAULT_FOREGROUND_COLOR, DEFAULT_BACKGROUND_COLOR); |
333 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
337 | nsend_call(fb_info.phone, FB_CLEAR, 0); |
334 | 338 | ||
335 | /* Init virtual consoles */ |
339 | /* Init virtual consoles */ |
336 | for (i = 0; i < CONSOLE_COUNT; i++) { |
340 | for (i = 0; i < CONSOLE_COUNT; i++) { |
337 | connections[i].used = 0; |
341 | connections[i].used = 0; |
338 | keybuffer_init(&(connections[i].keybuffer)); |
342 | keybuffer_init(&(connections[i].keybuffer)); |
339 | 343 | ||
340 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
344 | connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
341 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
345 | connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
342 | connections[i].keyrequest_counter = 0; |
346 | connections[i].keyrequest_counter = 0; |
343 | 347 | ||
344 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
348 | if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
345 | /*FIXME: handle error */ |
349 | /*FIXME: handle error */ |
346 | return -1; |
350 | return -1; |
347 | } |
351 | } |
348 | } |
352 | } |
349 | 353 | ||
350 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) { |
354 | if ((interbuffer = mmap(NULL, sizeof(keyfield_t) * fb_info.cols * fb_info.rows , PROTO_READ|PROTO_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0 ,0 )) != NULL) { |
351 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ | AS_AREA_CACHEABLE, NULL, NULL, NULL) != 0) { |
355 | if (ipc_call_sync_3(fb_info.phone, IPC_M_AS_AREA_SEND, (ipcarg_t)interbuffer, 0, AS_AREA_READ | AS_AREA_CACHEABLE, NULL, NULL, NULL) != 0) { |
352 | // ipc_call_async_3(fb_info.phone, FB_PUTCHAR, '?', 10, 10, NULL, NULL); |
- | |
353 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
356 | munmap(interbuffer, sizeof(keyfield_t) * fb_info.cols * fb_info.rows); |
354 | interbuffer = NULL; |
357 | interbuffer = NULL; |
355 | } |
358 | } |
356 | /* } else { |
- | |
357 | ipc_call_async_3(fb_info.phone, FB_PUTCHAR, '!', 10, 10, NULL, NULL); |
- | |
358 | */ |
- | |
359 | } |
359 | } |
360 | 360 | ||
- | 361 | /* FIXME: save kernel console screen */ |
|
- | 362 | ||
361 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
363 | async_new_connection(phonehash, 0, NULL, keyboard_events); |
362 | 364 | ||
363 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0); |
365 | nsend_call_2(fb_info.phone, FB_CURSOR_GOTO, 0, 0); |
- | 366 | nsend_call(fb_info.phone, FB_CURSOR_VISIBILITY, 1); |
|
364 | 367 | ||
365 | /* Register at NS */ |
368 | /* Register at NS */ |
366 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
369 | if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
367 | return -1; |
370 | return -1; |
368 | }; |
371 | }; |
369 | 372 | ||
370 | async_manager(); |
373 | async_manager(); |
371 | 374 | ||
372 | return 0; |
375 | return 0; |
373 | } |
376 | } |
- | 377 | ||
374 | 378 |