-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdt.c
64 lines (58 loc) · 1.37 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
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
// SPDX-License-Identifier: GPL-2.0-only
#include "arch/gdt.h"
#define GDT_TABLE_SIZE (GDT_ENTRIES * sizeof(Gdt)) - 1
static Gdt gdt[GDT_ENTRIES];
static GdtDescr gdt_ptr = {
.size = GDT_TABLE_SIZE,
.address = gdt,
};
static inline void load_gdt(const GdtDescr *p) {
asm volatile("lgdt %0"::"m" (*p));
}
public void gdt_init(void) {
// kernel cs
gdt[1] = (Gdt) {
.base2 = 0,
// flags
.g = 1, .l = 1, .p = 1, .dpl = 0,
.limit1 = 0xF,
// access byte
.s = 1, .e = 1, .rw = 1,
.base1 = 0,
.base0 = 0, .limit0 = 0xFFFF
};
// kernel ds
gdt[2] = (Gdt) {
.base2 = 0,
// flags
.g = 1, .l = 1, .p = 1, .dpl = 0,
.limit1 = 0xF,
// access byte
.s = 1, .rw = 1,
.base1 = 0,
.base0 = 0, .limit0 = 0xFFFF
};
// user cs
gdt[3] = (Gdt) {
.base2 = 0,
// flags
.g = 1, .l = 1, .p = 1, .dpl = 0, // TODO: update it to 3, and fix those problems.
.limit1 = 0xF,
// access byte
.s = 1, .e = 1, .rw = 1,
.base1 = 0,
.base0 = 0, .limit0 = 0xFFFF
};
// user ds
gdt[4] = (Gdt) {
.base2 = 0,
// flags
.g = 1, .l = 1, .p = 1, .dpl = 0, // TODO: update it to 3, and fix those problems.
.limit1 = 0xF,
// access byte
.s = 1, .rw = 1,
.base1 = 0,
.base0 = 0, .limit0 = 0xFFFF
};
load_gdt(&gdt_ptr);
}