Rev 1888 | Rev 1944 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1888 | Rev 1942 | ||
---|---|---|---|
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 | #include <arch/types.h> |
|
- | 41 | #include <typedefs.h> |
|
- | 42 | #include <ddi/device.h> |
|
- | 43 | #include <ddi/irq.h> |
|
- | 44 | #include <ipc/irq.h> |
|
- | 45 | #include <synch/spinlock.h> |
|
- | 46 | #include <arch/asm.h> |
|
- | 47 | ||
- | 48 | #define SKI_KBD_INR 0 |
|
- | 49 | ||
- | 50 | static irq_t ski_kbd_irq; |
|
- | 51 | static devno_t ski_kbd_devno; |
|
40 | 52 | ||
41 | chardev_t ski_console; |
53 | chardev_t ski_console; |
42 | chardev_t ski_uconsole; |
54 | chardev_t ski_uconsole; |
- | 55 | ||
43 | static bool kb_disable; |
56 | static bool kbd_disabled; |
44 | int kbd_uspace=0; |
- | |
45 | 57 | ||
46 | static void ski_putchar(chardev_t *d, const char ch); |
58 | static void ski_putchar(chardev_t *d, const char ch); |
47 | static int32_t ski_getchar(void); |
59 | static int32_t ski_getchar(void); |
48 | 60 | ||
49 | /** Display character on debug console |
61 | /** Display character on debug console |
50 | * |
62 | * |
51 | * Use SSC (Simulator System Call) to |
63 | * Use SSC (Simulator System Call) to |
52 | * display character on debug console. |
64 | * display character on debug console. |
53 | * |
65 | * |
54 | * @param d Character device. |
66 | * @param d Character device. |
55 | * @param ch Character to be printed. |
67 | * @param ch Character to be printed. |
56 | */ |
68 | */ |
57 | void ski_putchar(chardev_t *d, const char ch) |
69 | void ski_putchar(chardev_t *d, const char ch) |
58 | { |
70 | { |
59 | __asm__ volatile ( |
71 | __asm__ volatile ( |
60 | "mov r15=%0\n" |
72 | "mov r15 = %0\n" |
61 | "mov r32=%1\n" /* r32 is in0 */ |
73 | "mov r32 = %1\n" /* r32 is in0 */ |
62 | "break 0x80000\n" /* modifies r8 */ |
74 | "break 0x80000\n" /* modifies r8 */ |
63 | : |
75 | : |
64 | : "i" (SKI_PUTCHAR), "r" (ch) |
76 | : "i" (SKI_PUTCHAR), "r" (ch) |
65 | : "r15", "in0", "r8" |
77 | : "r15", "in0", "r8" |
66 | ); |
78 | ); |
67 | 79 | ||
68 | if (ch == '\n') |
80 | if (ch == '\n') |
69 | ski_putchar(d, '\r'); |
81 | ski_putchar(d, '\r'); |
70 | } |
82 | } |
71 | 83 | ||
72 | /** Ask debug console if a key was pressed. |
84 | /** Ask debug console if a key was pressed. |
73 | * |
85 | * |
74 | * Use SSC (Simulator System Call) to |
86 | * Use SSC (Simulator System Call) to |
75 | * get character from debug console. |
87 | * get character from debug console. |
76 | * |
88 | * |
77 | * This call is non-blocking. |
89 | * This call is non-blocking. |
78 | * |
90 | * |
79 | * @return ASCII code of pressed key or 0 if no key pressed. |
91 | * @return ASCII code of pressed key or 0 if no key pressed. |
80 | */ |
92 | */ |
81 | int32_t ski_getchar(void) |
93 | int32_t ski_getchar(void) |
82 | { |
94 | { |
83 | uint64_t ch; |
95 | uint64_t ch; |
84 | 96 | ||
85 | __asm__ volatile ( |
97 | __asm__ volatile ( |
86 | "mov r15=%1\n" |
98 | "mov r15 = %1\n" |
87 | "break 0x80000;;\n" /* modifies r8 */ |
99 | "break 0x80000;;\n" /* modifies r8 */ |
88 | "mov %0=r8;;\n" |
100 | "mov %0 = r8;;\n" |
89 | 101 | ||
90 | : "=r" (ch) |
102 | : "=r" (ch) |
91 | : "i" (SKI_GETCHAR) |
103 | : "i" (SKI_GETCHAR) |
92 | : "r15", "r8" |
104 | : "r15", "r8" |
93 | ); |
105 | ); |
94 | 106 | ||
95 | return (int32_t) ch; |
107 | return (int32_t) ch; |
96 | } |
108 | } |
97 | 109 | ||
98 | /** |
110 | /** |
99 | * This is a blocking wrapper for ski_getchar(). |
111 | * This is a blocking wrapper for ski_getchar(). |
100 | * To be used when the kernel crashes. |
112 | * To be used when the kernel crashes. |
101 | */ |
113 | */ |
102 | static char ski_getchar_blocking(chardev_t *d) |
114 | static char ski_getchar_blocking(chardev_t *d) |
103 | { |
115 | { |
104 | int ch; |
116 | int ch; |
105 | 117 | ||
106 | while(!(ch=ski_getchar())) |
118 | while(!(ch = ski_getchar())) |
107 | ; |
119 | ; |
108 | if(ch == '\r') |
120 | if(ch == '\r') |
109 | ch = '\n'; |
121 | ch = '\n'; |
110 | return (char) ch; |
122 | return (char) ch; |
111 | } |
123 | } |
112 | 124 | ||
113 | /** Ask keyboard if a key was pressed. */ |
125 | /** Ask keyboard if a key was pressed. */ |
114 | void poll_keyboard(void) |
126 | void poll_keyboard(void) |
115 | { |
127 | { |
116 | char ch; |
128 | char ch; |
117 | static char last; |
129 | static char last; |
- | 130 | ipl_t ipl; |
|
- | 131 | ||
- | 132 | ipl = interrupts_disable(); |
|
118 | 133 | ||
119 | if (kb_disable) |
134 | if (kbd_disabled) { |
- | 135 | interrupts_restore(ipl); |
|
120 | return; |
136 | return; |
- | 137 | } |
|
- | 138 | ||
- | 139 | spinlock_lock(&ski_kbd_irq.lock); |
|
121 | 140 | ||
122 | ch = ski_getchar(); |
141 | ch = ski_getchar(); |
123 | if(ch == '\r') |
142 | if(ch == '\r') |
124 | ch = '\n'; |
143 | ch = '\n'; |
125 | if (ch){ |
144 | if (ch) { |
126 | if(kbd_uspace){ |
145 | if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) { |
127 | chardev_push_character(&ski_uconsole, ch); |
146 | chardev_push_character(&ski_uconsole, ch); |
128 | virtual_interrupt(IRQ_KBD,NULL); |
147 | ipc_irq_send_notif(&ski_kbd_irq); |
129 | } |
- | |
130 | else { |
148 | } else { |
131 | chardev_push_character(&ski_console, ch); |
149 | chardev_push_character(&ski_console, ch); |
132 | } |
150 | } |
133 | last = ch; |
151 | last = ch; |
- | 152 | spinlock_unlock(&ski_kbd_irq.lock); |
|
- | 153 | interrupts_restore(ipl); |
|
134 | return; |
154 | return; |
135 | } |
155 | } |
136 | 156 | ||
137 | if (last){ |
157 | if (last) { |
138 | if(kbd_uspace){ |
158 | if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) { |
139 | chardev_push_character(&ski_uconsole, 0); |
159 | chardev_push_character(&ski_uconsole, 0); |
140 | virtual_interrupt(IRQ_KBD,NULL); |
160 | ipc_irq_send_notif(&ski_kbd_irq); |
141 | } |
161 | } |
142 | else { |
- | |
143 | } |
- | |
144 | last = 0; |
162 | last = 0; |
145 | } |
163 | } |
146 | 164 | ||
- | 165 | spinlock_unlock(&ski_kbd_irq.lock); |
|
- | 166 | interrupts_restore(ipl); |
|
147 | } |
167 | } |
148 | 168 | ||
149 | /* Called from getc(). */ |
169 | /* Called from getc(). */ |
150 | static void ski_kb_enable(chardev_t *d) |
170 | static void ski_kbd_enable(chardev_t *d) |
151 | { |
171 | { |
152 | kb_disable = false; |
172 | kbd_disabled = false; |
153 | } |
173 | } |
154 | 174 | ||
155 | /* Called from getc(). */ |
175 | /* Called from getc(). */ |
156 | static void ski_kb_disable(chardev_t *d) |
176 | static void ski_kbd_disable(chardev_t *d) |
157 | { |
177 | { |
158 | kb_disable = true; |
178 | kbd_disabled = true; |
- | 179 | } |
|
- | 180 | ||
- | 181 | /** Decline to service hardware IRQ. |
|
- | 182 | * |
|
- | 183 | * This is only a virtual IRQ, so always decline. |
|
- | 184 | * |
|
- | 185 | * @return Always IRQ_DECLINE. |
|
- | 186 | */ |
|
- | 187 | static irq_ownership_t ski_kbd_claim(void) |
|
- | 188 | { |
|
- | 189 | return IRQ_DECLINE; |
|
159 | } |
190 | } |
160 | 191 | ||
161 | static chardev_operations_t ski_ops = { |
192 | static chardev_operations_t ski_ops = { |
162 | .resume = ski_kb_enable, |
193 | .resume = ski_kbd_enable, |
163 | .suspend = ski_kb_disable, |
194 | .suspend = ski_kbd_disable, |
164 | .write = ski_putchar, |
195 | .write = ski_putchar, |
165 | .read = ski_getchar_blocking |
196 | .read = ski_getchar_blocking |
166 | }; |
197 | }; |
167 | 198 | ||
168 | /** Initialize debug console |
199 | /** Initialize debug console |
169 | * |
200 | * |
170 | * Issue SSC (Simulator System Call) to |
201 | * Issue SSC (Simulator System Call) to |
171 | * to open debug console. |
202 | * to open debug console. |
172 | */ |
203 | */ |
173 | void ski_init_console(void) |
204 | void ski_init_console(void) |
174 | { |
205 | { |
175 | __asm__ volatile ( |
206 | __asm__ volatile ( |
176 | "mov r15=%0\n" |
207 | "mov r15 = %0\n" |
177 | "break 0x80000\n" |
208 | "break 0x80000\n" |
178 | : |
209 | : |
179 | : "i" (SKI_INIT_CONSOLE) |
210 | : "i" (SKI_INIT_CONSOLE) |
180 | : "r15", "r8" |
211 | : "r15", "r8" |
181 | ); |
212 | ); |
182 | 213 | ||
183 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
214 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
184 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
215 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
185 | stdin = &ski_console; |
216 | stdin = &ski_console; |
186 | stdout = &ski_console; |
217 | stdout = &ski_console; |
187 | 218 | ||
- | 219 | ski_kbd_devno = device_assign_devno(); |
|
- | 220 | ||
- | 221 | irq_initialize(&ski_kbd_irq); |
|
- | 222 | ski_kbd_irq.inr = SKI_KBD_INR; |
|
- | 223 | ski_kbd_irq.devno = ski_kbd_devno; |
|
- | 224 | ski_kbd_irq.claim = ski_kbd_claim; |
|
- | 225 | irq_register(&ski_kbd_irq); |
|
- | 226 | ||
188 | } |
227 | } |
189 | 228 | ||
190 | /** Setup console sysinfo (i.e. Keyboard IRQ) |
229 | /** Setup console sysinfo (i.e. Keyboard IRQ) |
191 | * |
230 | * |
192 | * Because sysinfo neads memory allocation/dealocation |
231 | * Because sysinfo neads memory allocation/dealocation |
193 | * this functions should be called separetely from init. |
232 | * this functions should be called separetely from init. |
194 | * |
233 | * |
195 | */ |
234 | */ |
196 | void ski_set_console_sysinfo(void) |
235 | void ski_set_console_sysinfo(void) |
197 | { |
236 | { |
198 | sysinfo_set_item_val("kbd",NULL,true); |
237 | sysinfo_set_item_val("kbd", NULL, true); |
199 | sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD); |
238 | sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR); |
- | 239 | sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno); |
|
- | 240 | } |
|
- | 241 | ||
- | 242 | void ski_kbd_grab(void) |
|
- | 243 | { |
|
- | 244 | ski_kbd_irq.notif_cfg.notify = false; |
|
- | 245 | } |
|
- | 246 | ||
- | 247 | void ski_kbd_release(void) |
|
- | 248 | { |
|
- | 249 | if (ski_kbd_irq.notif_cfg.answerbox) |
|
- | 250 | ski_kbd_irq.notif_cfg.notify = true; |
|
200 | } |
251 | } |
201 | 252 | ||
202 | /** @} |
253 | /** @} |
203 | */ |
254 | */ |
204 | 255 |