aboutsummaryrefslogtreecommitdiff
path: root/i686
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-10-31 15:39:51 +0200
committeraqua <aqua@iserlohn-fortress.net>2022-10-31 21:59:49 +0200
commitcbd3cdf7cb34529e269bb27c654765a0c9c21799 (patch)
tree4ee555d5cb575af003e10e597666b4a7b17b17a7 /i686
parentmakefile: auto-generate OBJS from SRCS (diff)
downloadkernel-cbd3cdf7cb34529e269bb27c654765a0c9c21799.tar.xz
add ps2_keyboard driver
Diffstat (limited to 'i686')
-rw-r--r--i686/Makefile4
-rw-r--r--i686/idt.h8
-rw-r--r--i686/init.s2
-rw-r--r--i686/isr.c42
-rw-r--r--i686/lidt.c12
5 files changed, 61 insertions, 7 deletions
diff --git a/i686/Makefile b/i686/Makefile
index e77f1c6..d472ebe 100644
--- a/i686/Makefile
+++ b/i686/Makefile
@@ -1,12 +1,12 @@
include ../${ARCH}/toolchain.mk
-CCFLAGS += -I../grub/include
+CCFLAGS += -I../grub/include -I../lib
all: arch.a
arch,SRCS = boot.S init.s \
gdt.c lgdt.c \
- lidt.c
+ lidt.c isr.c
include ../rules.mk
diff --git a/i686/idt.h b/i686/idt.h
index 22dc6de..f96e2b1 100644
--- a/i686/idt.h
+++ b/i686/idt.h
@@ -10,9 +10,13 @@ struct interrupt_frame {
uint32_t ss;
};
+// typedef void (*irq_handler)();
+
+/* isr.c */
void abort_handler(struct interrupt_frame *frame);
-void interrupt_handler(struct interrupt_frame *frame);
-void interrupt_handler_e(struct interrupt_frame *frame, uint32_t error);
void syscall_handler(struct interrupt_frame *frame);
+void irq0x00(struct interrupt_frame *frame); // timer interrupt
+void irq0x01(struct interrupt_frame *frame); // keyboard interrupt
+/* lidt.c */
void idt_install();
diff --git a/i686/init.s b/i686/init.s
index c0c25c0..d16de51 100644
--- a/i686/init.s
+++ b/i686/init.s
@@ -37,9 +37,9 @@ k_init:
mov $k_stack, %esp # point stack pointer to the stack
# hardware init
- call pic_init # Programmable Interrupt Controller
call gdt_install # Global Descriptor Table
call idt_install # Interrupt Descriptor Table
+ call pic_init # Programmable Interrupt Controller
# jump into kernel
call kmain
diff --git a/i686/isr.c b/i686/isr.c
new file mode 100644
index 0000000..4f6729b
--- /dev/null
+++ b/i686/isr.c
@@ -0,0 +1,42 @@
+/*
+ * Interrupt Service Routines
+ */
+
+#include "idt.h"
+#include "sys/control.h"
+#include <stdio.h>
+
+__attribute__((interrupt)) void
+abort_handler(struct interrupt_frame *frame)
+{
+ printf("### system abort ###\n");
+ printf("# ip: %x cs=%x\n", frame->ip, frame->cs);
+ printf("# sp: %x ss=%x\n", frame->sp, frame->ss);
+ printf("# flags: %x\n", frame->flags);
+ abort();
+}
+
+__attribute__((interrupt)) void
+syscall_handler(struct interrupt_frame *)
+{
+ printf("syscall\n");
+ abort();
+}
+
+extern void pic_clear(unsigned char irq);
+
+__attribute__((interrupt)) void
+irq0x00(struct interrupt_frame *)
+{
+ // printf("irq0x00\n");
+ pic_clear(0x00);
+}
+
+extern void ps2_keyboard_irq_handler();
+__attribute__((interrupt)) void
+irq0x01(struct interrupt_frame *)
+{
+ // printf("irq0x01\n");
+ ps2_keyboard_irq_handler();
+ pic_clear(0x00);
+}
diff --git a/i686/lidt.c b/i686/lidt.c
index 3e261ac..aa6185b 100644
--- a/i686/lidt.c
+++ b/i686/lidt.c
@@ -1,5 +1,6 @@
#include "idt.h"
#include <stdint.h>
+#include <stdio.h>
struct __attribute__((packed)) Pointer {
uint16_t limit;
@@ -21,7 +22,7 @@ struct __attribute__((packed)) Gate_t {
_Static_assert(sizeof(struct Gate_t) == 8);
void
-Gate(struct Gate_t *entry, void *f, uint16_t selector)
+Gate(struct Gate_t *entry, void (*f)(struct interrupt_frame *), uint16_t selector)
{
uint32_t f_addr = (uint32_t)f;
entry->offset_15_0 = f_addr & 0xffff;
@@ -36,7 +37,14 @@ static struct Gate_t interrupt_table[256] __attribute((aligned(4096)));
void
idt_install()
{
- for (int i = 0; i <= 0x2f; ++i) Gate(&interrupt_table[i], &interrupt_handler, 0x10);
+ // exceptions 0x00~0x13
+ for (int i = 0; i <= 0x13; ++i) Gate(&interrupt_table[i], &abort_handler, 0x10);
+ // irq 0x20~0x2f
+ // for (int i = 0; i < 16; ++i) irq_table[i] = NULL;
+ for (int i = 0x20; i <= 0x2f; ++i) Gate(&interrupt_table[i], &abort_handler, 0x10);
+ Gate(&interrupt_table[0x20], &irq0x00, 0x10);
+ Gate(&interrupt_table[0x21], &irq0x01, 0x10);
+ // syscall 0x80
Gate(&interrupt_table[0x80], &abort_handler, 0x10);
const struct Pointer ptr = {.limit = sizeof(interrupt_table) - 1, .base = (unsigned)&interrupt_table};