summaryrefslogtreecommitdiff
path: root/src/sys/arch
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-16 16:19:15 -0400
committerIan Moffett <ian@osmora.org>2025-09-16 16:19:15 -0400
commit727c5fb46b3b68ed1d00912e87de4874e63405cf (patch)
treef430b423ce9a7fac1e579c5c1ee694a1c9be0b72 /src/sys/arch
parent60e3d4205a7c739ba7e421efd40bbb8a33c6823d (diff)
kern/amd64: mmu: Add routine to switch VAS
This commit introduces a new mmu_write_vas() function to allow the caller to change the virtual address space used by the current processor. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/arch')
-rw-r--r--src/sys/arch/amd64/cpu/mmu.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/sys/arch/amd64/cpu/mmu.c b/src/sys/arch/amd64/cpu/mmu.c
index 3f11781..66f8584 100644
--- a/src/sys/arch/amd64/cpu/mmu.c
+++ b/src/sys/arch/amd64/cpu/mmu.c
@@ -147,6 +147,22 @@ __mmu_read_cr3(void)
}
/*
+ * Write a value to the CR3 register
+ *
+ * @cr3: Value to write
+ */
+static inline void
+__mmu_write_cr3(uint64_t val)
+{
+ __ASMV(
+ "mov %0, %%cr3"
+ :
+ : "r" (val)
+ : "memory"
+ );
+}
+
+/*
* Acquire the paging level used by the
* current processing element (pcore)
*/
@@ -364,6 +380,20 @@ mmu_new_vas(struct vm_vas *res)
}
/*
+ * Switch the VAS
+ */
+int
+mmu_write_vas(struct vm_vas *vas)
+{
+ if (vas->cr3 == 0) {
+ return -EINVAL;
+ }
+
+ __mmu_write_cr3(vas->cr3);
+ return 0;
+}
+
+/*
* Verify that we are in a known state
*/
int