Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[console] Add configurable scancode vs BIOS keyboard driver #933

Merged
merged 1 commit into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions elks/arch/i86/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ CONFIG_BLK_DEV_CHAR=y
CONFIG_CONSOLE_DIRECT=y
# CONFIG_CONSOLE_BIOS is not set
# CONFIG_CONSOLE_HEADLESS is not set
CONFIG_KEYBOARD_SCANCODE=y
# CONFIG_CONSOLE_SERIAL is not set
CONFIG_EMUL_ANSI=y
# CONFIG_EMUL_VT52 is not set
Expand Down
10 changes: 8 additions & 2 deletions elks/arch/i86/drivers/char/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ ifdef CONFIG_CHAR_DEV_CGATEXT
endif

ifdef CONFIG_CONSOLE_DIRECT
OBJS += dircon.o xt_key.o
OBJS += dircon.o
endif

ifdef CONFIG_CONSOLE_BIOS
OBJS += bioscon.o bioscon-asm.o
endif

ifdef CONFIG_CONSOLE_HEADLESS
OBJS += headless-bios.o bios-asm.o
OBJS += headless-bios.o
endif

ifdef CONFIG_KEYBOARD_SCANCODE
OBJS += kbd-scancode.o
else
OBJS += kbd-bios.o bios-asm.o
endif

endif # CONFIG_ARCH_SIBO
Expand Down
76 changes: 1 addition & 75 deletions elks/arch/i86/drivers/char/bioscon.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,9 @@

#include <linuxmt/types.h>
#include <linuxmt/config.h>
#include <linuxmt/errno.h>
#include <linuxmt/fcntl.h>
#include <linuxmt/fs.h>
#include <linuxmt/kernel.h>
#include <linuxmt/major.h>
#include <linuxmt/mm.h>
#include <linuxmt/timer.h>
#include <linuxmt/sched.h>
#include <linuxmt/chqueue.h>
#include <linuxmt/ntty.h>
#include <arch/io.h>
#include <arch/segment.h>
#include "console.h"
#include "bioscon-asm.h"

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

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

static void std_char(register Console *, char);

static void kbd_timer(int data);
/*
* Restart timer
*/
static void restart_timer(void)
{
init_timer(&timer);
timer.tl_expires = jiffies + 8;
timer.tl_function = kbd_timer;
add_timer(&timer);
}

/*
* Bios Keyboard Decoder
*/
static void kbd_timer(int data)
{
int dav, extra = 0;

if ((dav = bios_kbd_poll())) {
if (dav & 0xFF)
Console_conin(dav & 0x7F);
else {
dav = (dav >> 8) & 0xFF;
if (dav >= 0x3B && dav <= 0x3D) { /* temp console switch on F1-F3*/
Console_set_vc(dav - 0x3B);
dav = 0;
}
else if ((dav >= 0x68) && (dav < 0x6B)) { /* Change VC */
Console_set_vc((unsigned)(dav - 0x68));
dav = 0;
}
else if (dav >= 0x3B && dav < 0x45) /* Function keys */
dav = dav - 0x3B + 'a';
else {
switch(dav) {
case 0x48: dav = 'A'; break; /* up*/
case 0x50: dav = 'B'; break; /* down*/
case 0x4d: dav = 'C'; break; /* right*/
case 0x4b: dav = 'D'; break; /* left*/
case 0x47: dav = 'H'; break; /* home*/
case 0x4f: dav = 'F'; break; /* end*/
case 0x49: dav = '5'; extra = '~'; break; /* pgup*/
case 0x51: dav = '6'; extra = '~'; break; /* pgdn*/
default: dav = 0;
}
}
if (dav) {
Console_conin(ESC);
#ifdef CONFIG_EMUL_ANSI
Console_conin('[');
#endif
Console_conin(dav);
#ifdef CONFIG_EMUL_ANSI
if (extra)
Console_conin(extra);
#endif
}
}
}
restart_timer();
}

static void PositionCursor(register Console * C)
{
int x, y, p;
Expand Down Expand Up @@ -276,8 +203,7 @@ void console_init(void)
C++;
}

enable_irq(1); /* enable BIOS Keyboard interrupts */
restart_timer();
kbd_init();

printk("BIOS console %ux%u"TERM_TYPE"(%u virtual consoles)\n",
Width, Height, NumConsoles);
Expand Down
1 change: 1 addition & 0 deletions elks/arch/i86/drivers/char/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mainmenu_option next_comment
"Direct CONFIG_CONSOLE_DIRECT \
BIOS CONFIG_CONSOLE_BIOS \
Headless CONFIG_CONSOLE_HEADLESS" Direct
bool ' Scancode keyboard driver' CONFIG_KEYBOARD_SCANCODE y
bool 'Serial Console' CONFIG_CONSOLE_SERIAL n
if [[ "$CONFIG_CONSOLE_DIRECT" = "y" || "$CONFIG_CONSOLE_BIOS" = "y" ]]; then
choice 'Console terminal emulation' \
Expand Down
6 changes: 5 additions & 1 deletion elks/arch/i86/drivers/char/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ void Console_conin(unsigned char Key);
void Console_conout(dev_t dev, char Ch);
extern struct tty ttys[];

void kbd_init(void);
extern char kbd_name[];

void bell(void);

/* for direct and bios consoles only*/
void Console_set_vc(unsigned int N);
void kbd_init(void);
16 changes: 4 additions & 12 deletions elks/arch/i86/drivers/char/dircon.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@

#include <linuxmt/types.h>
#include <linuxmt/config.h>
#include <linuxmt/errno.h>
#include <linuxmt/fcntl.h>
#include <linuxmt/fs.h>
#include <linuxmt/kernel.h>
#include <linuxmt/major.h>
#include <linuxmt/mm.h>
#include <linuxmt/sched.h>
#include <linuxmt/chqueue.h>
#include <linuxmt/ntty.h>
#include <linuxmt/kdev_t.h>
#include <arch/io.h>
#include "console.h"

Expand Down Expand Up @@ -72,9 +65,8 @@ static void *CCBase;
static int Width, MaxCol, Height, MaxRow;
static unsigned short int NumConsoles = MAX_CONSOLES;

/* from xt_kbd.c */
extern int Current_VCminor;
extern int kraw;
int Current_VCminor = 0;
int kraw = 0;

#ifdef CONFIG_EMUL_ANSI
#define TERM_TYPE " emulating ANSI "
Expand Down Expand Up @@ -228,6 +220,6 @@ void console_init(void)

kbd_init();

printk("Direct console %ux%u"TERM_TYPE"(%u virtual consoles)\n",
Width, Height, NumConsoles);
printk("Direct console, %s kbd %ux%u"TERM_TYPE"(%u virtual consoles)\n",
kbd_name, Width, Height, NumConsoles);
}
52 changes: 1 addition & 51 deletions elks/arch/i86/drivers/char/headless-bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,10 @@
#include "console.h"
#include "bios-asm.h"

static void restart_timer(void);

/* called by scheduler to poll BIOS keyboard*/
static void kbd_timer(int data)
{
int dav, extra;

if ((dav = bios_kbd_poll())) {
if (dav & 0xFF)
Console_conin(dav & 0x7F);
else {
dav = (dav >> 8) & 0xFF;
if (dav >= 0x3B && dav < 0x45) /* Function keys */
dav = dav - 0x3B + 'a';
else {
switch(dav) {
case 0x48: dav = 'A'; break; /* up*/
case 0x50: dav = 'B'; break; /* down*/
case 0x4d: dav = 'C'; break; /* right*/
case 0x4b: dav = 'D'; break; /* left*/
case 0x47: dav = 'H'; break; /* home*/
case 0x4f: dav = 'F'; break; /* end*/
case 0x49: dav = '5'; extra = '~'; break; /* pgup*/
case 0x51: dav = '6'; extra = '~'; break; /* pgdn*/
default: dav = 0;
}
}
if (dav) {
Console_conin(033);
Console_conin('[');
Console_conin(dav);
if (extra)
Console_conin(extra);
}
}
}
restart_timer();
}

/* initialize timer for scheduler*/
static void restart_timer(void)
{
static struct timer_list timer;

init_timer(&timer);
timer.tl_expires = jiffies + 8; /* every 8/100 second*/
timer.tl_function = kbd_timer;
add_timer(&timer);
}

void console_init(void)
{
enable_irq(1); /* enable BIOS Keyboard interrupts */
restart_timer();
kbd_init();
printk("Headless console\n");
}

Expand Down
86 changes: 86 additions & 0 deletions elks/arch/i86/drivers/char/kbd-bios.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* BIOS polling keyboard
*
* INT 16h functions 0,1 (keyboard)
*/
#include <linuxmt/types.h>
#include <linuxmt/config.h>
#include <linuxmt/timer.h>
#include <linuxmt/sched.h>
#include "console.h"
#include "bios-asm.h"

char kbd_name[] = "bios";

static void restart_timer(void);

/*
* BIOS Keyboard Decoder
*/
static void kbd_timer(int data)
{
int dav, extra = 0;

if ((dav = bios_kbd_poll())) {
if (dav & 0xFF)
Console_conin(dav & 0x7F);
else {
dav = (dav >> 8) & 0xFF;
#ifndef CONFIG_CONSOLE_HEADLESS
if (dav >= 0x3B && dav <= 0x3D) { /* temp console switch on F1-F3*/
Console_set_vc(dav - 0x3B);
dav = 0;
}
else if ((dav >= 0x68) && (dav < 0x6B)) { /* Change VC */
Console_set_vc((unsigned)(dav - 0x68));
dav = 0;
}
else
#endif
if (dav >= 0x3B && dav < 0x45) /* Function keys */
dav = dav - 0x3B + 'a';
else {
switch(dav) {
case 0x48: dav = 'A'; break; /* up*/
case 0x50: dav = 'B'; break; /* down*/
case 0x4d: dav = 'C'; break; /* right*/
case 0x4b: dav = 'D'; break; /* left*/
case 0x47: dav = 'H'; break; /* home*/
case 0x4f: dav = 'F'; break; /* end*/
case 0x49: dav = '5'; extra = '~'; break; /* pgup*/
case 0x51: dav = '6'; extra = '~'; break; /* pgdn*/
default: dav = 0;
}
}
if (dav) {
Console_conin(033);
#ifdef CONFIG_EMUL_ANSI
Console_conin('[');
#endif
Console_conin(dav);
#ifdef CONFIG_EMUL_ANSI
if (extra)
Console_conin(extra);
#endif
}
}
}
restart_timer();
}

static void restart_timer(void)
{
static struct timer_list timer;

init_timer(&timer);
timer.tl_expires = jiffies + 8; /* every 8/100 second*/
timer.tl_function = kbd_timer;
add_timer(&timer);
}


void kbd_init(void)
{
enable_irq(1); /* enable BIOS Keyboard interrupts */
restart_timer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ static int kb_read(void);
#define SCAN_F1 0x3B /* scan code for F1 key*/
#define SCAN_KP7 0x47 /* scan code for Keypad 7 key*/

char kbd_name[] = "scan";

/*
* Include the relevant keymap.
*/
#include "KeyMaps/keymaps.h"

int Current_VCminor = 0;
int kraw = 0;
extern int kraw;
/*
* Keyboard state - the poor little keyboard controller hasnt
* got the brains to remember itself.
Expand Down
1 change: 1 addition & 0 deletions emu86-disk.config
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ CONFIG_BLK_DEV_CHAR=y
# CONFIG_CONSOLE_DIRECT is not set
# CONFIG_CONSOLE_BIOS is not set
CONFIG_CONSOLE_HEADLESS=y
# CONFIG_KEYBOARD_SCANCODE is not set
# CONFIG_CONSOLE_SERIAL is not set
CONFIG_CHAR_DEV_RS=y
CONFIG_CHAR_DEV_LP=y
Expand Down
1 change: 1 addition & 0 deletions emu86-rom-full.config
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ CONFIG_BLK_DEV_CHAR=y
# CONFIG_CONSOLE_DIRECT is not set
# CONFIG_CONSOLE_BIOS is not set
CONFIG_CONSOLE_HEADLESS=y
# CONFIG_KEYBOARD_SCANCODE is not set
# CONFIG_CONSOLE_SERIAL is not set
# CONFIG_CHAR_DEV_RS is not set
# CONFIG_CHAR_DEV_LP is not set
Expand Down
1 change: 1 addition & 0 deletions emu86-rom.config
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ CONFIG_BLK_DEV_CHAR=y
# CONFIG_CONSOLE_DIRECT is not set
# CONFIG_CONSOLE_BIOS is not set
CONFIG_CONSOLE_HEADLESS=y
# CONFIG_KEYBOARD_SCANCODE is not set
# CONFIG_CONSOLE_SERIAL is not set
# CONFIG_CHAR_DEV_RS is not set
# CONFIG_CHAR_DEV_LP is not set
Expand Down
2 changes: 1 addition & 1 deletion emu86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exec emu86 -w 0xe0000 -f elks/arch/i86/boot/Image -w 0x80000 -f image/romfs.bin
# ELKS must be configured minimaly with 'cp emu86-rom-full.config .config'
# This adds MINIX/FAT filesytems with BIOS driver

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

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