From 532e46c62f7fcf841cfa507065bc1363e80b5694 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Mon, 22 Jun 2026 21:46:51 +0000 Subject: [PATCH] stos: hal: Add virtual address space helpers Signed-off-by: Chloe M. --- paw/stos/arch/amd64/cpu/mmu.c | 41 ++++++++++++++++++++++++++++++++++ paw/stos/head/arch/amd64/vas.h | 23 +++++++++++++++++++ paw/stos/head/hal/mmu.h | 29 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 paw/stos/arch/amd64/cpu/mmu.c create mode 100644 paw/stos/head/arch/amd64/vas.h create mode 100644 paw/stos/head/hal/mmu.h diff --git a/paw/stos/arch/amd64/cpu/mmu.c b/paw/stos/arch/amd64/cpu/mmu.c new file mode 100644 index 0000000..aac78ea --- /dev/null +++ b/paw/stos/arch/amd64/cpu/mmu.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: AMD64 MMU management + * Author: Chloe M. + */ + +#include +#include +#include + +VOID +HalMmuReadVas(MMU_VAS *Result) +{ + if (Result == NULL) { + return; + } + + ASMV( + "mov %%cr3, %0" + : "=r" (Result->Cr3) + : + : "memory" + ); +} + +VOID +HalMmuWriteVas(MMU_VAS *Vas) +{ + if (Vas == NULL) { + return; + } + + ASMV( + "mov %0, %%cr3" + : + : "r" (Vas->Cr3) + : "memory" + ); +} diff --git a/paw/stos/head/arch/amd64/vas.h b/paw/stos/head/arch/amd64/vas.h new file mode 100644 index 0000000..d34e756 --- /dev/null +++ b/paw/stos/head/arch/amd64/vas.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: MD virtual address space + * Author: Chloe M. + */ + +#ifndef _MACHINE_VAS_H_ +#define _MACHINE_VAS_H_ 1 + +#include + +/* + * Represents a virtual address space + * + * @Cr3: Control register 3 value + */ +typedef struct { + UPTR Cr3; +} MMU_VAS; + +#endif /* !_MACHINE_VAS_H_ */ diff --git a/paw/stos/head/hal/mmu.h b/paw/stos/head/hal/mmu.h new file mode 100644 index 0000000..73b22d8 --- /dev/null +++ b/paw/stos/head/hal/mmu.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: MMU HAL layer + * Author: Chloe M. + */ + +#ifndef _HAL_MMU_H_ +#define _HAL_MMU_H_ 1 + +#include +#include + +/* + * Read the current virtual address space + * + * @Result: Result is written here + */ +VOID HalMmuReadVas(MMU_VAS *Result); + +/* + * Write a new virtual address space + * + * @Vas: Virtual address space to write + */ +VOID HalMmuWriteVas(MMU_VAS *Vas); + +#endif /* !_HAL_MMU_H_ */