| 1 | /*
|
|---|
| 2 | * Copyright (c) 2006 Josef Cejka
|
|---|
| 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 kbdmips32 mips32
|
|---|
| 30 | * @brief HelenOS mips32 arch dependent parts of uspace keyboard handler.
|
|---|
| 31 | * @ingroup kbd
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /** @file
|
|---|
| 35 | */
|
|---|
| 36 | #include <arch/kbd.h>
|
|---|
| 37 | #include <genarch/nofb.h>
|
|---|
| 38 | #include <ipc/ipc.h>
|
|---|
| 39 | #include <sysinfo.h>
|
|---|
| 40 | #include <kbd.h>
|
|---|
| 41 | #include <keys.h>
|
|---|
| 42 |
|
|---|
| 43 | #define MSIM_KEY_F1 0x504f1bL
|
|---|
| 44 | #define MSIM_KEY_F2 0x514f1bL
|
|---|
| 45 | #define MSIM_KEY_F3 0x524f1bL
|
|---|
| 46 | #define MSIM_KEY_F4 0x534f1bL
|
|---|
| 47 | #define MSIM_KEY_F5 0x35315b1bL
|
|---|
| 48 | #define MSIM_KEY_F6 0x37315b1bL
|
|---|
| 49 | #define MSIM_KEY_F7 0x38315b1bL
|
|---|
| 50 | #define MSIM_KEY_F8 0x39315b1bL
|
|---|
| 51 | #define MSIM_KEY_F9 0x30325b1bL
|
|---|
| 52 | #define MSIM_KEY_F10 0x31325b1bL
|
|---|
| 53 | #define MSIM_KEY_F11 0x33325b1bL
|
|---|
| 54 | #define MSIM_KEY_F12 0x34325b1bL
|
|---|
| 55 |
|
|---|
| 56 | #define GXEMUL_KEY_F1 0x504f5b1bL
|
|---|
| 57 | #define GXEMUL_KEY_F2 0x514f5b1bL
|
|---|
| 58 | #define GXEMUL_KEY_F3 0x524f5b1bL
|
|---|
| 59 | #define GXEMUL_KEY_F4 0x534f5b1bL
|
|---|
| 60 | #define GXEMUL_KEY_F5 0x35315b1bL
|
|---|
| 61 | #define GXEMUL_KEY_F6 0x37315b1bL
|
|---|
| 62 | #define GXEMUL_KEY_F7 0x38315b1bL
|
|---|
| 63 | #define GXEMUL_KEY_F8 0x39315b1bL
|
|---|
| 64 | #define GXEMUL_KEY_F9 0x38325b1bL
|
|---|
| 65 | #define GXEMUL_KEY_F10 0x39325b1bL
|
|---|
| 66 | #define GXEMUL_KEY_F11 0x33325b1bL
|
|---|
| 67 | #define GXEMUL_KEY_F12 0x34325b1bL
|
|---|
| 68 |
|
|---|
| 69 | #define FUNCTION_KEYS 0x100
|
|---|
| 70 |
|
|---|
| 71 | irq_cmd_t msim_cmds[1] = {
|
|---|
| 72 | { CMD_MEM_READ_1, (void *) 0, 0, 2 }
|
|---|
| 73 | };
|
|---|
| 74 |
|
|---|
| 75 | irq_code_t msim_kbd = {
|
|---|
| 76 | 1,
|
|---|
| 77 | msim_cmds
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | static int msim,gxemul;
|
|---|
| 81 | static int fb_fb;
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 | int kbd_arch_init(void)
|
|---|
| 85 | {
|
|---|
| 86 | fb_fb = (sysinfo_value("fb.kind") == 1);
|
|---|
| 87 | msim_cmds[0].addr = sysinfo_value("kbd.address.virtual");
|
|---|
| 88 | ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"), 0, &msim_kbd);
|
|---|
| 89 | return 0;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | /*
|
|---|
| 94 | //*
|
|---|
| 95 | //* Please preserve this code (it can be used to determine scancodes)
|
|---|
| 96 | //*
|
|---|
| 97 | int to_hex(int v)
|
|---|
| 98 | {
|
|---|
| 99 | return "0123456789ABCDEF"[v];
|
|---|
| 100 | }
|
|---|
| 101 | */
|
|---|
| 102 |
|
|---|
| 103 | static int kbd_arch_process_fb(keybuffer_t *keybuffer, int scan_code)
|
|---|
| 104 | {
|
|---|
| 105 | static unsigned long buf = 0;
|
|---|
| 106 | static int count = 0;
|
|---|
| 107 |
|
|---|
| 108 | /* Please preserve this code (it can be used to determine scancodes)
|
|---|
| 109 |
|
|---|
| 110 | keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
|
|---|
| 111 | keybuffer_push(keybuffer, to_hex(scan_code&0xf));
|
|---|
| 112 | keybuffer_push(keybuffer, ' ');
|
|---|
| 113 | keybuffer_push(keybuffer, ' ');
|
|---|
| 114 |
|
|---|
| 115 | return 1;
|
|---|
| 116 | */
|
|---|
| 117 |
|
|---|
| 118 | if (scan_code == '\r')
|
|---|
| 119 | scan_code = '\n';
|
|---|
| 120 |
|
|---|
| 121 | buf |= ((unsigned long) scan_code)<<(8*(count++));
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | if ((buf & 0xff) != (GXEMUL_KEY_F1 & 0xff)) {
|
|---|
| 125 | keybuffer_push(keybuffer, buf);
|
|---|
| 126 | buf = count = 0;
|
|---|
| 127 | return 1;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | if (count <= 1)
|
|---|
| 131 | return 1;
|
|---|
| 132 |
|
|---|
| 133 | if ((buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)) {
|
|---|
| 134 | keybuffer_push(keybuffer, buf & 0xff);
|
|---|
| 135 | keybuffer_push(keybuffer, (buf >> 8) &0xff);
|
|---|
| 136 | buf = count = 0;
|
|---|
| 137 | return 1;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | if (count <= 2)
|
|---|
| 141 | return 1;
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | if ((buf & 0xffffff) != (GXEMUL_KEY_F1 & 0xffffff)
|
|---|
| 145 | && (buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
|
|---|
| 146 | && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff)) {
|
|---|
| 147 |
|
|---|
| 148 | keybuffer_push(keybuffer, buf & 0xff);
|
|---|
| 149 | keybuffer_push(keybuffer, (buf >> 8) & 0xff);
|
|---|
| 150 | keybuffer_push(keybuffer, (buf >> 16) & 0xff);
|
|---|
| 151 | buf = count = 0;
|
|---|
| 152 | return 1;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | if ( count <= 3 )
|
|---|
| 156 | return 1;
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | switch (buf) {
|
|---|
| 160 | case GXEMUL_KEY_F1:
|
|---|
| 161 | keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
|
|---|
| 162 | buf=count=0;
|
|---|
| 163 | return 1;
|
|---|
| 164 | case GXEMUL_KEY_F2:
|
|---|
| 165 | keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
|
|---|
| 166 | buf=count=0;
|
|---|
| 167 | return 1;
|
|---|
| 168 | case GXEMUL_KEY_F3:
|
|---|
| 169 | keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
|
|---|
| 170 | buf=count=0;
|
|---|
| 171 | return 1;
|
|---|
| 172 | case GXEMUL_KEY_F4:
|
|---|
| 173 | keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
|
|---|
| 174 | buf=count=0;
|
|---|
| 175 | return 1;
|
|---|
| 176 | case GXEMUL_KEY_F5:
|
|---|
| 177 | keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
|
|---|
| 178 | buf=count=0;
|
|---|
| 179 | return 1;
|
|---|
| 180 | case GXEMUL_KEY_F6:
|
|---|
| 181 | keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
|
|---|
| 182 | buf=count=0;
|
|---|
| 183 | return 1;
|
|---|
| 184 | case GXEMUL_KEY_F7:
|
|---|
| 185 | keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
|
|---|
| 186 | buf=count=0;
|
|---|
| 187 | return 1;
|
|---|
| 188 | case GXEMUL_KEY_F8:
|
|---|
| 189 | keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
|
|---|
| 190 | buf=count=0;
|
|---|
| 191 | return 1;
|
|---|
| 192 | case GXEMUL_KEY_F9:
|
|---|
| 193 | keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
|
|---|
| 194 | buf=count=0;
|
|---|
| 195 | return 1;
|
|---|
| 196 | case GXEMUL_KEY_F10:
|
|---|
| 197 | keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
|
|---|
| 198 | buf=count=0;
|
|---|
| 199 | return 1;
|
|---|
| 200 | case GXEMUL_KEY_F11:
|
|---|
| 201 | keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
|
|---|
| 202 | buf=count=0;
|
|---|
| 203 | return 1;
|
|---|
| 204 | case GXEMUL_KEY_F12:
|
|---|
| 205 | keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
|
|---|
| 206 | buf=count=0;
|
|---|
| 207 | return 1;
|
|---|
| 208 | default:
|
|---|
| 209 | keybuffer_push(keybuffer, buf & 0xff );
|
|---|
| 210 | keybuffer_push(keybuffer, (buf >> 8) &0xff );
|
|---|
| 211 | keybuffer_push(keybuffer, (buf >> 16) &0xff );
|
|---|
| 212 | keybuffer_push(keybuffer, (buf >> 24) &0xff );
|
|---|
| 213 | buf=count=0;
|
|---|
| 214 | return 1;
|
|---|
| 215 | }
|
|---|
| 216 | return 1;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
|
|---|
| 220 | {
|
|---|
| 221 | int scan_code = IPC_GET_ARG2(*call);
|
|---|
| 222 | static int esc_count=0;
|
|---|
| 223 |
|
|---|
| 224 | if (scan_code == 0x1b) {
|
|---|
| 225 | esc_count++;
|
|---|
| 226 | if (esc_count == 3)
|
|---|
| 227 | __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
|
|---|
| 228 | } else {
|
|---|
| 229 | esc_count=0;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | if (fb_fb)
|
|---|
| 233 | return kbd_arch_process_fb(keybuffer, scan_code);
|
|---|
| 234 |
|
|---|
| 235 | return kbd_process_no_fb(keybuffer, scan_code);
|
|---|
| 236 | }
|
|---|
| 237 | /** @}
|
|---|
| 238 | */
|
|---|