From c0c846cc15bbc4a14f705eeb923ed1024f4ee1a0 Mon Sep 17 00:00:00 2001 From: Simponic Date: Mon, 1 Mar 2021 15:17:24 -0700 Subject: Move to GitHub for flexing --- src/gdt.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/gdt.c') diff --git a/src/gdt.c b/src/gdt.c index a9808aa..fa52f38 100644 --- a/src/gdt.c +++ b/src/gdt.c @@ -1,5 +1,7 @@ #include "gdt.h" +extern void reloadSegments(); + void encodeGDT(uint8_t* gdtEntry, struct GDT source) { if ((source.limit > 65536) && ((source.limit & 0xFFF) == 0xFFF)) { // Set the GDT to use paging @@ -34,3 +36,32 @@ void encodeGDT(uint8_t* gdtEntry, struct GDT source) { // where most of the ideas for this function are taken from shamelessly gdtEntry[5] = source.type; } + +void initializeGDT() { + struct GDT nullEntry; + nullEntry.limit = 0; + nullEntry.base = 0; + nullEntry.type = 0; + + struct GDT codeSection; + codeSection.limit = 0xFFFFFFFF; + codeSection.base = 0; + codeSection.type = 0x9A; + + struct GDT dataSection; + dataSection.limit = 0xFFFFFFFF; + dataSection.base = 0; + dataSection.type = 0x92; + + encodeGDT(gdt_entries , nullEntry ); + encodeGDT(gdt_entries + 8 , codeSection); + encodeGDT(gdt_entries + 16, dataSection); + + struct GDT_ptr gdt_ptr; + gdt_ptr.limit = 8*3; + gdt_ptr.base = (uint32_t)(&gdt_entries); + + asm("lgdt (%0)" : :"r" ((uint8_t*)(&gdt_ptr))); + + reloadSegments(); +} -- cgit v1.2.3-70-g09d2