diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-08 12:32:41 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-08 12:32:41 +0200 |
| commit | 09dd11ddf800898c00ecb04a65fb5cd10fb481fa (patch) | |
| tree | eda0b4e23d6a71da7de3a78f0bb76ec3201dd2f9 /Private/HALKit/AMD64/HalPageAlloc.cpp | |
| parent | ca83108fd138cc0398f900e6a6c0a53ad51aee31 (diff) | |
MHR-23: :boom: changes, reworked project tree.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/HALKit/AMD64/HalPageAlloc.cpp')
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.cpp | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp deleted file mode 100644 index abf340f2..00000000 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include <ArchKit/ArchKit.hpp> -#include <HALKit/AMD64/HalPageAlloc.hpp> -#include <NewKit/Defines.hpp> -#include <NewKit/KernelCheck.hpp> - -STATIC NewOS::Boolean kAllocationInProgress = false; - -namespace NewOS -{ - namespace HAL - { - namespace Detail - { - struct VirtualMemoryHeader - { - UInt32 Magic; - Boolean Present; - Boolean ReadWrite; - Boolean User; - SizeT PageSize; - }; - - struct VirtualMemoryHeaderTraits - { - /// @brief Get next header. - /// @param current - /// @return - VirtualMemoryHeader* Next(VirtualMemoryHeader* current) - { - return current + sizeof(PTE) + current->PageSize; - } - - /// @brief Get previous header. - /// @param current - /// @return - VirtualMemoryHeader* Prev(VirtualMemoryHeader* current) - { - return current - sizeof(PTE) - current->PageSize; - } - }; - } // namespace Detail - - /// @brief Allocates a new page of memory. - /// @param sz the size of it. - /// @param rw read/write flag. - /// @param user user flag. - /// @return the page table of it. - STATIC auto hal_try_alloc_new_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - if (kAllocationInProgress) - return nullptr; - - kAllocationInProgress = true; - - constexpr auto cVMTMagic = 0xDEEFD00D; - - ///! fetch from the start. - Detail::VirtualMemoryHeader* vmHeader = reinterpret_cast<Detail::VirtualMemoryHeader*>(kKernelVirtualStart); - Detail::VirtualMemoryHeaderTraits traits; - - while (vmHeader->Present && - vmHeader->Magic != cVMTMagic) - { - vmHeader = traits.Next(vmHeader); - } - - vmHeader->Magic = cVMTMagic; - vmHeader->Present = true; - vmHeader->ReadWrite = rw; - vmHeader->User = user; - vmHeader->PageSize = size; - - kAllocationInProgress = false; - - return reinterpret_cast<VoidPtr>(vmHeader); - } - - /// @brief Allocate a new page to be used by the OS. - /// @param rw read/write bit. - /// @param user user bit. - /// @return - auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - /// Wait for a ongoing allocation to complete. - while (kAllocationInProgress) - { - ; - } - - if (size == 0) - ++size; - - /// allocate new page. - return hal_try_alloc_new_page(rw, user, size); - } - } // namespace HAL -} // namespace NewOS |
