Files
novaos/kernel/arch/paging/paging.c

56 lines
1.4 KiB
C

#include <stdint.h>
#include <stdio.h>
#include <kernel/paging.h>
//extern uint32_t endkernel; // found in link.ld
/**
* The page table must be page aligned (aligned at 4KiB)
*
*
* This is a temporary solution, as we want a page frame allocator, to properly get page frames.. but this works for now
*/
uint32_t page_directory[PAGE_DIRECTORY_ENTRIES] __attribute__((aligned(4096)));
uint32_t first_page_table[PAGE_TABLE_ENTRIES] __attribute__((aligned(4096)));
void setup_page_table(void)
{
uint32_t i;
for (i = 0; i < PAGE_TABLE_ENTRIES; i++) {
first_page_table[i] = (i * 0x1000) | 3; // supervisor, r/w, present
}
puts("test");
}
void setup_page_dir(void)
{
setup_page_table();
/**
* Now that we have a page directory, we need to blank it.
*
* The page directory should have exactly 1024 entries. We will set each entry to not present, so that the if the
* MMU looks for that page table, it will see that it is not there yet.
*/
int i;
for (i = 0; i < PAGE_DIRECTORY_ENTRIES; i++) {
// This sets the following flags to the pages:
// Supervisor: Only kernel-mode can access them
// Write Enabled: It can be both read from and written to
// Not Present: The page table is not present
page_directory[i] = 0x00000002;
}
page_directory[0] = ((uint32_t) first_page_table) | 3;
}
void setup_paging(void)
{
setup_page_dir();
load_page_directory(page_directory);
enable_paging();
}