cfenollosa_os-tutorial/23-fixes/cpu/idt.c

18 lines
483 B
C
Raw Normal View History

2015-08-17 16:41:38 +00:00
#include "idt.h"
2015-08-18 08:31:28 +00:00
#include "type.h"
2015-08-17 16:41:38 +00:00
2015-08-18 08:31:28 +00:00
void set_idt_gate(int n, uint32_t handler) {
2015-08-17 16:41:38 +00:00
idt[n].low_offset = low_16(handler);
idt[n].sel = KERNEL_CS;
idt[n].always0 = 0;
idt[n].flags = 0x8E;
idt[n].high_offset = high_16(handler);
}
void set_idt() {
2015-08-18 08:31:28 +00:00
idt_reg.base = (uint32_t) &idt;
2015-08-17 16:41:38 +00:00
idt_reg.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1;
/* Don't make the mistake of loading &idt -- always load &idt_reg */
2015-08-18 09:44:24 +00:00
asm volatile("lidtl (%0)" : : "r" (&idt_reg));
2015-08-17 16:41:38 +00:00
}