diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | devices/Makefile | 2 | ||||
-rw-r--r-- | devices/i8042.c | 53 | ||||
-rw-r--r-- | devices/keyboard.h | 2 | ||||
-rw-r--r-- | devices/pckbd.c | 3 | ||||
-rw-r--r-- | devices/ps2_controller.h (renamed from devices/ps2_ctrl.h) | 0 | ||||
-rw-r--r-- | devices/ps2_ctrl_8042.c | 43 | ||||
-rw-r--r-- | grub/grub.cfg | 2 | ||||
-rw-r--r-- | src/kernel.c | 7 |
9 files changed, 66 insertions, 51 deletions
@@ -3,7 +3,7 @@ MAKEFLAGS += --no-print-directory include Makefile.config -.PHONY: all run clean FORCE +.PHONY: all run clean test FORCE all: glitch.elf run: glitch.iso @@ -24,6 +24,9 @@ info: @echo " LD $(shell ${LD} --version | head -n1)" @echo " ${LDFLAGS}" +test: + grep -r 'asm' devices lib src + FORCE: .config: Kconfig diff --git a/devices/Makefile b/devices/Makefile index 4ee04ca..62a0b88 100644 --- a/devices/Makefile +++ b/devices/Makefile @@ -2,7 +2,7 @@ include ../Makefile.config CCFLAGS += -I. -I../${ARCH} -I../lib -devs,SRCS = pic_8259.c uart_16550.c vga.c ps2_ctrl_8042.c pckbd.c mouse.c +devs,SRCS = pic_8259.c uart_16550.c vga.c i8042.c pckbd.c mouse.c include ../rules.mk diff --git a/devices/i8042.c b/devices/i8042.c new file mode 100644 index 0000000..cf8c6ec --- /dev/null +++ b/devices/i8042.c @@ -0,0 +1,53 @@ +/* + * https://wiki.osdev.org/%228042%22_PS/2_Controller + */ + +#include "keyboard.h" +#include "ps2_controller.h" +#include <stdint.h> +#include <stdio.h> +#include <sys/io.h> + +// r status register +// w command register +#define comm_port 0x64 +#define comm_enable_first_ps2 0xae +#define comm_read_ctrl_config 0x20 +#define comm_write_ctrl_config 0x60 + +#define data_port 0x60 +#define data_enable_scanning 0xf4 + +void +ps2_ctrl_init() +{ + // eat all previous keystrikes + while (inb(comm_port) & 0x1) inb(data_port); + + uint8_t test; + outb(0xaa, comm_port); + test = inb(data_port); + printf("i8042: self test 0xaa:%x %s\n", test, test == 0x55 ? "ok" : "failed"); + outb(0xab, comm_port); + test = inb(data_port); + printf("i8042: port1 test 0xab:%x %s\n", test, test == 0x00 ? "ok" : "failed"); + outb(0xa9, comm_port); + test = inb(data_port); + printf("i8042: port2 test 0xa9:%x %s\n", test, test == 0x00 ? "ok" : "failed"); + + // printf("8042: init keyboard\n"); + + outb(comm_enable_first_ps2, comm_port); + outb(comm_read_ctrl_config, comm_port); + const uint8_t conf = (inb(data_port) | 1) & ~0x10; + outb(comm_write_ctrl_config, comm_port); + + outb(conf, data_port); + outb(data_enable_scanning, data_port); +} + +unsigned char +kbd_read_next() +{ + return inb(data_port); +} diff --git a/devices/keyboard.h b/devices/keyboard.h index 5f4fcc2..2375552 100644 --- a/devices/keyboard.h +++ b/devices/keyboard.h @@ -2,3 +2,5 @@ void ps2_keyboard_init(); void ps2_keyboard_irq_handler(); + +unsigned char kbd_read_next(); diff --git a/devices/pckbd.c b/devices/pckbd.c index f3dcb6c..916e8e6 100644 --- a/devices/pckbd.c +++ b/devices/pckbd.c @@ -1,5 +1,4 @@ #include "keyboard.h" -#include "ps2_ctrl.h" #include "vga.h" #include <stdint.h> #include <stdio.h> @@ -24,7 +23,7 @@ ps2_keyboard_init() void ps2_keyboard_irq_handler() { - const uint8_t key = ps2_ctrl_read(); + const uint8_t key = kbd_read_next(); switch (key) { case 0x2a: // left shift down diff --git a/devices/ps2_ctrl.h b/devices/ps2_controller.h index 9bed4f2..9bed4f2 100644 --- a/devices/ps2_ctrl.h +++ b/devices/ps2_controller.h diff --git a/devices/ps2_ctrl_8042.c b/devices/ps2_ctrl_8042.c deleted file mode 100644 index 4157bd8..0000000 --- a/devices/ps2_ctrl_8042.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "ps2_ctrl.h" -#include <stdint.h> -#include <stdio.h> -#include <sys/io.h> - -const uint8_t comm_port = 0x64; // r status register - // w command register -const uint8_t comm_enable_first_ps2 = 0xae; -const uint8_t comm_read_ctrl_config = 0x20; -const uint8_t comm_write_ctrl_config = 0x60; - -const uint8_t data_port = 0x60; // rw -const uint8_t data_enable_scanning = 0xf4; - -void -ps2_ctrl_init() -{ - // eat all previous keystrikes - while (inb(comm_port) & 0x1) inb(data_port); - - outb(0x64, 0xaa); - printf("8042: self test 0xaa: %x\n", inb(0x60)); - outb(0x64, 0xab); - printf("8042: port1 test 0xab: %x\n", inb(0x60)); - outb(0x64, 0xa9); - printf("8042: port2 test 0xa9: %x\n", inb(0x60)); - - // printf("8042: init keyboard\n"); - - outb(comm_port, comm_enable_first_ps2); - outb(comm_port, comm_read_ctrl_config); - const uint8_t conf = (inb(data_port) | 1) & ~0x10; - outb(comm_port, comm_write_ctrl_config); - outb(data_port, conf); - outb(data_port, data_enable_scanning); - -} - -unsigned char -ps2_ctrl_read() -{ - return inb(0x60); -} diff --git a/grub/grub.cfg b/grub/grub.cfg index 5307624..bd7c5fb 100644 --- a/grub/grub.cfg +++ b/grub/grub.cfg @@ -1,4 +1,4 @@ -set timeout=1 +set timeout=0 set default=0 menuentry "glitch" { diff --git a/src/kernel.c b/src/kernel.c index 5305b12..a9c54fe 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -7,7 +7,7 @@ #include "devices/keyboard.h" #include "devices/mouse.h" #include "devices/pic.h" -#include "devices/ps2_ctrl.h" +#include "devices/ps2_controller.h" #include "devices/uart_16550.h" #include "devices/vga.h" #include "mem.h" @@ -30,13 +30,14 @@ void kmain() { } pic_init(); - pic_enable(); - printf("interrupts enabled\n"); ps2_ctrl_init(); ps2_keyboard_init(); // mouse_init(); + pic_enable(); + printf("interrupts enabled\n"); + /* alloc4M(); char *c = (char *)0xc0700000; |