diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-19 17:56:55 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-19 17:57:16 +0200 |
| commit | 19d0857d84cbc0267a8b222368e143bdcdaaf9a7 (patch) | |
| tree | 8d8a274003cbe6837a5f565e97a810d0774f0624 /Kernel/HALKit/AMD64 | |
| parent | 720e24cea004356da037648b92fd7eb02f3c74a8 (diff) | |
ARM64: Got into the linking stage, writing missing drivers in HAL now.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/HALKit/AMD64')
| -rw-r--r-- | Kernel/HALKit/AMD64/HalPageAlloc.cpp | 103 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalPageAlloc.hpp | 2 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/Processor.hpp | 12 |
3 files changed, 8 insertions, 109 deletions
diff --git a/Kernel/HALKit/AMD64/HalPageAlloc.cpp b/Kernel/HALKit/AMD64/HalPageAlloc.cpp deleted file mode 100644 index ac043cff..00000000 --- a/Kernel/HALKit/AMD64/HalPageAlloc.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#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 diff --git a/Kernel/HALKit/AMD64/HalPageAlloc.hpp b/Kernel/HALKit/AMD64/HalPageAlloc.hpp index 29947f2f..332c8ed4 100644 --- a/Kernel/HALKit/AMD64/HalPageAlloc.hpp +++ b/Kernel/HALKit/AMD64/HalPageAlloc.hpp @@ -45,7 +45,7 @@ namespace NewOS::HAL bool Cache : 1; bool Accessed : 1; NewOS::Int32 Reserved : 6; - NewOS::UIntPtr PhysicalAddress : 36; + NewOS::UInt64 PhysicalAddress : 36; NewOS::Int32 Reserved1 : 15; bool ExecDisable : 1; }; diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hpp index c52fecdf..7c0a4415 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hpp @@ -54,7 +54,7 @@ namespace NewOS namespace NewOS::HAL { - + /// @brief Virtual memory flags. enum { eFlagsUser, @@ -87,9 +87,11 @@ namespace NewOS::HAL { kcout << "PM is already present.\r"; - kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl; - kcout << "User: " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r"; - kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r"; + kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress); + kcout << "\r"; + + kcout << "User: " << (pde->Pte[pml4_index].User ? "YES" : "NO") << "\r"; + kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "YES" : "NO") << "\r"; return 1; } @@ -146,7 +148,7 @@ namespace NewOS::HAL using RawRegister = UInt64; using InterruptId = UShort; /* For each element in the IVT */ - using interruptTrap = UIntPtr(UIntPtr sp); + using InterruptTrapKind = UIntPtr(UIntPtr sp); typedef UIntPtr Reg; |
