hippOS/cpu/idt.c

28 lines
735 B
C
Raw Permalink Normal View History

2022-02-22 21:20:57 +02:00
#include <stdbool.h>
#include <stddef.h>
#include "cpu/idt.h"
struct interrupt_descriptor_32 idt[256];
static size_t idt_ptr[2];
void idt_init(void) {
2022-02-22 21:20:57 +02:00
size_t idt_address = (size_t)idt;
idt_ptr[0] = (sizeof (struct interrupt_descriptor_32) * 256) + ((idt_address & 0xffff) << 16);
idt_ptr[1] = idt_address >> 16;
__asm__ __volatile__(
"lidt %0\n\t"
"sti\n\t" : : "m"(idt_ptr)
);
}
void idt_register_handler(uint8_t interrupt, size_t address) {
idt[interrupt].offset_1 = address & 0xffff;
idt[interrupt].selector = KERNEL_CODE_SEGMENT_OFFSET;
idt[interrupt].zero = 0;
idt[interrupt].type_attributes = INTERRUPT_GATE;
idt[interrupt].offset_2 = (address & 0xffff0000) >> 16;
}