summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit/AMD64/HalPageAlloc.cpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-26 22:26:48 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-26 22:27:09 +0100
commiteba8b7ddd0a455d9e49f32dcae712c5612c0093c (patch)
tree749a3d34546d055507a920bce4ab10e8a9945719 /Private/HALKit/AMD64/HalPageAlloc.cpp
parentdd192787a70a973f2474720aea49af3f6ddabb7a (diff)
Kernel: Major repository refactor.
Rework the repo into Private and Public modules. 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.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp
new file mode 100644
index 00000000..ccdfa8b6
--- /dev/null
+++ b/Private/HALKit/AMD64/HalPageAlloc.cpp
@@ -0,0 +1,61 @@
+/*
+ * ========================================================
+ *
+ * hCore
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <HALKit/AMD64/HalPageAlloc.hpp>
+#include <NewKit/Defines.hpp>
+#include <NewKit/Panic.hpp>
+
+// this files handles paging.
+
+static hCore::UIntPtr kPagePtr = 0x0900000;
+static hCore::SizeT kPageCnt = 0UL;
+
+namespace hCore
+{
+ namespace HAL
+ {
+ static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64*
+ {
+ char *ptr = &(reinterpret_cast<char*>(kPagePtr))[kPageCnt + 1];
+
+ PageTable64 *pte = reinterpret_cast<PageTable64*>(ptr);
+ pte->Rw = rw;
+ pte->User = user;
+ pte->Present = true;
+
+ return pte;
+ }
+
+ auto hal_alloc_page(SizeT sz, Boolean rw, Boolean user) -> PageTable64*
+ {
+ for (SizeT i = 0; i < kPageCnt; ++i)
+ {
+ PageTable64 *pte = (reinterpret_cast<PageTable64*>(&kPagePtr) + i);
+
+ if (!pte->Present) {
+ pte->User = user;
+ pte->Rw = rw;
+ pte->Present = true;
+
+ return pte;
+ }
+ }
+
+ return hal_try_alloc_new_page(sz, rw, user);
+ }
+
+ auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr
+ {
+ PageTable64 *new_pte = hal_alloc_page(sizeof(PageTable64), rw, user);
+ MUST_PASS(new_pte);
+
+ return reinterpret_cast<UIntPtr>(new_pte);
+ }
+ } // namespace HAL
+} // namespace hCore