diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/arch/amd64/cpu/mmu.c | 32 | ||||
-rw-r--r-- | src/sys/include/vm/mmu.h | 9 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/sys/arch/amd64/cpu/mmu.c b/src/sys/arch/amd64/cpu/mmu.c index 60fb4f1..05e8b55 100644 --- a/src/sys/arch/amd64/cpu/mmu.c +++ b/src/sys/arch/amd64/cpu/mmu.c @@ -333,6 +333,38 @@ mmu_map_single(struct vm_vas *vas, struct mmu_map *spec, int prot) } /* + * Create a new virtual address space + */ +int +mmu_new_vas(struct vm_vas *res) +{ + uint64_t *dest, *src; + paddr_t frame; + + src = PHYS_TO_VIRT(g_kvas.cr3 & PTE_ADDR_MASK); + frame = vm_alloc_frame(1); + if (frame == 0) { + return -ENOMEM; + } + + /* + * Copy only the higher half but zero the + * lower half. + */ + dest = PHYS_TO_VIRT(frame); + for (int i = 0; i < 512; ++i) { + if (i < 256) { + dest[i] = 0; + } else { + dest[i] = src[i]; + } + } + + res->cr3 = VIRT_TO_PHYS(dest); + return 0; +} + +/* * Verify that we are in a known state */ int diff --git a/src/sys/include/vm/mmu.h b/src/sys/include/vm/mmu.h index 5c1c2bb..908748b 100644 --- a/src/sys/include/vm/mmu.h +++ b/src/sys/include/vm/mmu.h @@ -97,4 +97,13 @@ int mmu_map_single(struct vm_vas *vas, struct mmu_map *spec, int prot); */ int mmu_this_vas(struct vm_vas *vasres_p); +/* + * Create a new virtual address structure with a zeroed + * user porition. + * + * Returns zero on success, otherwise a less than zero + * value on failure. + */ +int mmu_new_vas(struct vm_vas *res); + #endif /* !_MACHINE_MMU_H_ */ |