paging is now enabled with __shaky__ code
This commit is contained in:
55
kernel/arch/paging/paging.c
Normal file
55
kernel/arch/paging/paging.c
Normal file
@ -0,0 +1,55 @@
|
||||
#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();
|
||||
}
|
20
kernel/arch/paging/paging_src.s
Normal file
20
kernel/arch/paging/paging_src.s
Normal file
@ -0,0 +1,20 @@
|
||||
global load_page_directory
|
||||
load_page_directory:
|
||||
push ebp
|
||||
mov esp, ebp
|
||||
mov eax, [esp + 4]
|
||||
mov cr3, eax
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
global enable_paging
|
||||
enable_paging:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
mov eax, cr0
|
||||
or eax, 0x80000000
|
||||
mov cr0, eax
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
ret
|
Reference in New Issue
Block a user