diff --git a/src/kernel/arch/i686/util.asm b/src/kernel/arch/i686/util.asm index 07fe9df..dabfc5e 100644 --- a/src/kernel/arch/i686/util.asm +++ b/src/kernel/arch/i686/util.asm @@ -11,7 +11,6 @@ Reboot: in al, 0x64 test al, 0x02 jnz Reboot - mov al, 0xFC out 0x64, al @@ -42,11 +41,6 @@ Write_CR3: mov ebp, esp mov eax, [ebp+8] mov cr3, eax + mov esp, ebp pop ebp retn - -global Enable_Paging -Enable_Paging: - mov eax, cr4 - or eax, 0x00000010 - mov cr4, eax diff --git a/src/kernel/arch/i686/util.h b/src/kernel/arch/i686/util.h index f6c7c74..7f8db63 100644 --- a/src/kernel/arch/i686/util.h +++ b/src/kernel/arch/i686/util.h @@ -8,8 +8,7 @@ #include void __attribute__((cdecl)) Reboot(); -unsigned long __attribute__((cdecl)) Read_CR0(); -void __attribute__((cdecl)) Write_CR0(unsigned long value); -unsigned long* __attribute__((cdecl)) Read_CR3(); -void __attribute__((cdecl)) Write_CR3(unsigned long* value); -void __attribute__((cdecl)) Enable_Paging(); +uint32_t __attribute__((cdecl)) Read_CR0(); +void __attribute__((cdecl)) Write_CR0(uint32_t value); +uint32_t* __attribute__((cdecl)) Read_CR3(); +void __attribute__((cdecl)) Write_CR3(uint32_t* value); diff --git a/src/kernel/core/memory/page.c b/src/kernel/core/memory/page.c index f5412d5..319af8e 100644 --- a/src/kernel/core/memory/page.c +++ b/src/kernel/core/memory/page.c @@ -12,29 +12,28 @@ extern uint16_t DEBUG_COM_PORT; -unsigned long* Page_Directory = (unsigned long*) 0x9C000; -unsigned long* Page_Table = (unsigned long*) 0x9D000; +uint32_t Page_Directory[1024] __attribute__((aligned(4096))); +uint32_t Page_Table[1024] __attribute__((aligned(4096))); void Memory_Page_Init() { unsigned long address = 0; - unsigned int i; + unsigned int PDi; - Serial_Printf(DEBUG_COM_PORT, "MEMORY:> Mapping First 4MB of Memory.\n"); - for(i=0; i<1024; i++) { - Page_Table[i] = address | 3; - address = address + 4096; // 4096 = 4kb + Serial_Printf(DEBUG_COM_PORT, "MEMORY:> Inititalizing Memory Paging\n"); + // Set entries to not Present + for(PDi=0; PDi<1024; PDi++) { + Page_Directory[PDi] = 0x00000002; } - Serial_Printf(DEBUG_COM_PORT, "MEMORY:> Inititalizing Page Directory and Table.\n"); + // Set R/W + Supervisor Flags For Table + unsigned int PTi; + for(PTi=0; PTi<1024; PTi++) { + Page_Table[PTi] = (PTi * 0x1000) | 3; + } + // Add Table to Directory & Set R/W Supervisor + Page_Directory[0] = ((unsigned int)Page_Table) | 3; - // fill the first entry of the page directory - Page_Directory[0] = *Page_Table; - Page_Directory[0] = Page_Directory[0] | 3; // attribute set to: supervisor level, read/write - for(i=1; i<1024; i++) { - Page_Directory[i] = 0 | 2; // attribute set to: supervisor level, read/write - } - // Enable_Paging(); + // Enable Paging Write_CR3(Page_Directory); - Write_CR0(Read_CR0() | 0x60000001); // set the paging bit in CR0 to 1 - /* Holy Shit i Fixed Paging */ + Write_CR0(Read_CR0() | 0x80000000); } \ No newline at end of file diff --git a/src/kernel/version.h b/src/kernel/version.h index 47a3b55..849dc6b 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -6,4 +6,4 @@ #pragma once #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" -#define VERSION "RD-00051" \ No newline at end of file +#define VERSION "RD-00052" \ No newline at end of file