Rev 4060 | Rev 4220 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
78 | jermar | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2005 Jakub Jermar |
78 | 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 | |||
1888 | jermar | 29 | /** @addtogroup ia64 |
1702 | cejka | 30 | * @{ |
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
78 | jermar | 35 | #include <arch/ski/ski.h> |
577 | palkovsky | 36 | #include <console/console.h> |
37 | #include <console/chardev.h> |
||
1507 | vana | 38 | #include <sysinfo/sysinfo.h> |
1942 | jermar | 39 | #include <arch/types.h> |
1945 | jermar | 40 | #include <proc/thread.h> |
1942 | jermar | 41 | #include <synch/spinlock.h> |
42 | #include <arch/asm.h> |
||
3661 | vana | 43 | #include <arch/drivers/kbd.h> |
4060 | jermar | 44 | #include <arch.h> |
78 | jermar | 45 | |
4114 | jermar | 46 | static indev_t skiin; /**< Ski input device. */ |
47 | static outdev_t skiout; /**< Ski output device. */ |
||
1942 | jermar | 48 | |
49 | static bool kbd_disabled; |
||
50 | |||
79 | jermar | 51 | /** Display character on debug console |
52 | * |
||
53 | * Use SSC (Simulator System Call) to |
||
54 | * display character on debug console. |
||
55 | * |
||
583 | jermar | 56 | * @param d Character device. |
57 | * @param ch Character to be printed. |
||
79 | jermar | 58 | */ |
4114 | jermar | 59 | static void ski_putchar(outdev_t *d, const char ch, bool silent) |
78 | jermar | 60 | { |
3844 | decky | 61 | if (!silent) { |
62 | asm volatile ( |
||
63 | "mov r15 = %0\n" |
||
64 | "mov r32 = %1\n" /* r32 is in0 */ |
||
65 | "break 0x80000\n" /* modifies r8 */ |
||
66 | : |
||
67 | : "i" (SKI_PUTCHAR), "r" (ch) |
||
68 | : "r15", "in0", "r8" |
||
69 | ); |
||
70 | |||
71 | if (ch == '\n') |
||
3854 | decky | 72 | ski_putchar(d, '\r', false); |
3844 | decky | 73 | } |
78 | jermar | 74 | } |
519 | vana | 75 | |
4114 | jermar | 76 | static indev_operations_t skiin_ops = { |
77 | .poll = NULL |
||
78 | }; |
||
79 | |||
80 | static outdev_operations_t skiout_ops = { |
||
4060 | jermar | 81 | .write = ski_putchar |
82 | }; |
||
83 | |||
523 | jermar | 84 | /** Ask debug console if a key was pressed. |
519 | vana | 85 | * |
86 | * Use SSC (Simulator System Call) to |
||
87 | * get character from debug console. |
||
523 | jermar | 88 | * |
89 | * This call is non-blocking. |
||
90 | * |
||
91 | * @return ASCII code of pressed key or 0 if no key pressed. |
||
519 | vana | 92 | */ |
3844 | decky | 93 | static int32_t ski_getchar(void) |
519 | vana | 94 | { |
1780 | jermar | 95 | uint64_t ch; |
519 | vana | 96 | |
2082 | decky | 97 | asm volatile ( |
1942 | jermar | 98 | "mov r15 = %1\n" |
519 | vana | 99 | "break 0x80000;;\n" /* modifies r8 */ |
1942 | jermar | 100 | "mov %0 = r8;;\n" |
519 | vana | 101 | |
584 | jermar | 102 | : "=r" (ch) |
103 | : "i" (SKI_GETCHAR) |
||
1942 | jermar | 104 | : "r15", "r8" |
519 | vana | 105 | ); |
106 | |||
1780 | jermar | 107 | return (int32_t) ch; |
519 | vana | 108 | } |
577 | palkovsky | 109 | |
110 | /** Ask keyboard if a key was pressed. */ |
||
1945 | jermar | 111 | static void poll_keyboard(void) |
577 | palkovsky | 112 | { |
113 | char ch; |
||
3880 | decky | 114 | |
4114 | jermar | 115 | if (kbd_disabled) |
577 | palkovsky | 116 | return; |
117 | ch = ski_getchar(); |
||
118 | if(ch == '\r') |
||
119 | ch = '\n'; |
||
4114 | jermar | 120 | if (ch) { |
121 | indev_push_character(&skiin, ch); |
||
1570 | vana | 122 | return; |
1942 | jermar | 123 | } |
577 | palkovsky | 124 | } |
125 | |||
4060 | jermar | 126 | #define POLL_INTERVAL 10000 /* 10 ms */ |
577 | palkovsky | 127 | |
4060 | jermar | 128 | /** Kernel thread for polling keyboard. */ |
129 | static void kkbdpoll(void *arg) |
||
577 | palkovsky | 130 | { |
4060 | jermar | 131 | while (1) { |
132 | if (!silent) { |
||
133 | poll_keyboard(); |
||
134 | } |
||
135 | thread_usleep(POLL_INTERVAL); |
||
136 | } |
||
577 | palkovsky | 137 | } |
138 | |||
139 | /** Initialize debug console |
||
140 | * |
||
141 | * Issue SSC (Simulator System Call) to |
||
142 | * to open debug console. |
||
143 | */ |
||
4114 | jermar | 144 | static void ski_init(void) |
577 | palkovsky | 145 | { |
4114 | jermar | 146 | static bool initialized; |
147 | |||
148 | if (initialized) |
||
149 | return; |
||
150 | |||
2082 | decky | 151 | asm volatile ( |
1942 | jermar | 152 | "mov r15 = %0\n" |
577 | palkovsky | 153 | "break 0x80000\n" |
154 | : |
||
155 | : "i" (SKI_INIT_CONSOLE) |
||
156 | : "r15", "r8" |
||
157 | ); |
||
4114 | jermar | 158 | |
159 | initialized = true; |
||
160 | } |
||
577 | palkovsky | 161 | |
4114 | jermar | 162 | indev_t *skiin_init(void) |
163 | { |
||
164 | ski_init(); |
||
1507 | vana | 165 | |
4114 | jermar | 166 | indev_initialize("skiin", &skiin, &skiin_ops); |
4060 | jermar | 167 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true); |
4114 | jermar | 168 | if (t) |
169 | thread_ready(t); |
||
170 | else |
||
171 | return NULL; |
||
1942 | jermar | 172 | |
173 | sysinfo_set_item_val("kbd", NULL, true); |
||
3657 | vana | 174 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
3718 | svoboda | 175 | |
4114 | jermar | 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 | |||
3718 | svoboda | 187 | sysinfo_set_item_val("fb", NULL, false); |
1507 | vana | 188 | } |
1702 | cejka | 189 | |
1942 | jermar | 190 | void ski_kbd_grab(void) |
191 | { |
||
4060 | jermar | 192 | kbd_disabled = true; |
1942 | jermar | 193 | } |
194 | |||
195 | void ski_kbd_release(void) |
||
196 | { |
||
4060 | jermar | 197 | kbd_disabled = false; |
1942 | jermar | 198 | } |
199 | |||
1888 | jermar | 200 | /** @} |
1702 | cejka | 201 | */ |