]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/irq/idt.c
Handle interrupts
[nameless-os.git] / kernel / arch / x86 / irq / idt.c
1 #include <irq/idt.h>
2 #include <stdint.h>
3
4 /* Note to self: passing a pointer to an asm constraint as "m" will give a pointer to pointer */
5 inline void load_idt(struct idtr idtr)
6 {
7 asm volatile ("lidt %0": : "m" (idtr));
8 }
9
10 void idt_set_descriptor(struct idt_descriptor *idt, uint8_t vector, uint16_t segment, uint32_t offset, uint8_t type, uint8_t dpl)
11 {
12 struct idt_descriptor *descriptor = &idt[vector];
13
14 descriptor->offset_1 = offset & 0xFFFF;
15 descriptor->segsel = segment;
16 descriptor->unused = 0;
17 descriptor->type = type;
18 descriptor->dpl = dpl;
19 descriptor->present = 1;
20 descriptor->offset_2 = offset >> 16;
21 }
22
23 inline void populate_idtr(struct idtr *idtr, struct idt_descriptor *idt)
24 {
25 idtr->limit = ((IDT_VECTOR_COUNT * IDT_DESCRIPTOR_SIZE) - 1); /* limit must be size - 1 */
26 idtr->base = (uint32_t) idt;
27 }