diff --git a/kernel/GDT/gdt.cpp b/kernel/GDT/gdt.cpp index 4e2c28c..3b84e71 100644 --- a/kernel/GDT/gdt.cpp +++ b/kernel/GDT/gdt.cpp @@ -1,5 +1,6 @@ #include "gdt.hpp" #include "../Helpers/types.hpp" +#include "../Helpers/memory.hpp" Gdt::Gdt(){ @@ -39,7 +40,14 @@ void Gdt::initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, gdtDescriptorStr } void Gdt::loadGdt(){ + int *gdtAdress=(int *)&m_Pointer; //Copy Gdt into memory and init registers + memcpy((u32)m_Descriptors, (u32)m_Pointer.segment, (u32)m_Pointer.size); + + __asm__("lgdtl (%0);" + : + :"r"(gdtAdress) + ); } diff --git a/kernel/Helpers/helpers.o b/kernel/Helpers/helpers.o index 596d276..9141e7d 100644 Binary files a/kernel/Helpers/helpers.o and b/kernel/Helpers/helpers.o differ diff --git a/kernel/Helpers/memory.cpp b/kernel/Helpers/memory.cpp index a2b130e..741a094 100644 --- a/kernel/Helpers/memory.cpp +++ b/kernel/Helpers/memory.cpp @@ -1,12 +1,12 @@ #include "./memory.hpp" #include "./types.hpp" -int memcpy(u8 source, u8 dest, u32 size){ +int memcpy(u32 source, u32 dest, u32 size){ - u8 *sourceTmp=(u8 *)source; - u8 *destTmp=(u8 *)dest; + u32 *sourceTmp=(u32 *)source; + u32 *destTmp=(u32 *)dest; - int progress=0; + u32 progress=0; while(progress != size){ diff --git a/kernel/Helpers/memory.hpp b/kernel/Helpers/memory.hpp index e0b629b..fcd08a5 100644 --- a/kernel/Helpers/memory.hpp +++ b/kernel/Helpers/memory.hpp @@ -3,7 +3,7 @@ #include "./types.hpp" -int memcpy(u8 source, u8 dest, u32 size); +int memcpy(u32 source, u32 dest, u32 size); #endif diff --git a/kernel/Makefile b/kernel/Makefile index 66ee967..8fdfe2d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -7,7 +7,7 @@ all:$(EXEC) #----- Kernel ----- $(EXEC):entry.o main.o GDT/gdt.o Helpers/helpers.o - ld -m elf_i386 --entry=_start -Ttext=0x100000 -o $@ $^ + $(CXX) --entry=_start -Ttext=0x100000 -o $@ $^ #----------------- diff --git a/kernel/entry.asm b/kernel/entry.asm index cb41910..04f580a 100644 --- a/kernel/entry.asm +++ b/kernel/entry.asm @@ -4,10 +4,10 @@ extern main ;Define entry point as global for linking -global _start +global _kernelEntry ;Define kernel entry point -_start: +_kernelEntry: jmp begin ;Go to begin (for skip Multiboot Specification Header) diff --git a/kernel/main.cpp b/kernel/main.cpp index af5f048..634a147 100644 --- a/kernel/main.cpp +++ b/kernel/main.cpp @@ -4,6 +4,12 @@ int main(){ + //Create Gdt instance + Gdt gdt; + + //Load Gdt into memory + gdt.loadGdt(); + while(1); return 0;