-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdt.c
39 lines (30 loc) · 1.04 KB
/
gdt.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
#include <gdt.h>
gdt_entry_t gdt[10];
gdt_ptr_t gp;
void gdt_install(void);
void gdt_set_gate(int num, u32_t, u32_t, u8_t, u8_t);
/* Setup a descriptor in the Global Descriptor Table */
void gdt_set_gate(int num, u32_t base, u32_t limit, u8_t access, u8_t gran)
{
/* Setup the descriptor base address */
gdt[num].base_low = (base & 0xFFFF);
gdt[num].base_middle = (base >> 16) & 0xFF;
gdt[num].base_high = (base >> 24) & 0xFF;
/* Setup the descriptor limits */
gdt[num].limit_low = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
/* Finally, set up the granularity and access flags */
gdt[num].granularity |= (gran & 0xF0);
gdt[num].access = access;
}
void gdt_install(void)
{
/* Setup the GDT pointer and limit */
gp.limit = sizeof(gdt_entry_t)*3 - 1;
gp.base = (u32_t)&gdt;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
//gdt_set_gate(3, 4, 0xFFFFFFF0, 0x92, 0xCF);
gdt_flush((u32_t)&gp);
}