2021-03-07 02:52:25 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/gdt.h>
|
2021-11-25 23:51:41 +03:00
|
|
|
#include <mm/pmm.h>
|
|
|
|
#include <lib/libc.h>
|
2021-03-07 02:52:25 +03:00
|
|
|
|
|
|
|
static struct gdt_desc gdt_descs[] = {
|
|
|
|
{0},
|
|
|
|
|
|
|
|
{
|
|
|
|
.limit = 0xffff,
|
|
|
|
.base_low = 0x0000,
|
|
|
|
.base_mid = 0x00,
|
|
|
|
.access = 0b10011010,
|
|
|
|
.granularity = 0b00000000,
|
|
|
|
.base_hi = 0x00
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.limit = 0xffff,
|
|
|
|
.base_low = 0x0000,
|
|
|
|
.base_mid = 0x00,
|
|
|
|
.access = 0b10010010,
|
|
|
|
.granularity = 0b00000000,
|
|
|
|
.base_hi = 0x00
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.limit = 0xffff,
|
|
|
|
.base_low = 0x0000,
|
|
|
|
.base_mid = 0x00,
|
|
|
|
.access = 0b10011010,
|
|
|
|
.granularity = 0b11001111,
|
|
|
|
.base_hi = 0x00
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.limit = 0xffff,
|
|
|
|
.base_low = 0x0000,
|
|
|
|
.base_mid = 0x00,
|
|
|
|
.access = 0b10010010,
|
|
|
|
.granularity = 0b11001111,
|
|
|
|
.base_hi = 0x00
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.limit = 0x0000,
|
|
|
|
.base_low = 0x0000,
|
|
|
|
.base_mid = 0x00,
|
|
|
|
.access = 0b10011010,
|
|
|
|
.granularity = 0b00100000,
|
|
|
|
.base_hi = 0x00
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
.limit = 0x0000,
|
|
|
|
.base_low = 0x0000,
|
|
|
|
.base_mid = 0x00,
|
|
|
|
.access = 0b10010010,
|
|
|
|
.granularity = 0b00000000,
|
|
|
|
.base_hi = 0x00
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-15 11:03:47 +03:00
|
|
|
#if bios == 1
|
2021-03-13 05:21:01 +03:00
|
|
|
__attribute__((section(".realmode")))
|
|
|
|
#endif
|
2021-03-07 02:52:25 +03:00
|
|
|
struct gdtr gdt = {
|
|
|
|
sizeof(gdt_descs) - 1,
|
2021-03-08 02:50:23 +03:00
|
|
|
(uintptr_t)gdt_descs,
|
2021-07-20 14:35:43 +03:00
|
|
|
#if defined (__i386__)
|
2021-03-08 02:50:23 +03:00
|
|
|
0
|
|
|
|
#endif
|
2021-03-07 02:52:25 +03:00
|
|
|
};
|
2021-11-25 23:51:41 +03:00
|
|
|
|
|
|
|
#if uefi == 1
|
|
|
|
void init_gdt(void) {
|
|
|
|
struct gdt_desc *gdt_copy = ext_mem_alloc(sizeof(gdt_descs));
|
|
|
|
memcpy(gdt_copy, gdt_descs, sizeof(gdt_descs));
|
|
|
|
gdt.ptr = (uintptr_t)gdt_copy;
|
|
|
|
}
|
|
|
|
#endif
|