diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-04-10 07:39:32 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-04-10 07:47:18 +0200 |
| commit | b3681aa66d52ac531f440a1a8da228f21a7d9546 (patch) | |
| tree | f1df65f71f9fb6883c073f2c77abfc2188650374 /Private/HALKit | |
| parent | 92af2056d51e56b12702c439c82ef335420c9d83 (diff) | |
Kernel: Lots of changes.
ArchKit: Remove rt_wait_400ns, as it is unused outside the AMD64 HAL.
Processor.hpp: Fix typo inside AMD64's StackFrame.
HalPageAlloc.hpp: Rename ControlRegisterBits::Paging to ControlRegisterBits::PageEnable.
HalPageAlloc.cpp: Rework Page allocation API.
HalHardwareMP.cpp: Rename from HalHardwareAPIC.cpp, implement primitive routines.
MBCI: Add new fields inside MBCI host according to standard.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/HALKit')
| -rw-r--r-- | Private/HALKit/AMD64/HalHardwareMP.cpp (renamed from Private/HALKit/AMD64/HalHardwareAPIC.cpp) | 20 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.cpp | 49 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.hpp | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Processor.hpp | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/AHCI.cxx | 4 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/ATA-DMA.cxx | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/ATA-PIO.cxx | 2 | ||||
| -rw-r--r-- | Private/HALKit/PowerPC/HalThread.cxx | 3 | ||||
| -rw-r--r-- | Private/HALKit/PowerPC/HalVirtualMemory.cxx | 10 |
9 files changed, 68 insertions, 26 deletions
diff --git a/Private/HALKit/AMD64/HalHardwareAPIC.cpp b/Private/HALKit/AMD64/HalHardwareMP.cpp index 6d5fe234..0e9f3022 100644 --- a/Private/HALKit/AMD64/HalHardwareAPIC.cpp +++ b/Private/HALKit/AMD64/HalHardwareMP.cpp @@ -9,27 +9,31 @@ // bugs = 0 namespace NewOS { -// @brief wakes up thread. -// wakes up thread from hang. +/// @brief wakes up thread. +/// wakes up thread from hang. void rt_wakeup_thread(HAL::StackFrame* stack) { HAL::rt_cli(); - // TODO + stack->Rcx = 0; HAL::rt_sti(); } -static void __rt_hang_proc(void) { - while (1) { - +/// @brief Hangs until RCX register is cleared. +/// @param stack +static void __rt_hang_proc(HAL::StackFrame* stack) { + while (stack->Rcx == 1) { + ; } } -// @brief makes thread sleep. -// hooks and hangs thread to prevent code from executing. +/// @brief makes thread sleep. +/// hooks and hangs thread to prevent code from executing. void rt_hang_thread(HAL::StackFrame* stack) { HAL::rt_cli(); + __rt_hang_proc(stack); + HAL::rt_sti(); } } // namespace NewOS diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 53680668..3a8d3047 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -12,34 +12,65 @@ STATIC NewOS::Boolean kAllocationInProgress = false; namespace NewOS { namespace HAL { +namespace Detail { +struct VirtualMemoryHeader { + Boolean Present : 1; + Boolean ReadWrite : 1; + Boolean User : 1; +}; + +struct VirtualMemoryHeaderTraits { + /// @brief Get next header. + /// @param current + /// @return + VirtualMemoryHeader* Next(VirtualMemoryHeader* current) { + return current + sizeof(PTE); + } + + /// @brief Get previous header. + /// @param current + /// @return + VirtualMemoryHeader* Prev(VirtualMemoryHeader* current) { + return current - sizeof(PTE); + } +}; +} + /// @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) -> VoidPtr { + if (kAllocationInProgress) return nullptr; + kAllocationInProgress = true; - PTE* newAddress = (PTE*)kKernelVirtualStart; - while (newAddress->Present) { - newAddress = newAddress + sizeof(PTE); + ///! fetch from the start. + Detail::VirtualMemoryHeader* vmHeader = reinterpret_cast<Detail::VirtualMemoryHeader*>(kKernelVirtualStart); + Detail::VirtualMemoryHeaderTraits traits; + + while (vmHeader->Present) { + vmHeader = traits.Next(vmHeader); } - newAddress->Present = true; - newAddress->Rw = rw; - newAddress->User = user; + vmHeader->Present = true; + vmHeader->ReadWrite = rw; + vmHeader->User = user; kAllocationInProgress = false; - return reinterpret_cast<VoidPtr>(newAddress); + return reinterpret_cast<VoidPtr>(vmHeader); } /// @brief Allocate a new page to be used by the OS. -/// @param rw -/// @param user +/// @param rw read/write bit. +/// @param user user bit. /// @return auto hal_alloc_page(Boolean rw, Boolean user) -> VoidPtr { + /// Wait for a ongoing allocation to complete. while (kAllocationInProgress) { + ; } /// allocate new page. diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp index 9cd10213..d23c6e96 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.hpp +++ b/Private/HALKit/AMD64/HalPageAlloc.hpp @@ -60,7 +60,7 @@ enum class ControlRegisterBits { AlignementMask = 18, NotWriteThrough = 29, CacheDisable = 30, - Paging = 31, + PageEnable = 31, }; inline UInt8 control_register_cast(ControlRegisterBits reg) { diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index a2aaf8f7..7e2624d7 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -82,7 +82,7 @@ using interruptTrap = UIntPtr(UIntPtr sp); typedef UIntPtr Reg; struct PACKED StackFrame final { - Reg IntNum, Excpetion; + Reg IntNum, Exception; Reg Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax; Reg R8, R9, R10, R11, R12, R13, R14, R15; Reg Gs, Fs; diff --git a/Private/HALKit/AMD64/Storage/AHCI.cxx b/Private/HALKit/AMD64/Storage/AHCI.cxx index 2b58b744..5e6b3348 100644 --- a/Private/HALKit/AMD64/Storage/AHCI.cxx +++ b/Private/HALKit/AMD64/Storage/AHCI.cxx @@ -15,7 +15,7 @@ * */ -#include <Builtins/AHCI/Defines.hxx> +#include <Builtins/AHCI/AHCI.hxx> #include <KernelKit/PCI/Iterator.hpp> #ifdef __AHCI__ @@ -36,7 +36,7 @@ NewOS::Boolean drv_std_init(NewOS::UInt16& PortsImplemented) { iterator[devIndex].Leak().EnableMmio(); kAhciDevice = iterator[devIndex].Leak(); - kcout << "NewKernel: Found AHCI controller.\r\n"; + kcout << "NewKernel: [PCI] Found AHCI controller.\r\n"; return true; } diff --git a/Private/HALKit/AMD64/Storage/ATA-DMA.cxx b/Private/HALKit/AMD64/Storage/ATA-DMA.cxx index 523c7e17..b40910ab 100644 --- a/Private/HALKit/AMD64/Storage/ATA-DMA.cxx +++ b/Private/HALKit/AMD64/Storage/ATA-DMA.cxx @@ -17,7 +17,7 @@ #include <StorageKit/PRDT.hpp> -#include <Builtins/ATA/Defines.hxx> +#include <Builtins/ATA/ATA.hxx> #include <ArchKit/ArchKit.hpp> using namespace NewOS; diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx index 0ff3591e..ebced11c 100644 --- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -15,7 +15,7 @@ * */ -#include <Builtins/ATA/Defines.hxx> +#include <Builtins/ATA/ATA.hxx> #include <ArchKit/ArchKit.hpp> #ifdef __ATA_PIO__ diff --git a/Private/HALKit/PowerPC/HalThread.cxx b/Private/HALKit/PowerPC/HalThread.cxx index af8bcc6f..a91e7f28 100644 --- a/Private/HALKit/PowerPC/HalThread.cxx +++ b/Private/HALKit/PowerPC/HalThread.cxx @@ -7,7 +7,4 @@ #include <HALKit/PowerPC/Processor.hpp> #include <KernelKit/DebugOutput.hpp> -extern "C" void hal_flush_tlb() {} -extern "C" void rt_wait_400ns() {} - extern "C" NewOS::HAL::StackFramePtr rt_get_current_context() { return nullptr; } diff --git a/Private/HALKit/PowerPC/HalVirtualMemory.cxx b/Private/HALKit/PowerPC/HalVirtualMemory.cxx new file mode 100644 index 00000000..0015257e --- /dev/null +++ b/Private/HALKit/PowerPC/HalVirtualMemory.cxx @@ -0,0 +1,10 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <HALKit/PowerPC/Processor.hpp> +#include <KernelKit/DebugOutput.hpp> + +extern "C" void hal_flush_tlb() {} |
