From eb009076b2fb2eb06e2524075e1fab3f8e9dd614 Mon Sep 17 00:00:00 2001 From: Chloe M Date: Fri, 10 Jul 2026 21:02:57 -0400 Subject: [PATCH] ptos/amd64: mmu: Add virtual address space helpers Signed-off-by: Chloe M --- service/ptos/arch/amd64/cpu/mmu.c | 40 +++++++++++++++++++++++++++++++ service/ptos/head/hal/mmu.h | 31 ++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 service/ptos/arch/amd64/cpu/mmu.c create mode 100644 service/ptos/head/hal/mmu.h diff --git a/service/ptos/arch/amd64/cpu/mmu.c b/service/ptos/arch/amd64/cpu/mmu.c new file mode 100644 index 0000000..8e5cfd3 --- /dev/null +++ b/service/ptos/arch/amd64/cpu/mmu.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Platform MMU HAL interface + * Author: Chloe M. + */ + +#include +#include + +VOID +HalMmuReadVas(MMU_VAS *Result) +{ + if (Result == NULL) { + return; + } + + ASMV( + "mov %%cr3, %0" + : "=r" (Result->Cr3) + : + : "memory" + ); +} + +VOID +HalMmuWriteVas(const MMU_VAS *Vas) +{ + if (Vas == NULL) { + return; + } + + ASMV( + "mov %0, %%cr3" + : + : "r" (Vas->Cr3) + : "memory" + ); +} diff --git a/service/ptos/head/hal/mmu.h b/service/ptos/head/hal/mmu.h new file mode 100644 index 0000000..d6559b8 --- /dev/null +++ b/service/ptos/head/hal/mmu.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Platform MMU HAL interface + * Author: Chloe M. + */ + +#ifndef _HAL_MMU_H_ +#define _HAL_MMU_H_ 1 + +#include +#include + +/* + * Read the current virtual address space into an + * MMU_VAS descriptor. + * + * @Result: Result is written here + */ +VOID HalMmuReadVas(MMU_VAS *Result); + +/* + * Write a virtual address space into the current context + * from an MMU_VAS descriptor + * + * @Vas: VAS to write to current context + */ +VOID HalMmuWriteVas(const MMU_VAS *Vas); + +#endif /* !_HAL_MMU_H_ */