summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-16 21:46:29 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-16 21:46:29 +0100
commita4d4de6913fb7dd54847b0e5a004c3100bc02459 (patch)
tree4b7eba7d0bcc282f96db8725466ee403f95e35ec
parente8d46c98880ed3f33fc1760e8f3a99577fa31eb3 (diff)
HCR-14: Reworked page allocator for AMD64.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
-rw-r--r--Private/FSKit/Defines.hxx (renamed from Private/FSKit/Defines.hpp)0
-rw-r--r--Private/FSKit/NewFSIteratorInterface.hxx (renamed from Private/FSKit/NewFSIndexer.hxx)12
-rw-r--r--Private/HALKit/AMD64/HalControlRegister.s24
-rw-r--r--Private/HALKit/AMD64/HalInterruptRouting.asm64
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx7
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.cpp43
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.hpp14
-rw-r--r--Private/HALKit/AXP/CR.s2
-rw-r--r--Private/HALKit/AXP/VM.s4
-rw-r--r--Private/HALKit/PowerPC/HalThread.cxx2
-rw-r--r--Private/KernelKit/DeviceManager.hpp3
-rw-r--r--Private/NewBoot/BootKit/Arch/AHCI.hxx10
-rw-r--r--Private/NewKit/CxxAbi.hpp2
-rw-r--r--Private/NewKit/PageManager.hpp2
-rw-r--r--Private/Source/CxxAbi.cxx5
-rw-r--r--Private/Source/PageAllocator.cxx4
-rw-r--r--Private/Source/PageManager.cxx6
17 files changed, 78 insertions, 126 deletions
diff --git a/Private/FSKit/Defines.hpp b/Private/FSKit/Defines.hxx
index 73c422be..73c422be 100644
--- a/Private/FSKit/Defines.hpp
+++ b/Private/FSKit/Defines.hxx
diff --git a/Private/FSKit/NewFSIndexer.hxx b/Private/FSKit/NewFSIteratorInterface.hxx
index 023ebdc0..0c7a6743 100644
--- a/Private/FSKit/NewFSIndexer.hxx
+++ b/Private/FSKit/NewFSIteratorInterface.hxx
@@ -11,22 +11,22 @@
namespace HCore {
namespace Indexer {
-class INewFSIterator;
+class NewFSIteratorInterface;
using IndexElement = VoidPtr;
///
-/// @name INewFSIterator
+/// @name NewFSIteratorInterface
/// @brief Stores relevant information for file indexing.
///
-class INewFSIterator {
+class NewFSIteratorInterface {
public:
- explicit INewFSIterator() = default;
- virtual ~INewFSIterator() = default;
+ explicit NewFSIteratorInterface() = default;
+ virtual ~NewFSIteratorInterface() = default;
public:
- HCORE_COPY_DEFAULT(INewFSIterator);
+ HCORE_COPY_DEFAULT(NewFSIteratorInterface);
public:
void Append(IndexableProperty& indexProp) { fProps.Add(indexProp); }
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; }
diff --git a/Private/KernelKit/DeviceManager.hpp b/Private/KernelKit/DeviceManager.hpp
index 9f014c1a..4c9c7970 100644
--- a/Private/KernelKit/DeviceManager.hpp
+++ b/Private/KernelKit/DeviceManager.hpp
@@ -62,7 +62,6 @@ class DeviceInterface {
};
///
-///
/// @brief Input Output Buffer
/// Used mainly to communicate between hardware.
///
@@ -94,7 +93,7 @@ class IOBuf final {
T m_Data;
};
-///! @brief Device types enum.
+///! @brief Device enum types.
enum {
kDeviceTypeIDE,
kDeviceTypeEthernet,
diff --git a/Private/NewBoot/BootKit/Arch/AHCI.hxx b/Private/NewBoot/BootKit/Arch/AHCI.hxx
index 2047c404..9505377b 100644
--- a/Private/NewBoot/BootKit/Arch/AHCI.hxx
+++ b/Private/NewBoot/BootKit/Arch/AHCI.hxx
@@ -17,14 +17,14 @@ class BDeviceAHCI final {
HCORE_COPY_DEFAULT(BDeviceAHCI);
struct AHCITraits final {
- HCore::SizeT mBase{1024};
- HCore::Boolean mErr{false};
- HCore::Boolean mDetected{false};
+ HCore::SizeT fBase{1024};
+ HCore::Boolean fError{false};
+ HCore::Boolean fDetected{false};
- operator bool() { return !this->mErr; }
+ operator bool() { return !this->fError; }
};
- operator bool() { return this->Leak().mDetected; }
+ operator bool() { return this->Leak().fDetected; }
BDeviceAHCI& Read(HCore::WideChar* Buf, const HCore::SizeT& SecCount);
BDeviceAHCI& Write(HCore::WideChar* Buf, const HCore::SizeT& SecCount);
diff --git a/Private/NewKit/CxxAbi.hpp b/Private/NewKit/CxxAbi.hpp
index b82da51a..d210bf18 100644
--- a/Private/NewKit/CxxAbi.hpp
+++ b/Private/NewKit/CxxAbi.hpp
@@ -9,7 +9,7 @@
#ifdef __GNUC__
-#define DSO_MAX_OBJECTS (128)
+#define kDSOMaxObjects (128)
struct atexit_func_entry_t
{
diff --git a/Private/NewKit/PageManager.hpp b/Private/NewKit/PageManager.hpp
index 21c34abf..ace13233 100644
--- a/Private/NewKit/PageManager.hpp
+++ b/Private/NewKit/PageManager.hpp
@@ -32,7 +32,7 @@ class PTEWrapper final {
public:
void FlushTLB(Ref<PageManager> &pm);
- const UIntPtr &VirtualAddress();
+ const UIntPtr VirtualAddress();
void NoExecute(const bool enable = false);
const bool &NoExecute();
diff --git a/Private/Source/CxxAbi.cxx b/Private/Source/CxxAbi.cxx
index 2d3a5aec..d251ffca 100644
--- a/Private/Source/CxxAbi.cxx
+++ b/Private/Source/CxxAbi.cxx
@@ -8,9 +8,8 @@
#include <NewKit/CxxAbi.hpp>
#include <NewKit/KernelCheck.hpp>
-void *__dso_handle;
+atexit_func_entry_t __atexit_funcs[kDSOMaxObjects];
-atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS];
uarch_t __atexit_func_count;
extern "C" void __cxa_pure_virtual() {
@@ -25,7 +24,7 @@ extern "C" void ___chkstk_ms() {
}
extern "C" int atexit(void (*f)(void *), void *arg, void *dso) {
- if (__atexit_func_count >= DSO_MAX_OBJECTS) return -1;
+ if (__atexit_func_count >= kDSOMaxObjects) return -1;
__atexit_funcs[__atexit_func_count].destructor_func = f;
__atexit_funcs[__atexit_func_count].obj_ptr = arg;
diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx
index 990b738b..eb22dd35 100644
--- a/Private/Source/PageAllocator.cxx
+++ b/Private/Source/PageAllocator.cxx
@@ -26,7 +26,7 @@ void exec_disable(UIntPtr VirtualAddr) {
MUST_PASS(!VirtualAddrTable->Accessed);
VirtualAddrTable->ExecDisable = true;
- flush_tlb(VirtualAddr);
+ hal_flush_tlb(VirtualAddr);
}
bool page_disable(UIntPtr VirtualAddr) {
@@ -37,7 +37,7 @@ bool page_disable(UIntPtr VirtualAddr) {
if (VirtualAddrTable->Accessed) return false;
VirtualAddrTable->Present = false;
- flush_tlb(VirtualAddr);
+ hal_flush_tlb(VirtualAddr);
return true;
}
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index 758d69c7..1b535e43 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -57,7 +57,7 @@ void PTEWrapper::FlushTLB(Ref<PageManager> &pm) {
void PageManager::FlushTLB(UIntPtr VirtAddr) {
if (VirtAddr == kBadAddress) return;
- flush_tlb(VirtAddr);
+ hal_flush_tlb(VirtAddr);
}
bool PTEWrapper::Reclaim() {
@@ -94,11 +94,11 @@ bool PageManager::Free(Ref<PTEWrapper *> &wrapper) {
////////////////////////////
-// VIRTUAL ADDRESS
+// VIRTUAL ADDRESS GETTER (SKIP PTE)
////////////////////////////
-const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; }
+const UIntPtr PTEWrapper::VirtualAddress() { return (m_VirtAddr + sizeof(PTE)); }
////////////////////////////