diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-23 19:13:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-23 19:15:17 +0100 |
| commit | a13e1c0911c0627184bc38f18c7fdda64447b3ad (patch) | |
| tree | 073a62c09bf216e85a3f310376640fa1805147f9 /dev/kernel/src/PageMgr.cc | |
| parent | 149fa096eb306d03686b3b67e813cf1a78e08cd0 (diff) | |
meta(kernel): Reworked repository's filesystem structure.
Removing useless parts of the project too.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/kernel/src/PageMgr.cc')
| -rw-r--r-- | dev/kernel/src/PageMgr.cc | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/dev/kernel/src/PageMgr.cc b/dev/kernel/src/PageMgr.cc new file mode 100644 index 00000000..eb7c7e03 --- /dev/null +++ b/dev/kernel/src/PageMgr.cc @@ -0,0 +1,110 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include <KernelKit/DebugOutput.h> +#include <NewKit/PageMgr.h> + +#ifdef __NE_AMD64__ +#include <HALKit/AMD64/Paging.h> +#elif defined(__NE_ARM64__) +#include <HALKit/ARM64/Paging.h> +#endif // ifdef __NE_AMD64__ || defined(__NE_ARM64__) + +namespace NeOS +{ + PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr) + : fRw(Rw), + fUser(User), + fExecDisable(ExecDisable), + fVirtAddr(VirtAddr), + fCache(false), + fShareable(false), + fWt(false), + fPresent(true), + fAccessed(false) + { + } + + PTEWrapper::~PTEWrapper() = default; + + /// @brief Flush virtual address. + /// @param VirtAddr + Void PageMgr::FlushTLB() + { +#ifndef __NE_MINIMAL_OS__ + hal_flush_tlb(); +#endif // !__NE_MINIMAL_OS__ + } + + /// @brief Reclaim freed page. + /// @return + Bool PTEWrapper::Reclaim() + { + if (!this->fPresent) + { + this->fPresent = true; + return true; + } + + return false; + } + + /// @brief Request a PTE. + /// @param Rw r/w? + /// @param User user mode? + /// @param ExecDisable disable execution on page? + /// @return + PTEWrapper PageMgr::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) + { + // Store PTE wrapper right after PTE. + VoidPtr ptr = NeOS::HAL::mm_alloc_bitmap(Rw, User, Sz, false); + + return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast<UIntPtr>(ptr)}; + } + + /// @brief Disable BitMap. + /// @param wrapper the wrapper. + /// @return If the page bitmap was cleared or not. + Bool PageMgr::Free(Ref<PTEWrapper>& wrapper) + { + if (!NeOS::HAL::mm_free_bitmap((VoidPtr)wrapper.Leak().VirtualAddress())) + return false; + + return true; + } + + /// @brief Virtual PTE address. + /// @return The virtual address of the page. + const UIntPtr PTEWrapper::VirtualAddress() + { + return (fVirtAddr); + } + + Bool PTEWrapper::Shareable() + { + return fShareable; + } + + Bool PTEWrapper::Present() + { + return fPresent; + } + + Bool PTEWrapper::Access() + { + return fAccessed; + } + + Void PTEWrapper::NoExecute(const bool enable) + { + fExecDisable = enable; + } + + Bool PTEWrapper::NoExecute() + { + return fExecDisable; + } +} // namespace NeOS |
