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
|
#include "gdt.h"
gdt_entry gdt[] = {
gdt_entry_init(0, 0, 0),
gdt_entry_init(0, 0xfffff, 0xc09a), // Code segment.
gdt_entry_init(0, 0xfffff, 0xc092), // Data segment.
gdt_entry_init(0, 0xfffff, 0xc0fa), // User mode code segment.
gdt_entry_init(0, 0xfffff, 0xc0f2), // User mode data segment.
};
gdt_ptr gdtr = {
.base = gdt,
.limit = sizeof(gdt) - 1
};
void gdt_init() {
asm volatile(
"lgdt (%0)\n"
"mov %w1, %%ds\n"
"mov %w1, %%es\n"
"mov %w1, %%fs\n"
"mov %w1, %%gs\n"
"mov %w1, %%ss\n"
"ljmp $0x08, $.flush\n"
".flush:\n"
: : "r" (&gdtr), "r" (0x10)
);
}
|