From 819e76156b9b955074a58bc177965a3d65d837ae Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 14 Sep 2025 20:45:19 -0400 Subject: kern: vm: Implement page mapping and VASes This commit implements an interface to allow other parts of Lunos to talk to the MMU: - Added the 'vas' structure as the virtual address space - Added MMU specific prot flags - Added mmu_map_single() to map pages - Added mmu_this_vas() to grab the current VAS ... Signed-off-by: Ian Moffett --- src/sys/include/arch/amd64/mmu.h | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/sys/include/arch/amd64/mmu.h') diff --git a/src/sys/include/arch/amd64/mmu.h b/src/sys/include/arch/amd64/mmu.h index 09298b6..0cecd68 100644 --- a/src/sys/include/arch/amd64/mmu.h +++ b/src/sys/include/arch/amd64/mmu.h @@ -35,6 +35,46 @@ #ifndef _MACHINE_MMU_H_ #define _MACHINE_MMU_H_ +#include +#include +#include + +/* + * Standard memory protection flags + */ +#define MMU_PROT_NONE 0x0 /* Nothing */ +#define MMU_PROT_READ BIT(0) /* Readable */ +#define MMU_PROT_WRITE BIT(1) /* Writable */ +#define MMU_PROT_EXEC BIT(2) /* Executable */ + + +/* + * This will represent a virtual to + * physical address mapping. + * + * @va: Virtual address + * @pa: Physical address + */ +struct mmu_map { + vaddr_t va; + paddr_t pa; +}; + +/* + * Represents the current virtual address + * + * @cr3: The value of CR3 for this VAS + */ +struct vm_vas { + paddr_t cr3; +}; + +/* + * Global early kernel VAS structure used in the + * creation of new virtual address spaces. + */ +extern struct vm_vas g_kvas; + /* * Initialize arch-specific MMU state such as * page tables, initial mappings and sanity checks. @@ -44,4 +84,24 @@ */ int mmu_init(void); +/* + * Map a single virtual page into physical address + * space. + * + * @spec: Mapping specifier (virtual/physical address) + * @prot: Protection flags for the mapping (see MMU_PROT_*) + */ +int mmu_map_single(struct vm_vas *vas, struct mmu_map *spec, int prot); + +/* + * Get a pointer to the current virtual address + * space. + * + * @vasres_p: Resulting VAS is written here + * + * Returns zero on success, otherwise a less than zero + * value on failure. + */ +int mmu_this_vas(struct vm_vas *vasres_p); + #endif /* !_MACHINE_MMU_H_ */ -- cgit v1.2.3