keyboard irq

This commit is contained in:
Jack Halford 2019-05-11 14:52:00 +02:00
parent 14ff4db74a
commit 0273c9a8c8
5 changed files with 108 additions and 6 deletions

View file

@ -5,6 +5,7 @@ slowly porting from rust.
### features ### features
- vga frame buffer - vga frame buffer
- ps2 keyboard driver
- interrupts - interrupts
- todo: terminal console - todo: terminal console
- todo: memory mapping - todo: memory mapping

5
run.sh
View file

@ -5,6 +5,7 @@ KERNEL=build/bzImage
qemu() { qemu() {
start() { start() {
killqemu
sudo qemu-system-i386\ sudo qemu-system-i386\
-kernel ${KERNEL}\ -kernel ${KERNEL}\
-gdb tcp::${QEMU_GDB_PORT}\ -gdb tcp::${QEMU_GDB_PORT}\
@ -18,6 +19,10 @@ qemu() {
sudo ${QEMU_MONITOR} sudo ${QEMU_MONITOR}
} }
killqemu() {
sudo pkill -9 qemu
}
reload() { reload() {
echo "stop" | ${QEMU_MONITOR} &>/dev/null echo "stop" | ${QEMU_MONITOR} &>/dev/null
echo "change ide1-cd0 ${KERNEL}" | ${QEMU_MONITOR} &>/dev/null echo "change ide1-cd0 ${KERNEL}" | ${QEMU_MONITOR} &>/dev/null

View file

@ -7,7 +7,8 @@ SECTIONS {
. = 0xb8000; . = 0xb8000;
. += 80 * 25 * 2; . += 80 * 25 * 2;
. = 1M; . = 0x100000;
/* ensure that the multiboot header is at the beginning */ /* ensure that the multiboot header is at the beginning */
.multiboot : .multiboot :
{ {

View file

@ -1,15 +1,18 @@
const interrupt = @import("arch/x86/interrupt.zig"); const interrupt = @import("arch/x86/interrupt.zig");
const x86 = @import("arch/x86/lib/index.zig");
const ps2 = @import("ps2.zig");
use @import("vga.zig"); use @import("vga.zig");
var vga = VGA.init(VRAM_ADDR); var vga = VGA.init(VRAM_ADDR);
pub fn keyboard_handler() void { pub fn keypress(char: u8) void {
vga.writeString("hello"); vga.writeChar(char);
if (char == '\n')
vga.writeString("> ");
} }
pub fn initialize() void { pub fn initialize() void {
vga.clear(); vga.clear();
vga.writeString("zzzzzzzzzzzzzzzz"); vga.writeString("> ");
interrupt.registerIRQ(1, keyboard_handler); interrupt.registerIRQ(1, ps2.keyboard_handler);
vga.writeString("aaaa");
} }

92
src/ps2.zig Normal file
View file

@ -0,0 +1,92 @@
const x86 = @import("arch/x86/lib/index.zig");
const console = @import("console.zig");
const PS2_DATA = 0x60;
const PS2_STATUS = 0x64;
const KEYMAP_MAX = 59;
const KEYMAP_US = [][2]u8{
"\x00\x00",
"\x00\x00", //escape
"1!",
"2@",
"3#",
"4$",
"5%",
"6^",
"7&",
"8*",
"9(",
"0)",
"-_",
"=+",
"\x00\x00", //backspace
"\x00\x00", //tab
"qQ",
"wW",
"eE",
"rR",
"tT",
"yY",
"uU",
"iI",
"oO",
"pP",
"[{",
"]}",
"\n\n",
"\x00\x00", //left_control
"aA",
"sS",
"dD",
"fF",
"gG",
"hH",
"jJ",
"kK",
"lL",
";:",
"'\"",
"`~",
"\x00\x00", //left shift
"\\|",
"zZ",
"xX",
"cC",
"vV",
"bB",
"nN",
"mM",
",<",
".>",
"/?",
"\x00\x00", //right shift
"**",
"\x00\x00", //left alt
" ",
"\x00\x00", //capslock
};
fn ps2_scancode() u8 {
var scancode: u8 = 0;
while (true) {
if (x86.inb(PS2_DATA) != scancode) {
scancode = x86.inb(PS2_DATA);
if (scancode > 0)
return scancode;
}
}
}
fn key_isrelease(scancode: u8) bool {
return (scancode & 1 << 7 != 0);
}
pub fn keyboard_handler() void {
const scancode = ps2_scancode();
const isrelease = key_isrelease(scancode);
if (isrelease) {
return;
}
const shift = false;
console.keypress(KEYMAP_US[scancode][if (shift) 1 else 0]);
}