Move vmm fully into hal
This commit is contained in:
@ -7,8 +7,10 @@
|
||||
#include "paging.h"
|
||||
#include "proc/proc.h"
|
||||
#include "kprintf.h"
|
||||
#include "spinlock/spinlock.h"
|
||||
|
||||
PgTable *KERNEL_CR3 = NULL;
|
||||
SpinLock spinlock;
|
||||
|
||||
PgTable *hal_vmm_current_cr3(void) {
|
||||
PgTable *cr3;
|
||||
@ -49,7 +51,9 @@ void hal_vmm_map_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr, uint3
|
||||
uint64_t *pml1 = hal_vmm_nexttable((uint64_t *)pml2, pi.pml2);
|
||||
uint64_t *pte = &pml1[pi.pml1];
|
||||
|
||||
spinlock_acquire(&spinlock);
|
||||
*pte = (physaddr & ~0xFFF) | (flags & 0x7);
|
||||
spinlock_release(&spinlock);
|
||||
}
|
||||
|
||||
void hal_vmm_unmap_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr) {
|
||||
@ -60,7 +64,9 @@ void hal_vmm_unmap_page(PgTable *pml4, uint64_t virtaddr, uint64_t physaddr) {
|
||||
uint64_t *pml1 = hal_vmm_nexttable((uint64_t *)pml2, pi.pml2);
|
||||
uint64_t *pte = &pml1[pi.pml1];
|
||||
|
||||
spinlock_acquire(&spinlock);
|
||||
*pte &= ~HAL_PG_PRESENT;
|
||||
spinlock_release(&spinlock);
|
||||
}
|
||||
|
||||
void hal_vmm_map_range(PgTable *cr3, void *virtstart, void *physstart, size_t size, uint32_t flags) {
|
||||
@ -113,6 +119,6 @@ PgTable *hal_vmm_userproc_pml4(Proc *proc) {
|
||||
}
|
||||
|
||||
void hal_vmm_init(void) {
|
||||
spinlock_init(&spinlock);
|
||||
KERNEL_CR3 = hal_vmm_current_cr3();
|
||||
kprintf("KERNEL_CR3 = %p\n", KERNEL_CR3);
|
||||
}
|
||||
|
Reference in New Issue
Block a user