Subversion Repositories HelenOS

Rev

Rev 4153 | Rev 4327 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4153 Rev 4263
1
/*
1
/*
2
 * Copyright (c) 2006 Josef Cejka
2
 * Copyright (c) 2006 Josef Cejka
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup console
29
/** @addtogroup console
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <libc.h>
35
#include <libc.h>
36
#include <fb.h>
36
#include <fb.h>
37
#include <ipc/ipc.h>
37
#include <ipc/ipc.h>
38
#include <kbd.h>
38
#include <kbd.h>
39
#include <kbd/keycode.h>
39
#include <kbd/keycode.h>
40
#include <ipc/fb.h>
40
#include <ipc/fb.h>
41
#include <ipc/services.h>
41
#include <ipc/services.h>
42
#include <errno.h>
42
#include <errno.h>
43
#include <key_buffer.h>
43
#include <key_buffer.h>
44
#include <ipc/console.h>
44
#include <ipc/console.h>
45
#include <unistd.h>
45
#include <unistd.h>
46
#include <async.h>
46
#include <async.h>
47
#include <libadt/fifo.h>
47
#include <libadt/fifo.h>
48
#include <screenbuffer.h>
48
#include <screenbuffer.h>
49
#include <sys/mman.h>
49
#include <sys/mman.h>
50
#include <stdio.h>
50
#include <stdio.h>
-
 
51
#include <string.h>
51
#include <sysinfo.h>
52
#include <sysinfo.h>
-
 
53
#include <event.h>
52
 
54
 
53
#include "console.h"
55
#include "console.h"
54
#include "gcons.h"
56
#include "gcons.h"
55
 
57
 
56
#define MAX_KEYREQUESTS_BUFFERED 32
58
#define MAX_KEYREQUESTS_BUFFERED 32
57
 
59
 
58
#define NAME "console"
60
#define NAME "console"
59
 
61
 
60
/** Index of currently used virtual console.
62
/** Index of currently used virtual console.
61
 */
63
 */
62
int active_console = 0;
64
int active_console = 0;
63
int prev_console = 0;
65
int prev_console = 0;
64
 
66
 
65
/** Information about framebuffer
67
/** Information about framebuffer */
66
 */
-
 
67
struct {
68
struct {
68
    int phone;      /**< Framebuffer phone */
69
    int phone;      /**< Framebuffer phone */
69
    ipcarg_t rows;      /**< Framebuffer rows */
70
    ipcarg_t rows;      /**< Framebuffer rows */
70
    ipcarg_t cols;      /**< Framebuffer columns */
71
    ipcarg_t cols;      /**< Framebuffer columns */
71
} fb_info;
72
} fb_info;
72
 
73
 
73
typedef struct {
74
typedef struct {
74
    keybuffer_t keybuffer;      /**< Buffer for incoming keys. */
75
    keybuffer_t keybuffer;      /**< Buffer for incoming keys. */
75
    /** Buffer for unsatisfied request for keys. */
76
    /** Buffer for unsatisfied request for keys. */
76
    FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
77
    FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
77
        MAX_KEYREQUESTS_BUFFERED); 
78
        MAX_KEYREQUESTS_BUFFERED); 
78
    int keyrequest_counter;     /**< Number of requests in buffer. */
79
    int keyrequest_counter;     /**< Number of requests in buffer. */
79
    int client_phone;       /**< Phone to connected client. */
80
    int client_phone;       /**< Phone to connected client. */
80
    int used;           /**< 1 if this virtual console is
81
    int used;           /**< 1 if this virtual console is
81
                     * connected to some client.*/
82
                     * connected to some client.*/
82
    screenbuffer_t screenbuffer;    /**< Screenbuffer for saving screen
83
    screenbuffer_t screenbuffer;    /**< Screenbuffer for saving screen
83
                     * contents and related settings. */
84
                     * contents and related settings. */
84
} connection_t;
85
} connection_t;
85
 
86
 
86
static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual
87
static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual
87
                         * consoles */
88
                         * consoles */
88
static keyfield_t *interbuffer = NULL;      /**< Pointer to memory shared
89
static keyfield_t *interbuffer = NULL;      /**< Pointer to memory shared
89
                         * with framebufer used for
90
                         * with framebufer used for
90
                         * faster virtual console
91
                         * faster virtual console
91
                         * switching */
92
                         * switching */
92
 
93
 
-
 
94
/** Information on row-span yet unsent to FB driver. */
-
 
95
struct {
-
 
96
    int row;        /**< Row where the span lies. */
-
 
97
    int col;        /**< Leftmost column of the span. */
-
 
98
    int n;          /**< Width of the span. */
-
 
99
} fb_pending;
-
 
100
 
-
 
101
/** Size of cwrite_buf. */
-
 
102
#define CWRITE_BUF_SIZE 256
-
 
103
 
-
 
104
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
-
 
105
static char cwrite_buf[CWRITE_BUF_SIZE];
-
 
106
 
-
 
107
static void fb_putchar(wchar_t c, int row, int col);
-
 
108
 
93
 
109
 
94
/** Find unused virtual console.
110
/** Find unused virtual console.
95
 *
111
 *
96
 */
112
 */
97
static int find_free_connection(void)
113
static int find_free_connection(void)
98
{
114
{
99
    int i;
115
    int i;
100
   
116
   
101
    for (i = 0; i < CONSOLE_COUNT; i++) {
117
    for (i = 0; i < CONSOLE_COUNT; i++) {
102
        if (!connections[i].used)
118
        if (!connections[i].used)
103
            return i;
119
            return i;
104
    }
120
    }
105
    return -1;
121
    return -1;
106
}
122
}
107
 
123
 
108
static void clrscr(void)
124
static void clrscr(void)
109
{
125
{
110
    async_msg_0(fb_info.phone, FB_CLEAR);
126
    async_msg_0(fb_info.phone, FB_CLEAR);
111
}
127
}
112
 
128
 
113
static void curs_visibility(bool visible)
129
static void curs_visibility(bool visible)
114
{
130
{
115
    async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
131
    async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
116
}
132
}
117
 
133
 
118
static void curs_hide_sync(void)
134
static void curs_hide_sync(void)
119
{
135
{
120
    ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
136
    ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
121
}
137
}
122
 
138
 
123
static void curs_goto(int row, int col)
139
static void curs_goto(int row, int col)
124
{
140
{
125
    async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
141
    async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
126
}
142
}
127
 
143
 
128
static void set_style(int style)
144
static void set_style(int style)
129
{
145
{
130
    async_msg_1(fb_info.phone, FB_SET_STYLE, style);
146
    async_msg_1(fb_info.phone, FB_SET_STYLE, style);
131
}
147
}
132
 
148
 
133
static void set_color(int fgcolor, int bgcolor, int flags)
149
static void set_color(int fgcolor, int bgcolor, int flags)
134
{
150
{
135
    async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
151
    async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
136
}
152
}
137
 
153
 
138
static void set_rgb_color(int fgcolor, int bgcolor)
154
static void set_rgb_color(int fgcolor, int bgcolor)
139
{
155
{
140
    async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
156
    async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
141
}
157
}
142
 
158
 
143
static void set_attrs(attrs_t *attrs)
159
static void set_attrs(attrs_t *attrs)
144
{
160
{
145
    switch (attrs->t) {
161
    switch (attrs->t) {
146
    case at_style:
162
    case at_style:
147
        set_style(attrs->a.s.style);
163
        set_style(attrs->a.s.style);
148
        break;
164
        break;
149
 
165
 
150
    case at_idx:
166
    case at_idx:
151
        set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
167
        set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
152
            attrs->a.i.flags);
168
            attrs->a.i.flags);
153
        break;
169
        break;
154
 
170
 
155
    case at_rgb:
171
    case at_rgb:
156
        set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
172
        set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
157
        break;
173
        break;
158
    }
174
    }
159
}
175
}
160
 
176
 
-
 
177
/** Send an area of screenbuffer to the FB driver. */
161
static void prtchr(char c, int row, int col)
178
static void fb_update_area(connection_t *conn, int x, int y, int w, int h)
162
{
179
{
-
 
180
    int i, j;
-
 
181
    int rc;
-
 
182
    attrs_t *attrs;
-
 
183
    keyfield_t *field;
-
 
184
 
-
 
185
    if (interbuffer) {
-
 
186
        for (j = 0; j < h; j++) {
-
 
187
            for (i = 0; i < w; i++) {
-
 
188
                interbuffer[i + j * w] =
-
 
189
                    *get_field_at(&conn->screenbuffer,
-
 
190
                    x + i, y + j);
-
 
191
            }
-
 
192
        }
-
 
193
 
163
    async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
194
        rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
-
 
195
            x, y, w, h);
-
 
196
    } else {
-
 
197
        rc = ENOTSUP;
-
 
198
    }
-
 
199
 
-
 
200
    if (rc != 0) {
-
 
201
        /*
-
 
202
        attrs = &conn->screenbuffer.attrs;
-
 
203
 
-
 
204
        for (j = 0; j < h; j++) {
-
 
205
            for (i = 0; i < w; i++) {
-
 
206
                field = get_field_at(&conn->screenbuffer,
-
 
207
                    x + i, y + j);
-
 
208
                if (!attrs_same(*attrs, field->attrs))
-
 
209
                    set_attrs(&field->attrs);
-
 
210
                attrs = &field->attrs;
-
 
211
 
-
 
212
                fb_putchar(field->character, y + j, x + i);
-
 
213
            }
-
 
214
        }*/
-
 
215
    }
164
}
216
}
165
 
217
 
166
/** Check key and process special keys.
218
/** Flush pending cells to FB. */
-
 
219
static void fb_pending_flush(void)
-
 
220
{
-
 
221
    screenbuffer_t *scr;
-
 
222
 
-
 
223
    scr = &(connections[active_console].screenbuffer);
-
 
224
 
-
 
225
    if (fb_pending.n > 0) {
-
 
226
        fb_update_area(&connections[active_console], fb_pending.col,
-
 
227
            fb_pending.row, fb_pending.n, 1);
-
 
228
        fb_pending.n = 0;
167
 *
229
    }
-
 
230
}
-
 
231
 
-
 
232
/** Mark a character cell as changed.
168
 *
233
 *
-
 
234
 * This adds the cell to the pending rowspan if possible. Otherwise
-
 
235
 * the old span is flushed first.
169
 */
236
 */
-
 
237
static void cell_mark_changed(int row, int col)
-
 
238
{
-
 
239
    if (fb_pending.n != 0) {
-
 
240
        if (row != fb_pending.row ||
-
 
241
            col != fb_pending.col + fb_pending.n) {
-
 
242
            fb_pending_flush();
-
 
243
        }
-
 
244
    }
-
 
245
 
-
 
246
    if (fb_pending.n == 0) {
-
 
247
        fb_pending.row = row;
-
 
248
        fb_pending.col = col;
-
 
249
    }
-
 
250
 
-
 
251
    ++fb_pending.n;
-
 
252
}
-
 
253
 
-
 
254
 
-
 
255
/** Print a character to the active VC with buffering. */
170
static void write_char(int console, char key)
256
static void fb_putchar(wchar_t c, int row, int col)
171
{
257
{
-
 
258
    async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
-
 
259
}
-
 
260
 
-
 
261
/** Process a character from the client (TTY emulation). */
-
 
262
static void write_char(int console, wchar_t ch)
-
 
263
{
-
 
264
    bool flush_cursor = false;
172
    screenbuffer_t *scr = &(connections[console].screenbuffer);
265
    screenbuffer_t *scr = &(connections[console].screenbuffer);
173
   
266
 
174
    switch (key) {
267
    switch (ch) {
175
    case '\n':
268
    case '\n':
-
 
269
        fb_pending_flush();
-
 
270
        flush_cursor = true;
176
        scr->position_y++;
271
        scr->position_y++;
177
        scr->position_x = 0;
272
        scr->position_x = 0;
178
        break;
273
        break;
179
    case '\r':
274
    case '\r':
180
        break;
275
        break;
181
    case '\t':
276
    case '\t':
182
        scr->position_x += 8;
277
        scr->position_x += 8;
183
        scr->position_x -= scr->position_x % 8;
278
        scr->position_x -= scr->position_x % 8;
184
        break;
279
        break;
185
    case '\b':
280
    case '\b':
186
        if (scr->position_x == 0)
281
        if (scr->position_x == 0)
187
            break;
282
            break;
188
        scr->position_x--;
283
        scr->position_x--;
189
        if (console == active_console)
284
        if (console == active_console)
190
            prtchr(' ', scr->position_y, scr->position_x);
285
            cell_mark_changed(scr->position_y, scr->position_x);
191
        screenbuffer_putchar(scr, ' ');
286
        screenbuffer_putchar(scr, ' ');
192
        break;
287
        break;
193
    default:   
288
    default:   
194
        if (console == active_console)
289
        if (console == active_console)
195
            prtchr(key, scr->position_y, scr->position_x);
290
            cell_mark_changed(scr->position_y, scr->position_x);
196
 
291
 
197
        screenbuffer_putchar(scr, key);
292
        screenbuffer_putchar(scr, ch);
198
        scr->position_x++;
293
        scr->position_x++;
199
    }
294
    }
200
   
295
 
201
    scr->position_y += (scr->position_x >= scr->size_x);
296
    if (scr->position_x >= scr->size_x) {
-
 
297
        flush_cursor = true;
-
 
298
        scr->position_y++;
-
 
299
    }
202
   
300
   
203
    if (scr->position_y >= scr->size_y) {
301
    if (scr->position_y >= scr->size_y) {
-
 
302
        fb_pending_flush();
204
        scr->position_y = scr->size_y - 1;
303
        scr->position_y = scr->size_y - 1;
205
        screenbuffer_clear_line(scr, scr->top_line);
304
        screenbuffer_clear_line(scr, scr->top_line);
206
        scr->top_line = (scr->top_line + 1) % scr->size_y;
305
        scr->top_line = (scr->top_line + 1) % scr->size_y;
207
        if (console == active_console)
306
        if (console == active_console)
208
            async_msg_1(fb_info.phone, FB_SCROLL, 1);
307
            async_msg_1(fb_info.phone, FB_SCROLL, 1);
209
    }
308
    }
210
   
309
 
211
    scr->position_x = scr->position_x % scr->size_x;
310
    scr->position_x = scr->position_x % scr->size_x;
212
   
311
 
213
    if (console == active_console)
312
    if (console == active_console && flush_cursor)
214
        curs_goto(scr->position_y, scr->position_x);
313
        curs_goto(scr->position_y, scr->position_x);
215
   
-
 
216
}
314
}
217
 
315
 
218
/** Switch to new console */
316
/** Switch to new console */
219
static void change_console(int newcons)
317
static void change_console(int newcons)
220
{
318
{
221
    connection_t *conn;
319
    connection_t *conn;
222
    int i, j, rc;
320
    int i, j, rc;
223
    keyfield_t *field;
321
    keyfield_t *field;
224
    attrs_t *attrs;
322
    attrs_t *attrs;
225
   
323
   
226
    if (newcons == active_console)
324
    if (newcons == active_console)
227
        return;
325
        return;
-
 
326
 
-
 
327
    fb_pending_flush();
228
   
328
 
229
    if (newcons == KERNEL_CONSOLE) {
329
    if (newcons == KERNEL_CONSOLE) {
230
        async_serialize_start();
330
        async_serialize_start();
231
        curs_hide_sync();
331
        curs_hide_sync();
232
        gcons_in_kernel();
332
        gcons_in_kernel();
233
        async_serialize_end();
333
        async_serialize_end();
234
       
334
       
235
        if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
335
        if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
236
            prev_console = active_console;
336
            prev_console = active_console;
237
            active_console = KERNEL_CONSOLE;
337
            active_console = KERNEL_CONSOLE;
238
        } else
338
        } else
239
            newcons = active_console;
339
            newcons = active_console;
240
    }
340
    }
241
   
341
   
242
    if (newcons != KERNEL_CONSOLE) {
342
    if (newcons != KERNEL_CONSOLE) {
243
        async_serialize_start();
343
        async_serialize_start();
244
       
344
       
245
        if (active_console == KERNEL_CONSOLE)
345
        if (active_console == KERNEL_CONSOLE)
246
            gcons_redraw_console();
346
            gcons_redraw_console();
247
       
347
       
248
        active_console = newcons;
348
        active_console = newcons;
249
        gcons_change_console(newcons);
349
        gcons_change_console(newcons);
250
        conn = &connections[active_console];
350
        conn = &connections[active_console];
251
       
351
       
252
        set_attrs(&conn->screenbuffer.attrs);
352
        set_attrs(&conn->screenbuffer.attrs);
253
        curs_visibility(false);
353
        curs_visibility(false);
254
        if (interbuffer) {
354
        if (interbuffer) {
255
            for (i = 0; i < conn->screenbuffer.size_x; i++)
355
            for (j = 0; j < conn->screenbuffer.size_y; j++) {
256
                for (j = 0; j < conn->screenbuffer.size_y; j++) {
356
                for (i = 0; i < conn->screenbuffer.size_x; i++) {
257
                    unsigned int size_x;
357
                    unsigned int size_x;
258
                   
358
                   
259
                    size_x = conn->screenbuffer.size_x;
359
                    size_x = conn->screenbuffer.size_x;
260
                    interbuffer[i + j * size_x] =
360
                    interbuffer[j * size_x + i] =
261
                        *get_field_at(&conn->screenbuffer, i, j);
361
                        *get_field_at(&conn->screenbuffer, i, j);
262
                }
362
                }
-
 
363
            }
263
            /* This call can preempt, but we are already at the end */
364
            /* This call can preempt, but we are already at the end */
264
            rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);
365
            rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
-
 
366
                0, 0, conn->screenbuffer.size_x,
-
 
367
                conn->screenbuffer.size_y);
265
        }
368
        }
266
       
369
       
267
        if ((!interbuffer) || (rc != 0)) {
370
        if ((!interbuffer) || (rc != 0)) {
268
            set_attrs(&conn->screenbuffer.attrs);
371
            set_attrs(&conn->screenbuffer.attrs);
269
            clrscr();
372
            clrscr();
270
            attrs = &conn->screenbuffer.attrs;
373
            attrs = &conn->screenbuffer.attrs;
271
           
374
           
272
            for (j = 0; j < conn->screenbuffer.size_y; j++)
375
            for (j = 0; j < conn->screenbuffer.size_y; j++)
273
                for (i = 0; i < conn->screenbuffer.size_x; i++) {
376
                for (i = 0; i < conn->screenbuffer.size_x; i++) {
274
                    field = get_field_at(&conn->screenbuffer, i, j);
377
                    field = get_field_at(&conn->screenbuffer, i, j);
275
                    if (!attrs_same(*attrs, field->attrs))
378
                    if (!attrs_same(*attrs, field->attrs))
276
                        set_attrs(&field->attrs);
379
                        set_attrs(&field->attrs);
277
                    attrs = &field->attrs;
380
                    attrs = &field->attrs;
278
                    if ((field->character == ' ') &&
381
                    if ((field->character == ' ') &&
279
                        (attrs_same(field->attrs,
382
                        (attrs_same(field->attrs,
280
                        conn->screenbuffer.attrs)))
383
                        conn->screenbuffer.attrs)))
281
                        continue;
384
                        continue;
282
 
385
 
283
                    prtchr(field->character, j, i);
386
                    fb_putchar(field->character, j, i);
284
                }
387
                }
285
        }
388
        }
286
       
389
       
287
        curs_goto(conn->screenbuffer.position_y,
390
        curs_goto(conn->screenbuffer.position_y,
288
            conn->screenbuffer.position_x);
391
            conn->screenbuffer.position_x);
289
        curs_visibility(conn->screenbuffer.is_cursor_visible);
392
        curs_visibility(conn->screenbuffer.is_cursor_visible);
290
       
393
       
291
        async_serialize_end();
394
        async_serialize_end();
292
    }
395
    }
293
}
396
}
294
 
397
 
295
/** Handler for keyboard */
398
/** Handler for keyboard */
296
static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
399
static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
297
{
400
{
298
    ipc_callid_t callid;
401
    ipc_callid_t callid;
299
    ipc_call_t call;
402
    ipc_call_t call;
300
    int retval;
403
    int retval;
301
    kbd_event_t ev;
404
    kbd_event_t ev;
302
    connection_t *conn;
405
    connection_t *conn;
303
    int newcon;
406
    int newcon;
304
   
407
   
305
    /* Ignore parameters, the connection is alread opened */
408
    /* Ignore parameters, the connection is alread opened */
306
    while (1) {
409
    while (1) {
307
        callid = async_get_call(&call);
410
        callid = async_get_call(&call);
308
        switch (IPC_GET_METHOD(call)) {
411
        switch (IPC_GET_METHOD(call)) {
309
        case IPC_M_PHONE_HUNGUP:
412
        case IPC_M_PHONE_HUNGUP:
310
            /* TODO: Handle hangup */
413
            /* TODO: Handle hangup */
311
            return;
414
            return;
312
        case KBD_MS_LEFT:
415
        case KBD_MS_LEFT:
313
            newcon = gcons_mouse_btn(IPC_GET_ARG1(call));
416
            newcon = gcons_mouse_btn(IPC_GET_ARG1(call));
314
            if (newcon != -1)
417
            if (newcon != -1)
315
                change_console(newcon);
418
                change_console(newcon);
316
            retval = 0;
419
            retval = 0;
317
            break;
420
            break;
318
        case KBD_MS_MOVE:
421
        case KBD_MS_MOVE:
319
            gcons_mouse_move(IPC_GET_ARG1(call),
422
            gcons_mouse_move(IPC_GET_ARG1(call),
320
                IPC_GET_ARG2(call));
423
                IPC_GET_ARG2(call));
321
            retval = 0;
424
            retval = 0;
322
            break;
425
            break;
323
        case KBD_EVENT:
426
        case KBD_EVENT:
324
            /* Got event from keyboard driver. */
427
            /* Got event from keyboard driver. */
325
            retval = 0;
428
            retval = 0;
326
            ev.type = IPC_GET_ARG1(call);
429
            ev.type = IPC_GET_ARG1(call);
327
            ev.key = IPC_GET_ARG2(call);
430
            ev.key = IPC_GET_ARG2(call);
328
            ev.mods = IPC_GET_ARG3(call);
431
            ev.mods = IPC_GET_ARG3(call);
329
            ev.c = IPC_GET_ARG4(call);
432
            ev.c = IPC_GET_ARG4(call);
330
           
433
           
331
            /* switch to another virtual console */
434
            /* switch to another virtual console */
332
           
435
           
333
            conn = &connections[active_console];
436
            conn = &connections[active_console];
334
 
437
 
335
            if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
438
            if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
336
                CONSOLE_COUNT)) {
439
                CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
337
                if (ev.key == KC_F12)
440
                if (ev.key == KC_F12)
338
                    change_console(KERNEL_CONSOLE);
441
                    change_console(KERNEL_CONSOLE);
339
                else
442
                else
340
                    change_console(ev.key - KC_F1);
443
                    change_console(ev.key - KC_F1);
341
                break;
444
                break;
342
            }
445
            }
343
           
446
           
344
            /* if client is awaiting key, send it */
447
            /* if client is awaiting key, send it */
345
            if (conn->keyrequest_counter > 0) {    
448
            if (conn->keyrequest_counter > 0) {    
346
                conn->keyrequest_counter--;
449
                conn->keyrequest_counter--;
347
                ipc_answer_4(fifo_pop(conn->keyrequests), EOK,
450
                ipc_answer_4(fifo_pop(conn->keyrequests), EOK,
348
                    ev.type, ev.key, ev.mods, ev.c);
451
                    ev.type, ev.key, ev.mods, ev.c);
349
                break;
452
                break;
350
            }
453
            }
351
 
454
 
352
            keybuffer_push(&conn->keybuffer, &ev);
455
            keybuffer_push(&conn->keybuffer, &ev);
353
            retval = 0;
456
            retval = 0;
354
 
457
 
355
            break;
458
            break;
356
        default:
459
        default:
357
            retval = ENOENT;
460
            retval = ENOENT;
358
        }
461
        }
359
        ipc_answer_0(callid, retval);
462
        ipc_answer_0(callid, retval);
360
    }
463
    }
361
}
464
}
362
 
465
 
-
 
466
/** Handle CONSOLE_WRITE call. */
-
 
467
static void cons_write(int consnum, ipc_callid_t rid, ipc_call_t *request)
-
 
468
{
-
 
469
    ipc_callid_t callid;
-
 
470
    size_t size;
-
 
471
    wchar_t ch;
-
 
472
    size_t off;
-
 
473
 
-
 
474
    if (!ipc_data_write_receive(&callid, &size)) {
-
 
475
        ipc_answer_0(callid, EINVAL);
-
 
476
        ipc_answer_0(rid, EINVAL);
-
 
477
    }
-
 
478
 
-
 
479
    if (size > CWRITE_BUF_SIZE)
-
 
480
        size = CWRITE_BUF_SIZE;
-
 
481
 
-
 
482
    (void) ipc_data_write_finalize(callid, cwrite_buf, size);
-
 
483
 
-
 
484
    off = 0;
-
 
485
    while (off < size) {
-
 
486
        ch = str_decode(cwrite_buf, &off, size);
-
 
487
        write_char(consnum, ch);
-
 
488
    }
-
 
489
 
-
 
490
    gcons_notify_char(consnum);
-
 
491
    ipc_answer_1(rid, EOK, size);
-
 
492
}
-
 
493
 
363
/** Default thread for new connections */
494
/** Default thread for new connections */
364
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
495
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
365
{
496
{
366
    ipc_callid_t callid;
497
    ipc_callid_t callid;
367
    ipc_call_t call;
498
    ipc_call_t call;
368
    int consnum;
499
    int consnum;
369
    ipcarg_t arg1, arg2, arg3, arg4;
500
    ipcarg_t arg1, arg2, arg3, arg4;
370
    connection_t *conn;
501
    connection_t *conn;
-
 
502
    screenbuffer_t *scr;
371
   
503
   
372
    if ((consnum = find_free_connection()) == -1) {
504
    if ((consnum = find_free_connection()) == -1) {
373
        ipc_answer_0(iid, ELIMIT);
505
        ipc_answer_0(iid, ELIMIT);
374
        return;
506
        return;
375
    }
507
    }
376
    conn = &connections[consnum];
508
    conn = &connections[consnum];
377
    conn->used = 1;
509
    conn->used = 1;
378
   
510
   
379
    async_serialize_start();
511
    async_serialize_start();
380
    gcons_notify_connect(consnum);
512
    gcons_notify_connect(consnum);
381
    conn->client_phone = IPC_GET_ARG5(*icall);
513
    conn->client_phone = IPC_GET_ARG5(*icall);
382
    screenbuffer_clear(&conn->screenbuffer);
514
    screenbuffer_clear(&conn->screenbuffer);
383
   
515
   
384
    /* Accept the connection */
516
    /* Accept the connection */
385
    ipc_answer_0(iid, EOK);
517
    ipc_answer_0(iid, EOK);
386
   
518
   
387
    while (1) {
519
    while (1) {
388
        async_serialize_end();
520
        async_serialize_end();
389
        callid = async_get_call(&call);
521
        callid = async_get_call(&call);
390
        async_serialize_start();
522
        async_serialize_start();
391
       
523
       
392
        arg1 = 0;
524
        arg1 = 0;
393
        arg2 = 0;
525
        arg2 = 0;
394
        arg3 = 0;
526
        arg3 = 0;
395
        arg4 = 0;
527
        arg4 = 0;
396
 
528
 
397
        switch (IPC_GET_METHOD(call)) {
529
        switch (IPC_GET_METHOD(call)) {
398
        case IPC_M_PHONE_HUNGUP:
530
        case IPC_M_PHONE_HUNGUP:
399
            gcons_notify_disconnect(consnum);
531
            gcons_notify_disconnect(consnum);
400
           
532
           
401
            /* Answer all pending requests */
533
            /* Answer all pending requests */
402
            while (conn->keyrequest_counter > 0) {
534
            while (conn->keyrequest_counter > 0) {
403
                conn->keyrequest_counter--;
535
                conn->keyrequest_counter--;
404
                ipc_answer_0(fifo_pop(conn->keyrequests),
536
                ipc_answer_0(fifo_pop(conn->keyrequests),
405
                    ENOENT);
537
                    ENOENT);
406
                break;
538
                break;
407
            }
539
            }
408
            conn->used = 0;
540
            conn->used = 0;
409
            return;
541
            return;
410
        case CONSOLE_PUTCHAR:
542
        case CONSOLE_PUTCHAR:
411
            write_char(consnum, IPC_GET_ARG1(call));
543
            write_char(consnum, IPC_GET_ARG1(call));
412
            gcons_notify_char(consnum);
544
            gcons_notify_char(consnum);
413
            break;
545
            break;
-
 
546
        case CONSOLE_WRITE:
-
 
547
            cons_write(consnum, callid, &call);
-
 
548
            continue;
414
        case CONSOLE_CLEAR:
549
        case CONSOLE_CLEAR:
415
            /* Send message to fb */
550
            /* Send message to fb */
416
            if (consnum == active_console) {
551
            if (consnum == active_console) {
417
                async_msg_0(fb_info.phone, FB_CLEAR);
552
                async_msg_0(fb_info.phone, FB_CLEAR);
418
            }
553
            }
419
           
554
           
420
            screenbuffer_clear(&conn->screenbuffer);
555
            screenbuffer_clear(&conn->screenbuffer);
421
           
556
           
422
            break;
557
            break;
423
        case CONSOLE_GOTO:
558
        case CONSOLE_GOTO:
424
            screenbuffer_goto(&conn->screenbuffer,
559
            screenbuffer_goto(&conn->screenbuffer,
425
                IPC_GET_ARG2(call), IPC_GET_ARG1(call));
560
                IPC_GET_ARG2(call), IPC_GET_ARG1(call));
426
            if (consnum == active_console)
561
            if (consnum == active_console)
427
                curs_goto(IPC_GET_ARG1(call),
562
                curs_goto(IPC_GET_ARG1(call),
428
                    IPC_GET_ARG2(call));
563
                    IPC_GET_ARG2(call));
429
            break;
564
            break;
430
        case CONSOLE_GETSIZE:
565
        case CONSOLE_GETSIZE:
431
            arg1 = fb_info.rows;
566
            arg1 = fb_info.rows;
432
            arg2 = fb_info.cols;
567
            arg2 = fb_info.cols;
433
            break;
568
            break;
434
        case CONSOLE_FLUSH:
569
        case CONSOLE_FLUSH:
-
 
570
            fb_pending_flush();
435
            if (consnum == active_console)
571
            if (consnum == active_console) {
436
                async_req_0_0(fb_info.phone, FB_FLUSH);
572
                async_req_0_0(fb_info.phone, FB_FLUSH);
-
 
573
 
-
 
574
                scr = &(connections[consnum].screenbuffer);
-
 
575
                curs_goto(scr->position_y, scr->position_x);
-
 
576
            }
437
            break;
577
            break;
438
        case CONSOLE_SET_STYLE:
578
        case CONSOLE_SET_STYLE:
-
 
579
            fb_pending_flush();
439
            arg1 = IPC_GET_ARG1(call);
580
            arg1 = IPC_GET_ARG1(call);
440
            screenbuffer_set_style(&conn->screenbuffer, arg1);
581
            screenbuffer_set_style(&conn->screenbuffer, arg1);
441
            if (consnum == active_console)
582
            if (consnum == active_console)
442
                set_style(arg1);
583
                set_style(arg1);
443
            break;
584
            break;
444
        case CONSOLE_SET_COLOR:
585
        case CONSOLE_SET_COLOR:
-
 
586
            fb_pending_flush();
445
            arg1 = IPC_GET_ARG1(call);
587
            arg1 = IPC_GET_ARG1(call);
446
            arg2 = IPC_GET_ARG2(call);
588
            arg2 = IPC_GET_ARG2(call);
447
            arg3 = IPC_GET_ARG3(call);
589
            arg3 = IPC_GET_ARG3(call);
448
            screenbuffer_set_color(&conn->screenbuffer, arg1,
590
            screenbuffer_set_color(&conn->screenbuffer, arg1,
449
                arg2, arg3);
591
                arg2, arg3);
450
            if (consnum == active_console)
592
            if (consnum == active_console)
451
                set_color(arg1, arg2, arg3);
593
                set_color(arg1, arg2, arg3);
452
            break;
594
            break;
453
        case CONSOLE_SET_RGB_COLOR:
595
        case CONSOLE_SET_RGB_COLOR:
-
 
596
            fb_pending_flush();
454
            arg1 = IPC_GET_ARG1(call);
597
            arg1 = IPC_GET_ARG1(call);
455
            arg2 = IPC_GET_ARG2(call);
598
            arg2 = IPC_GET_ARG2(call);
456
            screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
599
            screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
457
                arg2);
600
                arg2);
458
            if (consnum == active_console)
601
            if (consnum == active_console)
459
                set_rgb_color(arg1, arg2);
602
                set_rgb_color(arg1, arg2);
460
            break;
603
            break;
461
        case CONSOLE_CURSOR_VISIBILITY:
604
        case CONSOLE_CURSOR_VISIBILITY:
-
 
605
            fb_pending_flush();
462
            arg1 = IPC_GET_ARG1(call);
606
            arg1 = IPC_GET_ARG1(call);
463
            conn->screenbuffer.is_cursor_visible = arg1;
607
            conn->screenbuffer.is_cursor_visible = arg1;
464
            if (consnum == active_console)
608
            if (consnum == active_console)
465
                curs_visibility(arg1);
609
                curs_visibility(arg1);
466
            break;
610
            break;
467
        case CONSOLE_GETKEY:
611
        case CONSOLE_GETKEY:
468
            if (keybuffer_empty(&conn->keybuffer)) {
612
            if (keybuffer_empty(&conn->keybuffer)) {
469
                /* buffer is empty -> store request */
613
                /* buffer is empty -> store request */
470
                if (conn->keyrequest_counter <
614
                if (conn->keyrequest_counter <
471
                    MAX_KEYREQUESTS_BUFFERED) {
615
                    MAX_KEYREQUESTS_BUFFERED) {
472
                    fifo_push(conn->keyrequests, callid);
616
                    fifo_push(conn->keyrequests, callid);
473
                    conn->keyrequest_counter++;
617
                    conn->keyrequest_counter++;
474
                } else {
618
                } else {
475
                    /*
619
                    /*
476
                     * No key available and too many
620
                     * No key available and too many
477
                     * requests => fail.
621
                     * requests => fail.
478
                    */
622
                    */
479
                    ipc_answer_0(callid, ELIMIT);
623
                    ipc_answer_0(callid, ELIMIT);
480
                }
624
                }
481
                continue;
625
                continue;
482
            }
626
            }
483
            kbd_event_t ev;
627
            kbd_event_t ev;
484
            keybuffer_pop(&conn->keybuffer, &ev);
628
            keybuffer_pop(&conn->keybuffer, &ev);
485
            arg1 = ev.type;
629
            arg1 = ev.type;
486
            arg2 = ev.key;
630
            arg2 = ev.key;
487
            arg3 = ev.mods;
631
            arg3 = ev.mods;
488
            arg4 = ev.c;
632
            arg4 = ev.c;
489
            break;
633
            break;
-
 
634
        case CONSOLE_KCON_ENABLE:
-
 
635
            change_console(KERNEL_CONSOLE);
-
 
636
            break;
490
        }
637
        }
491
        ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4);
638
        ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4);
492
    }
639
    }
493
}
640
}
494
 
641
 
495
static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
642
static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
496
{
643
{
497
    change_console(prev_console);
644
    change_console(prev_console);
498
}
645
}
499
 
646
 
500
int main(int argc, char *argv[])
647
int main(int argc, char *argv[])
501
{
648
{
502
    printf(NAME ": HelenOS Console service\n");
649
    printf(NAME ": HelenOS Console service\n");
503
   
650
   
504
    ipcarg_t phonehash;
651
    ipcarg_t phonehash;
505
    int kbd_phone;
652
    int kbd_phone;
506
    size_t ib_size;
653
    size_t ib_size;
507
    int i;
654
    int i;
508
   
655
   
509
    async_set_client_connection(client_connection);
656
    async_set_client_connection(client_connection);
510
   
657
   
511
    /* Connect to keyboard driver */
658
    /* Connect to keyboard driver */
512
    kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
659
    kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
513
    if (kbd_phone < 0) {
660
    if (kbd_phone < 0) {
514
        printf(NAME ": Failed to connect to keyboard service\n");
661
        printf(NAME ": Failed to connect to keyboard service\n");
515
        return -1;
662
        return -1;
516
    }
663
    }
517
   
664
   
518
    if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
665
    if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
519
        printf(NAME ": Failed to create callback from keyboard service\n");
666
        printf(NAME ": Failed to create callback from keyboard service\n");
520
        return -1;
667
        return -1;
521
    }
668
    }
522
   
669
   
523
    async_new_connection(phonehash, 0, NULL, keyboard_events);
670
    async_new_connection(phonehash, 0, NULL, keyboard_events);
524
   
671
   
525
    /* Connect to framebuffer driver */
672
    /* Connect to framebuffer driver */
526
    fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
673
    fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
527
    if (fb_info.phone < 0) {
674
    if (fb_info.phone < 0) {
528
        printf(NAME ": Failed to connect to video service\n");
675
        printf(NAME ": Failed to connect to video service\n");
529
        return -1;
676
        return -1;
530
    }
677
    }
531
   
678
   
532
    /* Disable kernel output to the console */
679
    /* Disable kernel output to the console */
533
    __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
680
    __SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
534
   
681
   
535
    /* Initialize gcons */
682
    /* Initialize gcons */
536
    gcons_init(fb_info.phone);
683
    gcons_init(fb_info.phone);
537
    /* Synchronize, the gcons can have something in queue */
684
    /* Synchronize, the gcons can have something in queue */
538
    async_req_0_0(fb_info.phone, FB_FLUSH);
685
    async_req_0_0(fb_info.phone, FB_FLUSH);
539
   
686
   
540
    async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
687
    async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
541
        &fb_info.cols);
688
        &fb_info.cols);
542
    set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
689
    set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
543
    clrscr();
690
    clrscr();
544
   
691
   
545
    /* Init virtual consoles */
692
    /* Init virtual consoles */
546
    for (i = 0; i < CONSOLE_COUNT; i++) {
693
    for (i = 0; i < CONSOLE_COUNT; i++) {
547
        connections[i].used = 0;
694
        connections[i].used = 0;
548
        keybuffer_init(&connections[i].keybuffer);
695
        keybuffer_init(&connections[i].keybuffer);
549
       
696
       
550
        connections[i].keyrequests.head = 0;
697
        connections[i].keyrequests.head = 0;
551
        connections[i].keyrequests.tail = 0;
698
        connections[i].keyrequests.tail = 0;
552
        connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
699
        connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
553
        connections[i].keyrequest_counter = 0;
700
        connections[i].keyrequest_counter = 0;
554
       
701
       
555
        if (screenbuffer_init(&connections[i].screenbuffer,
702
        if (screenbuffer_init(&connections[i].screenbuffer,
556
            fb_info.cols, fb_info.rows) == NULL) {
703
            fb_info.cols, fb_info.rows) == NULL) {
557
            /* FIXME: handle error */
704
            /* FIXME: handle error */
558
            return -1;
705
            return -1;
559
        }
706
        }
560
    }
707
    }
561
    connections[KERNEL_CONSOLE].used = 1;
708
    connections[KERNEL_CONSOLE].used = 1;
562
 
709
 
563
    /* Set up shared memory buffer. */
710
    /* Set up shared memory buffer. */
564
    ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
711
    ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
565
    interbuffer = as_get_mappable_page(ib_size);
712
    interbuffer = as_get_mappable_page(ib_size);
566
 
713
 
-
 
714
    fb_pending.n = 0;
-
 
715
 
567
    if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
716
    if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
568
        AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
717
        AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
569
        interbuffer = NULL;
718
        interbuffer = NULL;
570
    }
719
    }
571
 
720
 
572
    if (interbuffer) {
721
    if (interbuffer) {
573
        if (ipc_share_out_start(fb_info.phone, interbuffer,
722
        if (ipc_share_out_start(fb_info.phone, interbuffer,
574
            AS_AREA_READ) != EOK) {
723
            AS_AREA_READ) != EOK) {
575
            as_area_destroy(interbuffer);
724
            as_area_destroy(interbuffer);
576
            interbuffer = NULL;
725
            interbuffer = NULL;
577
        }
726
        }
578
    }
727
    }
579
   
728
   
580
    curs_goto(0, 0);
729
    curs_goto(0, 0);
581
    curs_visibility(
730
    curs_visibility(
582
        connections[active_console].screenbuffer.is_cursor_visible);
731
        connections[active_console].screenbuffer.is_cursor_visible);
583
   
732
   
584
    /* Register at NS */
733
    /* Register at NS */
585
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
734
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
586
        return -1;
735
        return -1;
587
   
736
   
588
    /* Receive kernel notifications */
737
    /* Receive kernel notifications */
589
//  if (sysinfo_value("kconsole.present")) {
-
 
590
//      int inr = sysinfo_value("kconsole.inr");
-
 
591
//      if (ipc_register_irq(inr, device_assign_devno(), 0, NULL) != EOK)
738
    if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
592
//          printf(NAME ": Error registering kconsole notifications\n");
739
        printf(NAME ": Error registering kconsole notifications\n");
593
//      
740
       
594
//      async_set_interrupt_received(interrupt_received);
741
    async_set_interrupt_received(interrupt_received);
595
//  }
-
 
596
   
742
   
597
    // FIXME: avoid connectiong to itself, keep using klog
743
    // FIXME: avoid connectiong to itself, keep using klog
598
    // printf(NAME ": Accepting connections\n");
744
    // printf(NAME ": Accepting connections\n");
599
    async_manager();
745
    async_manager();
600
   
746
   
601
    return 0;
747
    return 0;
602
}
748
}
603
 
749
 
604
/** @}
750
/** @}
605
 */
751
 */
606
 
752