2
* Copyright (c) 2005 Jakub Jermar
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
35
#include <arch/drivers/ski.h>
36
#include <console/console.h>
37
#include <console/chardev.h>
38
#include <sysinfo/sysinfo.h>
39
#include <arch/types.h>
40
#include <proc/thread.h>
41
#include <synch/spinlock.h>
43
#include <arch/drivers/kbd.h>
48
/** Interval between polling in microseconds */
49
POLL_INTERVAL = 10000, /* 0.01 s */
51
/** Max. number of characters to pull out at a time */
54
SKI_INIT_CONSOLE = 20,
59
static void ski_putchar(outdev_t *, const wchar_t, bool);
61
static outdev_operations_t skiout_ops = {
65
static outdev_t skiout; /**< Ski output device. */
66
static bool initialized = false;
67
static bool kbd_disabled = false;
69
/** Initialize debug console
71
* Issue SSC (Simulator System Call) to
72
* to open debug console.
75
static void ski_init(void)
84
: "i" (SKI_INIT_CONSOLE)
91
static void ski_do_putchar(const wchar_t ch)
95
"mov r32 = %[ch]\n" /* r32 is in0 */
96
"break 0x80000\n" /* modifies r8 */
98
: [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
103
/** Display character on debug console
105
* Use SSC (Simulator System Call) to
106
* display character on debug console.
108
* @param dev Character device.
109
* @param ch Character to be printed.
110
* @param silent Whether the output should be silenced.
113
static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
116
if (ascii_check(ch)) {
118
ski_do_putchar('\r');
122
ski_do_putchar(U_SPECIAL);
126
void skiout_init(void)
130
outdev_initialize("skiout", &skiout, &skiout_ops);
133
sysinfo_set_item_val("fb", NULL, false);
136
/** Ask debug console if a key was pressed.
138
* Use SSC (Simulator System Call) to
139
* get character from debug console.
141
* This call is non-blocking.
143
* @return ASCII code of pressed key or 0 if no key pressed.
146
static wchar_t ski_getchar(void)
152
"break 0x80000;;\n" /* modifies r8 */
163
/** Ask keyboard if a key was pressed.
165
* If so, it will repeat and pull up to POLL_LIMIT characters.
167
static void poll_keyboard(ski_instance_t *instance)
183
indev_push_character(instance->srlnin, ch);
188
/** Kernel thread for polling keyboard. */
189
static void kskipoll(void *arg)
191
ski_instance_t *instance = (ski_instance_t *) arg;
195
poll_keyboard(instance);
197
thread_usleep(POLL_INTERVAL);
201
ski_instance_t *skiin_init(void)
205
ski_instance_t *instance =
206
malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
209
instance->thread = thread_create(kskipoll, instance, TASK, 0,
212
if (!instance->thread) {
217
instance->srlnin = NULL;
223
void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
228
instance->srlnin = srlnin;
229
thread_ready(instance->thread);
231
sysinfo_set_item_val("kbd", NULL, true);
232
sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
235
void ski_kbd_grab(void)
237
kbd_disabled = false;
240
void ski_kbd_release(void)