Subversion Repositories HelenOS

Rev

Rev 3747 | Rev 3767 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1445 cejka 1
/*
2071 jermar 2
 * Copyright (c) 2006 Josef Cejka
1445 cejka 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
1649 cejka 28
 
1740 jermar 29
/** @addtogroup console
1649 cejka 30
 * @{ 
31
 */
32
/** @file
33
 */
34
 
2618 jermar 35
#include <libc.h>
1451 cejka 36
#include <fb.h>
1445 cejka 37
#include <ipc/ipc.h>
1694 palkovsky 38
#include <keys.h>
1451 cejka 39
#include <ipc/fb.h>
1445 cejka 40
#include <ipc/services.h>
41
#include <errno.h>
1451 cejka 42
#include <key_buffer.h>
43
#include <console.h>
3747 svoboda 44
#include <ipc/console.h>
1453 palkovsky 45
#include <unistd.h>
46
#include <async.h>
1481 cejka 47
#include <libadt/fifo.h>
1487 cejka 48
#include <screenbuffer.h>
1867 jermar 49
#include <sys/mman.h>
3084 decky 50
#include <stdio.h>
3761 decky 51
#include <sysinfo.h>
1445 cejka 52
 
1522 palkovsky 53
#include "gcons.h"
54
 
1481 cejka 55
#define MAX_KEYREQUESTS_BUFFERED 32
1451 cejka 56
 
3084 decky 57
#define NAME "console"
1445 cejka 58
 
1526 cejka 59
/** Index of currently used virtual console.
60
 */
1512 cejka 61
int active_console = 0;
3761 decky 62
int prev_console = 0;
1453 palkovsky 63
 
1526 cejka 64
/** Information about framebuffer
65
 */
1487 cejka 66
struct {
67
	int phone;		/**< Framebuffer phone */
1506 cejka 68
	ipcarg_t rows;		/**< Framebuffer rows */
69
	ipcarg_t cols;		/**< Framebuffer columns */
1487 cejka 70
} fb_info;
71
 
1451 cejka 72
typedef struct {
1526 cejka 73
	keybuffer_t keybuffer;		/**< Buffer for incoming keys. */
2025 jermar 74
	/** Buffer for unsatisfied request for keys. */
75
	FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
76
		MAX_KEYREQUESTS_BUFFERED);	
1526 cejka 77
	int keyrequest_counter;		/**< Number of requests in buffer. */
78
	int client_phone;		/**< Phone to connected client. */
2025 jermar 79
	int used;			/**< 1 if this virtual console is
80
					 * connected to some client.*/
81
	screenbuffer_t screenbuffer;	/**< Screenbuffer for saving screen
82
					 * contents and related settings. */
1451 cejka 83
} connection_t;
84
 
2025 jermar 85
static connection_t connections[CONSOLE_COUNT];	/**< Array of data for virtual
86
						 * consoles */
87
static keyfield_t *interbuffer = NULL;		/**< Pointer to memory shared
88
						 * with framebufer used for
89
						 * faster virtual console
2069 jermar 90
						 * switching */
1506 cejka 91
 
92
 
1526 cejka 93
/** Find unused virtual console.
94
 *
95
 */
1574 palkovsky 96
static int find_free_connection(void) 
1451 cejka 97
{
2069 jermar 98
	int i;
1451 cejka 99
 
2069 jermar 100
	for (i = 0; i < CONSOLE_COUNT; i++) {
1574 palkovsky 101
		if (!connections[i].used)
1451 cejka 102
			return i;
103
	}
1574 palkovsky 104
	return -1;
1451 cejka 105
}
106
 
1552 palkovsky 107
static void clrscr(void)
108
{
2621 jermar 109
	async_msg_0(fb_info.phone, FB_CLEAR);
1552 palkovsky 110
}
111
 
3735 decky 112
static void curs_visibility(bool visible)
1552 palkovsky 113
{
3735 decky 114
	async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible); 
1552 palkovsky 115
}
116
 
3735 decky 117
static void curs_hide_sync(void)
118
{
119
	ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false); 
120
}
121
 
1552 palkovsky 122
static void curs_goto(int row, int col)
123
{
1610 palkovsky 124
	async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col); 
1552 palkovsky 125
}
126
 
127
static void set_style(style_t *style)
128
{
2025 jermar 129
	async_msg_2(fb_info.phone, FB_SET_STYLE, style->fg_color,
2539 jermar 130
	    style->bg_color); 
1552 palkovsky 131
}
132
 
133
static void set_style_col(int fgcolor, int bgcolor)
134
{
1610 palkovsky 135
	async_msg_2(fb_info.phone, FB_SET_STYLE, fgcolor, bgcolor); 
1552 palkovsky 136
}
137
 
138
static void prtchr(char c, int row, int col)
139
{
1610 palkovsky 140
	async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
1552 palkovsky 141
}
142
 
1497 cejka 143
/** Check key and process special keys. 
144
 *
2566 jermar 145
 *
146
 */
1497 cejka 147
static void write_char(int console, char key)
148
{
149
	screenbuffer_t *scr = &(connections[console].screenbuffer);
150
 
151
	switch (key) {
2025 jermar 152
	case '\n':
2069 jermar 153
		scr->position_y++;
154
		scr->position_x = 0;
2025 jermar 155
		break;
156
	case '\r':
157
		break;
158
	case '\t':
159
		scr->position_x += 8;
160
		scr->position_x -= scr->position_x % 8; 
161
		break;
162
	case '\b':
163
		if (scr->position_x == 0) 
1497 cejka 164
			break;
2025 jermar 165
		scr->position_x--;
166
		if (console == active_console)
167
			prtchr(' ', scr->position_y, scr->position_x);
168
		screenbuffer_putchar(scr, ' ');
169
		break;
170
	default:	
171
		if (console == active_console)
172
			prtchr(key, scr->position_y, scr->position_x);
1497 cejka 173
 
2025 jermar 174
		screenbuffer_putchar(scr, key);
175
		scr->position_x++;
1497 cejka 176
	}
177
 
178
	scr->position_y += (scr->position_x >= scr->size_x);
179
 
180
	if (scr->position_y >= scr->size_y) {
181
		scr->position_y = scr->size_y - 1;
1674 palkovsky 182
		screenbuffer_clear_line(scr, scr->top_line);
2069 jermar 183
		scr->top_line = (scr->top_line + 1) % scr->size_y;
1518 palkovsky 184
		if (console == active_console)
2621 jermar 185
			async_msg_1(fb_info.phone, FB_SCROLL, 1);
1497 cejka 186
	}
187
 
188
	scr->position_x = scr->position_x % scr->size_x;
189
 
1552 palkovsky 190
	if (console == active_console)
191
		curs_goto(scr->position_y, scr->position_x);
1504 cejka 192
 
1497 cejka 193
}
194
 
1552 palkovsky 195
/** Switch to new console */
196
static void change_console(int newcons)
197
{
198
	connection_t *conn;
1673 palkovsky 199
	int i, j, rc;
1578 cejka 200
	keyfield_t *field;
201
	style_t *style;
3707 decky 202
 
1552 palkovsky 203
	if (newcons == active_console)
204
		return;
3707 decky 205
 
1555 palkovsky 206
	if (newcons == KERNEL_CONSOLE) {
3707 decky 207
		async_serialize_start();
3735 decky 208
		curs_hide_sync();
3707 decky 209
		gcons_in_kernel();
210
		async_serialize_end();
211
 
3761 decky 212
		if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
213
			prev_console = active_console;
3707 decky 214
			active_console = KERNEL_CONSOLE;
3761 decky 215
		} else
3735 decky 216
			newcons = active_console;
3707 decky 217
	}
218
 
219
	if (newcons != KERNEL_CONSOLE) {
220
		async_serialize_start();
221
 
1555 palkovsky 222
		if (active_console == KERNEL_CONSOLE)
3707 decky 223
			gcons_redraw_console();
224
 
225
		active_console = newcons;
226
		gcons_change_console(newcons);
227
		conn = &connections[active_console];
228
 
229
		set_style(&conn->screenbuffer.style);
3735 decky 230
		curs_visibility(false);
3707 decky 231
		if (interbuffer) {
232
			for (i = 0; i < conn->screenbuffer.size_x; i++)
233
				for (j = 0; j < conn->screenbuffer.size_y; j++) {
234
					unsigned int size_x;
235
 
236
					size_x = conn->screenbuffer.size_x; 
237
					interbuffer[i + j * size_x] =
238
					    *get_field_at(&conn->screenbuffer, i, j);
239
				}
240
			/* This call can preempt, but we are already at the end */
3761 decky 241
			rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);
3707 decky 242
		}
243
 
244
		if ((!interbuffer) || (rc != 0)) {
245
			set_style(&conn->screenbuffer.style);
1552 palkovsky 246
			clrscr();
3707 decky 247
			style = &conn->screenbuffer.style;
248
 
3761 decky 249
			for (j = 0; j < conn->screenbuffer.size_y; j++)
3707 decky 250
				for (i = 0; i < conn->screenbuffer.size_x; i++) {
251
					field = get_field_at(&conn->screenbuffer, i, j);
252
					if (!style_same(*style, field->style))
253
						set_style(&field->style);
254
					style = &field->style;
255
					if ((field->character == ' ') &&
256
					    (style_same(field->style,
257
					    conn->screenbuffer.style)))
258
						continue;
259
 
260
					prtchr(field->character, j, i);
261
				}
1552 palkovsky 262
		}
3707 decky 263
 
264
		curs_goto(conn->screenbuffer.position_y,
265
		    conn->screenbuffer.position_x);
266
		curs_visibility(conn->screenbuffer.is_cursor_visible);
267
 
1717 palkovsky 268
		async_serialize_end();
1552 palkovsky 269
	}
270
}
271
 
1526 cejka 272
/** Handler for keyboard */
1453 palkovsky 273
static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
1445 cejka 274
{
1453 palkovsky 275
	ipc_callid_t callid;
1445 cejka 276
	ipc_call_t call;
1453 palkovsky 277
	int retval;
1560 vana 278
	int c;
1489 palkovsky 279
	connection_t *conn;
1717 palkovsky 280
	int newcon;
1506 cejka 281
 
1453 palkovsky 282
	/* Ignore parameters, the connection is alread opened */
283
	while (1) {
284
		callid = async_get_call(&call);
285
		switch (IPC_GET_METHOD(call)) {
286
		case IPC_M_PHONE_HUNGUP:
287
			/* TODO: Handle hangup */
288
			return;
1717 palkovsky 289
		case KBD_MS_LEFT:
290
			newcon = gcons_mouse_btn(IPC_GET_ARG1(call));
291
			if (newcon != -1)
292
				change_console(newcon);
1721 palkovsky 293
			retval = 0;
1717 palkovsky 294
			break;
1707 palkovsky 295
		case KBD_MS_MOVE:
2025 jermar 296
			gcons_mouse_move(IPC_GET_ARG1(call),
2539 jermar 297
			    IPC_GET_ARG2(call));
1721 palkovsky 298
			retval = 0;
1707 palkovsky 299
			break;
1453 palkovsky 300
		case KBD_PUSHCHAR:
301
			/* got key from keyboard driver */
302
			retval = 0;
1520 cejka 303
			c = IPC_GET_ARG1(call);
1453 palkovsky 304
			/* switch to another virtual console */
1481 cejka 305
 
1489 palkovsky 306
			conn = &connections[active_console];
2025 jermar 307
/*
308
 *			if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 +
309
 *				CONSOLE_COUNT)) {
310
 */
1560 vana 311
			if ((c >= 0x101) && (c < 0x101 + CONSOLE_COUNT)) {
312
				if (c == 0x112)
1555 palkovsky 313
					change_console(KERNEL_CONSOLE);
1552 palkovsky 314
				else
1560 vana 315
					change_console(c - 0x101);
1453 palkovsky 316
				break;
317
			}
1481 cejka 318
 
319
			/* if client is awaiting key, send it */
1489 palkovsky 320
			if (conn->keyrequest_counter > 0) {		
321
				conn->keyrequest_counter--;
2619 jermar 322
				ipc_answer_1(fifo_pop(conn->keyrequests), EOK,
323
				    c);
1481 cejka 324
				break;
325
			}
326
 
1489 palkovsky 327
			keybuffer_push(&conn->keybuffer, c);
1721 palkovsky 328
			retval = 0;
1476 cejka 329
 
1453 palkovsky 330
			break;
331
		default:
1459 palkovsky 332
			retval = ENOENT;
1610 palkovsky 333
		}
2619 jermar 334
		ipc_answer_0(callid, retval);
1453 palkovsky 335
	}
336
}
337
 
338
/** Default thread for new connections */
1518 palkovsky 339
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
1453 palkovsky 340
{
1445 cejka 341
	ipc_callid_t callid;
1453 palkovsky 342
	ipc_call_t call;
343
	int consnum;
1521 cejka 344
	ipcarg_t arg1, arg2;
1592 palkovsky 345
	connection_t *conn;
3761 decky 346
 
1574 palkovsky 347
	if ((consnum = find_free_connection()) == -1) {
2619 jermar 348
		ipc_answer_0(iid, ELIMIT);
1453 palkovsky 349
		return;
350
	}
1592 palkovsky 351
	conn = &connections[consnum];
1610 palkovsky 352
	conn->used = 1;
1555 palkovsky 353
 
1610 palkovsky 354
	async_serialize_start();
1555 palkovsky 355
	gcons_notify_connect(consnum);
2637 cejka 356
	conn->client_phone = IPC_GET_ARG5(*icall);
1592 palkovsky 357
	screenbuffer_clear(&conn->screenbuffer);
1497 cejka 358
 
1453 palkovsky 359
	/* Accept the connection */
2619 jermar 360
	ipc_answer_0(iid, EOK);
3761 decky 361
 
1453 palkovsky 362
	while (1) {
1610 palkovsky 363
		async_serialize_end();
1453 palkovsky 364
		callid = async_get_call(&call);
1610 palkovsky 365
		async_serialize_start();
3761 decky 366
 
2566 jermar 367
		arg1 = 0;
368
		arg2 = 0;
1453 palkovsky 369
		switch (IPC_GET_METHOD(call)) {
370
		case IPC_M_PHONE_HUNGUP:
1592 palkovsky 371
			gcons_notify_disconnect(consnum);
1610 palkovsky 372
 
1592 palkovsky 373
			/* Answer all pending requests */
3761 decky 374
			while (conn->keyrequest_counter > 0) {
1592 palkovsky 375
				conn->keyrequest_counter--;
2619 jermar 376
				ipc_answer_0(fifo_pop(conn->keyrequests),
377
				    ENOENT);
1592 palkovsky 378
				break;
379
			}
1616 palkovsky 380
			conn->used = 0;
1453 palkovsky 381
			return;
382
		case CONSOLE_PUTCHAR:
1497 cejka 383
			write_char(consnum, IPC_GET_ARG1(call));
1528 palkovsky 384
			gcons_notify_char(consnum);
1453 palkovsky 385
			break;
1476 cejka 386
		case CONSOLE_CLEAR:
1487 cejka 387
			/* Send message to fb */
388
			if (consnum == active_console) {
2621 jermar 389
				async_msg_0(fb_info.phone, FB_CLEAR); 
1487 cejka 390
			}
391
 
1592 palkovsky 392
			screenbuffer_clear(&conn->screenbuffer);
1487 cejka 393
 
1476 cejka 394
			break;
395
		case CONSOLE_GOTO:
2025 jermar 396
			screenbuffer_goto(&conn->screenbuffer,
2539 jermar 397
			    IPC_GET_ARG2(call), IPC_GET_ARG1(call));
1567 palkovsky 398
			if (consnum == active_console)
2025 jermar 399
				curs_goto(IPC_GET_ARG1(call),
2539 jermar 400
				    IPC_GET_ARG2(call));
1476 cejka 401
			break;
1521 cejka 402
		case CONSOLE_GETSIZE:
1528 palkovsky 403
			arg1 = fb_info.rows;
404
			arg2 = fb_info.cols;
1521 cejka 405
			break;
1523 cejka 406
		case CONSOLE_FLUSH:
1723 palkovsky 407
			if (consnum == active_console)
2621 jermar 408
				async_req_0_0(fb_info.phone, FB_FLUSH);
1523 cejka 409
			break;
1525 cejka 410
		case CONSOLE_SET_STYLE:
411
			arg1 = IPC_GET_ARG1(call);
412
			arg2 = IPC_GET_ARG2(call);
2539 jermar 413
			screenbuffer_set_style(&conn->screenbuffer, arg1,
414
			    arg2);
1525 cejka 415
			if (consnum == active_console)
1552 palkovsky 416
				set_style_col(arg1, arg2);
1525 cejka 417
			break;
1575 cejka 418
		case CONSOLE_CURSOR_VISIBILITY:
419
			arg1 = IPC_GET_ARG1(call);
1592 palkovsky 420
			conn->screenbuffer.is_cursor_visible = arg1;
1575 cejka 421
			if (consnum == active_console)
422
				curs_visibility(arg1);
423
			break;
1453 palkovsky 424
		case CONSOLE_GETCHAR:
1592 palkovsky 425
			if (keybuffer_empty(&conn->keybuffer)) {
1481 cejka 426
				/* buffer is empty -> store request */
2025 jermar 427
				if (conn->keyrequest_counter <
428
					MAX_KEYREQUESTS_BUFFERED) {	
1592 palkovsky 429
					fifo_push(conn->keyrequests, callid);
430
					conn->keyrequest_counter++;
1481 cejka 431
				} else {
2025 jermar 432
					/*
433
					 * No key available and too many
434
					 * requests => fail.
435
					*/
2619 jermar 436
					ipc_answer_0(callid, ELIMIT);
1481 cejka 437
				}
438
				continue;
2025 jermar 439
			}
3599 jermar 440
			int ch;
441
			keybuffer_pop(&conn->keybuffer, &ch);
442
			arg1 = ch;
1453 palkovsky 443
			break;
444
		}
2619 jermar 445
		ipc_answer_2(callid, EOK, arg1, arg2);
1453 palkovsky 446
	}
447
}
448
 
3761 decky 449
static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
450
{
451
	change_console(prev_console);
452
}
453
 
1453 palkovsky 454
int main(int argc, char *argv[])
455
{
3084 decky 456
	printf(NAME ": HelenOS Console service\n");
457
 
1453 palkovsky 458
	ipcarg_t phonehash;
1721 palkovsky 459
	int kbd_phone;
1451 cejka 460
	int i;
3761 decky 461
 
1490 palkovsky 462
	async_set_client_connection(client_connection);
1445 cejka 463
 
464
	/* Connect to keyboard driver */
3761 decky 465
 
2635 cejka 466
	kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
2069 jermar 467
	while (kbd_phone < 0) {
1453 palkovsky 468
		usleep(10000);
2635 cejka 469
		kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
2025 jermar 470
	}
1445 cejka 471
 
2637 cejka 472
	if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
1445 cejka 473
		return -1;
1689 palkovsky 474
	async_new_connection(phonehash, 0, NULL, keyboard_events);
475
 
1445 cejka 476
	/* Connect to framebuffer driver */
2635 cejka 477
	fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0);
2069 jermar 478
	while (fb_info.phone < 0) {
1487 cejka 479
		usleep(10000);
2635 cejka 480
		fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0);
1487 cejka 481
	}
1552 palkovsky 482
 
1522 palkovsky 483
	/* Initialize gcons */
484
	gcons_init(fb_info.phone);
485
	/* Synchronize, the gcons can have something in queue */
2621 jermar 486
	async_req_0_0(fb_info.phone, FB_FLUSH);
1487 cejka 487
 
2621 jermar 488
	async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
2539 jermar 489
	    &fb_info.cols); 
1552 palkovsky 490
	set_style_col(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
491
	clrscr();
1487 cejka 492
 
493
	/* Init virtual consoles */
1451 cejka 494
	for (i = 0; i < CONSOLE_COUNT; i++) {
495
		connections[i].used = 0;
2539 jermar 496
		keybuffer_init(&connections[i].keybuffer);
1481 cejka 497
 
2539 jermar 498
		connections[i].keyrequests.head = 0;
499
		connections[i].keyrequests.tail = 0;
1481 cejka 500
		connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
501
		connections[i].keyrequest_counter = 0;
1487 cejka 502
 
2539 jermar 503
		if (screenbuffer_init(&connections[i].screenbuffer,
504
		    fb_info.cols, fb_info.rows) == NULL) {
2069 jermar 505
			/* FIXME: handle error */
1487 cejka 506
			return -1;
507
		}
1451 cejka 508
	}
1574 palkovsky 509
	connections[KERNEL_CONSOLE].used = 1;
1445 cejka 510
 
2069 jermar 511
	interbuffer = mmap(NULL,
2539 jermar 512
	    sizeof(keyfield_t) * fb_info.cols * fb_info.rows,
513
	    PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
2069 jermar 514
	if (!interbuffer) {
2678 jermar 515
		if (ipc_share_out_start(fb_info.phone, interbuffer,
2677 jermar 516
		    AS_AREA_READ) != EOK) {
2539 jermar 517
			munmap(interbuffer,
518
			    sizeof(keyfield_t) * fb_info.cols * fb_info.rows);
1512 cejka 519
			interbuffer = NULL;
520
		}
521
	}
3761 decky 522
 
2069 jermar 523
	curs_goto(0, 0);
2539 jermar 524
	curs_visibility(
525
	    connections[active_console].screenbuffer.is_cursor_visible);
3761 decky 526
 
1518 palkovsky 527
	/* Register at NS */
3084 decky 528
	if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
1445 cejka 529
		return -1;
530
 
3761 decky 531
	/* Receive kernel notifications */
532
	if (sysinfo_value("kconsole.present")) {
533
		int devno = sysinfo_value("kconsole.devno");
534
		int inr = sysinfo_value("kconsole.inr");
535
		if (ipc_register_irq(inr, devno, 0, NULL) != EOK)
536
			printf(NAME ": Error registering kconsole notifications\n");
537
 
538
		async_set_interrupt_received(interrupt_received);
539
	}
540
 
3084 decky 541
	// FIXME: avoid connectiong to itself, keep using klog
542
	// printf(NAME ": Accepting connections\n");
1453 palkovsky 543
	async_manager();
3761 decky 544
 
545
	return 0;
1445 cejka 546
}
1649 cejka 547
 
548
/** @}
549
 */