wip: page_tables allocation

This commit is contained in:
2024-10-21 16:29:50 +02:00
parent 4337bc11c8
commit f5147e78f9
6 changed files with 67 additions and 42 deletions

View File

@ -1,13 +1,22 @@
#include "memory.h"
#include "debug.h"
#include "kprintf.h"
#include "string.h"
#include <stdint.h>
extern uint32_t boot_page_directory;
uint32_t *page_directory = &boot_page_directory;
uint32_t page_table1[1024] __attribute__((aligned(4096)));
uint32_t page_table_default[1024] __attribute__((aligned(4096)));
static void alloc_page_tables(void)
{
uint32_t *frame_ptr = NULL;
for (int16_t i = 1; i < 768; i++) {
uint32_t *page_table = alloc_pages(PAGE_SIZE, &frame_ptr);
for (int16_t j = 0; j < 1024; j++)
page_table[j] = j << 12 | 0x03;
page_directory[i] = ((uint32_t)frame_ptr & PAGE_MASK) | 0x03;
}
}
void init_memory(void)
{
@ -15,6 +24,7 @@ void init_memory(void)
for (int16_t i = 0; i < 0x300; i++)
page_directory[i] = 0x02;
for (int16_t i = 0; i < 1024; i++)
page_table1[i] = (i << 12) | 0x03;
page_directory[342] = ((uint32_t)page_table1 - HEAP_END) | 0x03;
page_table_default[i] = (i << 12) | 0x03;
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
alloc_page_tables();
}