BarinkOS/src/kernel/gdt/gdtc.cpp

32 lines
786 B
C++
Raw Normal View History

2021-05-12 22:03:00 +00:00
#include "gdtc.h"
#include "../tty/kterm.h"
2021-05-12 22:03:00 +00:00
gdtEntry_t gdt[3];
2021-11-06 20:56:42 +00:00
gdtSegmentPointer gdtPointer{};
2021-05-12 22:03:00 +00:00
void gdtSetGate(int num, uint64_t base, uint64_t limit, uint8_t access,
uint8_t gran){
gdt[num].lBase = (base & 0xFFFF);
gdt[num].mBase = (base >> 16) & 0xFF;
gdt[num].hBase = (base >> 24) & 0xFF;
gdt[num].lLimit = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
gdt[num].granularity |= (gran & 0xF0);
gdt[num].access = access;
}
void setupGdt(){
gdtPointer.limit = (sizeof(gdtEntry_t) * 3) - 1;
2021-11-06 20:56:42 +00:00
gdtPointer.base = (uint32_t) &gdt;
2021-05-12 22:03:00 +00:00
gdtSetGate(0, 0, 0, 0, 0);
gdtSetGate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdtSetGate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
2021-11-06 20:56:42 +00:00
printf("call to load gdt\n");
load_gdt();
2021-05-12 22:03:00 +00:00
}