feature: enable paging and load page directory

This commit is contained in:
2024-09-18 17:14:06 +02:00
parent 65a59534b4
commit ddf3cfff68
5 changed files with 74 additions and 4 deletions

12
src/memory/load_pd.s Normal file
View File

@ -0,0 +1,12 @@
.intel_syntax noprefix
.text
.global load_page_directory
load_page_directory:
push ebp
mov ebp, esp
mov eax, [esp + 8]
mov cr3, eax
mov esp, ebp
pop ebp
ret

18
src/memory/memory.c Normal file
View File

@ -0,0 +1,18 @@
#include "memory.h"
#include "string.h"
extern void load_page_directory(uint32_t *);
extern void enable_paging(void);
uint32_t page_directory_entries[1024] __attribute__((aligned(4096)));
uint32_t page_table_entries[1024] __attribute__((aligned(4096)));
void init_memory(void)
{
memset(page_directory_entries, INIT_FLAGS, 1024);
for (int i = 0; i < 1024; i++)
page_table_entries[i] = (i << 12) | INIT_FLAGS;
page_directory_entries[0] = (uint32_t)page_table_entries | INIT_FLAGS;
load_page_directory(page_directory_entries);
enable_paging();
}

13
src/memory/paging.s Normal file
View File

@ -0,0 +1,13 @@
.intel_syntax noprefix
.text
.global enable_paging
enable_paging:
push ebp
mov ebp, esp
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
mov esp, ebp
pop ebp
ret