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