Rev 4060 | Rev 4220 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4060 | Rev 4114 | ||
---|---|---|---|
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 <sysinfo/sysinfo.h> |
38 | #include <sysinfo/sysinfo.h> |
39 | #include <arch/types.h> |
39 | #include <arch/types.h> |
40 | #include <proc/thread.h> |
40 | #include <proc/thread.h> |
41 | #include <synch/spinlock.h> |
41 | #include <synch/spinlock.h> |
42 | #include <arch/asm.h> |
42 | #include <arch/asm.h> |
43 | #include <arch/drivers/kbd.h> |
43 | #include <arch/drivers/kbd.h> |
44 | #include <arch.h> |
44 | #include <arch.h> |
45 | 45 | ||
46 | static chardev_t *skiout; |
46 | static indev_t skiin; /**< Ski input device. */ |
47 | - | ||
48 | static chardev_t ski_stdout; |
47 | static outdev_t skiout; /**< Ski output device. */ |
49 | 48 | ||
50 | static bool kbd_disabled; |
49 | static bool kbd_disabled; |
51 | 50 | ||
52 | /** Display character on debug console |
51 | /** Display character on debug console |
53 | * |
52 | * |
54 | * Use SSC (Simulator System Call) to |
53 | * Use SSC (Simulator System Call) to |
55 | * display character on debug console. |
54 | * display character on debug console. |
56 | * |
55 | * |
57 | * @param d Character device. |
56 | * @param d Character device. |
58 | * @param ch Character to be printed. |
57 | * @param ch Character to be printed. |
59 | */ |
58 | */ |
60 | static void ski_putchar(chardev_t *d, const char ch, bool silent) |
59 | static void ski_putchar(outdev_t *d, const char ch, bool silent) |
61 | { |
60 | { |
62 | if (!silent) { |
61 | if (!silent) { |
63 | asm volatile ( |
62 | asm volatile ( |
64 | "mov r15 = %0\n" |
63 | "mov r15 = %0\n" |
65 | "mov r32 = %1\n" /* r32 is in0 */ |
64 | "mov r32 = %1\n" /* r32 is in0 */ |
66 | "break 0x80000\n" /* modifies r8 */ |
65 | "break 0x80000\n" /* modifies r8 */ |
67 | : |
66 | : |
68 | : "i" (SKI_PUTCHAR), "r" (ch) |
67 | : "i" (SKI_PUTCHAR), "r" (ch) |
69 | : "r15", "in0", "r8" |
68 | : "r15", "in0", "r8" |
70 | ); |
69 | ); |
71 | 70 | ||
72 | if (ch == '\n') |
71 | if (ch == '\n') |
73 | ski_putchar(d, '\r', false); |
72 | ski_putchar(d, '\r', false); |
74 | } |
73 | } |
75 | } |
74 | } |
76 | 75 | ||
77 | static chardev_operations_t ski_ops = { |
76 | static indev_operations_t skiin_ops = { |
- | 77 | .poll = NULL |
|
- | 78 | }; |
|
- | 79 | ||
- | 80 | static outdev_operations_t skiout_ops = { |
|
78 | .write = ski_putchar |
81 | .write = ski_putchar |
79 | }; |
82 | }; |
80 | 83 | ||
81 | /** Ask debug console if a key was pressed. |
84 | /** Ask debug console if a key was pressed. |
82 | * |
85 | * |
83 | * Use SSC (Simulator System Call) to |
86 | * Use SSC (Simulator System Call) to |
84 | * get character from debug console. |
87 | * get character from debug console. |
85 | * |
88 | * |
86 | * This call is non-blocking. |
89 | * This call is non-blocking. |
87 | * |
90 | * |
88 | * @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. |
89 | */ |
92 | */ |
90 | static int32_t ski_getchar(void) |
93 | static int32_t ski_getchar(void) |
91 | { |
94 | { |
92 | uint64_t ch; |
95 | uint64_t ch; |
93 | 96 | ||
94 | asm volatile ( |
97 | asm volatile ( |
95 | "mov r15 = %1\n" |
98 | "mov r15 = %1\n" |
96 | "break 0x80000;;\n" /* modifies r8 */ |
99 | "break 0x80000;;\n" /* modifies r8 */ |
97 | "mov %0 = r8;;\n" |
100 | "mov %0 = r8;;\n" |
98 | 101 | ||
99 | : "=r" (ch) |
102 | : "=r" (ch) |
100 | : "i" (SKI_GETCHAR) |
103 | : "i" (SKI_GETCHAR) |
101 | : "r15", "r8" |
104 | : "r15", "r8" |
102 | ); |
105 | ); |
103 | 106 | ||
104 | return (int32_t) ch; |
107 | return (int32_t) ch; |
105 | } |
108 | } |
106 | 109 | ||
107 | /** Ask keyboard if a key was pressed. */ |
110 | /** Ask keyboard if a key was pressed. */ |
108 | static void poll_keyboard(void) |
111 | static void poll_keyboard(void) |
109 | { |
112 | { |
110 | char ch; |
113 | char ch; |
111 | ipl_t ipl; |
- | |
112 | 114 | ||
113 | ipl = interrupts_disable(); |
- | |
114 | - | ||
115 | if (kbd_disabled) { |
115 | if (kbd_disabled) |
116 | interrupts_restore(ipl); |
- | |
117 | return; |
116 | return; |
118 | } |
- | |
119 | - | ||
120 | ch = ski_getchar(); |
117 | ch = ski_getchar(); |
121 | if(ch == '\r') |
118 | if(ch == '\r') |
122 | ch = '\n'; |
119 | ch = '\n'; |
123 | if (ch && skiout) { |
120 | if (ch) { |
124 | chardev_push_character(skiout, ch); |
121 | indev_push_character(&skiin, ch); |
125 | interrupts_restore(ipl); |
- | |
126 | return; |
122 | return; |
127 | } |
123 | } |
128 | - | ||
129 | interrupts_restore(ipl); |
- | |
130 | } |
124 | } |
131 | 125 | ||
132 | #define POLL_INTERVAL 10000 /* 10 ms */ |
126 | #define POLL_INTERVAL 10000 /* 10 ms */ |
133 | 127 | ||
134 | /** Kernel thread for polling keyboard. */ |
128 | /** Kernel thread for polling keyboard. */ |
135 | static void kkbdpoll(void *arg) |
129 | static void kkbdpoll(void *arg) |
136 | { |
130 | { |
137 | while (1) { |
131 | while (1) { |
138 | if (!silent) { |
132 | if (!silent) { |
139 | poll_keyboard(); |
133 | poll_keyboard(); |
140 | } |
134 | } |
141 | thread_usleep(POLL_INTERVAL); |
135 | thread_usleep(POLL_INTERVAL); |
142 | } |
136 | } |
143 | } |
137 | } |
144 | 138 | ||
145 | /** Initialize debug console |
139 | /** Initialize debug console |
146 | * |
140 | * |
147 | * Issue SSC (Simulator System Call) to |
141 | * Issue SSC (Simulator System Call) to |
148 | * to open debug console. |
142 | * to open debug console. |
149 | */ |
143 | */ |
150 | void ski_console_init(chardev_t *devout) |
144 | static void ski_init(void) |
151 | { |
145 | { |
- | 146 | static bool initialized; |
|
- | 147 | ||
- | 148 | if (initialized) |
|
- | 149 | return; |
|
- | 150 | ||
152 | asm volatile ( |
151 | asm volatile ( |
153 | "mov r15 = %0\n" |
152 | "mov r15 = %0\n" |
154 | "break 0x80000\n" |
153 | "break 0x80000\n" |
155 | : |
154 | : |
156 | : "i" (SKI_INIT_CONSOLE) |
155 | : "i" (SKI_INIT_CONSOLE) |
157 | : "r15", "r8" |
156 | : "r15", "r8" |
158 | ); |
157 | ); |
- | 158 | ||
- | 159 | initialized = true; |
|
- | 160 | } |
|
159 | 161 | ||
160 | skiout = devout; |
162 | indev_t *skiin_init(void) |
161 | chardev_initialize("ski_stdout", &ski_stdout, &ski_ops); |
- | |
- | 163 | { |
|
162 | stdout = &ski_stdout; |
164 | ski_init(); |
163 | 165 | ||
- | 166 | indev_initialize("skiin", &skiin, &skiin_ops); |
|
164 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
167 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
165 | if (!t) |
168 | if (t) |
166 | panic("Cannot create kkbdpoll."); |
169 | thread_ready(t); |
- | 170 | else |
|
167 | thread_ready(t); |
171 | return NULL; |
168 | 172 | ||
169 | sysinfo_set_item_val("kbd", NULL, true); |
173 | sysinfo_set_item_val("kbd", NULL, true); |
170 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
174 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
171 | 175 | ||
- | 176 | return &skiin; |
|
- | 177 | } |
|
- | 178 | ||
- | 179 | ||
- | 180 | void skiout_init(void) |
|
- | 181 | { |
|
- | 182 | ski_init(); |
|
- | 183 | ||
- | 184 | outdev_initialize("skiout", &skiout, &skiout_ops); |
|
- | 185 | stdout = &skiout; |
|
- | 186 | ||
172 | sysinfo_set_item_val("fb", NULL, false); |
187 | sysinfo_set_item_val("fb", NULL, false); |
173 | } |
188 | } |
174 | 189 | ||
175 | void ski_kbd_grab(void) |
190 | void ski_kbd_grab(void) |
176 | { |
191 | { |
177 | kbd_disabled = true; |
192 | kbd_disabled = true; |
178 | } |
193 | } |
179 | 194 | ||
180 | void ski_kbd_release(void) |
195 | void ski_kbd_release(void) |
181 | { |
196 | { |
182 | kbd_disabled = false; |
197 | kbd_disabled = false; |
183 | } |
198 | } |
184 | 199 | ||
185 | /** @} |
200 | /** @} |
186 | */ |
201 | */ |
187 | 202 |