aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-07-22 22:25:28 +0200
committerMarvin Borner2020-07-22 22:25:28 +0200
commite7662496ad331266b8fcc0df514523f97cb703e4 (patch)
tree52a7bc6e0d37e051abdbd3f529e7967a1c18ef50
parent6f0f8d26d2710e24192e56e85ecb5fc2b7f54da7 (diff)
Initial keyboard implementation
-rw-r--r--Makefile1
-rw-r--r--src/drivers/interrupts.c10
-rw-r--r--src/drivers/keyboard.c43
-rw-r--r--src/inc/keyboard.h8
-rw-r--r--src/main.c2
5 files changed, 61 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 29217ea..9c172f4 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ COBJS = src/main.o \
src/drivers/cpu.o \
src/drivers/serial.o \
src/drivers/interrupts.o \
+ src/drivers/keyboard.o \
src/lib/string.o
CC = cross/opt/bin/i686-elf-gcc
LD = cross/opt/bin/i686-elf-ld
diff --git a/src/drivers/interrupts.c b/src/drivers/interrupts.c
index 23cbf72..bd20911 100644
--- a/src/drivers/interrupts.c
+++ b/src/drivers/interrupts.c
@@ -28,7 +28,7 @@ void idt_install()
idt_ptr.limit = (sizeof(struct idt_entry) * 256) - 1;
idt_ptr.base = &idt;
- // Clear IDT by setting memory cells to 0
+ // Clear IDT by setting memory cells to 0 // TODO
//memset(&idt, 0, sizeof(struct idt_entry) * 256);
__asm__("lidt %0" : : "m"(idt_ptr));
@@ -70,6 +70,7 @@ void irq_remap()
// Handle IRQ ISRs
__attribute__((interrupt)) void irq_handler(struct regs *r)
{
+ __asm__("cli");
void (*handler)(struct regs * r);
// Execute custom handler if exists
@@ -83,6 +84,7 @@ __attribute__((interrupt)) void irq_handler(struct regs *r)
// Send EOI to master PIC
outb(0x20, 0x20);
+ __asm__("sti");
}
// Map ISRs to the correct entries in the IDT
@@ -111,18 +113,20 @@ void isr_uninstall_handler(int isr)
__attribute__((interrupt)) void isr_handler(struct regs *r)
{
+ __asm__("cli");
void (*handler)(struct regs * r);
// Execute fault handler if exists
handler = isr_routines[r->int_no];
if (handler) {
handler(r);
- } else {
- serial_print("Got ISR!\n");
+ } else if (r->int_no <= 32) {
+ serial_print("Exception, halting!\n");
__asm__("cli");
while (1) {
};
}
+ __asm__("sti");
}
void isr_install()
diff --git a/src/drivers/keyboard.c b/src/drivers/keyboard.c
new file mode 100644
index 0000000..85b905e
--- /dev/null
+++ b/src/drivers/keyboard.c
@@ -0,0 +1,43 @@
+#include <cpu.h>
+#include <def.h>
+#include <interrupts.h>
+#include <serial.h>
+#include <vesa.h>
+
+u8 scancode;
+
+void keyboard_handler(struct regs *r)
+{
+ scancode = inb(0x60);
+ serial_print("KEY\n");
+ //struct keyboard_event *event = malloc(sizeof(struct keyboard_event));
+ //event->scancode = scancode;
+ //event_trigger(MAP_KEYBOARD, (u8 *)event);
+}
+
+void keyboard_acknowledge()
+{
+ while (inb(0x60) != 0xfa)
+ ;
+}
+
+void keyboard_rate()
+{
+ outb(0x60, 0xF3);
+ keyboard_acknowledge();
+ outb(0x60, 0x0); // Rate{00000} Delay{00} 0
+}
+
+char wait_scancode()
+{
+ scancode = 0;
+ while (scancode == 0) {
+ };
+ return scancode;
+}
+
+void keyboard_install()
+{
+ //keyboard_rate(); TODO: Fix keyboard rate?
+ irq_install_handler(1, keyboard_handler);
+}
diff --git a/src/inc/keyboard.h b/src/inc/keyboard.h
new file mode 100644
index 0000000..f0effc7
--- /dev/null
+++ b/src/inc/keyboard.h
@@ -0,0 +1,8 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef KEYBOARD_H
+#define KEYBOARD_H
+
+void keyboard_install();
+
+#endif
diff --git a/src/main.c b/src/main.c
index b873791..947c0e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,7 @@
#include <boot.h>
#include <def.h>
#include <interrupts.h>
+#include <keyboard.h>
#include <serial.h>
#include <vesa.h>
@@ -13,6 +14,7 @@ void main(struct mem_info *mem_info, struct vid_info *vid_info)
{
HEAP_START = HEAP; // For malloc function
interrupts_install();
+ keyboard_install();
mem_info++; // TODO: Use the mmap (or remove)!
vbe = vid_info->info;