summaryrefslogtreecommitdiff
path: root/kernel/src/interrupt
diff options
context:
space:
mode:
authorTyler Murphy <=>2023-07-17 19:34:52 -0400
committerTyler Murphy <=>2023-07-17 19:34:52 -0400
commit7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5 (patch)
tree4e86ff20e73171285156631db043e12aaf63bf04 /kernel/src/interrupt
parentpaging (diff)
downloadfinix-7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5.tar.gz
finix-7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5.tar.bz2
finix-7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5.zip
refactoring
Diffstat (limited to 'kernel/src/interrupt')
-rw-r--r--kernel/src/interrupt/idt.asm99
-rw-r--r--kernel/src/interrupt/idt.c118
-rw-r--r--kernel/src/interrupt/idt.h36
-rw-r--r--kernel/src/interrupt/pic.c85
-rw-r--r--kernel/src/interrupt/pic.h11
5 files changed, 0 insertions, 349 deletions
diff --git a/kernel/src/interrupt/idt.asm b/kernel/src/interrupt/idt.asm
deleted file mode 100644
index 6cccdc6..0000000
--- a/kernel/src/interrupt/idt.asm
+++ /dev/null
@@ -1,99 +0,0 @@
-extern idt_exception_handler
-extern idt_pic_timer
-extern idt_pic_keyboard
-extern idt_pic_mouse
-extern idt_pic_eoi
-global isr_stub_table
-
-%macro ISRErrorStub 1
-isr_stub_%+%1:
- push dword %1
- call idt_exception_handler
- pop eax
- iret
-%endmacro
-
-%macro PICGeneric 1
-isr_stub_%+%1:
- push dword %1
- call idt_pic_eoi
- pop eax
- iret
-%endmacro
-
-%macro PICTimer 1
-isr_stub_%+%1:
- call idt_pic_timer
- push dword %1
- call idt_pic_eoi
- pop eax
- iret
-%endmacro
-
-%macro PICKeyboard 1
-isr_stub_%+%1:
- call idt_pic_keyboard
- push dword %1
- call idt_pic_eoi
- pop eax
- iret
-%endmacro
-
-%macro PICMouse 1
-isr_stub_%+%1:
- call idt_pic_mouse
- push dword %1
- call idt_pic_eoi
- pop eax
- iret
-%endmacro
-
-%macro ISRSyscall 1
-isr_stub_%+%1:
- push eax
- push ebx
- push ecx
- push edx
- call idt_syscall
- add esp, 16
- pop eax
- iret
-%endmacro
-
-section .text
-align 8
-%assign i 0
-%rep 32
- ISRErrorStub i
-%assign i i+1
-%endrep
-PICTimer 32 ; 0
-PICKeyboard 33 ; 1
-PICGeneric 34 ; 2
-PICGeneric 35 ; 3
-PICGeneric 36 ; 4
-PICGeneric 37 ; 5
-PICGeneric 38 ; 6
-PICGeneric 39 ; 7
-PICGeneric 40 ; 8
-PICGeneric 41 ; 9
-PICGeneric 42 ; 10
-PICGeneric 43 ; 11
-PICMouse 44 ; 12
-PICGeneric 45 ; 13
-PICGeneric 46 ; 14
-PICGeneric 47 ; 15
-%assign i 48
-%rep 256 - 48
- ISRErrorStub i
-%assign i i+1
-%endrep
-
-section .rodata
-align 8
-isr_stub_table:
-%assign i 0x00
-%rep 256
- dd isr_stub_%+i
-%assign i i+0x01
-%endrep
diff --git a/kernel/src/interrupt/idt.c b/kernel/src/interrupt/idt.c
deleted file mode 100644
index aaa7034..0000000
--- a/kernel/src/interrupt/idt.c
+++ /dev/null
@@ -1,118 +0,0 @@
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <sys.h>
-#include <print.h>
-#include <panic.h>
-
-#include "acpi/acpi.h"
-#include "drivers/ps2kb.h"
-#include "drivers/ps2mouse.h"
-#include "time.h"
-#include "tty/color.h"
-#include "idt.h"
-#include "pic.h"
-#include "tty/term.h"
-
-#define WIDTH 30
-static char buf[WIDTH];
-static int timer = -1;
-
-void idt_pic_eoi(uint8_t exception) {
- pic_eoi(exception - PIC_REMAP_OFFSET);
-}
-
-void idt_pic_timer(void) {
-
- timer += 1;
- if (timer % 20 != 0) return;
-
- uint32_t state = term_save();
-
- term_setfg(VGA_LIGHT_GREEN);
- term_setpos(TERM_W - WIDTH - 1, 0);
- for (size_t i = 0; i < WIDTH; i++) putchar(' ');
- term_setpos(TERM_W - WIDTH - 1, 0);
-
- timetostr(rtc_localtime(), "%a %b %d %Y %H:%M:%S", buf, WIDTH);
- printk("%s", buf);
-
- term_load(state);
-}
-
-void idt_pic_keyboard(void) {
- ps2kb_recv();
-}
-
-void idt_pic_mouse(void) {
- ps2mouse_recv();
-}
-
-void idt_exception_handler(uint8_t exception) {
- char* msg;
- switch(exception) {
- case 0x00:
- msg = "Division by zero";
- break;
- case 0x02:
- msg = "NMI";
- break;
- case 0x04:
- msg = "Overflow";
- break;
- case 0x06:
- msg = "invalid opcode";
- break;
- case 0x08:
- msg = "double fault";
- break;
- case 0x0A:
- msg = "invalid task state segment";
- break;
- case 0x0C:
- msg = "stack segment fault";
- break;
- case 0x0D:
- msg = "general protection fault";
- break;
- case 0x0E:
- msg = "page fault";
- break;
- default:
- msg = "unknown exception";
- break;
- }
- panic("E%u: %s", exception, msg);
-}
-
-__attribute__((aligned(0x10)))
-static struct IdtEntry idt[256];
-static struct Idtr idtr;
-extern void* isr_stub_table[];
-
-static void set_descriptor(uint8_t vector, void* isr, uint8_t flags) {
- struct IdtEntry* entry = &idt[vector];
- entry->isr_low = (size_t)isr & 0xffff;
- entry->kernel_cs = 0x08;
- entry->attributes = flags;
- entry->isr_high = (size_t)isr >> 16;
- entry->_reserved = 0;
-}
-
-void idt_init(void) {
-
- debugk("Loading IDT");
-
- idtr.base = (uintptr_t)&idt[0];
- idtr.limit = (uint16_t)sizeof(struct IdtEntry) * IDT_SIZE - 1;
-
- for(int i = 0; i < IDT_INTERRUPTS; i++) {
- set_descriptor(i, isr_stub_table[i], 0x8e);
- }
-
- __asm__ volatile ("lidt %0" : : "m"(idtr));
-
- succek("IDT has been loaded");
-}
-
diff --git a/kernel/src/interrupt/idt.h b/kernel/src/interrupt/idt.h
deleted file mode 100644
index 86a685f..0000000
--- a/kernel/src/interrupt/idt.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#define IDT_SIZE 256
-#define IDT_INTERRUPTS 256
-
-struct IdtEntry {
- uint16_t isr_low;
- uint16_t kernel_cs;
- uint8_t _reserved;
- uint8_t attributes;
- uint16_t isr_high;
-} __attribute__((packed));
-
-struct Idtr {
- uint16_t limit;
- uint32_t base;
-} __attribute__((packed));
-
-enum IDTFlags {
- IDT_FLAG_GATE_TASK = 0x5,
- IDT_FLAG_GATE_16BIT_INT = 0x6,
- IDT_FLAG_GATE_16BIT_TRAP = 0x7,
- IDT_FLAG_GATE_32BIT_INT = 0xE,
- IDT_FLAG_GATE_32BIT_TRAP = 0xF,
-
- IDT_FLAG_RING0 = (0 << 5),
- IDT_FLAG_RING1 = (1 << 5),
- IDT_FLAG_RING2 = (2 << 5),
- IDT_FLAG_RING3 = (3 << 5),
-
- IDT_FLAG_PRESENT = 0x80,
-};
-
-void idt_init(void);
diff --git a/kernel/src/interrupt/pic.c b/kernel/src/interrupt/pic.c
deleted file mode 100644
index 86056a1..0000000
--- a/kernel/src/interrupt/pic.c
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <sys.h>
-#include <print.h>
-
-#include "pic.h"
-
-#define PIC1_COMMAND_PORT 0x20
-#define PIC1_DATA_PORT 0x21
-#define PIC2_COMMAND_PORT 0xA0
-#define PIC2_DATA_PORT 0xA1
-
-void pic_remap(uint8_t offset) {
-
- debugk("Remapping PIC");
-
- char a1 = inb(PIC1_DATA_PORT);
- char a2 = inb(PIC2_DATA_PORT);
- // control word 1
- // 0x11: initialize, enable ICW4
- outb(PIC1_COMMAND_PORT, 0x11);
- io_wait();
- outb(PIC2_COMMAND_PORT, 0x11);
- io_wait();
- // control word 2
- // interrupt offset
- outb(PIC1_DATA_PORT, offset);
- io_wait();
- outb(PIC2_DATA_PORT, offset + 8);
- io_wait();
- // control word 3
- // primary pic: set which pin secondary is connected to
- // (pin 2)
- outb(PIC1_DATA_PORT, 0x04);
- io_wait();
- outb(PIC2_DATA_PORT, 2);
- io_wait();
- // control word 3
- // 0x01: enable 8086 mode
- outb(PIC1_DATA_PORT, 0x01);
- io_wait();
- outb(PIC2_DATA_PORT, 0x01);
- io_wait();
- // clear data registers
- outb(PIC1_DATA_PORT, a1);
- outb(PIC2_DATA_PORT, a2);
-
- succek("PIC has been remapped to offset 0x%X", offset);
-}
-
-void pic_mask(int irq) {
- uint8_t port;
- if(irq < 8) {
- port = PIC1_DATA_PORT;
- } else {
- irq -= 8;
- port = PIC2_DATA_PORT;
- }
- uint8_t mask = inb(port);
- outb(port, mask | (1 << irq));
-}
-
-void pic_unmask(int irq) {
- uint8_t port;
- if(irq < 8) {
- port = PIC1_DATA_PORT;
- } else {
- irq -= 8;
- port = PIC2_DATA_PORT;
- }
- uint8_t mask = inb(port);
- outb(port, mask & ~(1 << irq));
-}
-
-void pic_disable(void) {
- outb(PIC1_DATA_PORT, 0xff);
- io_wait();
- outb(PIC2_DATA_PORT, 0xff);
- io_wait();
-}
-
-void pic_eoi(int irq) {
- if(irq >= 8) {
- outb(PIC2_COMMAND_PORT, 0x20);
- }
- outb(PIC1_COMMAND_PORT, 0x20);
-}
diff --git a/kernel/src/interrupt/pic.h b/kernel/src/interrupt/pic.h
deleted file mode 100644
index a87420d..0000000
--- a/kernel/src/interrupt/pic.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#define PIC_REMAP_OFFSET 0x20
-
-void pic_remap(uint8_t offset);
-void pic_mask(int irq);
-void pic_unmask(int irq);
-void pic_disable(void);
-void pic_eoi(int irq);