source: mainline/kernel/arch/ia64/src/drivers/ski.c@ 1769693

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1769693 was 28a5ebd, checked in by Martin Decky <martin@…>, 6 years ago

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kernel_ia64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/drivers/ski.h>
36#include <assert.h>
37#include <console/console.h>
38#include <console/chardev.h>
39#include <ddi/ddi.h>
40#include <sysinfo/sysinfo.h>
41#include <stdint.h>
42#include <proc/thread.h>
43#include <synch/spinlock.h>
44#include <arch/asm.h>
45#include <arch/drivers/kbd.h>
46#include <str.h>
47#include <arch.h>
48#include <stdlib.h>
49
50enum {
51 /** Interval between polling in microseconds */
52 POLL_INTERVAL = 10000, /* 0.01 s */
53
54 /** Max. number of characters to pull out at a time */
55 POLL_LIMIT = 30,
56
57 SKI_INIT_CONSOLE = 20,
58 SKI_GETCHAR = 21,
59 SKI_PUTCHAR = 31
60};
61
62static void ski_putuchar(outdev_t *, const char32_t);
63
64static outdev_operations_t skidev_ops = {
65 .write = ski_putuchar,
66 .redraw = NULL,
67 .scroll_up = NULL,
68 .scroll_down = NULL
69};
70
71static ski_instance_t *instance = NULL;
72static parea_t ski_parea;
73
74/** Ask debug console if a key was pressed.
75 *
76 * Use SSC (Simulator System Call) to
77 * get character from debug console.
78 *
79 * This call is non-blocking.
80 *
81 * @return ASCII code of pressed key or 0 if no key pressed.
82 *
83 */
84static char32_t ski_getchar(void)
85{
86 uint64_t ch;
87
88 asm volatile (
89 "mov r15 = %1\n"
90 "break 0x80000;;\n" /* modifies r8 */
91 "mov %0 = r8;;\n"
92
93 : "=r" (ch)
94 : "i" (SKI_GETCHAR)
95 : "r15", "r8"
96 );
97
98 return (char32_t) ch;
99}
100
101/** Ask keyboard if a key was pressed.
102 *
103 * If so, it will repeat and pull up to POLL_LIMIT characters.
104 */
105static void poll_keyboard(ski_instance_t *instance)
106{
107 int count = POLL_LIMIT;
108
109 if (ski_parea.mapped && !console_override)
110 return;
111
112 while (count > 0) {
113 char32_t ch = ski_getchar();
114
115 if (ch == '\0')
116 break;
117
118 indev_push_character(instance->srlnin, ch);
119 --count;
120 }
121}
122
123/** Kernel thread for polling keyboard. */
124static void kskipoll(void *arg)
125{
126 ski_instance_t *instance = (ski_instance_t *) arg;
127
128 while (true) {
129 poll_keyboard(instance);
130 thread_usleep(POLL_INTERVAL);
131 }
132}
133
134/** Initialize debug console
135 *
136 * Issue SSC (Simulator System Call) to
137 * to open debug console.
138 *
139 */
140static void ski_init(void)
141{
142 uintptr_t faddr;
143
144 if (instance)
145 return;
146
147 asm volatile (
148 "mov r15 = %0\n"
149 "break 0x80000\n"
150 :
151 : "i" (SKI_INIT_CONSOLE)
152 : "r15", "r8"
153 );
154
155 faddr = frame_alloc(1, FRAME_LOWMEM | FRAME_ATOMIC, 0);
156 if (faddr == 0)
157 panic("Cannot allocate page for ski console.");
158
159 ddi_parea_init(&ski_parea);
160 ski_parea.pbase = faddr;
161 ski_parea.frames = 1;
162 ski_parea.unpriv = false;
163 ski_parea.mapped = false;
164 ddi_parea_register(&ski_parea);
165
166 sysinfo_set_item_val("ski.paddr", NULL, (sysarg_t) faddr);
167
168 instance = malloc(sizeof(ski_instance_t));
169
170 if (instance) {
171 instance->thread = thread_create(kskipoll, instance, TASK,
172 THREAD_FLAG_UNCOUNTED, "kskipoll");
173
174 if (!instance->thread) {
175 free(instance);
176 instance = NULL;
177 return;
178 }
179
180 instance->srlnin = NULL;
181 }
182}
183
184static void ski_do_putchar(char ch)
185{
186 asm volatile (
187 "mov r15 = %[cmd]\n"
188 "mov r32 = %[ch]\n" /* r32 is in0 */
189 "break 0x80000\n" /* modifies r8 */
190 :
191 : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
192 : "r15", "in0", "r8"
193 );
194}
195
196/** Display character on debug console
197 *
198 * Use SSC (Simulator System Call) to
199 * display character on debug console.
200 *
201 * @param dev Character device.
202 * @param ch Character to be printed.
203 *
204 */
205static void ski_putuchar(outdev_t *dev, char32_t ch)
206{
207 if (ski_parea.mapped && !console_override)
208 return;
209
210 if (ascii_check(ch)) {
211 if (ch == '\n')
212 ski_do_putchar('\r');
213
214 ski_do_putchar(ch);
215 } else {
216 ski_do_putchar('?');
217 }
218}
219
220outdev_t *skiout_init(void)
221{
222 ski_init();
223 if (!instance)
224 return NULL;
225
226 outdev_t *skidev = malloc(sizeof(outdev_t));
227 if (!skidev)
228 return NULL;
229
230 outdev_initialize("skidev", skidev, &skidev_ops);
231 skidev->data = instance;
232
233 if (!fb_exported) {
234 /*
235 * This is the necessary evil until
236 * the userspace driver is entirely
237 * self-sufficient.
238 */
239 sysinfo_set_item_val("fb", NULL, true);
240 sysinfo_set_item_val("fb.kind", NULL, 6);
241
242 fb_exported = true;
243 }
244
245 return skidev;
246}
247
248ski_instance_t *skiin_init(void)
249{
250 ski_init();
251 return instance;
252}
253
254void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
255{
256 assert(instance);
257 assert(srlnin);
258
259 instance->srlnin = srlnin;
260 thread_ready(instance->thread);
261
262 sysinfo_set_item_val("kbd", NULL, true);
263 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
264}
265
266/** @}
267 */
Note: See TracBrowser for help on using the repository browser.