refactor: replace all stdint::uint32_t into short and more manageable u32_t
[lunaix-os.git] / lunaix-os / kernel / asm / x86 / gdt.c
1 #include <arch/x86/gdt.h>
2 #include <arch/x86/tss.h>
3 #include <lunaix/types.h>
4
5 #define GDT_ENTRY 6
6
7 uint64_t _gdt[GDT_ENTRY];
8 uint16_t _gdt_limit = sizeof(_gdt) - 1;
9
10 void
11 _set_gdt_entry(u32_t index, u32_t base, u32_t limit, u32_t flags)
12 {
13     _gdt[index] =
14       SEG_BASE_H(base) | flags | SEG_LIM_H(limit) | SEG_BASE_M(base);
15     _gdt[index] <<= 32;
16     _gdt[index] |= SEG_BASE_L(base) | SEG_LIM_L(limit);
17 }
18
19 extern struct x86_tss _tss;
20
21 void
22 _init_gdt()
23 {
24     _set_gdt_entry(0, 0, 0, 0);
25     _set_gdt_entry(1, 0, 0xfffff, SEG_R0_CODE);
26     _set_gdt_entry(2, 0, 0xfffff, SEG_R0_DATA);
27     _set_gdt_entry(3, 0, 0xfffff, SEG_R3_CODE);
28     _set_gdt_entry(4, 0, 0xfffff, SEG_R3_DATA);
29     _set_gdt_entry(5, &_tss, sizeof(struct x86_tss) - 1, SEG_TSS);
30 }