Rev 4223 | Rev 4313 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4223 | Rev 4311 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/ski/ski.h> |
35 | #include <arch/drivers/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> |
Line 42... | Line 42... | ||
42 | #include <arch/asm.h> |
42 | #include <arch/asm.h> |
43 | #include <arch/drivers/kbd.h> |
43 | #include <arch/drivers/kbd.h> |
44 | #include <string.h> |
44 | #include <string.h> |
45 | #include <arch.h> |
45 | #include <arch.h> |
46 | 46 | ||
47 | static indev_t skiin; /**< Ski input device. */ |
47 | #define POLL_INTERVAL 10000 /* 10 ms */ |
48 | static outdev_t skiout; /**< Ski output device. */ |
- | |
49 | 48 | ||
- | 49 | #define SKI_INIT_CONSOLE 20 |
|
- | 50 | #define SKI_GETCHAR 21 |
|
- | 51 | #define SKI_PUTCHAR 31 |
|
- | 52 | ||
- | 53 | static void ski_putchar(outdev_t *, const wchar_t, bool); |
|
- | 54 | ||
- | 55 | static outdev_operations_t skiout_ops = { |
|
- | 56 | .write = ski_putchar |
|
- | 57 | }; |
|
- | 58 | ||
- | 59 | static outdev_t skiout; /**< Ski output device. */ |
|
- | 60 | static bool initialized = false; |
|
50 | static bool kbd_disabled; |
61 | static bool kbd_disabled = false; |
- | 62 | ||
- | 63 | /** Initialize debug console |
|
- | 64 | * |
|
- | 65 | * Issue SSC (Simulator System Call) to |
|
- | 66 | * to open debug console. |
|
- | 67 | * |
|
- | 68 | */ |
|
- | 69 | static void ski_init(void) |
|
- | 70 | { |
|
- | 71 | if (initialized) |
|
- | 72 | return; |
|
- | 73 | ||
- | 74 | asm volatile ( |
|
- | 75 | "mov r15 = %0\n" |
|
- | 76 | "break 0x80000\n" |
|
- | 77 | : |
|
- | 78 | : "i" (SKI_INIT_CONSOLE) |
|
- | 79 | : "r15", "r8" |
|
- | 80 | ); |
|
- | 81 | ||
- | 82 | initialized = true; |
|
- | 83 | } |
|
51 | 84 | ||
52 | static void ski_do_putchar(const wchar_t ch) |
85 | static void ski_do_putchar(const wchar_t ch) |
53 | { |
86 | { |
54 | asm volatile ( |
87 | asm volatile ( |
55 | "mov r15 = %[cmd]\n" |
88 | "mov r15 = %[cmd]\n" |
56 | "mov r32 = %[ch]\n" /* r32 is in0 */ |
89 | "mov r32 = %[ch]\n" /* r32 is in0 */ |
57 | "break 0x80000\n" /* modifies r8 */ |
90 | "break 0x80000\n" /* modifies r8 */ |
58 | : |
91 | : |
59 | : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch) |
92 | : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch) |
60 | : "r15", "in0", "r8" |
93 | : "r15", "in0", "r8" |
61 | ); |
94 | ); |
62 | } |
95 | } |
Line 64... | Line 97... | ||
64 | /** Display character on debug console |
97 | /** Display character on debug console |
65 | * |
98 | * |
66 | * Use SSC (Simulator System Call) to |
99 | * Use SSC (Simulator System Call) to |
67 | * display character on debug console. |
100 | * display character on debug console. |
68 | * |
101 | * |
69 | * @param d Character device. |
102 | * @param dev Character device. |
70 | * @param ch Character to be printed. |
103 | * @param ch Character to be printed. |
- | 104 | * @param silent Whether the output should be silenced. |
|
- | 105 | * |
|
71 | */ |
106 | */ |
72 | static void ski_putchar(outdev_t *d, const wchar_t ch, bool silent) |
107 | static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent) |
73 | { |
108 | { |
74 | if (!silent) { |
109 | if (!silent) { |
75 | if (ascii_check(ch)) { |
110 | if (ascii_check(ch)) { |
76 | if (ch == '\n') |
111 | if (ch == '\n') |
77 | ski_do_putchar('\r'); |
112 | ski_do_putchar('\r'); |
78 | 113 | ||
79 | ski_do_putchar(ch); |
114 | ski_do_putchar(ch); |
80 | } else |
115 | } else |
81 | ski_do_putchar(SPECIAL); |
116 | ski_do_putchar(U_SPECIAL); |
82 | } |
117 | } |
83 | } |
118 | } |
84 | 119 | ||
85 | static indev_operations_t skiin_ops = { |
120 | void skiout_init(void) |
86 | .poll = NULL |
- | |
87 | }; |
121 | { |
- | 122 | ski_init(); |
|
88 | 123 | ||
89 | static outdev_operations_t skiout_ops = { |
124 | outdev_initialize("skiout", &skiout, &skiout_ops); |
90 | .write = ski_putchar |
125 | stdout = &skiout; |
- | 126 | ||
- | 127 | sysinfo_set_item_val("fb", NULL, false); |
|
91 | }; |
128 | } |
92 | 129 | ||
93 | /** Ask debug console if a key was pressed. |
130 | /** Ask debug console if a key was pressed. |
94 | * |
131 | * |
95 | * Use SSC (Simulator System Call) to |
132 | * Use SSC (Simulator System Call) to |
96 | * get character from debug console. |
133 | * get character from debug console. |
97 | * |
134 | * |
98 | * This call is non-blocking. |
135 | * This call is non-blocking. |
99 | * |
136 | * |
100 | * @return ASCII code of pressed key or 0 if no key pressed. |
137 | * @return ASCII code of pressed key or 0 if no key pressed. |
- | 138 | * |
|
101 | */ |
139 | */ |
102 | static int32_t ski_getchar(void) |
140 | static wchar_t ski_getchar(void) |
103 | { |
141 | { |
104 | uint64_t ch; |
142 | uint64_t ch; |
105 | 143 | ||
106 | asm volatile ( |
144 | asm volatile ( |
107 | "mov r15 = %1\n" |
145 | "mov r15 = %1\n" |
108 | "break 0x80000;;\n" /* modifies r8 */ |
146 | "break 0x80000;;\n" /* modifies r8 */ |
109 | "mov %0 = r8;;\n" |
147 | "mov %0 = r8;;\n" |
110 | 148 | ||
111 | : "=r" (ch) |
149 | : "=r" (ch) |
112 | : "i" (SKI_GETCHAR) |
150 | : "i" (SKI_GETCHAR) |
113 | : "r15", "r8" |
151 | : "r15", "r8" |
114 | ); |
152 | ); |
115 | 153 | ||
116 | return (int32_t) ch; |
154 | return (wchar_t) ch; |
117 | } |
155 | } |
118 | 156 | ||
119 | /** Ask keyboard if a key was pressed. */ |
157 | /** Ask keyboard if a key was pressed. */ |
120 | static void poll_keyboard(void) |
158 | static void poll_keyboard(ski_instance_t *instance) |
121 | { |
159 | { |
122 | char ch; |
- | |
123 | - | ||
124 | if (kbd_disabled) |
160 | if (kbd_disabled) |
125 | return; |
161 | return; |
- | 162 | ||
126 | ch = ski_getchar(); |
163 | wchar_t ch = ski_getchar(); |
127 | if(ch == '\r') |
- | |
128 | ch = '\n'; |
164 | |
129 | if (ch) { |
165 | if (ch != 0) |
130 | indev_push_character(&skiin, ch); |
166 | indev_push_character(instance->srlnin, ch); |
131 | return; |
- | |
132 | } |
- | |
133 | } |
167 | } |
134 | 168 | ||
135 | #define POLL_INTERVAL 10000 /* 10 ms */ |
- | |
136 | - | ||
137 | /** Kernel thread for polling keyboard. */ |
169 | /** Kernel thread for polling keyboard. */ |
138 | static void kkbdpoll(void *arg) |
170 | static void kskipoll(void *arg) |
139 | { |
171 | { |
- | 172 | ski_instance_t *instance = (ski_instance_t *) arg; |
|
- | 173 | ||
140 | while (1) { |
174 | while (true) { |
141 | if (!silent) { |
175 | if (!silent) |
142 | poll_keyboard(); |
176 | poll_keyboard(instance); |
143 | } |
177 | |
144 | thread_usleep(POLL_INTERVAL); |
178 | thread_usleep(POLL_INTERVAL); |
145 | } |
179 | } |
146 | } |
180 | } |
147 | 181 | ||
148 | /** Initialize debug console |
- | |
149 | * |
- | |
150 | * Issue SSC (Simulator System Call) to |
- | |
151 | * to open debug console. |
- | |
152 | */ |
- | |
153 | static void ski_init(void) |
182 | ski_instance_t *skiin_init(void) |
154 | { |
183 | { |
155 | static bool initialized; |
- | |
156 | - | ||
157 | if (initialized) |
184 | ski_init(); |
158 | return; |
- | |
159 | 185 | ||
160 | asm volatile ( |
- | |
161 | "mov r15 = %0\n" |
- | |
162 | "break 0x80000\n" |
186 | ski_instance_t *instance |
163 | : |
- | |
164 | : "i" (SKI_INIT_CONSOLE) |
187 | = malloc(sizeof(ski_instance_t), FRAME_ATOMIC); |
165 | : "r15", "r8" |
- | |
166 | ); |
- | |
167 | 188 | ||
- | 189 | if (instance) { |
|
- | 190 | instance->thread = thread_create(kskipoll, (void *) instance, TASK, 0, "kskipoll", true); |
|
- | 191 | ||
- | 192 | if (!instance->thread) { |
|
- | 193 | free(instance); |
|
- | 194 | return NULL; |
|
- | 195 | } |
|
- | 196 | ||
168 | initialized = true; |
197 | instance->srlnin = NULL; |
- | 198 | } |
|
- | 199 | ||
- | 200 | return instance; |
|
169 | } |
201 | } |
170 | 202 | ||
171 | indev_t *skiin_init(void) |
203 | void skiin_wire(ski_instance_t *instance, indev_t *srlnin) |
172 | { |
204 | { |
173 | ski_init(); |
205 | ASSERT(instance); |
- | 206 | ASSERT(srlnin); |
|
174 | 207 | ||
175 | indev_initialize("skiin", &skiin, &skiin_ops); |
208 | instance->srlnin = srlnin; |
176 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
- | |
177 | if (t) |
- | |
178 | thread_ready(t); |
209 | thread_ready(instance->thread); |
179 | else |
- | |
180 | return NULL; |
- | |
181 | 210 | ||
182 | sysinfo_set_item_val("kbd", NULL, true); |
211 | sysinfo_set_item_val("kbd", NULL, true); |
183 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
212 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
184 | - | ||
185 | return &skiin; |
- | |
186 | } |
- | |
187 | - | ||
188 | - | ||
189 | void skiout_init(void) |
- | |
190 | { |
- | |
191 | ski_init(); |
- | |
192 | - | ||
193 | outdev_initialize("skiout", &skiout, &skiout_ops); |
- | |
194 | stdout = &skiout; |
- | |
195 | - | ||
196 | sysinfo_set_item_val("fb", NULL, false); |
- | |
197 | } |
213 | } |
198 | 214 | ||
199 | void ski_kbd_grab(void) |
215 | void ski_kbd_grab(void) |
200 | { |
216 | { |
201 | kbd_disabled = true; |
217 | kbd_disabled = true; |