| 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/ski/ski.h>
|
|---|
| 36 | #include <console/console.h>
|
|---|
| 37 | #include <console/chardev.h>
|
|---|
| 38 | #include <sysinfo/sysinfo.h>
|
|---|
| 39 | #include <arch/types.h>
|
|---|
| 40 | #include <proc/thread.h>
|
|---|
| 41 | #include <synch/spinlock.h>
|
|---|
| 42 | #include <arch/asm.h>
|
|---|
| 43 | #include <arch/drivers/kbd.h>
|
|---|
| 44 | #include <arch.h>
|
|---|
| 45 |
|
|---|
| 46 | static chardev_t *skiout;
|
|---|
| 47 |
|
|---|
| 48 | static chardev_t ski_stdout;
|
|---|
| 49 |
|
|---|
| 50 | static bool kbd_disabled;
|
|---|
| 51 |
|
|---|
| 52 | /** Display character on debug console
|
|---|
| 53 | *
|
|---|
| 54 | * Use SSC (Simulator System Call) to
|
|---|
| 55 | * display character on debug console.
|
|---|
| 56 | *
|
|---|
| 57 | * @param d Character device.
|
|---|
| 58 | * @param ch Character to be printed.
|
|---|
| 59 | */
|
|---|
| 60 | static void ski_putchar(chardev_t *d, const char ch, bool silent)
|
|---|
| 61 | {
|
|---|
| 62 | if (!silent) {
|
|---|
| 63 | asm volatile (
|
|---|
| 64 | "mov r15 = %0\n"
|
|---|
| 65 | "mov r32 = %1\n" /* r32 is in0 */
|
|---|
| 66 | "break 0x80000\n" /* modifies r8 */
|
|---|
| 67 | :
|
|---|
| 68 | : "i" (SKI_PUTCHAR), "r" (ch)
|
|---|
| 69 | : "r15", "in0", "r8"
|
|---|
| 70 | );
|
|---|
| 71 |
|
|---|
| 72 | if (ch == '\n')
|
|---|
| 73 | ski_putchar(d, '\r', false);
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | static chardev_operations_t ski_ops = {
|
|---|
| 78 | .write = ski_putchar
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | /** Ask debug console if a key was pressed.
|
|---|
| 82 | *
|
|---|
| 83 | * Use SSC (Simulator System Call) to
|
|---|
| 84 | * get character from debug console.
|
|---|
| 85 | *
|
|---|
| 86 | * This call is non-blocking.
|
|---|
| 87 | *
|
|---|
| 88 | * @return ASCII code of pressed key or 0 if no key pressed.
|
|---|
| 89 | */
|
|---|
| 90 | static int32_t ski_getchar(void)
|
|---|
| 91 | {
|
|---|
| 92 | uint64_t ch;
|
|---|
| 93 |
|
|---|
| 94 | asm volatile (
|
|---|
| 95 | "mov r15 = %1\n"
|
|---|
| 96 | "break 0x80000;;\n" /* modifies r8 */
|
|---|
| 97 | "mov %0 = r8;;\n"
|
|---|
| 98 |
|
|---|
| 99 | : "=r" (ch)
|
|---|
| 100 | : "i" (SKI_GETCHAR)
|
|---|
| 101 | : "r15", "r8"
|
|---|
| 102 | );
|
|---|
| 103 |
|
|---|
| 104 | return (int32_t) ch;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /** Ask keyboard if a key was pressed. */
|
|---|
| 108 | static void poll_keyboard(void)
|
|---|
| 109 | {
|
|---|
| 110 | char ch;
|
|---|
| 111 | ipl_t ipl;
|
|---|
| 112 |
|
|---|
| 113 | ipl = interrupts_disable();
|
|---|
| 114 |
|
|---|
| 115 | if (kbd_disabled) {
|
|---|
| 116 | interrupts_restore(ipl);
|
|---|
| 117 | return;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | ch = ski_getchar();
|
|---|
| 121 | if(ch == '\r')
|
|---|
| 122 | ch = '\n';
|
|---|
| 123 | if (ch && skiout) {
|
|---|
| 124 | chardev_push_character(skiout, ch);
|
|---|
| 125 | interrupts_restore(ipl);
|
|---|
| 126 | return;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | interrupts_restore(ipl);
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | #define POLL_INTERVAL 10000 /* 10 ms */
|
|---|
| 133 |
|
|---|
| 134 | /** Kernel thread for polling keyboard. */
|
|---|
| 135 | static void kkbdpoll(void *arg)
|
|---|
| 136 | {
|
|---|
| 137 | while (1) {
|
|---|
| 138 | if (!silent) {
|
|---|
| 139 | poll_keyboard();
|
|---|
| 140 | }
|
|---|
| 141 | thread_usleep(POLL_INTERVAL);
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | /** Initialize debug console
|
|---|
| 146 | *
|
|---|
| 147 | * Issue SSC (Simulator System Call) to
|
|---|
| 148 | * to open debug console.
|
|---|
| 149 | */
|
|---|
| 150 | void ski_console_init(chardev_t *devout)
|
|---|
| 151 | {
|
|---|
| 152 | asm volatile (
|
|---|
| 153 | "mov r15 = %0\n"
|
|---|
| 154 | "break 0x80000\n"
|
|---|
| 155 | :
|
|---|
| 156 | : "i" (SKI_INIT_CONSOLE)
|
|---|
| 157 | : "r15", "r8"
|
|---|
| 158 | );
|
|---|
| 159 |
|
|---|
| 160 | skiout = devout;
|
|---|
| 161 | chardev_initialize("ski_stdout", &ski_stdout, &ski_ops);
|
|---|
| 162 | stdout = &ski_stdout;
|
|---|
| 163 |
|
|---|
| 164 | thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
|
|---|
| 165 | if (!t)
|
|---|
| 166 | panic("Cannot create kkbdpoll.");
|
|---|
| 167 | thread_ready(t);
|
|---|
| 168 |
|
|---|
| 169 | sysinfo_set_item_val("kbd", NULL, true);
|
|---|
| 170 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
|
|---|
| 171 |
|
|---|
| 172 | sysinfo_set_item_val("fb", NULL, false);
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | void ski_kbd_grab(void)
|
|---|
| 176 | {
|
|---|
| 177 | kbd_disabled = true;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | void ski_kbd_release(void)
|
|---|
| 181 | {
|
|---|
| 182 | kbd_disabled = false;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | /** @}
|
|---|
| 186 | */
|
|---|