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

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

update for string changes

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[244f284]1/*
[df4ed85]2 * Copyright (c) 2005 Jakub Jermar
[244f284]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
[06e1e95]29/** @addtogroup ia64
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[244f284]35#include <arch/ski/ski.h>
[6095342]36#include <console/console.h>
37#include <console/chardev.h>
[d0c5901]38#include <sysinfo/sysinfo.h>
[de57e060]39#include <arch/types.h>
[f0450658]40#include <proc/thread.h>
[de57e060]41#include <synch/spinlock.h>
42#include <arch/asm.h>
[50b3d30]43#include <arch/drivers/kbd.h>
[b60c582]44#include <string.h>
[2270bef]45#include <arch.h>
[de57e060]46
[c640876]47static indev_t skiin; /**< Ski input device. */
48static outdev_t skiout; /**< Ski output device. */
[de57e060]49
50static bool kbd_disabled;
[244f284]51
[b60c582]52static void ski_do_putchar(const wchar_t ch)
53{
54 asm volatile (
55 "mov r15 = %[cmd]\n"
56 "mov r32 = %[ch]\n" /* r32 is in0 */
57 "break 0x80000\n" /* modifies r8 */
58 :
59 : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
60 : "r15", "in0", "r8"
61 );
62}
63
[eb43679]64/** Display character on debug console
65 *
66 * Use SSC (Simulator System Call) to
67 * display character on debug console.
68 *
[72f5866d]69 * @param d Character device.
70 * @param ch Character to be printed.
[eb43679]71 */
[b60c582]72static void ski_putchar(outdev_t *d, const wchar_t ch, bool silent)
[244f284]73{
[516ff92]74 if (!silent) {
[b60c582]75 if (ascii_check(ch)) {
76 if (ch == '\n')
77 ski_do_putchar('\r');
78
79 ski_do_putchar(ch);
80 } else
81 ski_do_putchar(invalch);
[516ff92]82 }
[244f284]83}
[a8c48241]84
[c640876]85static indev_operations_t skiin_ops = {
86 .poll = NULL
87};
88
89static outdev_operations_t skiout_ops = {
[2270bef]90 .write = ski_putchar
91};
92
[880de6e]93/** Ask debug console if a key was pressed.
[a8c48241]94 *
95 * Use SSC (Simulator System Call) to
96 * get character from debug console.
[880de6e]97 *
98 * This call is non-blocking.
99 *
100 * @return ASCII code of pressed key or 0 if no key pressed.
[a8c48241]101 */
[516ff92]102static int32_t ski_getchar(void)
[a8c48241]103{
[7f1c620]104 uint64_t ch;
[a8c48241]105
[e7b7be3f]106 asm volatile (
[de57e060]107 "mov r15 = %1\n"
[a8c48241]108 "break 0x80000;;\n" /* modifies r8 */
[de57e060]109 "mov %0 = r8;;\n"
[a8c48241]110
[5bb20ec]111 : "=r" (ch)
112 : "i" (SKI_GETCHAR)
[de57e060]113 : "r15", "r8"
[a8c48241]114 );
115
[7f1c620]116 return (int32_t) ch;
[a8c48241]117}
[6095342]118
119/** Ask keyboard if a key was pressed. */
[f0450658]120static void poll_keyboard(void)
[6095342]121{
122 char ch;
[6da1013f]123
[c640876]124 if (kbd_disabled)
[6095342]125 return;
126 ch = ski_getchar();
127 if(ch == '\r')
128 ch = '\n';
[c640876]129 if (ch) {
130 indev_push_character(&skiin, ch);
[8adafa0]131 return;
[de57e060]132 }
[6095342]133}
134
[2270bef]135#define POLL_INTERVAL 10000 /* 10 ms */
[6095342]136
[2270bef]137/** Kernel thread for polling keyboard. */
138static void kkbdpoll(void *arg)
[de57e060]139{
[2270bef]140 while (1) {
141 if (!silent) {
142 poll_keyboard();
143 }
144 thread_usleep(POLL_INTERVAL);
145 }
[6095342]146}
147
148/** Initialize debug console
149 *
150 * Issue SSC (Simulator System Call) to
151 * to open debug console.
152 */
[c640876]153static void ski_init(void)
[6095342]154{
[c640876]155 static bool initialized;
156
157 if (initialized)
158 return;
159
[e7b7be3f]160 asm volatile (
[de57e060]161 "mov r15 = %0\n"
[6095342]162 "break 0x80000\n"
163 :
164 : "i" (SKI_INIT_CONSOLE)
165 : "r15", "r8"
166 );
[c640876]167
168 initialized = true;
169}
[6095342]170
[c640876]171indev_t *skiin_init(void)
172{
173 ski_init();
[d0c5901]174
[c640876]175 indev_initialize("skiin", &skiin, &skiin_ops);
[2270bef]176 thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
[c640876]177 if (t)
178 thread_ready(t);
179 else
180 return NULL;
[de57e060]181
182 sysinfo_set_item_val("kbd", NULL, true);
[323a5aaf]183 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
[36251c6]184
[c640876]185 return &skiin;
186}
187
188
189void skiout_init(void)
190{
191 ski_init();
192
193 outdev_initialize("skiout", &skiout, &skiout_ops);
194 stdout = &skiout;
195
[36251c6]196 sysinfo_set_item_val("fb", NULL, false);
[de57e060]197}
198
199void ski_kbd_grab(void)
200{
[2270bef]201 kbd_disabled = true;
[de57e060]202}
203
204void ski_kbd_release(void)
205{
[2270bef]206 kbd_disabled = false;
[f0450658]207}
208
[06e1e95]209/** @}
[b45c443]210 */
Note: See TracBrowser for help on using the repository browser.