wip: multiple pds and switch to kernel pd when needed

This commit is contained in:
2025-02-10 13:25:19 +01:00
parent 8dd5373e7f
commit 5e561bfa15
9 changed files with 41 additions and 27 deletions

View File

@ -4,12 +4,19 @@
#include <stdint.h>
uint32_t *page_directory = &boot_page_directory;
uint32_t *kernel_pd = &boot_page_directory;
uint32_t *current_pd;
uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t mem_size;
struct frame_zone *head;
void switch_pd(uint32_t *pd, uint32_t *cr3)
{
current_pd = pd;
asm volatile("mov %0, %%cr3" ::"r"(cr3));
}
static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
{
if (!*root) {
@ -61,7 +68,7 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
end_addr = ROUND_CEIL(start_addr + len, PAGE_SIZE);
init_page_table(frame_zones_page_table, 0);
page_directory[1022] = ((uint32_t)frame_zones_page_table - HEAP_END) | 0x03;
kernel_pd[1022] = ((uint32_t)frame_zones_page_table - HEAP_END) | 0x03;
frame_zones_page_table[index] =
((uint32_t)start_addr & PAGE_MASK) | INIT_FLAGS;
@ -107,9 +114,10 @@ static void init_frame_zones(void)
void init_memory(multiboot_info_t *mbd, uint32_t magic)
{
for (uint16_t i = 0; i < 0x300; i++)
page_directory[i] = 0x02;
kernel_pd[i] = 0x02;
init_page_table(page_table_default, 0);
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
kernel_pd[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
current_pd = kernel_pd;
init_multiboot(mbd, magic);
init_frame_zones();
}