stos: hal: Add virtual address space helpers
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: AMD64 MMU management
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <hal/mmu.h>
|
||||
#include <machine/vas.h>
|
||||
#include <stdef.h>
|
||||
|
||||
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"
|
||||
);
|
||||
}
|
||||
@@ -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 <stdef.h>
|
||||
|
||||
/*
|
||||
* Represents a virtual address space
|
||||
*
|
||||
* @Cr3: Control register 3 value
|
||||
*/
|
||||
typedef struct {
|
||||
UPTR Cr3;
|
||||
} MMU_VAS;
|
||||
|
||||
#endif /* !_MACHINE_VAS_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 <stdef.h>
|
||||
#include <machine/vas.h>
|
||||
|
||||
/*
|
||||
* 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_ */
|
||||
Reference in New Issue
Block a user