diff options
author | Marvin Borner | 2019-09-19 19:56:59 +0200 |
---|---|---|
committer | Marvin Borner | 2019-09-19 20:05:38 +0200 |
commit | 05e1fedcc9cd30d1a34a65e640da45e980b4f859 (patch) | |
tree | 9cfb7620907ac126f26cdfe9363cb73ed74ea179 /src/kernel/interrupts/idt.c | |
parent | ffd82e18b5259fab477ad375a7af8550fac526d8 (diff) |
Moved source to kernel directory
Diffstat (limited to 'src/kernel/interrupts/idt.c')
-rw-r--r-- | src/kernel/interrupts/idt.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/kernel/interrupts/idt.c b/src/kernel/interrupts/idt.c new file mode 100644 index 0000000..ba71339 --- /dev/null +++ b/src/kernel/interrupts/idt.c @@ -0,0 +1,46 @@ +#include "../lib/lib.h" + +struct idt_entry { + unsigned short base_lo; + unsigned short sel; // Kernel segment + unsigned char always0; // Always 0 + unsigned char flags; + unsigned short base_hi; +} __attribute__((packed)); + +struct idt_ptr { + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +// Initialize IDT with 256 entries +struct idt_entry idt[256]; +struct idt_ptr idtp; + +// Defined in idt.asm +extern void idt_load(); + +void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) { + // Specify the interrupt routine's base address + idt[num].base_lo = (base & 0xFFFF); + idt[num].base_hi = (base >> 16) & 0xFFFF; + + // Set selector/segment of IDT entry + idt[num].sel = sel; + idt[num].always0 = 0; + idt[num].flags = flags; +} + +// Install IDT +void idt_install() { + // Set IDT pointer and limit + idtp.limit = (sizeof(struct idt_entry) * 256) - 1; + idtp.base = &idt; + + // Clear IDT by setting memory cells to 0 + memory_set(&idt, 0, sizeof(struct idt_entry) * 256); + + // TODO: Add method to add ISRs to IDT + + idt_load(); +} |