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