Files

67 lines
2.7 KiB
C

#include "../includes/idt.h"
#include "../includes/interrupt_handler.h"
struct idt_entry idt_entries[256];
struct idt_ptr idt;
void idt_install()
{
idt.size = (sizeof (struct idt_entry) * 256) - 1;
idt.idt_entries_start = (struct idt_entry *) &idt_entries;
// IDT Selector value:
// 0x08 is the code segement we want, which, as defined by the GDT, is the kernel code segment entry in the GDT.
//
// IDT Flags value:
//
// Bit: 7 6-5 4-0
// P DPL Always 01110 (14)
// For the kernel ring 8E is chosen
// 100 for bits 7-5. 1 (present) 00 (the level in this case ring zero)
// 01110 for bits 4-0. This is always set to 14.
idt_set_gate(0, (unsigned int) isr0, 0x08, 0x8E);
idt_set_gate(1, (unsigned int) isr1, 0x08, 0x8E);
idt_set_gate(2, (unsigned int) isr2, 0x08, 0x8E);
idt_set_gate(3, (unsigned int) isr3, 0x08, 0x8E);
idt_set_gate(4, (unsigned int) isr4, 0x08, 0x8E);
idt_set_gate(5, (unsigned int) isr5, 0x08, 0x8E);
idt_set_gate(6, (unsigned int) isr6, 0x08, 0x8E);
idt_set_gate(7, (unsigned int) isr7, 0x08, 0x8E);
idt_set_gate(8, (unsigned int) isr8, 0x08, 0x8E);
idt_set_gate(9, (unsigned int) isr9, 0x08, 0x8E);
idt_set_gate(10, (unsigned int) isr10, 0x08, 0x8E);
idt_set_gate(11, (unsigned int) isr11, 0x08, 0x8E);
idt_set_gate(12, (unsigned int) isr12, 0x08, 0x8E);
idt_set_gate(13, (unsigned int) isr13, 0x08, 0x8E);
idt_set_gate(14, (unsigned int) isr14, 0x08, 0x8E);
idt_set_gate(15, (unsigned int) isr15, 0x08, 0x8E);
idt_set_gate(16, (unsigned int) isr16, 0x08, 0x8E);
idt_set_gate(17, (unsigned int) isr17, 0x08, 0x8E);
idt_set_gate(18, (unsigned int) isr18, 0x08, 0x8E);
idt_set_gate(19, (unsigned int) isr19, 0x08, 0x8E);
idt_set_gate(20, (unsigned int) isr20, 0x08, 0x8E);
idt_set_gate(21, (unsigned int) isr21, 0x08, 0x8E);
idt_set_gate(22, (unsigned int) isr22, 0x08, 0x8E);
idt_set_gate(23, (unsigned int) isr23, 0x08, 0x8E);
idt_set_gate(24, (unsigned int) isr24, 0x08, 0x8E);
idt_set_gate(25, (unsigned int) isr25, 0x08, 0x8E);
idt_set_gate(26, (unsigned int) isr26, 0x08, 0x8E);
idt_set_gate(27, (unsigned int) isr27, 0x08, 0x8E);
idt_set_gate(28, (unsigned int) isr28, 0x08, 0x8E);
idt_set_gate(29, (unsigned int) isr29, 0x08, 0x8E);
idt_set_gate(30, (unsigned int) isr30, 0x08, 0x8E);
idt_set_gate(31, (unsigned int) isr31, 0x08, 0x8E);
load_idt(&idt);
}
void idt_set_gate(unsigned char index, unsigned long base, unsigned short sel, unsigned char flags)
{
struct idt_entry* entry = &idt.idt_entries_start[index];
entry->base_lo = (base & 0xFFFF);
entry->base_hi = (base >> 16) & 0xFFFF;
entry->sel = sel;
entry->always0 = 0;
entry->flags = flags;
}