Subversion Repositories HelenOS

Rev

Rev 3747 | Rev 3767 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3747 Rev 3761
Line 46... Line 46...
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 <sysinfo.h>
51
 
52
 
52
#include "gcons.h"
53
#include "gcons.h"
53
 
54
 
54
#define MAX_KEYREQUESTS_BUFFERED 32
55
#define MAX_KEYREQUESTS_BUFFERED 32
55
 
56
 
56
#define NAME "console"
57
#define NAME "console"
57
 
58
 
58
/** Index of currently used virtual console.
59
/** Index of currently used virtual console.
59
 */
60
 */
60
int active_console = 0;
61
int active_console = 0;
-
 
62
int prev_console = 0;
61
 
63
 
62
/** Information about framebuffer
64
/** Information about framebuffer
63
 */
65
 */
64
struct {
66
struct {
65
    int phone;      /**< Framebuffer phone */
67
    int phone;      /**< Framebuffer phone */
Line 205... Line 207...
205
        async_serialize_start();
207
        async_serialize_start();
206
        curs_hide_sync();
208
        curs_hide_sync();
207
        gcons_in_kernel();
209
        gcons_in_kernel();
208
        async_serialize_end();
210
        async_serialize_end();
209
       
211
       
210
        if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE))
212
        if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
-
 
213
            prev_console = active_console;
211
            active_console = KERNEL_CONSOLE;
214
            active_console = KERNEL_CONSOLE;
212
        else
215
        } else
213
            newcons = active_console;
216
            newcons = active_console;
214
    }
217
    }
215
   
218
   
216
    if (newcons != KERNEL_CONSOLE) {
219
    if (newcons != KERNEL_CONSOLE) {
217
        async_serialize_start();
220
        async_serialize_start();
Line 233... Line 236...
233
                    size_x = conn->screenbuffer.size_x;
236
                    size_x = conn->screenbuffer.size_x;
234
                    interbuffer[i + j * size_x] =
237
                    interbuffer[i + j * size_x] =
235
                        *get_field_at(&conn->screenbuffer, i, j);
238
                        *get_field_at(&conn->screenbuffer, i, j);
236
                }
239
                }
237
            /* This call can preempt, but we are already at the end */
240
            /* This call can preempt, but we are already at the end */
238
            rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);      
241
            rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA);
239
        }
242
        }
240
       
243
       
241
        if ((!interbuffer) || (rc != 0)) {
244
        if ((!interbuffer) || (rc != 0)) {
242
            set_style(&conn->screenbuffer.style);
245
            set_style(&conn->screenbuffer.style);
243
            clrscr();
246
            clrscr();
244
            style = &conn->screenbuffer.style;
247
            style = &conn->screenbuffer.style;
245
           
248
           
246
            for (j = 0; j < conn->screenbuffer.size_y; j++)
249
            for (j = 0; j < conn->screenbuffer.size_y; j++)
247
                for (i = 0; i < conn->screenbuffer.size_x; i++) {
250
                for (i = 0; i < conn->screenbuffer.size_x; i++) {
248
                    field = get_field_at(&conn->screenbuffer, i, j);
251
                    field = get_field_at(&conn->screenbuffer, i, j);
249
                    if (!style_same(*style, field->style))
252
                    if (!style_same(*style, field->style))
250
                        set_style(&field->style);
253
                        set_style(&field->style);
251
                    style = &field->style;
254
                    style = &field->style;
Line 338... Line 341...
338
    ipc_callid_t callid;
341
    ipc_callid_t callid;
339
    ipc_call_t call;
342
    ipc_call_t call;
340
    int consnum;
343
    int consnum;
341
    ipcarg_t arg1, arg2;
344
    ipcarg_t arg1, arg2;
342
    connection_t *conn;
345
    connection_t *conn;
343
 
346
   
344
    if ((consnum = find_free_connection()) == -1) {
347
    if ((consnum = find_free_connection()) == -1) {
345
        ipc_answer_0(iid, ELIMIT);
348
        ipc_answer_0(iid, ELIMIT);
346
        return;
349
        return;
347
    }
350
    }
348
    conn = &connections[consnum];
351
    conn = &connections[consnum];
Line 353... Line 356...
353
    conn->client_phone = IPC_GET_ARG5(*icall);
356
    conn->client_phone = IPC_GET_ARG5(*icall);
354
    screenbuffer_clear(&conn->screenbuffer);
357
    screenbuffer_clear(&conn->screenbuffer);
355
   
358
   
356
    /* Accept the connection */
359
    /* Accept the connection */
357
    ipc_answer_0(iid, EOK);
360
    ipc_answer_0(iid, EOK);
358
 
361
   
359
    while (1) {
362
    while (1) {
360
        async_serialize_end();
363
        async_serialize_end();
361
        callid = async_get_call(&call);
364
        callid = async_get_call(&call);
362
        async_serialize_start();
365
        async_serialize_start();
363
 
366
       
364
        arg1 = 0;
367
        arg1 = 0;
365
        arg2 = 0;
368
        arg2 = 0;
366
        switch (IPC_GET_METHOD(call)) {
369
        switch (IPC_GET_METHOD(call)) {
367
        case IPC_M_PHONE_HUNGUP:
370
        case IPC_M_PHONE_HUNGUP:
368
            gcons_notify_disconnect(consnum);
371
            gcons_notify_disconnect(consnum);
369
           
372
           
370
            /* Answer all pending requests */
373
            /* Answer all pending requests */
371
            while (conn->keyrequest_counter > 0) {     
374
            while (conn->keyrequest_counter > 0) {
372
                conn->keyrequest_counter--;
375
                conn->keyrequest_counter--;
373
                ipc_answer_0(fifo_pop(conn->keyrequests),
376
                ipc_answer_0(fifo_pop(conn->keyrequests),
374
                    ENOENT);
377
                    ENOENT);
375
                break;
378
                break;
376
            }
379
            }
Line 441... Line 444...
441
        }
444
        }
442
        ipc_answer_2(callid, EOK, arg1, arg2);
445
        ipc_answer_2(callid, EOK, arg1, arg2);
443
    }
446
    }
444
}
447
}
445
 
448
 
-
 
449
static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
-
 
450
{
-
 
451
    change_console(prev_console);
-
 
452
}
-
 
453
 
446
int main(int argc, char *argv[])
454
int main(int argc, char *argv[])
447
{
455
{
448
    printf(NAME ": HelenOS Console service\n");
456
    printf(NAME ": HelenOS Console service\n");
449
   
457
   
450
    ipcarg_t phonehash;
458
    ipcarg_t phonehash;
451
    int kbd_phone;
459
    int kbd_phone;
452
    int i;
460
    int i;
453
 
461
   
454
    async_set_client_connection(client_connection);
462
    async_set_client_connection(client_connection);
455
   
463
   
456
    /* Connect to keyboard driver */
464
    /* Connect to keyboard driver */
457
 
465
   
458
    kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
466
    kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
459
    while (kbd_phone < 0) {
467
    while (kbd_phone < 0) {
460
        usleep(10000);
468
        usleep(10000);
461
        kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
469
        kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
462
    }
470
    }
Line 509... Line 517...
509
            munmap(interbuffer,
517
            munmap(interbuffer,
510
                sizeof(keyfield_t) * fb_info.cols * fb_info.rows);
518
                sizeof(keyfield_t) * fb_info.cols * fb_info.rows);
511
            interbuffer = NULL;
519
            interbuffer = NULL;
512
        }
520
        }
513
    }
521
    }
514
 
522
   
515
    curs_goto(0, 0);
523
    curs_goto(0, 0);
516
    curs_visibility(
524
    curs_visibility(
517
        connections[active_console].screenbuffer.is_cursor_visible);
525
        connections[active_console].screenbuffer.is_cursor_visible);
518
 
526
   
519
    /* Register at NS */
527
    /* Register at NS */
520
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
528
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
521
        return -1;
529
        return -1;
522
   
530
   
-
 
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
   
523
    // FIXME: avoid connectiong to itself, keep using klog
541
    // FIXME: avoid connectiong to itself, keep using klog
524
    // printf(NAME ": Accepting connections\n");
542
    // printf(NAME ": Accepting connections\n");
525
    async_manager();
543
    async_manager();
526
 
544
   
527
    return 0;  
545
    return 0;
528
}
546
}
529
 
547
 
530
/** @}
548
/** @}
531
 */
549
 */