2024-09-18 11:14:06 -04:00
|
|
|
#include "memory.h"
|
2024-10-18 08:45:37 -04:00
|
|
|
#include "debug.h"
|
2024-10-14 18:29:46 -04:00
|
|
|
#include "kprintf.h"
|
|
|
|
|
2024-09-26 10:18:06 -04:00
|
|
|
#include <stdint.h>
|
2024-09-18 11:14:06 -04:00
|
|
|
|
2024-10-14 18:29:46 -04:00
|
|
|
uint32_t *page_directory = &boot_page_directory;
|
2024-10-21 10:29:50 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-10-14 18:29:46 -04:00
|
|
|
|
2024-09-18 11:14:06 -04:00
|
|
|
void init_memory(void)
|
|
|
|
{
|
2024-10-18 08:45:37 -04:00
|
|
|
assert(page_directory);
|
2024-10-17 10:10:39 -04:00
|
|
|
for (int16_t i = 0; i < 0x300; i++)
|
|
|
|
page_directory[i] = 0x02;
|
|
|
|
for (int16_t i = 0; i < 1024; i++)
|
2024-10-21 10:29:50 -04:00
|
|
|
page_table_default[i] = (i << 12) | 0x03;
|
|
|
|
page_directory[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
|
|
|
|
alloc_page_tables();
|
2024-10-17 10:10:39 -04:00
|
|
|
}
|