summaryrefslogtreecommitdiff
path: root/src/kernel/arch/i386/interrupts
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/arch/i386/interrupts')
-rw-r--r--src/kernel/arch/i386/interrupts/idt.c68
-rw-r--r--src/kernel/arch/i386/interrupts/idt.h3
-rw-r--r--src/kernel/arch/i386/interrupts/irq.c33
-rw-r--r--src/kernel/arch/i386/interrupts/irq.h6
-rw-r--r--src/kernel/arch/i386/interrupts/isr.c38
-rw-r--r--src/kernel/arch/i386/interrupts/isr.h7
-rw-r--r--src/kernel/arch/i386/interrupts/isr_stub.s64
7 files changed, 0 insertions, 219 deletions
diff --git a/src/kernel/arch/i386/interrupts/idt.c b/src/kernel/arch/i386/interrupts/idt.c
deleted file mode 100644
index cd2adfd..0000000
--- a/src/kernel/arch/i386/interrupts/idt.c
+++ /dev/null
@@ -1,68 +0,0 @@
-#include <kernel/arch/i386/gdt.h>
-#include <kernel/arch/i386/interrupts/idt.h>
-#include <kernel/arch/i386/interrupts/isr.h>
-#include <kernel/panic.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-struct idt_entry {
- uint16_t offset_low ;
- uint16_t code_seg ;
- uint8_t zero ; // unused, has to be 0
- uint8_t type : 4; // 16/32 bit, task/interrupt/task gate
- uint8_t storage : 1; // 0 for interrupt/trap gates
- uint8_t ring : 2;
- uint8_t present : 1;
- uint16_t offset_high ;
-} __attribute__((packed));
-
-// is exactly the same as lgdt_arg, i should combine them into a single struct
-// later
-struct lidt_arg {
- uint16_t limit;
- uint32_t base;
-} __attribute__((packed));
-
-__attribute__((section(".shared")))
-static struct idt_entry IDT[256];
-static struct lidt_arg lidt_arg;
-
-static void idt_prepare(void);
-static void idt_load(void);
-static void idt_test(void);
-
-
-static void idt_prepare(void) {
- uintptr_t offset;
- for (int i = 0; i < 256; i++) {
- offset = (uintptr_t) &_isr_stubs + i * 8;
-
- IDT[i] = (struct idt_entry) {
- .offset_low = offset,
- .offset_high = offset >> 16,
- .code_seg = SEG_r0code << 3,
- .zero = 0,
- .present = 1,
- .ring = 0,
- .storage = 0,
- .type = 0xE, // 32-bit interrupt gate
- };
- }
-}
-
-static void idt_load(void) {
- lidt_arg.limit = sizeof(IDT) - 1;
- lidt_arg.base = (uintptr_t) &IDT;
- asm("lidt (%0)" : : "r" (&lidt_arg) : "memory");
-}
-
-static void idt_test(void) {
- asm("int $0x34" : : : "memory");
- assert(isr_test_interrupt_called);
-}
-
-void idt_init(void) {
- idt_prepare();
- idt_load();
- idt_test();
-}
diff --git a/src/kernel/arch/i386/interrupts/idt.h b/src/kernel/arch/i386/interrupts/idt.h
deleted file mode 100644
index 6576cf9..0000000
--- a/src/kernel/arch/i386/interrupts/idt.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-void idt_init(void);
diff --git a/src/kernel/arch/i386/interrupts/irq.c b/src/kernel/arch/i386/interrupts/irq.c
deleted file mode 100644
index 5918169..0000000
--- a/src/kernel/arch/i386/interrupts/irq.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <kernel/arch/i386/interrupts/irq.h>
-#include <kernel/arch/i386/port_io.h>
-#include <stdint.h>
-
-static const int PIC1 = 0x20;
-static const int PIC2 = 0xA0;
-
-void irq_init(void) {
- port_out8(PIC1, 0x11); /* start init sequence */
- port_out8(PIC2, 0x11);
-
- port_out8(PIC1+1, 0x20); /* interrupt offsets */
- port_out8(PIC2+1, 0x30);
-
- port_out8(PIC1+1, 0x4); /* just look at the osdev wiki lol */
- port_out8(PIC2+1, 0x2);
-
- port_out8(PIC1+1, 0x1); /* 8086 mode */
- port_out8(PIC2+1, 0x1);
-
- uint8_t mask = 0xff;
- mask &= ~(1 << 1); // keyboard
- mask &= ~(1 << 4); // COM1
-
- port_out8(PIC1+1, mask);
- port_out8(PIC2+1, 0xff);
-}
-
-void irq_eoi(uint8_t line) {
- port_out8(PIC1, 0x20);
- if (line >= 8)
- port_out8(PIC2, 0x20);
-}
diff --git a/src/kernel/arch/i386/interrupts/irq.h b/src/kernel/arch/i386/interrupts/irq.h
deleted file mode 100644
index f523154..0000000
--- a/src/kernel/arch/i386/interrupts/irq.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#pragma once
-#include <stdbool.h>
-#include <stdint.h>
-
-void irq_init(void);
-void irq_eoi(uint8_t line);
diff --git a/src/kernel/arch/i386/interrupts/isr.c b/src/kernel/arch/i386/interrupts/isr.c
deleted file mode 100644
index 2d893cb..0000000
--- a/src/kernel/arch/i386/interrupts/isr.c
+++ /dev/null
@@ -1,38 +0,0 @@
-#include <kernel/arch/i386/driver/ps2.h>
-#include <kernel/arch/i386/driver/serial.h>
-#include <kernel/arch/i386/interrupts/irq.h>
-#include <kernel/arch/i386/interrupts/isr.h>
-#include <kernel/arch/i386/port_io.h>
-#include <kernel/arch/generic.h>
-#include <kernel/panic.h>
-#include <kernel/proc.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-bool isr_test_interrupt_called = false;
-
-void isr_stage3(int interrupt) {
- switch (interrupt) {
- case 0x08: // double fault
- kprintf("#DF");
- panic_invalid_state();
- case 0x34:
- isr_test_interrupt_called = true;
- return;
-
- case 0x21: // keyboard irq
- ps2_recv(port_in8(0x60));
- irq_eoi(1);
- return;
-
- case 0x24: // COM1 irq
- serial_irq();
- irq_eoi(1);
- return;
-
- default:
- // TODO check if the exception was in the kernel
- process_kill(process_current, interrupt);
- process_switch_any();
- }
-}
diff --git a/src/kernel/arch/i386/interrupts/isr.h b/src/kernel/arch/i386/interrupts/isr.h
deleted file mode 100644
index 3189538..0000000
--- a/src/kernel/arch/i386/interrupts/isr.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-#include <stdbool.h>
-
-extern bool isr_test_interrupt_called; // used in the self-test in idt.c
-extern const char _isr_stubs;
-
-void isr_stage3(int interrupt);
diff --git a/src/kernel/arch/i386/interrupts/isr_stub.s b/src/kernel/arch/i386/interrupts/isr_stub.s
deleted file mode 100644
index fdbae6f..0000000
--- a/src/kernel/arch/i386/interrupts/isr_stub.s
+++ /dev/null
@@ -1,64 +0,0 @@
-.section .shared
-
-.global _isr_stubs
-_isr_stubs:
-.rept 256
- .set _stub_start, .
-
- cli
- call _isr_stage2
-
- .if . - _stub_start > 8
- .error "isr stubs over maximum size"
- .abort
- .endif
- .align 8
-.endr
-
-_isr_stage2:
- // pushal order, without %esp
- push %eax
- push %ecx
- push %edx
- push %ebx
- push %ebp
- push %esi
- push %edi
-
- // convert the return address into the vector nr
- mov 28(%esp), %eax
- add $-_isr_stubs, %eax
- shr $3, %eax
-
- // disable paging, if present
- mov %cr0, %ebx
- push %ebx // push original cr0
- and $0x7FFFFFFF, %ebx
- mov %ebx, %cr0
-
- mov %esp, %ebp
- mov $_isr_big_stack, %esp
- push %eax // push the vector nr
- call isr_stage3
-
- mov %ebp, %esp
- pop %eax // restore old cr0
- mov %eax, %cr0
-
- // restore registers
- pop %edi
- pop %esi
- pop %ebp
- pop %ebx
- pop %edx
- pop %ecx
- pop %eax
-
- add $4, %esp // skip call's return address
- iret
-
-.align 8
-// TODO overflow check
-.skip 64 // seems to be enough
-.global _isr_mini_stack
-_isr_mini_stack: