Subversion Repositories HelenOS-historic

Rev

Rev 1694 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1339 cejka 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
 
1649 cejka 29
/** @addtogroup kbdmips32 mips32
30
 * @brief   HelenOS mips32 arch dependent parts of uspace keyboard handler.
31
 * @ingroup  kbd
32
 * @{
33
 */
34
/** @file
35
 */
1339 cejka 36
#include <arch/kbd.h>
1353 jermar 37
#include <ipc/ipc.h>
1632 vana 38
#include <sysinfo.h>
1694 palkovsky 39
#include <kbd.h>
40
#include <keys.h>
1339 cejka 41
 
1632 vana 42
#define MSIM_KEY_F1 0x504f1bL
43
#define MSIM_KEY_F2 0x514f1bL
44
#define MSIM_KEY_F3 0x524f1bL
45
#define MSIM_KEY_F4 0x534f1bL
46
#define MSIM_KEY_F5 0x35315b1bL
47
#define MSIM_KEY_F6 0x37315b1bL
48
#define MSIM_KEY_F7 0x38315b1bL
49
#define MSIM_KEY_F8 0x39315b1bL
50
#define MSIM_KEY_F9 0x30325b1bL
51
#define MSIM_KEY_F10 0x31325b1bL
52
#define MSIM_KEY_F11 0x33325b1bL
53
#define MSIM_KEY_F12 0x34325b1bL
1622 vana 54
 
55
 
1632 vana 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
 
1622 vana 70
#define FUNCTION_KEYS 0x100
71
 
72
 
1339 cejka 73
irq_cmd_t msim_cmds[1] = {
1694 palkovsky 74
    { CMD_MEM_READ_1, (void *)0xB0000000, 0, 2 }
1339 cejka 75
};
76
 
77
irq_code_t msim_kbd = {
78
    1,
79
    msim_cmds
80
};
81
 
1632 vana 82
static int msim,gxemul;
1699 vana 83
static int fb_fb;
1632 vana 84
 
1699 vana 85
 
1347 palkovsky 86
int kbd_arch_init(void)
1339 cejka 87
{
1699 vana 88
    fb_fb=sysinfo_value("fb.kind")==1;
1339 cejka 89
    ipc_register_irq(2, &msim_kbd);
1694 palkovsky 90
    return 0;
1339 cejka 91
}
92
 
1622 vana 93
 
1699 vana 94
/*
1632 vana 95
//*
96
//* Please preserve this code (it can be used to determine scancodes)
97
//*
1622 vana 98
int to_hex(int v)
99
{
100
        return "0123456789ABCDEF"[v];
101
}
1699 vana 102
*/
1622 vana 103
 
1699 vana 104
static int kbd_arch_process_no_fb(keybuffer_t *keybuffer, int scan_code)
1347 palkovsky 105
{
1622 vana 106
 
107
    static unsigned long buf=0;
108
    static int count=0;
109
 
110
 
1699 vana 111
    /* Please preserve this code (it can be used to determine scancodes)
1622 vana 112
 
1699 vana 113
    keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
114
    keybuffer_push(keybuffer, to_hex(scan_code&0xf));
115
    keybuffer_push(keybuffer, ' ');
116
    keybuffer_push(keybuffer, ' ');
1622 vana 117
 
1699 vana 118
    return 1;
119
    */
120
 
1622 vana 121
    if(scan_code==0x7e)
122
    {
123
        switch (buf){
1632 vana 124
            case MSIM_KEY_F5:
1622 vana 125
                keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
126
                buf=count=0;
127
                return 1;
1632 vana 128
            case MSIM_KEY_F6:
1622 vana 129
                keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
130
                buf=count=0;
131
                return 1;
1632 vana 132
            case MSIM_KEY_F7:
1622 vana 133
                keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
134
                buf=count=0;
135
                return 1;
1632 vana 136
            case MSIM_KEY_F8:
1622 vana 137
                keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
138
                buf=count=0;
139
                return 1;
140
 
1632 vana 141
            case MSIM_KEY_F9:
1622 vana 142
                keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
143
                buf=count=0;
144
                return 1;
1632 vana 145
            case MSIM_KEY_F10:
1622 vana 146
                keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
147
                buf=count=0;
148
                return 1;
149
 
1632 vana 150
            case MSIM_KEY_F11:
1622 vana 151
                keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
152
                buf=count=0;
153
                return 1;
1632 vana 154
            case MSIM_KEY_F12:
1622 vana 155
                keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
156
                buf=count=0;
157
                return 1;
158
            default:
159
                keybuffer_push(keybuffer, buf & 0xff );
160
                keybuffer_push(keybuffer, (buf >> 8) &0xff );
161
                keybuffer_push(keybuffer, (buf >> 16) &0xff );
162
                keybuffer_push(keybuffer, (buf >> 24) &0xff );
163
                keybuffer_push(keybuffer, scan_code );
164
                buf=count=0;
165
                return 1;
166
 
167
        }
168
    }
169
 
170
    buf|=((unsigned long) scan_code)<<(8*(count++));
171
 
172
 
1632 vana 173
    if((buf & 0xff)!= (MSIM_KEY_F1 & 0xff)) {
1622 vana 174
 
175
        keybuffer_push(keybuffer,buf );
176
        buf=count=0;
177
        return 1;
178
    }
179
 
180
    if ( count <= 1 )
181
        return 1;
182
 
1632 vana 183
    if(    (buf & 0xffff) != (MSIM_KEY_F1 & 0xffff)
184
        && (buf & 0xffff) != (MSIM_KEY_F5 & 0xffff) ) {
1622 vana 185
 
186
        keybuffer_push(keybuffer, buf & 0xff );
187
        keybuffer_push(keybuffer, (buf >> 8) &0xff );
188
        buf=count=0;
189
        return 1;
190
    }
191
 
192
    if ( count <= 2)
193
        return 1;
194
 
195
    switch (buf){
1632 vana 196
        case MSIM_KEY_F1:
1622 vana 197
            keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
198
            buf=count=0;
199
            return 1;
1632 vana 200
        case MSIM_KEY_F2:
1622 vana 201
            keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
202
            buf=count=0;
203
            return 1;
1632 vana 204
        case MSIM_KEY_F3:
1622 vana 205
            keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
206
            buf=count=0;
207
            return 1;
1632 vana 208
        case MSIM_KEY_F4:
1622 vana 209
            keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
210
            buf=count=0;
211
            return 1;
212
    }
213
 
214
 
1632 vana 215
    if(    (buf & 0xffffff) != (MSIM_KEY_F5 & 0xffffff)
216
        && (buf & 0xffffff) != (MSIM_KEY_F9 & 0xffffff) ) {
1622 vana 217
 
218
        keybuffer_push(keybuffer, buf & 0xff );
219
        keybuffer_push(keybuffer, (buf >> 8) &0xff );
220
        keybuffer_push(keybuffer, (buf >> 16) &0xff );
221
        buf=count=0;
222
        return 1;
223
    }
224
 
225
    if ( count <= 3 )
226
        return 1;
227
 
228
 
229
 
230
 
231
    switch (buf){
1632 vana 232
        case MSIM_KEY_F5:
233
        case MSIM_KEY_F6:
234
        case MSIM_KEY_F7:
235
        case MSIM_KEY_F8:
236
        case MSIM_KEY_F9:
237
        case MSIM_KEY_F10:
238
        case MSIM_KEY_F11:
239
        case MSIM_KEY_F12:
1622 vana 240
            return 1;
241
        default:
242
            keybuffer_push(keybuffer, buf & 0xff );
243
            keybuffer_push(keybuffer, (buf >> 8) &0xff );
244
            keybuffer_push(keybuffer, (buf >> 16) &0xff );
245
            keybuffer_push(keybuffer, (buf >> 24) &0xff );
246
            buf=count=0;
247
            return 1;
248
 
249
        }
250
    return 1;
1347 palkovsky 251
}
1632 vana 252
 
253
 
254
 
1699 vana 255
static int kbd_arch_process_fb(keybuffer_t *keybuffer, int scan_code)
1632 vana 256
{
257
 
258
    static unsigned long buf=0;
259
    static int count=0;
260
 
261
 
1699 vana 262
    /* Please preserve this code (it can be used to determine scancodes)
1632 vana 263
 
1699 vana 264
    keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
265
    keybuffer_push(keybuffer, to_hex(scan_code&0xf));
266
    keybuffer_push(keybuffer, ' ');
267
    keybuffer_push(keybuffer, ' ');
1644 vana 268
 
1699 vana 269
    return 1;
270
    */
271
 
1644 vana 272
    if ( scan_code == '\r' )
273
        scan_code = '\n' ;
274
 
1632 vana 275
    buf|=((unsigned long) scan_code)<<(8*(count++));
276
 
277
 
278
    if((buf & 0xff)!= (GXEMUL_KEY_F1 & 0xff)) {
279
 
280
        keybuffer_push(keybuffer,buf );
281
        buf=count=0;
282
        return 1;
283
    }
284
 
285
    if ( count <= 1 )
286
        return 1;
287
 
288
    if(    (buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)  ) {
289
 
290
        keybuffer_push(keybuffer, buf & 0xff );
291
        keybuffer_push(keybuffer, (buf >> 8) &0xff );
292
        buf=count=0;
293
        return 1;
294
    }
295
 
296
    if ( count <= 2)
297
        return 1;
298
 
299
 
300
    if(    (buf & 0xffffff) != (GXEMUL_KEY_F1 & 0xffffff)
301
        && (buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
302
        && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff) ) {
303
 
304
        keybuffer_push(keybuffer, buf & 0xff );
305
        keybuffer_push(keybuffer, (buf >> 8) &0xff );
306
        keybuffer_push(keybuffer, (buf >> 16) &0xff );
307
        buf=count=0;
308
        return 1;
309
    }
310
 
311
    if ( count <= 3 )
312
        return 1;
313
 
314
 
315
    switch (buf){
316
 
317
        case GXEMUL_KEY_F1:
318
            keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
319
            buf=count=0;
320
            return 1;
321
        case GXEMUL_KEY_F2:
322
            keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
323
            buf=count=0;
324
            return 1;
325
        case GXEMUL_KEY_F3:
326
            keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
327
            buf=count=0;
328
            return 1;
329
        case GXEMUL_KEY_F4:
330
            keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
331
            buf=count=0;
332
            return 1;
333
        case GXEMUL_KEY_F5:
334
            keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
335
            buf=count=0;
336
            return 1;
337
        case GXEMUL_KEY_F6:
338
            keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
339
            buf=count=0;
340
            return 1;
341
        case GXEMUL_KEY_F7:
342
            keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
343
            buf=count=0;
344
            return 1;
345
        case GXEMUL_KEY_F8:
346
            keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
347
            buf=count=0;
348
            return 1;
349
        case GXEMUL_KEY_F9:
350
            keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
351
            buf=count=0;
352
            return 1;
353
        case GXEMUL_KEY_F10:
354
            keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
355
            buf=count=0;
356
            return 1;
357
        case GXEMUL_KEY_F11:
358
            keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
359
            buf=count=0;
360
            return 1;
361
        case GXEMUL_KEY_F12:
362
            keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
363
            buf=count=0;
364
            return 1;
365
 
366
        default:
367
            keybuffer_push(keybuffer, buf & 0xff );
368
            keybuffer_push(keybuffer, (buf >> 8) &0xff );
369
            keybuffer_push(keybuffer, (buf >> 16) &0xff );
370
            keybuffer_push(keybuffer, (buf >> 24) &0xff );
371
            buf=count=0;
372
            return 1;
373
 
374
        }
375
    return 1;
376
}
377
 
1694 palkovsky 378
int kbd_arch_process(keybuffer_t *keybuffer, ipc_call_t *call)
1632 vana 379
{
1694 palkovsky 380
    int scan_code = IPC_GET_ARG2(*call);
1645 vana 381
    static int esc_count=0;
382
 
383
 
384
    if ( scan_code == 0x1b ) {
385
        esc_count++;
386
        if ( esc_count == 3 ) {
387
            __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
388
        }  
389
    } else {
390
        esc_count=0;
391
    }
392
 
1699 vana 393
    if(fb_fb) return kbd_arch_process_fb(keybuffer, scan_code);
394
    return kbd_arch_process_no_fb(keybuffer, scan_code);
1645 vana 395
 
396
    return 0;
1632 vana 397
}
1699 vana 398
/** @}
399
*/