-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathidt.c
74 lines (61 loc) · 1.55 KB
/
idt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "idt.h"
#include "hal.h"
//array of idt entries in table
static idt_entry idt[MAX_INTERRUPTS]; // 256 interrupts
//register for idtr
static idt_register idtr; // one idt register
void load_idt() // loads the idt into idtr
{
__asm__ __volatile__("lidtl (%0)"
:
: "r"(&idtr));
}
void default_handler() // default handler for idts
{
vga_clear(' ');
vga_go_to_pixel(0, 0);
vga_printf("DEFAULT EXCEPTION HANDLER");
while (1)
{
}
}
idt_entry* get_idt_entry(uint32_t index) // get pointer to descriptor
{
if (index > MAX_INTERRUPTS)
{
return 0;
}
return &idt[index];
}
void install_idt_entry(
uint32_t index, uint8_t flags, uint16_t selector,
uint32_t handler_address) // installs an ir into the descriptor table
{
if (index > MAX_INTERRUPTS)
{
return;
}
if (handler_address == 0)
{
return;
}
idt[index].base_low = (uint16_t)(handler_address & 0xFFFF);
idt[index].base_high = (uint16_t)((handler_address >> 16) & 0xFFFF);
idt[index].reserved = 0;
idt[index].flags = flags;
idt[index].selector = selector;
}
void idt_init() // setups the descriptor table and the interrupt routines
{
// setup idtr
idtr.limit = (sizeof(idt_entry) * MAX_INTERRUPTS) - 1;
idtr.base = (uint32_t)&idt[0];
// zero out idt
for (uint32_t i = 0; i < MAX_INTERRUPTS; i++)
{
// using compound literals to zero intialize
idt[i] = (idt_entry){ 0 };
}
// load idt
load_idt();
}