Rev 3582 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3582 | Rev 3742 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2008 Martin Decky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @defgroup msimfb MSIM text console |
30 | /** @defgroup msimfb MSIM text console |
31 | * @brief HelenOS MSIM text console. |
31 | * @brief HelenOS MSIM text console. |
32 | * @ingroup fbs |
32 | * @ingroup fbs |
33 | * @{ |
33 | * @{ |
34 | */ |
34 | */ |
35 | /** @file |
35 | /** @file |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <ipc/fb.h> |
- | |
40 | #include <ipc/ipc.h> |
- | |
41 | #include <libc.h> |
39 | #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> |
40 | #include <sysinfo.h> |
48 | #include <as.h> |
41 | #include <as.h> |
49 | #include <align.h> |
- | |
50 | #include <ddi.h> |
42 | #include <ddi.h> |
51 | 43 | ||
52 | #include "serial_console.h" |
44 | #include "serial_console.h" |
53 | #include "msim.h" |
45 | #include "msim.h" |
54 | 46 | ||
55 | #define WIDTH 80 |
47 | #define WIDTH 80 |
56 | #define HEIGHT 25 |
48 | #define HEIGHT 25 |
57 | 49 | ||
58 | #define MAX_CONTROL 20 |
- | |
59 | - | ||
60 | /* Allow only 1 connection */ |
- | |
61 | static int client_connected = 0; |
- | |
62 | - | ||
63 | static char *virt_addr; |
50 | static char *virt_addr; |
64 | 51 | ||
65 | static void msim_putc(const char c) |
52 | static void msim_putc(const char c) |
66 | { |
53 | { |
67 | *virt_addr = c; |
54 | *virt_addr = c; |
68 | } |
55 | } |
69 | 56 | ||
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; |
- | |
90 | ipc_answer_0(iid, EOK); |
- | |
91 | - | ||
92 | /* Clear the terminal, set scrolling region |
- | |
93 | to 0 - 25 lines */ |
- | |
94 | serial_clrscr(); |
- | |
95 | serial_goto(0, 0); |
- | |
96 | serial_puts("\033[0;25r"); |
- | |
97 | - | ||
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)) |
- | |
110 | serial_goto(newrow, newcol); |
- | |
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); |
- | |
119 | serial_goto(newrow, newcol); |
- | |
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: |
- | |
128 | serial_clrscr(); |
- | |
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) |
- | |
135 | serial_set_style(0); |
- | |
136 | else |
- | |
137 | serial_set_style(7); |
- | |
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 | } |
- | |
146 | serial_scroll(i); |
- | |
147 | serial_goto(lastrow, lastcol); |
- | |
148 | retval = 0; |
- | |
149 | break; |
- | |
150 | case FB_CURSOR_VISIBILITY: |
- | |
151 | if(IPC_GET_ARG1(call)) |
- | |
152 | serial_cursor_enable(); |
- | |
153 | else |
- | |
154 | serial_cursor_disable(); |
- | |
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) |
57 | int msim_init(void) |
165 | { |
58 | { |
166 | void *phys_addr = (void *) sysinfo_value("fb.address.physical"); |
59 | void *phys_addr = (void *) sysinfo_value("fb.address.physical"); |
167 | virt_addr = (char *) as_get_mappable_page(1); |
60 | virt_addr = (char *) as_get_mappable_page(1); |
168 | 61 | ||
169 | physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE); |
62 | physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE); |
170 | 63 | ||
171 | serial_console_init(msim_putc, WIDTH, HEIGHT); |
64 | serial_console_init(msim_putc, WIDTH, HEIGHT); |
172 | 65 | ||
173 | async_set_client_connection(msim_client_connection); |
66 | async_set_client_connection(serial_client_connection); |
174 | return 0; |
67 | return 0; |
175 | } |
68 | } |
176 | 69 | ||
177 | /** |
70 | /** |
178 | * @} |
71 | * @} |
179 | */ |
72 | */ |
180 | 73 |