43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
|
#include "gdt/GDT.h"
|
||
|
#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);
|
||
|
load_gdt(&gdtr);
|
||
|
}
|