| [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 |
|
|---|
| [c8bf88d] | 29 | /** @addtogroup ia64
|
|---|
| [b45c443] | 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| [c2417bc] | 35 | #include <arch/drivers/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 |
|
|---|
| [66b430e] | 47 | enum {
|
|---|
| 48 | /** Interval between polling in microseconds */
|
|---|
| 49 | POLL_INTERVAL = 10000, /* 0.01 s */
|
|---|
| [de57e060] | 50 |
|
|---|
| [66b430e] | 51 | /** Max. number of characters to pull out at a time */
|
|---|
| 52 | POLL_LIMIT = 30,
|
|---|
| 53 |
|
|---|
| 54 | SKI_INIT_CONSOLE = 20,
|
|---|
| 55 | SKI_GETCHAR = 21,
|
|---|
| 56 | SKI_PUTCHAR = 31
|
|---|
| 57 | };
|
|---|
| [c2417bc] | 58 |
|
|---|
| 59 | static void ski_putchar(outdev_t *, const wchar_t, bool);
|
|---|
| 60 |
|
|---|
| 61 | static outdev_operations_t skiout_ops = {
|
|---|
| 62 | .write = ski_putchar
|
|---|
| 63 | };
|
|---|
| 64 |
|
|---|
| 65 | static outdev_t skiout; /**< Ski output device. */
|
|---|
| 66 | static bool initialized = false;
|
|---|
| 67 | static bool kbd_disabled = false;
|
|---|
| 68 |
|
|---|
| 69 | /** Initialize debug console
|
|---|
| 70 | *
|
|---|
| 71 | * Issue SSC (Simulator System Call) to
|
|---|
| 72 | * to open debug console.
|
|---|
| 73 | *
|
|---|
| 74 | */
|
|---|
| 75 | static void ski_init(void)
|
|---|
| 76 | {
|
|---|
| 77 | if (initialized)
|
|---|
| 78 | return;
|
|---|
| 79 |
|
|---|
| 80 | asm volatile (
|
|---|
| 81 | "mov r15 = %0\n"
|
|---|
| 82 | "break 0x80000\n"
|
|---|
| 83 | :
|
|---|
| 84 | : "i" (SKI_INIT_CONSOLE)
|
|---|
| 85 | : "r15", "r8"
|
|---|
| 86 | );
|
|---|
| 87 |
|
|---|
| 88 | initialized = true;
|
|---|
| 89 | }
|
|---|
| [244f284] | 90 |
|
|---|
| [b60c582] | 91 | static void ski_do_putchar(const wchar_t ch)
|
|---|
| 92 | {
|
|---|
| 93 | asm volatile (
|
|---|
| 94 | "mov r15 = %[cmd]\n"
|
|---|
| 95 | "mov r32 = %[ch]\n" /* r32 is in0 */
|
|---|
| [c2417bc] | 96 | "break 0x80000\n" /* modifies r8 */
|
|---|
| [b60c582] | 97 | :
|
|---|
| 98 | : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
|
|---|
| 99 | : "r15", "in0", "r8"
|
|---|
| 100 | );
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| [eb43679] | 103 | /** Display character on debug console
|
|---|
| 104 | *
|
|---|
| 105 | * Use SSC (Simulator System Call) to
|
|---|
| 106 | * display character on debug console.
|
|---|
| 107 | *
|
|---|
| [c2417bc] | 108 | * @param dev Character device.
|
|---|
| 109 | * @param ch Character to be printed.
|
|---|
| 110 | * @param silent Whether the output should be silenced.
|
|---|
| 111 | *
|
|---|
| [eb43679] | 112 | */
|
|---|
| [c2417bc] | 113 | static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
|
|---|
| [244f284] | 114 | {
|
|---|
| [516ff92] | 115 | if (!silent) {
|
|---|
| [b60c582] | 116 | if (ascii_check(ch)) {
|
|---|
| 117 | if (ch == '\n')
|
|---|
| 118 | ski_do_putchar('\r');
|
|---|
| 119 |
|
|---|
| 120 | ski_do_putchar(ch);
|
|---|
| 121 | } else
|
|---|
| [c2417bc] | 122 | ski_do_putchar(U_SPECIAL);
|
|---|
| [516ff92] | 123 | }
|
|---|
| [244f284] | 124 | }
|
|---|
| [a8c48241] | 125 |
|
|---|
| [c2417bc] | 126 | void skiout_init(void)
|
|---|
| 127 | {
|
|---|
| 128 | ski_init();
|
|---|
| 129 |
|
|---|
| 130 | outdev_initialize("skiout", &skiout, &skiout_ops);
|
|---|
| 131 | stdout = &skiout;
|
|---|
| 132 |
|
|---|
| 133 | sysinfo_set_item_val("fb", NULL, false);
|
|---|
| 134 | }
|
|---|
| [2270bef] | 135 |
|
|---|
| [880de6e] | 136 | /** Ask debug console if a key was pressed.
|
|---|
| [a8c48241] | 137 | *
|
|---|
| 138 | * Use SSC (Simulator System Call) to
|
|---|
| 139 | * get character from debug console.
|
|---|
| [880de6e] | 140 | *
|
|---|
| 141 | * This call is non-blocking.
|
|---|
| 142 | *
|
|---|
| 143 | * @return ASCII code of pressed key or 0 if no key pressed.
|
|---|
| [c2417bc] | 144 | *
|
|---|
| [a8c48241] | 145 | */
|
|---|
| [c2417bc] | 146 | static wchar_t ski_getchar(void)
|
|---|
| [a8c48241] | 147 | {
|
|---|
| [7f1c620] | 148 | uint64_t ch;
|
|---|
| [a8c48241] | 149 |
|
|---|
| [e7b7be3f] | 150 | asm volatile (
|
|---|
| [de57e060] | 151 | "mov r15 = %1\n"
|
|---|
| [c2417bc] | 152 | "break 0x80000;;\n" /* modifies r8 */
|
|---|
| 153 | "mov %0 = r8;;\n"
|
|---|
| 154 |
|
|---|
| [5bb20ec] | 155 | : "=r" (ch)
|
|---|
| 156 | : "i" (SKI_GETCHAR)
|
|---|
| [de57e060] | 157 | : "r15", "r8"
|
|---|
| [a8c48241] | 158 | );
|
|---|
| [c2417bc] | 159 |
|
|---|
| 160 | return (wchar_t) ch;
|
|---|
| [a8c48241] | 161 | }
|
|---|
| [6095342] | 162 |
|
|---|
| [66b430e] | 163 | /** Ask keyboard if a key was pressed.
|
|---|
| 164 | *
|
|---|
| 165 | * If so, it will repeat and pull up to POLL_LIMIT characters.
|
|---|
| 166 | */
|
|---|
| [c2417bc] | 167 | static void poll_keyboard(ski_instance_t *instance)
|
|---|
| [6095342] | 168 | {
|
|---|
| [66b430e] | 169 | wchar_t ch;
|
|---|
| 170 | int count;
|
|---|
| 171 |
|
|---|
| [c640876] | 172 | if (kbd_disabled)
|
|---|
| [6095342] | 173 | return;
|
|---|
| [66b430e] | 174 |
|
|---|
| 175 | count = POLL_LIMIT;
|
|---|
| 176 |
|
|---|
| 177 | while (count > 0) {
|
|---|
| 178 | ch = ski_getchar();
|
|---|
| 179 |
|
|---|
| 180 | if (ch == '\0')
|
|---|
| 181 | break;
|
|---|
| 182 |
|
|---|
| [c2417bc] | 183 | indev_push_character(instance->srlnin, ch);
|
|---|
| [66b430e] | 184 | --count;
|
|---|
| 185 | }
|
|---|
| [6095342] | 186 | }
|
|---|
| 187 |
|
|---|
| [2270bef] | 188 | /** Kernel thread for polling keyboard. */
|
|---|
| [c2417bc] | 189 | static void kskipoll(void *arg)
|
|---|
| [de57e060] | 190 | {
|
|---|
| [c2417bc] | 191 | ski_instance_t *instance = (ski_instance_t *) arg;
|
|---|
| 192 |
|
|---|
| 193 | while (true) {
|
|---|
| 194 | if (!silent)
|
|---|
| 195 | poll_keyboard(instance);
|
|---|
| 196 |
|
|---|
| [2270bef] | 197 | thread_usleep(POLL_INTERVAL);
|
|---|
| 198 | }
|
|---|
| [6095342] | 199 | }
|
|---|
| 200 |
|
|---|
| [c2417bc] | 201 | ski_instance_t *skiin_init(void)
|
|---|
| [6095342] | 202 | {
|
|---|
| [c2417bc] | 203 | ski_init();
|
|---|
| [c640876] | 204 |
|
|---|
| [253d3d0] | 205 | ski_instance_t *instance =
|
|---|
| 206 | malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
|
|---|
| [c640876] | 207 |
|
|---|
| [c2417bc] | 208 | if (instance) {
|
|---|
| [253d3d0] | 209 | instance->thread = thread_create(kskipoll, instance, TASK, 0,
|
|---|
| 210 | "kskipoll", true);
|
|---|
| [c2417bc] | 211 |
|
|---|
| 212 | if (!instance->thread) {
|
|---|
| 213 | free(instance);
|
|---|
| 214 | return NULL;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | instance->srlnin = NULL;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | return instance;
|
|---|
| [c640876] | 221 | }
|
|---|
| [6095342] | 222 |
|
|---|
| [c2417bc] | 223 | void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
|
|---|
| [c640876] | 224 | {
|
|---|
| [c2417bc] | 225 | ASSERT(instance);
|
|---|
| 226 | ASSERT(srlnin);
|
|---|
| 227 |
|
|---|
| 228 | instance->srlnin = srlnin;
|
|---|
| 229 | thread_ready(instance->thread);
|
|---|
| 230 |
|
|---|
| [de57e060] | 231 | sysinfo_set_item_val("kbd", NULL, true);
|
|---|
| [323a5aaf] | 232 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
|
|---|
| [de57e060] | 233 | }
|
|---|
| 234 |
|
|---|
| 235 | void ski_kbd_grab(void)
|
|---|
| 236 | {
|
|---|
| [ccd1a14] | 237 | kbd_disabled = false;
|
|---|
| [de57e060] | 238 | }
|
|---|
| 239 |
|
|---|
| 240 | void ski_kbd_release(void)
|
|---|
| 241 | {
|
|---|
| [ccd1a14] | 242 | kbd_disabled = true;
|
|---|
| [f0450658] | 243 | }
|
|---|
| 244 |
|
|---|
| [06e1e95] | 245 | /** @}
|
|---|
| [b45c443] | 246 | */
|
|---|