Create and load new page directories
This commit is contained in:
parent
d483d8f39e
commit
2d0f539e23
@ -35,6 +35,8 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data)
|
|||||||
|
|
||||||
cpu_init();
|
cpu_init();
|
||||||
|
|
||||||
|
uintptr_t P4 = new_P4();
|
||||||
|
write_cr3(P4);
|
||||||
|
|
||||||
debug_ok("Boot \"Complete\"\n");
|
debug_ok("Boot \"Complete\"\n");
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ read_cr2:
|
|||||||
read_cr3:
|
read_cr3:
|
||||||
mov rax, cr3
|
mov rax, cr3
|
||||||
ret
|
ret
|
||||||
|
.global write_cr3
|
||||||
|
write_cr3:
|
||||||
|
mov cr3, rdi
|
||||||
|
ret
|
||||||
.global read_cr4
|
.global read_cr4
|
||||||
read_cr4:
|
read_cr4:
|
||||||
mov rax, cr4
|
mov rax, cr4
|
||||||
|
@ -9,4 +9,5 @@ void load_idt(void *);
|
|||||||
uint64_t read_cr0();
|
uint64_t read_cr0();
|
||||||
uint64_t read_cr2();
|
uint64_t read_cr2();
|
||||||
uint64_t read_cr3();
|
uint64_t read_cr3();
|
||||||
|
void write_cr3(uint64_t);
|
||||||
uint64_t read_cr4();
|
uint64_t read_cr4();
|
||||||
|
@ -39,6 +39,7 @@ void pmm_free(uint64_t page);
|
|||||||
uint64_t pmm_alloc();
|
uint64_t pmm_alloc();
|
||||||
uint64_t pmm_calloc();
|
uint64_t pmm_calloc();
|
||||||
|
|
||||||
|
uint64_t new_P4();
|
||||||
uint64_t vmm_get_page(uint64_t P4, uint64_t addr);
|
uint64_t vmm_get_page(uint64_t P4, uint64_t addr);
|
||||||
#define PAGE_EXIST(p) ((p) != (uint64_t)-1)
|
#define PAGE_EXIST(p) ((p) != (uint64_t)-1)
|
||||||
int vmm_set_page(uint64_t P4, uint64_t addr, uint64_t page, uint16_t flags);
|
int vmm_set_page(uint64_t P4, uint64_t addr, uint64_t page, uint16_t flags);
|
||||||
|
@ -14,6 +14,13 @@
|
|||||||
#define P2E PT(P3E)[P2_OFFSET(addr)]
|
#define P2E PT(P3E)[P2_OFFSET(addr)]
|
||||||
#define P1E PT(P2E)[P1_OFFSET(addr)]
|
#define P1E PT(P2E)[P1_OFFSET(addr)]
|
||||||
|
|
||||||
|
uint64_t new_P4()
|
||||||
|
{
|
||||||
|
uint64_t p4 = pmm_alloc();
|
||||||
|
memcpy(P2V(p4), (void *)kernel_P4, PAGE_SIZE);
|
||||||
|
return p4;
|
||||||
|
}
|
||||||
|
|
||||||
static int page_exists(uint64_t P4, uint64_t addr)
|
static int page_exists(uint64_t P4, uint64_t addr)
|
||||||
{
|
{
|
||||||
if(P4 && PRESENT(P4E) && PRESENT(P3E) && PRESENT(P2E))
|
if(P4 && PRESENT(P4E) && PRESENT(P3E) && PRESENT(P2E))
|
||||||
|
@ -3,7 +3,13 @@
|
|||||||
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#undef P2V
|
#undef P2V
|
||||||
#define P2V(p) (p)
|
#define P2V(p) ((void *)(p))
|
||||||
|
|
||||||
|
uint64_t kernel_P4;
|
||||||
|
uint64_t pmm_alloc()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#include "vmm.c"
|
#include "vmm.c"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user