| 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 <sysinfo/sysinfo.h>
|
|---|
| 40 | #include <stdint.h>
|
|---|
| 41 | #include <proc/thread.h>
|
|---|
| 42 | #include <synch/spinlock.h>
|
|---|
| 43 | #include <arch/asm.h>
|
|---|
| 44 | #include <arch/drivers/kbd.h>
|
|---|
| 45 | #include <str.h>
|
|---|
| 46 | #include <arch.h>
|
|---|
| 47 | #include <stdlib.h>
|
|---|
| 48 |
|
|---|
| 49 | enum {
|
|---|
| 50 | /** Interval between polling in microseconds */
|
|---|
| 51 | POLL_INTERVAL = 10000, /* 0.01 s */
|
|---|
| 52 |
|
|---|
| 53 | /** Max. number of characters to pull out at a time */
|
|---|
| 54 | POLL_LIMIT = 30,
|
|---|
| 55 |
|
|---|
| 56 | SKI_INIT_CONSOLE = 20,
|
|---|
| 57 | SKI_GETCHAR = 21,
|
|---|
| 58 | SKI_PUTCHAR = 31
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | static void ski_putwchar(outdev_t *, const wchar_t);
|
|---|
| 62 |
|
|---|
| 63 | static outdev_operations_t skidev_ops = {
|
|---|
| 64 | .write = ski_putwchar,
|
|---|
| 65 | .redraw = NULL,
|
|---|
| 66 | .scroll_up = NULL,
|
|---|
| 67 | .scroll_down = NULL
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | static ski_instance_t *instance = NULL;
|
|---|
| 71 |
|
|---|
| 72 | /** Ask debug console if a key was pressed.
|
|---|
| 73 | *
|
|---|
| 74 | * Use SSC (Simulator System Call) to
|
|---|
| 75 | * get character from debug console.
|
|---|
| 76 | *
|
|---|
| 77 | * This call is non-blocking.
|
|---|
| 78 | *
|
|---|
| 79 | * @return ASCII code of pressed key or 0 if no key pressed.
|
|---|
| 80 | *
|
|---|
| 81 | */
|
|---|
| 82 | static wchar_t ski_getchar(void)
|
|---|
| 83 | {
|
|---|
| 84 | uint64_t ch;
|
|---|
| 85 |
|
|---|
| 86 | asm volatile (
|
|---|
| 87 | "mov r15 = %1\n"
|
|---|
| 88 | "break 0x80000;;\n" /* modifies r8 */
|
|---|
| 89 | "mov %0 = r8;;\n"
|
|---|
| 90 |
|
|---|
| 91 | : "=r" (ch)
|
|---|
| 92 | : "i" (SKI_GETCHAR)
|
|---|
| 93 | : "r15", "r8"
|
|---|
| 94 | );
|
|---|
| 95 |
|
|---|
| 96 | return (wchar_t) ch;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | /** Ask keyboard if a key was pressed.
|
|---|
| 100 | *
|
|---|
| 101 | * If so, it will repeat and pull up to POLL_LIMIT characters.
|
|---|
| 102 | */
|
|---|
| 103 | static void poll_keyboard(ski_instance_t *instance)
|
|---|
| 104 | {
|
|---|
| 105 | int count = POLL_LIMIT;
|
|---|
| 106 |
|
|---|
| 107 | while (count > 0) {
|
|---|
| 108 | wchar_t ch = ski_getchar();
|
|---|
| 109 |
|
|---|
| 110 | if (ch == '\0')
|
|---|
| 111 | break;
|
|---|
| 112 |
|
|---|
| 113 | indev_push_character(instance->srlnin, ch);
|
|---|
| 114 | --count;
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /** Kernel thread for polling keyboard. */
|
|---|
| 119 | static void kskipoll(void *arg)
|
|---|
| 120 | {
|
|---|
| 121 | ski_instance_t *instance = (ski_instance_t *) arg;
|
|---|
| 122 |
|
|---|
| 123 | while (true) {
|
|---|
| 124 | // TODO FIXME:
|
|---|
| 125 | // This currently breaks the kernel console
|
|---|
| 126 | // before we get the override from uspace.
|
|---|
| 127 | if (console_override)
|
|---|
| 128 | poll_keyboard(instance);
|
|---|
| 129 |
|
|---|
| 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 | */
|
|---|
| 140 | static void ski_init(void)
|
|---|
| 141 | {
|
|---|
| 142 | if (instance)
|
|---|
| 143 | return;
|
|---|
| 144 |
|
|---|
| 145 | asm volatile (
|
|---|
| 146 | "mov r15 = %0\n"
|
|---|
| 147 | "break 0x80000\n"
|
|---|
| 148 | :
|
|---|
| 149 | : "i" (SKI_INIT_CONSOLE)
|
|---|
| 150 | : "r15", "r8"
|
|---|
| 151 | );
|
|---|
| 152 |
|
|---|
| 153 | instance = malloc(sizeof(ski_instance_t));
|
|---|
| 154 |
|
|---|
| 155 | if (instance) {
|
|---|
| 156 | instance->thread = thread_create(kskipoll, instance, TASK,
|
|---|
| 157 | THREAD_FLAG_UNCOUNTED, "kskipoll");
|
|---|
| 158 |
|
|---|
| 159 | if (!instance->thread) {
|
|---|
| 160 | free(instance);
|
|---|
| 161 | instance = NULL;
|
|---|
| 162 | return;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | instance->srlnin = NULL;
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | static void ski_do_putchar(char ch)
|
|---|
| 170 | {
|
|---|
| 171 | asm volatile (
|
|---|
| 172 | "mov r15 = %[cmd]\n"
|
|---|
| 173 | "mov r32 = %[ch]\n" /* r32 is in0 */
|
|---|
| 174 | "break 0x80000\n" /* modifies r8 */
|
|---|
| 175 | :
|
|---|
| 176 | : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
|
|---|
| 177 | : "r15", "in0", "r8"
|
|---|
| 178 | );
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | /** Display character on debug console
|
|---|
| 182 | *
|
|---|
| 183 | * Use SSC (Simulator System Call) to
|
|---|
| 184 | * display character on debug console.
|
|---|
| 185 | *
|
|---|
| 186 | * @param dev Character device.
|
|---|
| 187 | * @param ch Character to be printed.
|
|---|
| 188 | *
|
|---|
| 189 | */
|
|---|
| 190 | static void ski_putwchar(outdev_t *dev, wchar_t ch)
|
|---|
| 191 | {
|
|---|
| 192 | // TODO FIXME:
|
|---|
| 193 | // This currently breaks the kernel console
|
|---|
| 194 | // before we get the override from uspace.
|
|---|
| 195 | if (console_override) {
|
|---|
| 196 | if (ascii_check(ch)) {
|
|---|
| 197 | if (ch == '\n')
|
|---|
| 198 | ski_do_putchar('\r');
|
|---|
| 199 |
|
|---|
| 200 | ski_do_putchar(ch);
|
|---|
| 201 | } else {
|
|---|
| 202 | ski_do_putchar('?');
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | outdev_t *skiout_init(void)
|
|---|
| 208 | {
|
|---|
| 209 | ski_init();
|
|---|
| 210 | if (!instance)
|
|---|
| 211 | return NULL;
|
|---|
| 212 |
|
|---|
| 213 | outdev_t *skidev = malloc(sizeof(outdev_t));
|
|---|
| 214 | if (!skidev)
|
|---|
| 215 | return NULL;
|
|---|
| 216 |
|
|---|
| 217 | outdev_initialize("skidev", skidev, &skidev_ops);
|
|---|
| 218 | skidev->data = instance;
|
|---|
| 219 |
|
|---|
| 220 | if (!fb_exported) {
|
|---|
| 221 | /*
|
|---|
| 222 | * This is the necessary evil until
|
|---|
| 223 | * the userspace driver is entirely
|
|---|
| 224 | * self-sufficient.
|
|---|
| 225 | */
|
|---|
| 226 | sysinfo_set_item_val("fb", NULL, true);
|
|---|
| 227 | sysinfo_set_item_val("fb.kind", NULL, 6);
|
|---|
| 228 |
|
|---|
| 229 | fb_exported = true;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | return skidev;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | ski_instance_t *skiin_init(void)
|
|---|
| 236 | {
|
|---|
| 237 | ski_init();
|
|---|
| 238 | return instance;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
|
|---|
| 242 | {
|
|---|
| 243 | assert(instance);
|
|---|
| 244 | assert(srlnin);
|
|---|
| 245 |
|
|---|
| 246 | instance->srlnin = srlnin;
|
|---|
| 247 | thread_ready(instance->thread);
|
|---|
| 248 |
|
|---|
| 249 | sysinfo_set_item_val("kbd", NULL, true);
|
|---|
| 250 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | /** @}
|
|---|
| 254 | */
|
|---|