:: limine / common / sys / gdt.s2.c 2.0 KB raw

1
#if defined (__x86_64__) || defined (__i386__)
2
3
#include <stdint.h>
4
#include <sys/gdt.h>
5
#include <mm/pmm.h>
6
#include <lib/libc.h>
7
8
static struct gdt_desc gdt_descs[] = {
9
    {0},
10
11
    {
12
        .limit       = 0xffff,
13
        .base_low    = 0x0000,
14
        .base_mid    = 0x00,
15
        .access      = 0b10011011,
16
        .granularity = 0b00000000,
17
        .base_hi     = 0x00
18
    },
19
20
    {
21
        .limit       = 0xffff,
22
        .base_low    = 0x0000,
23
        .base_mid    = 0x00,
24
        .access      = 0b10010011,
25
        .granularity = 0b00000000,
26
        .base_hi     = 0x00
27
    },
28
29
    {
30
        .limit       = 0xffff,
31
        .base_low    = 0x0000,
32
        .base_mid    = 0x00,
33
        .access      = 0b10011011,
34
        .granularity = 0b11001111,
35
        .base_hi     = 0x00
36
    },
37
38
    {
39
        .limit       = 0xffff,
40
        .base_low    = 0x0000,
41
        .base_mid    = 0x00,
42
        .access      = 0b10010011,
43
        .granularity = 0b11001111,
44
        .base_hi     = 0x00
45
    },
46
47
    {
48
        .limit       = 0x0000,
49
        .base_low    = 0x0000,
50
        .base_mid    = 0x00,
51
        .access      = 0b10011011,
52
        .granularity = 0b00100000,
53
        .base_hi     = 0x00
54
    },
55
56
    {
57
        .limit       = 0x0000,
58
        .base_low    = 0x0000,
59
        .base_mid    = 0x00,
60
        .access      = 0b10010011,
61
        .granularity = 0b00000000,
62
        .base_hi     = 0x00
63
    },
64
65
    {   // 0x38: TSS descriptor low (base 0, limit 0)
66
        .limit       = 0x0000,
67
        .base_low    = 0x0000,
68
        .base_mid    = 0x00,
69
        .access      = 0x89,
70
        .granularity = 0x00,
71
        .base_hi     = 0x00
72
    },
73
    {0} // 0x40: TSS descriptor high (base upper = 0)
74
};
75
76
#if defined (BIOS)
77
__attribute__((section(".realmode")))
78
#endif
79
struct gdtr gdt = {
80
    sizeof(gdt_descs) - 1,
81
    (uintptr_t)gdt_descs,
82
#if defined (__i386__)
83
    0
84
#endif
85
};
86
87
#if defined (UEFI)
88
void init_gdt(void) {
89
    struct gdt_desc *gdt_copy = ext_mem_alloc(sizeof(gdt_descs));
90
    memcpy(gdt_copy, gdt_descs, sizeof(gdt_descs));
91
    gdt.ptr = (uintptr_t)gdt_copy;
92
}
93
#endif
94
95
#endif
tab: 248 wrap: offon