Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
3234 decky 1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * Copyright (c) 2008 Martin Decky
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
/** @defgroup msimfb MSIM text console
31
 * @brief   HelenOS MSIM text console.
32
 * @ingroup fbs
33
 * @{
34
 */
35
/** @file
36
 */
37
 
38
#include <async.h>
39
#include <ipc/fb.h>
40
#include <ipc/ipc.h>
41
#include <libc.h>
42
#include <errno.h>
43
#include <string.h>
44
#include <libc.h>
45
#include <stdio.h>
46
#include <ipc/fb.h>
47
#include <sysinfo.h>
48
#include <as.h>
49
#include <align.h>
50
#include <ddi.h>
51
 
3672 jermar 52
#include "serial_console.h"
3234 decky 53
#include "msim.h"
54
 
55
#define WIDTH 80
56
#define HEIGHT 25
57
 
58
#define MAX_CONTROL 20
59
 
60
/* Allow only 1 connection */
61
static int client_connected = 0;
62
 
63
static char *virt_addr;
64
 
65
static void msim_putc(const char c)
66
{
67
    *virt_addr = c;
68
}
69
 
70
static void msim_client_connection(ipc_callid_t iid, ipc_call_t *icall)
71
{
72
    int retval;
73
    ipc_callid_t callid;
74
    ipc_call_t call;
75
    char c;
76
    int lastcol = 0;
77
    int lastrow = 0;
78
    int newcol;
79
    int newrow;
80
    int fgcolor;
81
    int bgcolor;
82
    int i;
83
 
84
    if (client_connected) {
85
        ipc_answer_0(iid, ELIMIT);
86
        return;
87
    }
88
 
89
    client_connected = 1;
3235 decky 90
    ipc_answer_0(iid, EOK);
3234 decky 91
 
3235 decky 92
    /* Clear the terminal, set scrolling region
93
       to 0 - 25 lines */
3672 jermar 94
    serial_clrscr();
95
    serial_goto(0, 0);
96
    serial_puts("\033[0;25r");
3235 decky 97
 
3234 decky 98
    while (true) {
99
        callid = async_get_call(&call);
100
        switch (IPC_GET_METHOD(call)) {
101
        case IPC_M_PHONE_HUNGUP:
102
            client_connected = 0;
103
            ipc_answer_0(callid, EOK);
104
            return;
105
        case FB_PUTCHAR:
106
            c = IPC_GET_ARG1(call);
107
            newrow = IPC_GET_ARG2(call);
108
            newcol = IPC_GET_ARG3(call);
109
            if ((lastcol != newcol) || (lastrow != newrow))
3672 jermar 110
                serial_goto(newrow, newcol);
3234 decky 111
            lastcol = newcol + 1;
112
            lastrow = newrow;
113
            msim_putc(c);
114
            retval = 0;
115
            break;
116
        case FB_CURSOR_GOTO:
117
            newrow = IPC_GET_ARG1(call);
118
            newcol = IPC_GET_ARG2(call);
3672 jermar 119
            serial_goto(newrow, newcol);
3234 decky 120
            lastrow = newrow;
121
            lastcol = newcol;
122
            retval = 0;
123
            break;
124
        case FB_GET_CSIZE:
125
            ipc_answer_2(callid, EOK, HEIGHT, WIDTH);
126
            continue;
127
        case FB_CLEAR:
3672 jermar 128
            serial_clrscr();
3234 decky 129
            retval = 0;
130
            break;
131
        case FB_SET_STYLE:
132
            fgcolor = IPC_GET_ARG1(call);
133
            bgcolor = IPC_GET_ARG2(call);
134
            if (fgcolor < bgcolor)
3672 jermar 135
                serial_set_style(0);
3234 decky 136
            else
3672 jermar 137
                serial_set_style(7);
3234 decky 138
            retval = 0;
139
            break;
140
        case FB_SCROLL:
141
            i = IPC_GET_ARG1(call);
142
            if ((i > HEIGHT) || (i < -HEIGHT)) {
143
                retval = EINVAL;
144
                break;
145
            }
3672 jermar 146
            serial_scroll(i);
147
            serial_goto(lastrow, lastcol);
3234 decky 148
            retval = 0;
149
            break;
150
        case FB_CURSOR_VISIBILITY:
151
            if(IPC_GET_ARG1(call))
3672 jermar 152
                serial_cursor_enable();
3234 decky 153
            else
3672 jermar 154
                serial_cursor_disable();
3234 decky 155
            retval = 0;
156
            break;
157
        default:
158
            retval = ENOENT;
159
        }
160
        ipc_answer_0(callid, retval);
161
    }
162
}
163
 
164
int msim_init(void)
165
{
166
    void *phys_addr = (void *) sysinfo_value("fb.address.physical");
167
    virt_addr = (char *) as_get_mappable_page(1);
168
 
169
    physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE);
170
 
3672 jermar 171
    serial_console_init(msim_putc, WIDTH, HEIGHT);
172
 
3234 decky 173
    async_set_client_connection(msim_client_connection);
174
    return 0;
175
}
176
 
177
/**
178
 * @}
179
 */