Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1964 → Rev 1968

/tags/0.2.0/uspace/kbd/arch/amd64
0,0 → 1,0
link ia32
Property changes:
Added: svn:special
+*
\ No newline at end of property
/tags/0.2.0/uspace/kbd/arch/ia32/include/kbd.h
0,0 → 1,52
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdamd64 amd64
* @brief HelenOS ia32 / amd64 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
 
/** @file
* @ingroup kbdia32
*/
 
#ifndef __ia32_KBD_H__
#define __ia32_KBD_H__
 
#include <key_buffer.h>
 
int kbd_arch_init(void);
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code);
 
#endif
 
/**
* @}
*/
 
/tags/0.2.0/uspace/kbd/arch/ia32/src/kbd.c
0,0 → 1,379
/*
* Copyright (C) 2001-2004 Jakub Jermar
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdia32 ia32
* @brief HelenOS ia32 / amd64 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
* @ingroup kbdamd64
*/
 
#include <arch/kbd.h>
#include <ipc/ipc.h>
 
#define SPECIAL 255
#define KEY_RELEASE 0x80
 
/**
* These codes read from i8042 data register are silently ignored.
*/
#define IGNORE_CODE 0x7f
 
#define PRESSED_SHIFT (1<<0)
#define PRESSED_CAPSLOCK (1<<1)
#define LOCKED_CAPSLOCK (1<<0)
 
/** Scancodes. */
#define SC_ESC 0x01
#define SC_BACKSPACE 0x0e
#define SC_LSHIFT 0x2a
#define SC_RSHIFT 0x36
#define SC_CAPSLOCK 0x3a
#define SC_SPEC_ESCAPE 0xe0
#define SC_LEFTARR 0x4b
#define SC_RIGHTARR 0x4d
#define SC_UPARR 0x48
#define SC_DOWNARR 0x50
#define SC_DELETE 0x53
#define SC_HOME 0x47
#define SC_END 0x4f
 
#define FUNCTION_KEYS 0x100
 
static volatile int keyflags; /**< Tracking of multiple keypresses. */
static volatile int lockflags; /**< Tracking of multiple keys lockings. */
 
/** Primary meaning of scancodes. */
static int sc_primary_map[] = {
SPECIAL, /* 0x00 */
SPECIAL, /* 0x01 - Esc */
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
'\b', /* 0x0e - Backspace */
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
SPECIAL, /* 0x1d - LCtrl */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'',
'`',
SPECIAL, /* 0x2a - LShift */
'\\',
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
SPECIAL, /* 0x36 - RShift */
'*',
SPECIAL, /* 0x38 - LAlt */
' ',
SPECIAL, /* 0x3a - CapsLock */
(FUNCTION_KEYS | 1), /* 0x3b - F1 */
(FUNCTION_KEYS | 2), /* 0x3c - F2 */
(FUNCTION_KEYS | 3), /* 0x3d - F3 */
(FUNCTION_KEYS | 4), /* 0x3e - F4 */
(FUNCTION_KEYS | 5), /* 0x3f - F5 */
(FUNCTION_KEYS | 6), /* 0x40 - F6 */
(FUNCTION_KEYS | 7), /* 0x41 - F7 */
(FUNCTION_KEYS | 8), /* 0x42 - F8 */
(FUNCTION_KEYS | 9), /* 0x43 - F9 */
(FUNCTION_KEYS | 10), /* 0x44 - F10 */
SPECIAL, /* 0x45 - NumLock */
SPECIAL, /* 0x46 - ScrollLock */
'7', '8', '9', '-',
'4', '5', '6', '+',
'1', '2', '3',
'0', '.',
SPECIAL, /* 0x54 - Alt-SysRq */
SPECIAL, /* 0x55 - F11/F12/PF1/FN */
SPECIAL, /* 0x56 - unlabelled key next to LAlt */
(FUNCTION_KEYS | 11), /* 0x57 - F11 */
(FUNCTION_KEYS | 12), /* 0x58 - F12 */
SPECIAL, /* 0x59 */
SPECIAL, /* 0x5a */
SPECIAL, /* 0x5b */
SPECIAL, /* 0x5c */
SPECIAL, /* 0x5d */
SPECIAL, /* 0x5e */
SPECIAL, /* 0x5f */
SPECIAL, /* 0x60 */
SPECIAL, /* 0x61 */
SPECIAL, /* 0x62 */
SPECIAL, /* 0x63 */
SPECIAL, /* 0x64 */
SPECIAL, /* 0x65 */
SPECIAL, /* 0x66 */
SPECIAL, /* 0x67 */
SPECIAL, /* 0x68 */
SPECIAL, /* 0x69 */
SPECIAL, /* 0x6a */
SPECIAL, /* 0x6b */
SPECIAL, /* 0x6c */
SPECIAL, /* 0x6d */
SPECIAL, /* 0x6e */
SPECIAL, /* 0x6f */
SPECIAL, /* 0x70 */
SPECIAL, /* 0x71 */
SPECIAL, /* 0x72 */
SPECIAL, /* 0x73 */
SPECIAL, /* 0x74 */
SPECIAL, /* 0x75 */
SPECIAL, /* 0x76 */
SPECIAL, /* 0x77 */
SPECIAL, /* 0x78 */
SPECIAL, /* 0x79 */
SPECIAL, /* 0x7a */
SPECIAL, /* 0x7b */
SPECIAL, /* 0x7c */
SPECIAL, /* 0x7d */
SPECIAL, /* 0x7e */
SPECIAL, /* 0x7f */
};
 
/** Secondary meaning of scancodes. */
static int sc_secondary_map[] = {
SPECIAL, /* 0x00 */
0x1b, /* 0x01 - Esc */
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
SPECIAL, /* 0x0e - Backspace */
'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
SPECIAL, /* 0x1d - LCtrl */
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"',
'~',
SPECIAL, /* 0x2a - LShift */
'|',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
SPECIAL, /* 0x36 - RShift */
'*',
SPECIAL, /* 0x38 - LAlt */
' ',
SPECIAL, /* 0x3a - CapsLock */
SPECIAL, /* 0x3b - F1 */
SPECIAL, /* 0x3c - F2 */
SPECIAL, /* 0x3d - F3 */
SPECIAL, /* 0x3e - F4 */
SPECIAL, /* 0x3f - F5 */
SPECIAL, /* 0x40 - F6 */
SPECIAL, /* 0x41 - F7 */
SPECIAL, /* 0x42 - F8 */
SPECIAL, /* 0x43 - F9 */
SPECIAL, /* 0x44 - F10 */
SPECIAL, /* 0x45 - NumLock */
SPECIAL, /* 0x46 - ScrollLock */
'7', '8', '9', '-',
'4', '5', '6', '+',
'1', '2', '3',
'0', '.',
SPECIAL, /* 0x54 - Alt-SysRq */
SPECIAL, /* 0x55 - F11/F12/PF1/FN */
SPECIAL, /* 0x56 - unlabelled key next to LAlt */
SPECIAL, /* 0x57 - F11 */
SPECIAL, /* 0x58 - F12 */
SPECIAL, /* 0x59 */
SPECIAL, /* 0x5a */
SPECIAL, /* 0x5b */
SPECIAL, /* 0x5c */
SPECIAL, /* 0x5d */
SPECIAL, /* 0x5e */
SPECIAL, /* 0x5f */
SPECIAL, /* 0x60 */
SPECIAL, /* 0x61 */
SPECIAL, /* 0x62 */
SPECIAL, /* 0x63 */
SPECIAL, /* 0x64 */
SPECIAL, /* 0x65 */
SPECIAL, /* 0x66 */
SPECIAL, /* 0x67 */
SPECIAL, /* 0x68 */
SPECIAL, /* 0x69 */
SPECIAL, /* 0x6a */
SPECIAL, /* 0x6b */
SPECIAL, /* 0x6c */
SPECIAL, /* 0x6d */
SPECIAL, /* 0x6e */
SPECIAL, /* 0x6f */
SPECIAL, /* 0x70 */
SPECIAL, /* 0x71 */
SPECIAL, /* 0x72 */
SPECIAL, /* 0x73 */
SPECIAL, /* 0x74 */
SPECIAL, /* 0x75 */
SPECIAL, /* 0x76 */
SPECIAL, /* 0x77 */
SPECIAL, /* 0x78 */
SPECIAL, /* 0x79 */
SPECIAL, /* 0x7a */
SPECIAL, /* 0x7b */
SPECIAL, /* 0x7c */
SPECIAL, /* 0x7d */
SPECIAL, /* 0x7e */
SPECIAL, /* 0x7f */
};
 
irq_cmd_t i8042_cmds[1] = {
{ CMD_PORT_READ_1, (void *)0x60, 0 }
};
 
irq_code_t i8042_kbd = {
1,
i8042_cmds
};
 
static int key_released(keybuffer_t *keybuffer, unsigned char key)
{
switch (key) {
case SC_LSHIFT:
case SC_RSHIFT:
keyflags &= ~PRESSED_SHIFT;
break;
case SC_CAPSLOCK:
keyflags &= ~PRESSED_CAPSLOCK;
if (lockflags & LOCKED_CAPSLOCK)
lockflags &= ~LOCKED_CAPSLOCK;
else
lockflags |= LOCKED_CAPSLOCK;
break;
default:
break;
}
}
 
static int key_pressed(keybuffer_t *keybuffer, unsigned char key)
{
int *map = sc_primary_map;
int ascii = sc_primary_map[key];
int shift, capslock;
int letter = 0;
 
static int esc_count=0;
 
if ( key == SC_ESC ) {
esc_count++;
if ( esc_count == 3 ) {
__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
}
} else {
esc_count=0;
}
 
switch (key) {
case SC_LSHIFT:
case SC_RSHIFT:
keyflags |= PRESSED_SHIFT;
break;
case SC_CAPSLOCK:
keyflags |= PRESSED_CAPSLOCK;
break;
case SC_SPEC_ESCAPE:
break;
/* case SC_LEFTARR:
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x44);
}
break;
case SC_RIGHTARR:
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x43);
}
break;
case SC_UPARR:
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x41);
}
break;
case SC_DOWNARR:
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x42);
}
break;
case SC_HOME:
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x4f);
keybuffer_push(keybuffer, 0x48);
}
break;
case SC_END:
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x4f);
keybuffer_push(keybuffer, 0x46);
}
break;
case SC_DELETE:
if (keybuffer_available(keybuffer) >= 4) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x33);
keybuffer_push(keybuffer, 0x7e);
}
break;
*/ default:
letter = ((ascii >= 'a') && (ascii <= 'z'));
capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
shift = keyflags & PRESSED_SHIFT;
if (letter && capslock)
shift = !shift;
if (shift)
map = sc_secondary_map;
if (map[key] != SPECIAL)
keybuffer_push(keybuffer, map[key]);
break;
}
}
 
/** Register uspace irq handler
* @return
*/
int kbd_arch_init(void)
{
return !(ipc_register_irq(1, &i8042_kbd));
}
 
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
{
if (scan_code != IGNORE_CODE) {
if (scan_code & KEY_RELEASE)
key_released(keybuffer, scan_code ^ KEY_RELEASE);
else
key_pressed(keybuffer, scan_code);
}
return 1;
}
 
/**
* @}
*/
 
/tags/0.2.0/uspace/kbd/arch/ia64/include/kbd.h
0,0 → 1,50
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdia64 ia64
* @brief HelenOS ia64 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
 
#ifndef __ia64_KBD_H__
#define __ia64_KBD_H__
 
#include <key_buffer.h>
 
int kbd_arch_init(void);
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code);
 
#endif
 
/**
* @}
*/
/tags/0.2.0/uspace/kbd/arch/ia64/src/kbd.c
0,0 → 1,169
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdia64 ia64
* @brief HelenOS ia64 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#include <arch/kbd.h>
#include <ipc/ipc.h>
#include <sysinfo.h>
 
#define KEY_F1 0x504f1b
#define KEY_F2 0x514f1b
#define KEY_F3 0x524f1b
#define KEY_F4 0x534f1b
#define KEY_F5 0x7e35315b1b
#define KEY_F6 0x7e37315b1b
#define KEY_F7 0x7e38315b1b
#define KEY_F8 0x7e39315b1b
#define KEY_F9 0x7e30325b1b
#define KEY_F10 0x7e31325b1b
#define KEY_F11 0x7e33325b1b
#define KEY_F12 0x7e34325b1b
 
 
#define FUNCTION_KEYS 0x100
 
irq_cmd_t ski_cmds[1] = {
{ CMD_IA64_GETCHAR, 0, 0 }
};
 
irq_code_t ski_kbd = {
1,
ski_cmds
};
 
int kbd_arch_init(void)
{
if(sysinfo_value("kbd")) {
ipc_register_irq(sysinfo_value("kbd.irq"), &ski_kbd);
return 1;
}
}
 
/*
* Please preserve this code (it can be used to determine scancodes)
*
int to_hex(int v)
{
return "0123456789ABCDEF"[v];
}
*/
 
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
{
static unsigned long long buf=0;
static int count=0;
static int esc_count=0;
 
 
/*
* Please preserve this code (it can be used to determine scancodes)
*/
//keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
//keybuffer_push(keybuffer, to_hex(scan_code&0xf));
//keybuffer_push(keybuffer, ' ');
//keybuffer_push(keybuffer, ' ');
//*/
if (scan_code){
buf|=(unsigned long long) scan_code<<(8*(count++));
} else {
 
if ( buf == 0x1b ) {
esc_count++;
if ( esc_count == 3 ) {
__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
}
} else {
esc_count=0;
}
if ( ! ( buf & 0xff00 ))
keybuffer_push(keybuffer, buf);
else {
switch (buf){
case KEY_F1:
keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
break;
case KEY_F2:
keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
break;
case KEY_F3:
keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
break;
case KEY_F4:
keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
break;
case KEY_F5:
keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
break;
case KEY_F6:
keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
break;
case KEY_F7:
keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
break;
case KEY_F8:
keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
break;
 
case KEY_F9:
keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
break;
case KEY_F10:
keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
break;
 
case KEY_F11:
keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
break;
case KEY_F12:
keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
break;
 
 
}
}
buf=count=0;
}
 
return 1;
}
 
/**
* @}
*/
/tags/0.2.0/uspace/kbd/arch/ppc32/include/kbd.h
0,0 → 1,49
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdppc32 ppc32
* @brief HelenOS ppc32 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#ifndef __ppc32_KBD_H__
#define __ppc32_KBD_H__
 
#include <key_buffer.h>
 
int kbd_arch_init(void);
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code);
 
#endif
 
/** @}
*/
 
/tags/0.2.0/uspace/kbd/arch/ppc32/src/kbd.c
0,0 → 1,206
/*
* Copyright (C) 2006 Martin Decky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdppc32 ppc32
* @brief HelenOS ppc32 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#include <arch/kbd.h>
#include <ipc/ipc.h>
#include <sysinfo.h>
 
irq_cmd_t cuda_cmds[1] = {
{ CMD_PPC32_GETCHAR, 0, 0 }
};
 
irq_code_t cuda_kbd = {
1,
cuda_cmds
};
 
 
#define SPECIAL 255
#define FUNCTION_KEYS 0x100
 
 
static int lchars[0x80] = {
'a',
's',
'd',
'f',
'h',
'g',
'z',
'x',
'c',
'v',
SPECIAL,
'b',
'q',
'w',
'e',
'r',
'y',
't',
'1',
'2',
'3',
'4',
'6',
'5',
'=',
'9',
'7',
'-',
'8',
'0',
']',
'o',
'u',
'[',
'i',
'p',
'\n', /* Enter */
'l',
'j',
'\'',
'k',
';',
'\\',
',',
'/',
'n',
'm',
'.',
'\t', /* Tab */
' ',
'`',
'\b', /* Backspace */
SPECIAL,
SPECIAL, /* Escape */
SPECIAL, /* Ctrl */
SPECIAL, /* Alt */
SPECIAL, /* Shift */
SPECIAL, /* Caps-Lock */
SPECIAL, /* RAlt */
SPECIAL, /* Left */
SPECIAL, /* Right */
SPECIAL, /* Down */
SPECIAL, /* Up */
SPECIAL,
SPECIAL,
'.', /* Keypad . */
SPECIAL,
'*', /* Keypad * */
SPECIAL,
'+', /* Keypad + */
SPECIAL,
SPECIAL, /* NumLock */
SPECIAL,
SPECIAL,
SPECIAL,
'/', /* Keypad / */
'\n', /* Keypad Enter */
SPECIAL,
'-', /* Keypad - */
SPECIAL,
SPECIAL,
SPECIAL,
'0', /* Keypad 0 */
'1', /* Keypad 1 */
'2', /* Keypad 2 */
'3', /* Keypad 3 */
'4', /* Keypad 4 */
'5', /* Keypad 5 */
'6', /* Keypad 6 */
'7', /* Keypad 7 */
SPECIAL,
'8', /* Keypad 8 */
'9', /* Keypad 9 */
SPECIAL,
SPECIAL,
SPECIAL,
(FUNCTION_KEYS | 5), /* F5 */
(FUNCTION_KEYS | 6), /* F6 */
(FUNCTION_KEYS | 7), /* F7 */
(FUNCTION_KEYS | 3), /* F3 */
(FUNCTION_KEYS | 8), /* F8 */
(FUNCTION_KEYS | 9), /* F9 */
SPECIAL,
(FUNCTION_KEYS | 11), /* F11 */
SPECIAL,
(FUNCTION_KEYS | 13), /* F13 */
SPECIAL,
SPECIAL, /* ScrollLock */
SPECIAL,
(FUNCTION_KEYS | 10), /* F10 */
SPECIAL,
(FUNCTION_KEYS | 12), /* F12 */
SPECIAL,
SPECIAL, /* Pause */
SPECIAL, /* Insert */
SPECIAL, /* Home */
SPECIAL, /* PageUp */
SPECIAL, /* Delete */
(FUNCTION_KEYS | 4), /* F4 */
SPECIAL, /* End */
(FUNCTION_KEYS | 2), /* F2 */
SPECIAL, /* PageDown */
(FUNCTION_KEYS | 1) /* F1 */
};
 
 
int kbd_arch_init(void)
{
return (!ipc_register_irq(sysinfo_value("cuda.irq"), &cuda_kbd));
}
 
 
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
{
if (scan_code != -1) {
uint8_t scancode = (uint8_t) scan_code;
if ((scancode & 0x80) != 0x80) {
int key = lchars[scancode & 0x7f];
if (key != SPECIAL)
keybuffer_push(keybuffer, key);
}
}
return 1;
}
 
/** @}
*/
 
/tags/0.2.0/uspace/kbd/arch/mips32/include/kbd.h
0,0 → 1,49
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdmips32 mips32
* @brief HelenOS mips32 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#ifndef __mips32_KBD_H__
#define __mips32_KBD_H__
 
#include <key_buffer.h>
 
int kbd_arch_init(void);
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code);
 
#endif
 
/**
* @}
*/
/tags/0.2.0/uspace/kbd/arch/mips32/src/kbd.c
0,0 → 1,399
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdmips32 mips32
* @brief HelenOS mips32 arch dependent parts of uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
#include <arch/kbd.h>
#include <ipc/ipc.h>
#include <sysinfo.h>
 
 
#define MSIM_KEY_F1 0x504f1bL
#define MSIM_KEY_F2 0x514f1bL
#define MSIM_KEY_F3 0x524f1bL
#define MSIM_KEY_F4 0x534f1bL
#define MSIM_KEY_F5 0x35315b1bL
#define MSIM_KEY_F6 0x37315b1bL
#define MSIM_KEY_F7 0x38315b1bL
#define MSIM_KEY_F8 0x39315b1bL
#define MSIM_KEY_F9 0x30325b1bL
#define MSIM_KEY_F10 0x31325b1bL
#define MSIM_KEY_F11 0x33325b1bL
#define MSIM_KEY_F12 0x34325b1bL
 
 
#define GXEMUL_KEY_F1 0x504f5b1bL
#define GXEMUL_KEY_F2 0x514f5b1bL
#define GXEMUL_KEY_F3 0x524f5b1bL
#define GXEMUL_KEY_F4 0x534f5b1bL
#define GXEMUL_KEY_F5 0x35315b1bL
#define GXEMUL_KEY_F6 0x37315b1bL
#define GXEMUL_KEY_F7 0x38315b1bL
#define GXEMUL_KEY_F8 0x39315b1bL
#define GXEMUL_KEY_F9 0x38325b1bL
#define GXEMUL_KEY_F10 0x39325b1bL
#define GXEMUL_KEY_F11 0x33325b1bL
#define GXEMUL_KEY_F12 0x34325b1bL
 
 
#define FUNCTION_KEYS 0x100
 
 
irq_cmd_t msim_cmds[1] = {
{ CMD_MEM_READ_1, (void *)0xB0000000, 0 }
};
 
irq_code_t msim_kbd = {
1,
msim_cmds
};
 
static int msim,gxemul;
 
int kbd_arch_init(void)
{
ipc_register_irq(2, &msim_kbd);
msim=sysinfo_value("machine.msim");
gxemul=sysinfo_value("machine.lgxemul");
return 1;
}
 
 
//*
//*
//* Please preserve this code (it can be used to determine scancodes)
//*
int to_hex(int v)
{
return "0123456789ABCDEF"[v];
}
//*/
 
static int kbd_arch_process_msim(keybuffer_t *keybuffer, int scan_code)
{
 
static unsigned long buf=0;
static int count=0;
 
 
//* Please preserve this code (it can be used to determine scancodes)
//*
//keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
//keybuffer_push(keybuffer, to_hex(scan_code&0xf));
//keybuffer_push(keybuffer, ' ');
//keybuffer_push(keybuffer, ' ');
//*/
//return 1;
if(scan_code==0x7e)
{
switch (buf){
case MSIM_KEY_F5:
keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
buf=count=0;
return 1;
case MSIM_KEY_F6:
keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
buf=count=0;
return 1;
case MSIM_KEY_F7:
keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
buf=count=0;
return 1;
case MSIM_KEY_F8:
keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
buf=count=0;
return 1;
 
case MSIM_KEY_F9:
keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
buf=count=0;
return 1;
case MSIM_KEY_F10:
keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
buf=count=0;
return 1;
 
case MSIM_KEY_F11:
keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
buf=count=0;
return 1;
case MSIM_KEY_F12:
keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
buf=count=0;
return 1;
default:
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
keybuffer_push(keybuffer, (buf >> 16) &0xff );
keybuffer_push(keybuffer, (buf >> 24) &0xff );
keybuffer_push(keybuffer, scan_code );
buf=count=0;
return 1;
}
}
 
buf|=((unsigned long) scan_code)<<(8*(count++));
if((buf & 0xff)!= (MSIM_KEY_F1 & 0xff)) {
 
keybuffer_push(keybuffer,buf );
buf=count=0;
return 1;
}
 
if ( count <= 1 )
return 1;
 
if( (buf & 0xffff) != (MSIM_KEY_F1 & 0xffff)
&& (buf & 0xffff) != (MSIM_KEY_F5 & 0xffff) ) {
 
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
buf=count=0;
return 1;
}
 
if ( count <= 2)
return 1;
 
switch (buf){
case MSIM_KEY_F1:
keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
buf=count=0;
return 1;
case MSIM_KEY_F2:
keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
buf=count=0;
return 1;
case MSIM_KEY_F3:
keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
buf=count=0;
return 1;
case MSIM_KEY_F4:
keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
buf=count=0;
return 1;
}
 
 
if( (buf & 0xffffff) != (MSIM_KEY_F5 & 0xffffff)
&& (buf & 0xffffff) != (MSIM_KEY_F9 & 0xffffff) ) {
 
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
keybuffer_push(keybuffer, (buf >> 16) &0xff );
buf=count=0;
return 1;
}
 
if ( count <= 3 )
return 1;
 
switch (buf){
case MSIM_KEY_F5:
case MSIM_KEY_F6:
case MSIM_KEY_F7:
case MSIM_KEY_F8:
case MSIM_KEY_F9:
case MSIM_KEY_F10:
case MSIM_KEY_F11:
case MSIM_KEY_F12:
return 1;
default:
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
keybuffer_push(keybuffer, (buf >> 16) &0xff );
keybuffer_push(keybuffer, (buf >> 24) &0xff );
buf=count=0;
return 1;
}
return 1;
}
 
 
 
static int kbd_arch_process_gxemul(keybuffer_t *keybuffer, int scan_code)
{
 
static unsigned long buf=0;
static int count=0;
 
 
//* Please preserve this code (it can be used to determine scancodes)
//*
//keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
//keybuffer_push(keybuffer, to_hex(scan_code&0xf));
//keybuffer_push(keybuffer, ' ');
//keybuffer_push(keybuffer, ' ');
//*/
//return 1;
if ( scan_code == '\r' )
scan_code = '\n' ;
buf|=((unsigned long) scan_code)<<(8*(count++));
if((buf & 0xff)!= (GXEMUL_KEY_F1 & 0xff)) {
 
keybuffer_push(keybuffer,buf );
buf=count=0;
return 1;
}
 
if ( count <= 1 )
return 1;
 
if( (buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff) ) {
 
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
buf=count=0;
return 1;
}
 
if ( count <= 2)
return 1;
 
 
if( (buf & 0xffffff) != (GXEMUL_KEY_F1 & 0xffffff)
&& (buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
&& (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff) ) {
 
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
keybuffer_push(keybuffer, (buf >> 16) &0xff );
buf=count=0;
return 1;
}
 
if ( count <= 3 )
return 1;
 
switch (buf){
 
case GXEMUL_KEY_F1:
keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
buf=count=0;
return 1;
case GXEMUL_KEY_F2:
keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
buf=count=0;
return 1;
case GXEMUL_KEY_F3:
keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
buf=count=0;
return 1;
case GXEMUL_KEY_F4:
keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
buf=count=0;
return 1;
case GXEMUL_KEY_F5:
keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
buf=count=0;
return 1;
case GXEMUL_KEY_F6:
keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
buf=count=0;
return 1;
case GXEMUL_KEY_F7:
keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
buf=count=0;
return 1;
case GXEMUL_KEY_F8:
keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
buf=count=0;
return 1;
case GXEMUL_KEY_F9:
keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
buf=count=0;
return 1;
case GXEMUL_KEY_F10:
keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
buf=count=0;
return 1;
case GXEMUL_KEY_F11:
keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
buf=count=0;
return 1;
case GXEMUL_KEY_F12:
keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
buf=count=0;
return 1;
 
default:
keybuffer_push(keybuffer, buf & 0xff );
keybuffer_push(keybuffer, (buf >> 8) &0xff );
keybuffer_push(keybuffer, (buf >> 16) &0xff );
keybuffer_push(keybuffer, (buf >> 24) &0xff );
buf=count=0;
return 1;
}
return 1;
}
 
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
{
 
static int esc_count=0;
 
if ( scan_code == 0x1b ) {
esc_count++;
if ( esc_count == 3 ) {
__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
}
} else {
esc_count=0;
}
 
if(msim) return kbd_arch_process_msim(keybuffer, scan_code);
if(gxemul) return kbd_arch_process_gxemul(keybuffer, scan_code);
 
return 0;
}
 
/**
* @}
*/
/tags/0.2.0/uspace/kbd/arch/mips32eb
0,0 → 1,0
link mips32
Property changes:
Added: svn:special
+*
\ No newline at end of property
/tags/0.2.0/uspace/kbd/include/kbd.h
0,0 → 1,60
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdgen generic
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#ifndef __KBD_H__
#define __KBD_H__
 
#define KBD_PUSHCHAR 1024
 
#define KBD_KEY_F1 0x3b
#define KBD_KEY_F2 0x3c
#define KBD_KEY_F3 0x3d
#define KBD_KEY_F4 0x3e
#define KBD_KEY_F5 0x3f
#define KBD_KEY_F6 0x40
#define KBD_KEY_F7 0x41
#define KBD_KEY_F8 0x42
#define KBD_KEY_F9 0x43
#define KBD_KEY_F10 0x44
#define KBD_KEY_F11 0x45
#define KBD_KEY_F12 0x46
 
#endif
 
/**
* @}
*/
 
/tags/0.2.0/uspace/kbd/include/key_buffer.h
0,0 → 1,64
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdgen
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#ifndef __KEY_BUFFER_H__
#define __KEY_BUFFER_H__
 
#include <types.h>
 
/** Size of buffer for pressed keys */
#define KEYBUFFER_SIZE 128
 
typedef struct {
int fifo[KEYBUFFER_SIZE];
unsigned long head;
unsigned long tail;
unsigned long items;
} keybuffer_t;
 
void keybuffer_free(keybuffer_t *keybuffer);
void keybuffer_init(keybuffer_t *keybuffer);
int keybuffer_available(keybuffer_t *keybuffer);
int keybuffer_empty(keybuffer_t *keybuffer);
void keybuffer_push(keybuffer_t *keybuffer, int key);
int keybuffer_pop(keybuffer_t *keybuffer, int *c);
 
#endif
 
/**
* @}
*/
 
/tags/0.2.0/uspace/kbd/generic/kbd.c
0,0 → 1,147
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @defgroup kbd Keyboard handler
* @brief HelenOS uspace keyboard handler.
* @{
* @}
*/
/** @addtogroup kbdgen generic
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
 
#include <ipc/ipc.h>
#include <ipc/services.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ipc/ns.h>
#include <errno.h>
#include <arch/kbd.h>
#include <kbd.h>
#include <libadt/fifo.h>
#include <key_buffer.h>
#include <async.h>
 
#define NAME "KBD"
 
int cons_connected = 0;
int phone2cons = -1;
keybuffer_t keybuffer;
 
static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
{
int chr;
if (cons_connected && phone2cons != -1) {
/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
kbd_arch_process(&keybuffer, IPC_GET_ARG2(*call));
while (!keybuffer_empty(&keybuffer)) {
if (!keybuffer_pop(&keybuffer, (int *)&chr))
break;
 
async_msg(phone2cons, KBD_PUSHCHAR, chr);
}
}
}
 
static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
int retval;
 
if (cons_connected) {
ipc_answer_fast(iid, ELIMIT, 0, 0);
return;
}
cons_connected = 1;
ipc_answer_fast(iid, 0, 0, 0);
 
while (1) {
callid = async_get_call(&call);
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
cons_connected = 0;
ipc_hangup(phone2cons);
phone2cons = -1;
ipc_answer_fast(callid, 0,0,0);
return;
case IPC_M_CONNECT_TO_ME:
if (phone2cons != -1) {
retval = ELIMIT;
break;
}
phone2cons = IPC_GET_ARG3(call);
retval = 0;
break;
}
ipc_answer_fast(callid, retval, 0, 0);
}
}
 
 
int main(int argc, char **argv)
{
ipc_call_t call;
ipc_callid_t callid;
int res;
ipcarg_t phonead;
ipcarg_t phoneid;
char connected = 0;
ipcarg_t retval, arg1, arg2;
/* Initialize arch dependent parts */
if (!(res = kbd_arch_init())) {
return -1;
};
/* Initialize key buffer */
keybuffer_init(&keybuffer);
async_set_client_connection(console_connection);
async_set_interrupt_received(irq_handler);
/* Register service at nameserver */
if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
return -1;
}
 
async_manager();
 
}
 
/**
* @}
*/
 
/tags/0.2.0/uspace/kbd/generic/key_buffer.c
0,0 → 1,114
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbdgen
* @brief HelenOS generic uspace keyboard handler.
* @ingroup kbd
* @{
*/
/** @file
*/
#include <key_buffer.h>
#include <futex.h>
 
atomic_t keybuffer_futex = FUTEX_INITIALIZER;
 
/** Clear key buffer.
*/
void keybuffer_free(keybuffer_t *keybuffer)
{
futex_down(&keybuffer_futex);
keybuffer->head = 0;
keybuffer->tail = 0;
keybuffer->items = 0;
futex_up(&keybuffer_futex);
}
 
/** Key buffer initialization.
*
*/
void keybuffer_init(keybuffer_t *keybuffer)
{
keybuffer_free(keybuffer);
}
 
/** Get free space in buffer.
* This function is useful for processing some scancodes that are translated
* to more than one character.
* @return empty buffer space
*/
int keybuffer_available(keybuffer_t *keybuffer)
{
return KEYBUFFER_SIZE - keybuffer->items;
}
 
/**
* @return nonzero, if buffer is not empty.
*/
int keybuffer_empty(keybuffer_t *keybuffer)
{
return (keybuffer->items == 0);
}
 
/** Push key to key buffer.
* If buffer is full, character is ignored.
* @param key code of stored key
*/
void keybuffer_push(keybuffer_t *keybuffer, int key)
{
futex_down(&keybuffer_futex);
if (keybuffer->items < KEYBUFFER_SIZE) {
keybuffer->fifo[keybuffer->tail] = key;
keybuffer->tail = (keybuffer->tail + 1) % KEYBUFFER_SIZE;
keybuffer->items++;
}
futex_up(&keybuffer_futex);
}
 
/** Pop character from buffer.
* @param c pointer to space where to store character from buffer.
* @return zero on empty buffer, nonzero else
*/
int keybuffer_pop(keybuffer_t *keybuffer, int *c)
{
futex_down(&keybuffer_futex);
if (keybuffer->items > 0) {
keybuffer->items--;
*c = (keybuffer->fifo[keybuffer->head]) ;
keybuffer->head = (keybuffer->head + 1) % KEYBUFFER_SIZE;
futex_up(&keybuffer_futex);
return 1;
}
futex_up(&keybuffer_futex);
return 0;
}
 
/**
* @}
*/
 
/tags/0.2.0/uspace/kbd/Makefile
0,0 → 1,82
#
# Copyright (C) 2005 Martin Decky
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
## Setup toolchain
#
 
LIBC_PREFIX = ../libc
SOFTINT_PREFIX = ../softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -Iinclude -I../libadt/include
 
LIBS = $(LIBC_PREFIX)/libc.a
 
## Sources
#
 
OUTPUT = kbd
GENERIC_SOURCES = \
generic/kbd.c \
generic/key_buffer.c
 
ARCH_SOURCES = \
arch/$(ARCH)/src/kbd.c
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
 
.PHONY: all clean depend disasm links
 
all: links $(OUTPUT) disasm
 
-include Makefile.depend
 
links:
ln -sfn ../arch/$(ARCH)/include include/arch
 
clean:
-rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend include/arch
 
depend:
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
 
%.o: %.S
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
 
%.o: %.s
$(AS) $(AFLAGS) $< -o $@
 
%.o: %.c
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@