]> git.dujemihanovic.xyz Git - nameless-os.git/blob - include/arch/x86/irq/idt.h
Fix interrupt trap gates
[nameless-os.git] / include / arch / x86 / irq / idt.h
1 #ifndef X86_IDT_H
2 #define X86_IDT_H
3
4 #include <stdint.h>
5
6 #define IDT_VECTOR_COUNT 256 /* our IDT will have 256 vectors */
7 #define IDT_DESCRIPTOR_SIZE 8 /* each IDT descriptor is 8 bytes long */
8
9 #define IDT_TRAP_GATE 0xF
10 #define IDT_INTERRUPT_GATE 0xE
11
12 struct idt_descriptor {
13 uint16_t offset_1; /* bits 0-15 of offset */
14 uint16_t segsel; /* segment selector */
15 unsigned unused : 8, type : 5, dpl : 2, present : 1;
16 uint16_t offset_2; /* bits 16-31 of offset */
17 } __attribute__((packed));
18
19 struct idtr {
20 uint16_t limit; /* size of IDT minus 1 */
21 uint32_t base; /* starting address of IDT */
22 } __attribute__((packed));
23
24 extern void idt_set_descriptor(struct idt_descriptor *idt, uint8_t vector, uint16_t segment, uint32_t offset, uint8_t type, uint8_t dpl);
25 extern inline void load_idt(struct idtr idtr);
26 extern inline void populate_idtr(struct idtr *idtr, struct idt_descriptor *idt);
27
28 #endif