Rev 1702 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1702 | Rev 1780 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Jakub Jermar |
2 | * Copyright (C) 2005 Jakub Jermar |
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 ia64 |
29 | /** @addtogroup ia64 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/ski/ski.h> |
35 | #include <arch/ski/ski.h> |
36 | #include <console/console.h> |
36 | #include <console/console.h> |
37 | #include <console/chardev.h> |
37 | #include <console/chardev.h> |
38 | #include <arch/interrupt.h> |
38 | #include <arch/interrupt.h> |
39 | #include <sysinfo/sysinfo.h> |
39 | #include <sysinfo/sysinfo.h> |
40 | 40 | ||
41 | chardev_t ski_console; |
41 | chardev_t ski_console; |
42 | chardev_t ski_uconsole; |
42 | chardev_t ski_uconsole; |
43 | static bool kb_disable; |
43 | static bool kb_disable; |
44 | int kbd_uspace=0; |
44 | int kbd_uspace=0; |
45 | 45 | ||
46 | static void ski_putchar(chardev_t *d, const char ch); |
46 | static void ski_putchar(chardev_t *d, const char ch); |
47 | static __s32 ski_getchar(void); |
47 | static int32_t ski_getchar(void); |
48 | 48 | ||
49 | /** Display character on debug console |
49 | /** Display character on debug console |
50 | * |
50 | * |
51 | * Use SSC (Simulator System Call) to |
51 | * Use SSC (Simulator System Call) to |
52 | * display character on debug console. |
52 | * display character on debug console. |
53 | * |
53 | * |
54 | * @param d Character device. |
54 | * @param d Character device. |
55 | * @param ch Character to be printed. |
55 | * @param ch Character to be printed. |
56 | */ |
56 | */ |
57 | void ski_putchar(chardev_t *d, const char ch) |
57 | void ski_putchar(chardev_t *d, const char ch) |
58 | { |
58 | { |
59 | __asm__ volatile ( |
59 | __asm__ volatile ( |
60 | "mov r15=%0\n" |
60 | "mov r15=%0\n" |
61 | "mov r32=%1\n" /* r32 is in0 */ |
61 | "mov r32=%1\n" /* r32 is in0 */ |
62 | "break 0x80000\n" /* modifies r8 */ |
62 | "break 0x80000\n" /* modifies r8 */ |
63 | : |
63 | : |
64 | : "i" (SKI_PUTCHAR), "r" (ch) |
64 | : "i" (SKI_PUTCHAR), "r" (ch) |
65 | : "r15", "in0", "r8" |
65 | : "r15", "in0", "r8" |
66 | ); |
66 | ); |
67 | 67 | ||
68 | if (ch == '\n') |
68 | if (ch == '\n') |
69 | ski_putchar(d, '\r'); |
69 | ski_putchar(d, '\r'); |
70 | } |
70 | } |
71 | 71 | ||
72 | /** Ask debug console if a key was pressed. |
72 | /** Ask debug console if a key was pressed. |
73 | * |
73 | * |
74 | * Use SSC (Simulator System Call) to |
74 | * Use SSC (Simulator System Call) to |
75 | * get character from debug console. |
75 | * get character from debug console. |
76 | * |
76 | * |
77 | * This call is non-blocking. |
77 | * This call is non-blocking. |
78 | * |
78 | * |
79 | * @return ASCII code of pressed key or 0 if no key pressed. |
79 | * @return ASCII code of pressed key or 0 if no key pressed. |
80 | */ |
80 | */ |
81 | __s32 ski_getchar(void) |
81 | int32_t ski_getchar(void) |
82 | { |
82 | { |
83 | __u64 ch; |
83 | uint64_t ch; |
84 | 84 | ||
85 | __asm__ volatile ( |
85 | __asm__ volatile ( |
86 | "mov r15=%1\n" |
86 | "mov r15=%1\n" |
87 | "break 0x80000;;\n" /* modifies r8 */ |
87 | "break 0x80000;;\n" /* modifies r8 */ |
88 | "mov %0=r8;;\n" |
88 | "mov %0=r8;;\n" |
89 | 89 | ||
90 | : "=r" (ch) |
90 | : "=r" (ch) |
91 | : "i" (SKI_GETCHAR) |
91 | : "i" (SKI_GETCHAR) |
92 | : "r15", "r8" |
92 | : "r15", "r8" |
93 | ); |
93 | ); |
94 | 94 | ||
95 | return (__s32) ch; |
95 | return (int32_t) ch; |
96 | } |
96 | } |
97 | 97 | ||
98 | /** |
98 | /** |
99 | * This is a blocking wrapper for ski_getchar(). |
99 | * This is a blocking wrapper for ski_getchar(). |
100 | * To be used when the kernel crashes. |
100 | * To be used when the kernel crashes. |
101 | */ |
101 | */ |
102 | static char ski_getchar_blocking(chardev_t *d) |
102 | static char ski_getchar_blocking(chardev_t *d) |
103 | { |
103 | { |
104 | int ch; |
104 | int ch; |
105 | 105 | ||
106 | while(!(ch=ski_getchar())) |
106 | while(!(ch=ski_getchar())) |
107 | ; |
107 | ; |
108 | if(ch == '\r') |
108 | if(ch == '\r') |
109 | ch = '\n'; |
109 | ch = '\n'; |
110 | return (char) ch; |
110 | return (char) ch; |
111 | } |
111 | } |
112 | 112 | ||
113 | /** Ask keyboard if a key was pressed. */ |
113 | /** Ask keyboard if a key was pressed. */ |
114 | void poll_keyboard(void) |
114 | void poll_keyboard(void) |
115 | { |
115 | { |
116 | char ch; |
116 | char ch; |
117 | static char last; |
117 | static char last; |
118 | 118 | ||
119 | if (kb_disable) |
119 | if (kb_disable) |
120 | return; |
120 | return; |
121 | 121 | ||
122 | ch = ski_getchar(); |
122 | ch = ski_getchar(); |
123 | if(ch == '\r') |
123 | if(ch == '\r') |
124 | ch = '\n'; |
124 | ch = '\n'; |
125 | if (ch){ |
125 | if (ch){ |
126 | if(kbd_uspace){ |
126 | if(kbd_uspace){ |
127 | chardev_push_character(&ski_uconsole, ch); |
127 | chardev_push_character(&ski_uconsole, ch); |
128 | virtual_interrupt(IRQ_KBD,NULL); |
128 | virtual_interrupt(IRQ_KBD,NULL); |
129 | } |
129 | } |
130 | else { |
130 | else { |
131 | chardev_push_character(&ski_console, ch); |
131 | chardev_push_character(&ski_console, ch); |
132 | } |
132 | } |
133 | last = ch; |
133 | last = ch; |
134 | return; |
134 | return; |
135 | } |
135 | } |
136 | 136 | ||
137 | if (last){ |
137 | if (last){ |
138 | if(kbd_uspace){ |
138 | if(kbd_uspace){ |
139 | chardev_push_character(&ski_uconsole, 0); |
139 | chardev_push_character(&ski_uconsole, 0); |
140 | virtual_interrupt(IRQ_KBD,NULL); |
140 | virtual_interrupt(IRQ_KBD,NULL); |
141 | } |
141 | } |
142 | else { |
142 | else { |
143 | } |
143 | } |
144 | last = 0; |
144 | last = 0; |
145 | } |
145 | } |
146 | 146 | ||
147 | } |
147 | } |
148 | 148 | ||
149 | /* Called from getc(). */ |
149 | /* Called from getc(). */ |
150 | static void ski_kb_enable(chardev_t *d) |
150 | static void ski_kb_enable(chardev_t *d) |
151 | { |
151 | { |
152 | kb_disable = false; |
152 | kb_disable = false; |
153 | } |
153 | } |
154 | 154 | ||
155 | /* Called from getc(). */ |
155 | /* Called from getc(). */ |
156 | static void ski_kb_disable(chardev_t *d) |
156 | static void ski_kb_disable(chardev_t *d) |
157 | { |
157 | { |
158 | kb_disable = true; |
158 | kb_disable = true; |
159 | } |
159 | } |
160 | 160 | ||
161 | 161 | ||
162 | static chardev_operations_t ski_ops = { |
162 | static chardev_operations_t ski_ops = { |
163 | .resume = ski_kb_enable, |
163 | .resume = ski_kb_enable, |
164 | .suspend = ski_kb_disable, |
164 | .suspend = ski_kb_disable, |
165 | .write = ski_putchar, |
165 | .write = ski_putchar, |
166 | .read = ski_getchar_blocking |
166 | .read = ski_getchar_blocking |
167 | }; |
167 | }; |
168 | 168 | ||
169 | 169 | ||
170 | /** Initialize debug console |
170 | /** Initialize debug console |
171 | * |
171 | * |
172 | * Issue SSC (Simulator System Call) to |
172 | * Issue SSC (Simulator System Call) to |
173 | * to open debug console. |
173 | * to open debug console. |
174 | */ |
174 | */ |
175 | void ski_init_console(void) |
175 | void ski_init_console(void) |
176 | { |
176 | { |
177 | __asm__ volatile ( |
177 | __asm__ volatile ( |
178 | "mov r15=%0\n" |
178 | "mov r15=%0\n" |
179 | "break 0x80000\n" |
179 | "break 0x80000\n" |
180 | : |
180 | : |
181 | : "i" (SKI_INIT_CONSOLE) |
181 | : "i" (SKI_INIT_CONSOLE) |
182 | : "r15", "r8" |
182 | : "r15", "r8" |
183 | ); |
183 | ); |
184 | 184 | ||
185 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
185 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
186 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
186 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
187 | stdin = &ski_console; |
187 | stdin = &ski_console; |
188 | stdout = &ski_console; |
188 | stdout = &ski_console; |
189 | 189 | ||
190 | } |
190 | } |
191 | /** Setup console sysinfo (i.e. Keyboard IRQ) |
191 | /** Setup console sysinfo (i.e. Keyboard IRQ) |
192 | * |
192 | * |
193 | * Because sysinfo neads memory allocation/dealocation |
193 | * Because sysinfo neads memory allocation/dealocation |
194 | * this functions should be called separetely from init. |
194 | * this functions should be called separetely from init. |
195 | * |
195 | * |
196 | */ |
196 | */ |
197 | void ski_set_console_sysinfo(void) |
197 | void ski_set_console_sysinfo(void) |
198 | { |
198 | { |
199 | sysinfo_set_item_val("kbd",NULL,true); |
199 | sysinfo_set_item_val("kbd",NULL,true); |
200 | sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD); |
200 | sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD); |
201 | } |
201 | } |
202 | 202 | ||
203 | /** @} |
203 | /** @} |
204 | */ |
204 | */ |
205 | 205 | ||
206 | 206 |