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