Skip to content

Commit e9d82e2

Browse files
committed
[console] Add configurable scancode vs BIOS keyboard driver
1 parent d4099d0 commit e9d82e2

13 files changed

+114
-144
lines changed

elks/arch/i86/defconfig

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ CONFIG_BLK_DEV_CHAR=y
136136
CONFIG_CONSOLE_DIRECT=y
137137
# CONFIG_CONSOLE_BIOS is not set
138138
# CONFIG_CONSOLE_HEADLESS is not set
139+
CONFIG_KEYBOARD_SCANCODE=y
139140
# CONFIG_CONSOLE_SERIAL is not set
140141
CONFIG_EMUL_ANSI=y
141142
# CONFIG_EMUL_VT52 is not set

elks/arch/i86/drivers/char/Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,21 @@ ifdef CONFIG_CHAR_DEV_CGATEXT
4848
endif
4949

5050
ifdef CONFIG_CONSOLE_DIRECT
51-
OBJS += dircon.o xt_key.o
51+
OBJS += dircon.o
5252
endif
5353

5454
ifdef CONFIG_CONSOLE_BIOS
5555
OBJS += bioscon.o bioscon-asm.o
5656
endif
5757

5858
ifdef CONFIG_CONSOLE_HEADLESS
59-
OBJS += headless-bios.o bios-asm.o
59+
OBJS += headless-bios.o
60+
endif
61+
62+
ifdef CONFIG_KEYBOARD_SCANCODE
63+
OBJS += kbd-scancode.o
64+
else
65+
OBJS += kbd-bios.o bios-asm.o
6066
endif
6167

6268
endif # CONFIG_ARCH_SIBO

elks/arch/i86/drivers/char/bioscon.c

+1-75
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,9 @@
1212

1313
#include <linuxmt/types.h>
1414
#include <linuxmt/config.h>
15-
#include <linuxmt/errno.h>
16-
#include <linuxmt/fcntl.h>
17-
#include <linuxmt/fs.h>
18-
#include <linuxmt/kernel.h>
19-
#include <linuxmt/major.h>
2015
#include <linuxmt/mm.h>
21-
#include <linuxmt/timer.h>
22-
#include <linuxmt/sched.h>
2316
#include <linuxmt/chqueue.h>
2417
#include <linuxmt/ntty.h>
25-
#include <arch/io.h>
26-
#include <arch/segment.h>
2718
#include "console.h"
2819
#include "bioscon-asm.h"
2920

@@ -71,7 +62,6 @@ static Console Con[MAX_CONSOLES], *Visible;
7162
static Console *glock; /* Which console owns the graphics hardware */
7263
static int Width, MaxCol, Height, MaxRow;
7364
static unsigned short int NumConsoles = MAX_CONSOLES;
74-
static struct timer_list timer;
7565
static int kraw;
7666
static int Current_VCminor = 0;
7767

@@ -85,69 +75,6 @@ static int Current_VCminor = 0;
8575

8676
static void std_char(register Console *, char);
8777

88-
static void kbd_timer(int data);
89-
/*
90-
* Restart timer
91-
*/
92-
static void restart_timer(void)
93-
{
94-
init_timer(&timer);
95-
timer.tl_expires = jiffies + 8;
96-
timer.tl_function = kbd_timer;
97-
add_timer(&timer);
98-
}
99-
100-
/*
101-
* Bios Keyboard Decoder
102-
*/
103-
static void kbd_timer(int data)
104-
{
105-
int dav, extra = 0;
106-
107-
if ((dav = bios_kbd_poll())) {
108-
if (dav & 0xFF)
109-
Console_conin(dav & 0x7F);
110-
else {
111-
dav = (dav >> 8) & 0xFF;
112-
if (dav >= 0x3B && dav <= 0x3D) { /* temp console switch on F1-F3*/
113-
Console_set_vc(dav - 0x3B);
114-
dav = 0;
115-
}
116-
else if ((dav >= 0x68) && (dav < 0x6B)) { /* Change VC */
117-
Console_set_vc((unsigned)(dav - 0x68));
118-
dav = 0;
119-
}
120-
else if (dav >= 0x3B && dav < 0x45) /* Function keys */
121-
dav = dav - 0x3B + 'a';
122-
else {
123-
switch(dav) {
124-
case 0x48: dav = 'A'; break; /* up*/
125-
case 0x50: dav = 'B'; break; /* down*/
126-
case 0x4d: dav = 'C'; break; /* right*/
127-
case 0x4b: dav = 'D'; break; /* left*/
128-
case 0x47: dav = 'H'; break; /* home*/
129-
case 0x4f: dav = 'F'; break; /* end*/
130-
case 0x49: dav = '5'; extra = '~'; break; /* pgup*/
131-
case 0x51: dav = '6'; extra = '~'; break; /* pgdn*/
132-
default: dav = 0;
133-
}
134-
}
135-
if (dav) {
136-
Console_conin(ESC);
137-
#ifdef CONFIG_EMUL_ANSI
138-
Console_conin('[');
139-
#endif
140-
Console_conin(dav);
141-
#ifdef CONFIG_EMUL_ANSI
142-
if (extra)
143-
Console_conin(extra);
144-
#endif
145-
}
146-
}
147-
}
148-
restart_timer();
149-
}
150-
15178
static void PositionCursor(register Console * C)
15279
{
15380
int x, y, p;
@@ -276,8 +203,7 @@ void console_init(void)
276203
C++;
277204
}
278205

279-
enable_irq(1); /* enable BIOS Keyboard interrupts */
280-
restart_timer();
206+
kbd_init();
281207

282208
printk("BIOS console %ux%u"TERM_TYPE"(%u virtual consoles)\n",
283209
Width, Height, NumConsoles);

elks/arch/i86/drivers/char/config.in

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mainmenu_option next_comment
1010
"Direct CONFIG_CONSOLE_DIRECT \
1111
BIOS CONFIG_CONSOLE_BIOS \
1212
Headless CONFIG_CONSOLE_HEADLESS" Direct
13+
bool ' Scancode keyboard driver' CONFIG_KEYBOARD_SCANCODE y
1314
bool 'Serial Console' CONFIG_CONSOLE_SERIAL n
1415
if [[ "$CONFIG_CONSOLE_DIRECT" = "y" || "$CONFIG_CONSOLE_BIOS" = "y" ]]; then
1516
choice 'Console terminal emulation' \

elks/arch/i86/drivers/char/console.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ void Console_conin(unsigned char Key);
44
void Console_conout(dev_t dev, char Ch);
55
extern struct tty ttys[];
66

7+
void kbd_init(void);
8+
extern char kbd_name[];
9+
10+
void bell(void);
11+
712
/* for direct and bios consoles only*/
813
void Console_set_vc(unsigned int N);
9-
void kbd_init(void);

elks/arch/i86/drivers/char/dircon.c

+4-12
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@
1212

1313
#include <linuxmt/types.h>
1414
#include <linuxmt/config.h>
15-
#include <linuxmt/errno.h>
16-
#include <linuxmt/fcntl.h>
17-
#include <linuxmt/fs.h>
18-
#include <linuxmt/kernel.h>
19-
#include <linuxmt/major.h>
2015
#include <linuxmt/mm.h>
21-
#include <linuxmt/sched.h>
2216
#include <linuxmt/chqueue.h>
2317
#include <linuxmt/ntty.h>
24-
#include <linuxmt/kdev_t.h>
2518
#include <arch/io.h>
2619
#include "console.h"
2720

@@ -72,9 +65,8 @@ static void *CCBase;
7265
static int Width, MaxCol, Height, MaxRow;
7366
static unsigned short int NumConsoles = MAX_CONSOLES;
7467

75-
/* from xt_kbd.c */
76-
extern int Current_VCminor;
77-
extern int kraw;
68+
int Current_VCminor = 0;
69+
int kraw = 0;
7870

7971
#ifdef CONFIG_EMUL_ANSI
8072
#define TERM_TYPE " emulating ANSI "
@@ -228,6 +220,6 @@ void console_init(void)
228220

229221
kbd_init();
230222

231-
printk("Direct console %ux%u"TERM_TYPE"(%u virtual consoles)\n",
232-
Width, Height, NumConsoles);
223+
printk("Direct console, %s kbd %ux%u"TERM_TYPE"(%u virtual consoles)\n",
224+
kbd_name, Width, Height, NumConsoles);
233225
}

elks/arch/i86/drivers/char/headless-bios.c

+1-51
Original file line numberDiff line numberDiff line change
@@ -23,60 +23,10 @@
2323
#include "console.h"
2424
#include "bios-asm.h"
2525

26-
static void restart_timer(void);
27-
28-
/* called by scheduler to poll BIOS keyboard*/
29-
static void kbd_timer(int data)
30-
{
31-
int dav, extra;
32-
33-
if ((dav = bios_kbd_poll())) {
34-
if (dav & 0xFF)
35-
Console_conin(dav & 0x7F);
36-
else {
37-
dav = (dav >> 8) & 0xFF;
38-
if (dav >= 0x3B && dav < 0x45) /* Function keys */
39-
dav = dav - 0x3B + 'a';
40-
else {
41-
switch(dav) {
42-
case 0x48: dav = 'A'; break; /* up*/
43-
case 0x50: dav = 'B'; break; /* down*/
44-
case 0x4d: dav = 'C'; break; /* right*/
45-
case 0x4b: dav = 'D'; break; /* left*/
46-
case 0x47: dav = 'H'; break; /* home*/
47-
case 0x4f: dav = 'F'; break; /* end*/
48-
case 0x49: dav = '5'; extra = '~'; break; /* pgup*/
49-
case 0x51: dav = '6'; extra = '~'; break; /* pgdn*/
50-
default: dav = 0;
51-
}
52-
}
53-
if (dav) {
54-
Console_conin(033);
55-
Console_conin('[');
56-
Console_conin(dav);
57-
if (extra)
58-
Console_conin(extra);
59-
}
60-
}
61-
}
62-
restart_timer();
63-
}
64-
65-
/* initialize timer for scheduler*/
66-
static void restart_timer(void)
67-
{
68-
static struct timer_list timer;
69-
70-
init_timer(&timer);
71-
timer.tl_expires = jiffies + 8; /* every 8/100 second*/
72-
timer.tl_function = kbd_timer;
73-
add_timer(&timer);
74-
}
7526

7627
void console_init(void)
7728
{
78-
enable_irq(1); /* enable BIOS Keyboard interrupts */
79-
restart_timer();
29+
kbd_init();
8030
printk("Headless console\n");
8131
}
8232

elks/arch/i86/drivers/char/kbd-bios.c

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* BIOS polling keyboard
3+
*
4+
* INT 16h functions 0,1 (keyboard)
5+
*/
6+
#include <linuxmt/types.h>
7+
#include <linuxmt/config.h>
8+
#include <linuxmt/timer.h>
9+
#include <linuxmt/sched.h>
10+
#include "console.h"
11+
#include "bios-asm.h"
12+
13+
char kbd_name[] = "bios";
14+
15+
static void restart_timer(void);
16+
17+
/*
18+
* BIOS Keyboard Decoder
19+
*/
20+
static void kbd_timer(int data)
21+
{
22+
int dav, extra = 0;
23+
24+
if ((dav = bios_kbd_poll())) {
25+
if (dav & 0xFF)
26+
Console_conin(dav & 0x7F);
27+
else {
28+
dav = (dav >> 8) & 0xFF;
29+
#ifndef CONFIG_CONSOLE_HEADLESS
30+
if (dav >= 0x3B && dav <= 0x3D) { /* temp console switch on F1-F3*/
31+
Console_set_vc(dav - 0x3B);
32+
dav = 0;
33+
}
34+
else if ((dav >= 0x68) && (dav < 0x6B)) { /* Change VC */
35+
Console_set_vc((unsigned)(dav - 0x68));
36+
dav = 0;
37+
}
38+
else
39+
#endif
40+
if (dav >= 0x3B && dav < 0x45) /* Function keys */
41+
dav = dav - 0x3B + 'a';
42+
else {
43+
switch(dav) {
44+
case 0x48: dav = 'A'; break; /* up*/
45+
case 0x50: dav = 'B'; break; /* down*/
46+
case 0x4d: dav = 'C'; break; /* right*/
47+
case 0x4b: dav = 'D'; break; /* left*/
48+
case 0x47: dav = 'H'; break; /* home*/
49+
case 0x4f: dav = 'F'; break; /* end*/
50+
case 0x49: dav = '5'; extra = '~'; break; /* pgup*/
51+
case 0x51: dav = '6'; extra = '~'; break; /* pgdn*/
52+
default: dav = 0;
53+
}
54+
}
55+
if (dav) {
56+
Console_conin(033);
57+
#ifdef CONFIG_EMUL_ANSI
58+
Console_conin('[');
59+
#endif
60+
Console_conin(dav);
61+
#ifdef CONFIG_EMUL_ANSI
62+
if (extra)
63+
Console_conin(extra);
64+
#endif
65+
}
66+
}
67+
}
68+
restart_timer();
69+
}
70+
71+
static void restart_timer(void)
72+
{
73+
static struct timer_list timer;
74+
75+
init_timer(&timer);
76+
timer.tl_expires = jiffies + 8; /* every 8/100 second*/
77+
timer.tl_function = kbd_timer;
78+
add_timer(&timer);
79+
}
80+
81+
82+
void kbd_init(void)
83+
{
84+
enable_irq(1); /* enable BIOS Keyboard interrupts */
85+
restart_timer();
86+
}

elks/arch/i86/drivers/char/xt_key.c renamed to elks/arch/i86/drivers/char/kbd-scancode.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ static int kb_read(void);
4747
#define SCAN_F1 0x3B /* scan code for F1 key*/
4848
#define SCAN_KP7 0x47 /* scan code for Keypad 7 key*/
4949

50+
char kbd_name[] = "scan";
51+
5052
/*
5153
* Include the relevant keymap.
5254
*/
5355
#include "KeyMaps/keymaps.h"
5456

55-
int Current_VCminor = 0;
56-
int kraw = 0;
57+
extern int kraw;
5758
/*
5859
* Keyboard state - the poor little keyboard controller hasnt
5960
* got the brains to remember itself.

emu86-disk.config

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ CONFIG_BLK_DEV_CHAR=y
101101
# CONFIG_CONSOLE_DIRECT is not set
102102
# CONFIG_CONSOLE_BIOS is not set
103103
CONFIG_CONSOLE_HEADLESS=y
104+
# CONFIG_KEYBOARD_SCANCODE is not set
104105
# CONFIG_CONSOLE_SERIAL is not set
105106
CONFIG_CHAR_DEV_RS=y
106107
CONFIG_CHAR_DEV_LP=y

emu86-rom-full.config

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ CONFIG_BLK_DEV_CHAR=y
119119
# CONFIG_CONSOLE_DIRECT is not set
120120
# CONFIG_CONSOLE_BIOS is not set
121121
CONFIG_CONSOLE_HEADLESS=y
122+
# CONFIG_KEYBOARD_SCANCODE is not set
122123
# CONFIG_CONSOLE_SERIAL is not set
123124
# CONFIG_CHAR_DEV_RS is not set
124125
# CONFIG_CHAR_DEV_LP is not set

emu86-rom.config

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ CONFIG_BLK_DEV_CHAR=y
114114
# CONFIG_CONSOLE_DIRECT is not set
115115
# CONFIG_CONSOLE_BIOS is not set
116116
CONFIG_CONSOLE_HEADLESS=y
117+
# CONFIG_KEYBOARD_SCANCODE is not set
117118
# CONFIG_CONSOLE_SERIAL is not set
118119
# CONFIG_CHAR_DEV_RS is not set
119120
# CONFIG_CHAR_DEV_LP is not set

emu86.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exec emu86 -w 0xe0000 -f elks/arch/i86/boot/Image -w 0x80000 -f image/romfs.bin
1717
# ELKS must be configured minimaly with 'cp emu86-rom-full.config .config'
1818
# This adds MINIX/FAT filesytems with BIOS driver
1919

20-
exec /emu86 -w 0xe0000 -f elks/arch/i86/boot/Image -w 0x80000 -f image/romfs.bin -I image/fd1440.bin ${1+"$@"}
20+
exec emu86 -w 0xe0000 -f elks/arch/i86/boot/Image -w 0x80000 -f image/romfs.bin -I image/fd1440.bin ${1+"$@"}
2121

2222
# For ELKS disk image Configuration:
2323
# ELKS must be configured with 'cp emu86-disk.config .config'

0 commit comments

Comments
 (0)