diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-14 20:45:19 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-14 20:45:19 -0400 |
commit | 819e76156b9b955074a58bc177965a3d65d837ae (patch) | |
tree | 33f4d69124905bfa97c17ee5a7cc848cfc468159 /src/sys/include/arch/amd64/mmu.h | |
parent | 977a102db2f47e097f7389313223d36ff7d47333 (diff) |
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 <ian@osmora.org>
Diffstat (limited to 'src/sys/include/arch/amd64/mmu.h')
-rw-r--r-- | src/sys/include/arch/amd64/mmu.h | 60 |
1 files changed, 60 insertions, 0 deletions
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 <sys/cpuvar.h> +#include <sys/param.h> +#include <vm/vm.h> + +/* + * 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_ */ |