Syncboot/kernel/idt.c
Jenny Curle 245d09b056 Implemented IDT
But something's wrong with the GDT
Next up is a Serial Console
2019-04-07 13:16:53 +01:00

42 lines
1004 B
C
Executable File

#include <kernel/utils.h>
struct idt_entry {
unsigned short base_low;
unsigned short selector;
unsigned char always0;
unsigned char flags;
unsigned short base_high;
} __attribute__((packed));
struct idt_ptr {
unsigned short limit;
unsigned int base;
}__attribute__((packed));
struct idt_entry idt[256]; // Interrupt table of 256 entries
struct idt_ptr idtp; // Pointer to idt table
extern void idt_load();
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) {
idt[num].base_low = base & 0xFFFF;
idt[num].base_high = (base >> 16) & 0xFFFF;
idt[num].selector = sel;
idt[num].always0 = 0;
// Must be uncommented when we get to usermode - it sets the permission
// level to 3
idt[num].flags = flags; // | 0x60;
}
void idt_install() {
idtp.limit = (sizeof (struct idt_entry) * 256) - 1;
idtp.base = &idt;
memset(&idt, 0, sizeof(struct idt_entry) * 256);
// All ISRs go here
idt_load();
}