aboutsummaryrefslogtreecommitdiff
path: root/sys/arch/amd64/amd64
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-01-13 00:17:55 -0500
committerIan Moffett <ian@osmora.org>2024-01-13 00:17:55 -0500
commita9c33d93caf401bda5cca516d1fa88c149cd8d01 (patch)
tree83d15aaad97303f4780cd7dedb4b6bd944bd49dd /sys/arch/amd64/amd64
parent28c5e1a7159cfb9a7b599cc1ef8149cfaa17612e (diff)
kernel/amd64: pmap: Add pmap_unmap()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/arch/amd64/amd64')
-rw-r--r--sys/arch/amd64/amd64/pmap.c24
1 files changed, 20 insertions, 4 deletions
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)
{