From a9c33d93caf401bda5cca516d1fa88c149cd8d01 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 13 Jan 2024 00:17:55 -0500 Subject: kernel/amd64: pmap: Add pmap_unmap() Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/pmap.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'sys/arch/amd64') diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c index cc9c2e8..7ef22f1 100644 --- a/sys/arch/amd64/amd64/pmap.c +++ b/sys/arch/amd64/amd64/pmap.c @@ -104,18 +104,19 @@ pmap_extract(uint8_t level, vaddr_t va, volatile uintptr_t *pmap) } /* + * Modify a page table by writing `val' to it. + * * TODO: Ensure operations here are serialized. * * TODO: Create pmap if they don't exist * i.e., them being null. */ -int -pmap_map(struct vm_ctx *ctx, vaddr_t va, paddr_t pa, vm_prot_t prot) +static int +pmap_modify_tbl(struct vm_ctx *ctx, vaddr_t va, size_t val) { struct vas vas = pmap_read_vas(); volatile uintptr_t *pml4 = PHYS_TO_VIRT(vas.top_level); volatile uintptr_t *pdpt, *pd, *tbl; - uint32_t flags = pmap_prot_to_pte(prot); int status = 0; pdpt = pmap_extract(4, va, pml4); @@ -137,11 +138,26 @@ pmap_map(struct vm_ctx *ctx, vaddr_t va, paddr_t pa, vm_prot_t prot) } /* Map our page */ - tbl[pmap_get_level_index(1, va)] = pa | flags; + tbl[pmap_get_level_index(1, va)] = val; tlb_flush(va); done: return status; } + +int +pmap_map(struct vm_ctx *ctx, vaddr_t va, paddr_t pa, vm_prot_t prot) +{ + uint32_t flags = pmap_prot_to_pte(prot); + + return pmap_modify_tbl(ctx, va, (pa | flags)); +} + +int +pmap_unmap(struct vm_ctx *ctx, vaddr_t va) +{ + return pmap_modify_tbl(ctx, va, 0); +} + struct vas pmap_read_vas(void) { -- cgit v1.2.3