diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-16 21:46:29 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-16 21:46:29 +0100 |
| commit | a4d4de6913fb7dd54847b0e5a004c3100bc02459 (patch) | |
| tree | 4b7eba7d0bcc282f96db8725466ee403f95e35ec /Private/HALKit | |
| parent | e8d46c98880ed3f33fc1760e8f3a99577fa31eb3 (diff) | |
HCR-14: Reworked page allocator for AMD64.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/HALKit')
| -rw-r--r-- | Private/HALKit/AMD64/HalControlRegister.s | 24 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalInterruptRouting.asm | 64 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMain.cxx | 7 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.cpp | 43 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.hpp | 14 | ||||
| -rw-r--r-- | Private/HALKit/AXP/CR.s | 2 | ||||
| -rw-r--r-- | Private/HALKit/AXP/VM.s | 4 | ||||
| -rw-r--r-- | Private/HALKit/PowerPC/HalThread.cxx | 2 |
8 files changed, 57 insertions, 103 deletions
diff --git a/Private/HALKit/AMD64/HalControlRegister.s b/Private/HALKit/AMD64/HalControlRegister.s index 0504d2fb..1f1f4512 100644 --- a/Private/HALKit/AMD64/HalControlRegister.s +++ b/Private/HALKit/AMD64/HalControlRegister.s @@ -4,36 +4,36 @@ ------------------------------------------- */ -.globl write_cr3 -.globl write_cr0 -.globl read_cr2 -.globl read_cr3 -.globl read_cr0 -.globl flush_tlb +.globl hal_write_cr3 +.globl hal_write_cr0 +.globl hal_read_cr2 +.globl hal_read_cr3 +.globl hal_read_cr0 +.globl hal_flush_tlb .section .text -flush_tlb: +hal_flush_tlb: invlpg (%rcx) ret -read_cr3: +hal_read_cr3: movq %rax, %cr3 ret -read_cr0: +hal_read_cr0: movq %rax, %cr0 ret -read_cr2: +hal_read_cr2: movq %rax, %cr2 ret -write_cr3: +hal_write_cr3: movq %cr3, %rdi ret -write_cr0: +hal_write_cr0: movq %cr0, %rdi ret diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm index 6bbc12fd..2364593d 100644 --- a/Private/HALKit/AMD64/HalInterruptRouting.asm +++ b/Private/HALKit/AMD64/HalInterruptRouting.asm @@ -128,56 +128,16 @@ __HCR_INT_33: sti iretq -__HCR_INT_34: - cld - - iretq - - -__HCR_INT_35: - cld - - iretq - -__HCR_INT_36: - cld - - iretq - -__HCR_INT_37: - cld - - iretq - -__HCR_INT_38: - cld - - iretq - -__HCR_INT_39: - cld - - iretq - -__HCR_INT_40: - cld - - iretq - -__HCR_INT_41: - cld - - iretq - -__HCR_INT_42: - cld - - iretq - -__HCR_INT_43: - cld - - iretq +IntNormal 34 +IntNormal 35 +IntNormal 36 +IntNormal 37 +IntNormal 38 +IntNormal 39 +IntNormal 40 +IntNormal 41 +IntNormal 42 +IntNormal 43 __HCR_INT_44: cli @@ -200,10 +160,8 @@ __HCR_INT_44: sti iretq -__HCR_INT_45: - cld - iretq +IntNormal 45 IntNormal 46 IntNormal 47 diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index 248ae8cb..b3f2aa42 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -31,7 +31,7 @@ STATIC HCore::Void ke_page_protect_nullptr(HCore::Void) { pageDirNull->Pte[indexPte].Rw = false; } - flush_tlb(reinterpret_cast<HCore::UIntPtr>(pageDirNull)); + hal_flush_tlb(reinterpret_cast<HCore::UIntPtr>(pageDirNull)); } } // namespace Detail @@ -43,7 +43,7 @@ EXTERN_C void RuntimeMain( kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = HandoverHeader->f_VirtualStart; - kKernelPhysicalSize = HandoverHeader->f_PhysicalSize; + kKernelPhysicalSize = HandoverHeader->f_PhysicalSize - kPTEAlign; kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; STATIC HCore::HAL::Detail::HCoreGDT GDT = { @@ -95,10 +95,9 @@ EXTERN_C void RuntimeMain( /// We already have an install of HCore. if (HandoverHeader->f_Bootloader == kInstalledMedia) { - HCore::kcout << "HCoreKrnl.exe: Running kernel...\r\n"; /// TODO: Parse system configuration. } else { - HCore::kcout << "HCoreKrnl.exe: Running setup...\r\n"; + /// TODO: Install hcore on host. } HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP); diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 599810f3..867f39cb 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -12,52 +12,49 @@ // this files handles paging. STATIC HCore::SizeT kPageCnt = 0UL; +STATIC HCore::Boolean kAllocationInProgress = false; -#define kKernelPagingPadding (4096) +#define kKernelPagingPadding kPTEAlign namespace HCore { namespace HAL { -static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) +/// @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(SizeT sz, Boolean rw, Boolean user) -> PageTable64 * { + kAllocationInProgress = true; MUST_PASS(sz > 0); - PageTable64 *pte = - &reinterpret_cast<PageDirectory64 *>((UIntPtr)kKernelVirtualStart)->Pte[0]; + PageTable64 *pte = reinterpret_cast<PageTable64 *>(kKernelVirtualStart); pte->Rw = rw; pte->User = user; pte->Present = true; + pte->PhysicalAddress = (UIntPtr)kKernelPhysicalStart; - write_cr3((UIntPtr)kKernelVirtualStart); + kKernelVirtualStart = (VoidPtr)((UIntPtr)kKernelVirtualStart + kKernelPagingPadding); + kKernelPhysicalStart = (VoidPtr)((UIntPtr)kKernelPhysicalStart + kKernelPagingPadding); - kKernelVirtualStart = (VoidPtr)((UIntPtr)kKernelVirtualStart + kPageCnt + sz + - kKernelPagingPadding); + ++kPageCnt; + kAllocationInProgress = false; return pte; } auto hal_alloc_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64 * { - for (SizeT i = 0; i < kPageCnt; ++i) { - PageDirectory64 *pte = reinterpret_cast<PageDirectory64 *>( - (UIntPtr)kKernelVirtualStart + kPageCnt); - - for (size_t indexPte = 0; indexPte < kPTEMax; ++indexPte) - { - if (!pte->Pte[indexPte].Present) { - pte->Pte[indexPte].User = user; - pte->Pte[indexPte].Rw = rw; - pte->Pte[indexPte].Present = true; - - return &(pte->Pte[indexPte]); - } - } - - } + if (sz == 0) + ++sz; + /// allocate new page. return hal_try_alloc_new_page(sz, rw, user); } auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr { + while (kAllocationInProgress) {} + PageTable64 *new_pte = hal_alloc_page(sizeof(PageTable64), rw, user); MUST_PASS(new_pte); diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp index bea28808..34d76d3d 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.hpp +++ b/Private/HALKit/AMD64/HalPageAlloc.hpp @@ -26,16 +26,16 @@ #define kPTESize (0x1000) #endif // !kPTESize -EXTERN_C void flush_tlb(HCore::UIntPtr pde); -EXTERN_C void write_cr3(HCore::UIntPtr pde); -EXTERN_C void write_cr0(HCore::UIntPtr bit); +EXTERN_C void hal_flush_tlb(HCore::UIntPtr pde); +EXTERN_C void hal_write_cr3(HCore::UIntPtr pde); +EXTERN_C void hal_write_cr0(HCore::UIntPtr bit); -EXTERN_C HCore::UIntPtr read_cr0(); // @brief CPU control register. -EXTERN_C HCore::UIntPtr read_cr2(); // @brief Fault address. -EXTERN_C HCore::UIntPtr read_cr3(); // @brief Page table. +EXTERN_C HCore::UIntPtr hal_read_cr0(); // @brief CPU control register. +EXTERN_C HCore::UIntPtr hal_read_cr2(); // @brief Fault address. +EXTERN_C HCore::UIntPtr hal_read_cr3(); // @brief Page table. namespace HCore::HAL { -struct PageTable64 { +struct PACKED PageTable64 final { bool Present : 1; bool Rw : 1; bool User : 1; diff --git a/Private/HALKit/AXP/CR.s b/Private/HALKit/AXP/CR.s index b01dc619..4d68257d 100644 --- a/Private/HALKit/AXP/CR.s +++ b/Private/HALKit/AXP/CR.s @@ -6,6 +6,6 @@ movq %r30, %cr3 ret - read_cr0: + hal_read_cr0: movq %r30, %cr0 ret
\ No newline at end of file diff --git a/Private/HALKit/AXP/VM.s b/Private/HALKit/AXP/VM.s index d8d7aa71..7024086b 100644 --- a/Private/HALKit/AXP/VM.s +++ b/Private/HALKit/AXP/VM.s @@ -1,5 +1,5 @@ -.global flush_tlb +.global hal_flush_tlb .section .text -flush_tlb: +hal_flush_tlb: swppal
\ No newline at end of file diff --git a/Private/HALKit/PowerPC/HalThread.cxx b/Private/HALKit/PowerPC/HalThread.cxx index 4b8ef8d8..585ae706 100644 --- a/Private/HALKit/PowerPC/HalThread.cxx +++ b/Private/HALKit/PowerPC/HalThread.cxx @@ -7,7 +7,7 @@ #include <HALKit/PowerPC/Processor.hpp> #include <KernelKit/DebugOutput.hpp> -extern "C" void flush_tlb() {} +extern "C" void hal_flush_tlb() {} extern "C" void rt_wait_400ns() {} extern "C" HCore::HAL::StackFramePtr rt_get_current_context() { return nullptr; } |
