feature: enable paging and load page directory
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
#include "gdt.h"
|
||||
#include "memory.h"
|
||||
#include "shell.h"
|
||||
#include "terminal.h"
|
||||
/* #include "power.h" */
|
||||
#include "gdt.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@ -21,9 +20,8 @@
|
||||
|
||||
void kernel_main(void)
|
||||
{
|
||||
/* Initialize terminal interface */
|
||||
terminal_initialize();
|
||||
|
||||
init_gdt();
|
||||
init_memory();
|
||||
shell_init();
|
||||
}
|
||||
|
12
src/memory/load_pd.s
Normal file
12
src/memory/load_pd.s
Normal 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
18
src/memory/memory.c
Normal 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
13
src/memory/paging.s
Normal 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
|
Reference in New Issue
Block a user