2022-09-07 17:41:08 +00:00
|
|
|
#define MODULE "gdt"
|
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
#include "gdt/GDT.h"
|
2022-09-07 17:41:08 +00:00
|
|
|
#include "log/Log.h"
|
2022-09-05 14:13:51 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
struct GDTR
|
|
|
|
{
|
|
|
|
uint16_t size;
|
|
|
|
uint64_t offset;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct GDTEntry
|
|
|
|
{
|
|
|
|
uint16_t limit0;
|
|
|
|
uint16_t base0;
|
|
|
|
uint8_t base1;
|
|
|
|
uint8_t access;
|
|
|
|
uint8_t limit1_flags;
|
|
|
|
uint8_t base2;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct InternalGDT
|
|
|
|
{
|
|
|
|
GDTEntry null;
|
|
|
|
GDTEntry kernel_code;
|
|
|
|
GDTEntry kernel_data;
|
|
|
|
GDTEntry user_null;
|
|
|
|
GDTEntry user_code;
|
|
|
|
GDTEntry user_data;
|
|
|
|
} __attribute__((packed)) __attribute((aligned(0x1000)));
|
|
|
|
|
|
|
|
__attribute__((aligned(0x1000))) static InternalGDT internal_gdt = {
|
|
|
|
{0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00}, {0xffff, 0x0000, 0x00, 0x9a, 0xaf, 0x00},
|
|
|
|
{0xffff, 0x0000, 0x00, 0x92, 0xcf, 0x00}, {0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xffff, 0x0000, 0x00, 0xfa, 0xaf, 0x00}, {0xffff, 0x0000, 0x00, 0xf2, 0xcf, 0x00}};
|
|
|
|
|
|
|
|
extern "C" void load_gdt(GDTR* gdtr);
|
|
|
|
|
|
|
|
void GDT::load()
|
|
|
|
{
|
|
|
|
static GDTR gdtr;
|
|
|
|
gdtr.offset = (uint64_t)&internal_gdt;
|
|
|
|
gdtr.size = sizeof(InternalGDT);
|
2022-09-08 15:03:17 +00:00
|
|
|
kdbgln("Loading GDT at offset %lx, size %d", gdtr.offset, gdtr.size);
|
2022-09-05 14:13:51 +00:00
|
|
|
load_gdt(&gdtr);
|
|
|
|
}
|