fix: paging with higher half kernel

This commit is contained in:
starnakin 2024-10-15 00:29:46 +02:00
parent 9855669662
commit 5fc90ea240
3 changed files with 36 additions and 7 deletions

View File

@ -21,6 +21,8 @@ stack_top:
# Preallocate pages used for paging. Don't hard-code addresses and assume they # Preallocate pages used for paging. Don't hard-code addresses and assume they
# are available, as the bootloader might have loaded its multiboot structures or # are available, as the bootloader might have loaded its multiboot structures or
# modules there. This lets the bootloader know it must avoid the addresses. # modules there. This lets the bootloader know it must avoid the addresses.
.global boot_page_directory
.global boot_page_table1
.section .bss, "aw", @nobits .section .bss, "aw", @nobits
.align 4096 .align 4096
boot_page_directory: boot_page_directory:

View File

@ -1,3 +1,4 @@
#include "alloc.h"
#include "drivers.h" #include "drivers.h"
#include "gdt.h" #include "gdt.h"
#include "idt.h" #include "idt.h"
@ -33,5 +34,7 @@ void kernel_main(void)
"I see no way to confuse an array of 256 seg:off pairs with a " "I see no way to confuse an array of 256 seg:off pairs with a "
"complex 8*unknown quantity -byte descriptor table. -- Troy " "complex 8*unknown quantity -byte descriptor table. -- Troy "
"Martin 03:50, 22 March 2009 (UTC)\n"); "Martin 03:50, 22 March 2009 (UTC)\n");
while (!kmalloc(10))
;
shell_init(); shell_init();
} }

View File

@ -1,19 +1,43 @@
#include "memory.h" #include "memory.h"
#include "kprintf.h"
#include "string.h" #include "string.h"
#include <stdint.h> #include <stdint.h>
extern void load_page_directory(uint32_t *);
extern void enable_paging(void); extern void enable_paging(void);
extern void load_page_directory(uint32_t *);
uint32_t page_directory_entries[1024] __attribute__((aligned(4096))); extern uint32_t boot_page_table1;
extern uint32_t boot_page_directory;
// Pour récupérer une entrée spécifique
uint32_t *page_directory = &boot_page_directory;
uint32_t page_table_entries[1024] __attribute__((aligned(4096))); uint32_t page_table_entries[1024] __attribute__((aligned(4096)));
unsigned long read_cr3()
{
unsigned long cr3_value;
// Inline assembly to read CR3
__asm__ volatile(
"mov %%cr3, %0" // Move the value of CR3 into cr3_value
: "=r"(
cr3_value) // Output operand: cr3_value will receive the value
: // No input operands
: // No clobber list
);
return cr3_value;
}
static inline void load_cr3(uint64_t cr3_value)
{
asm volatile("mov %0, %%cr3" ::"r"(cr3_value) : "memory");
}
void init_memory(void) void init_memory(void)
{ {
memset(page_directory_entries, INIT_FLAGS, 1024);
for (int i = 0; i < 1024; i++) for (int i = 0; i < 1024; i++)
page_table_entries[i] = (i << 12) | INIT_FLAGS; page_table_entries[i] = (i << 12) | INIT_FLAGS;
page_directory_entries[0] = (uint32_t)page_table_entries | INIT_FLAGS; page_directory[1] = (uint32_t)page_table_entries | INIT_FLAGS;
load_page_directory(page_directory_entries);
enable_paging();
} }