summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-20 18:24:58 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-20 18:25:02 +0100
commitf48c5b2cda43241919d3ea1b263bef01e014c537 (patch)
tree5bf74621fcff0a98163b3908d35cef2a6339bfb7 /Private/Source
parent4ba02280f19b8a2beb1ad8445be7df6b7f9e1805 (diff)
Kernel: See below.
- Fix: Kernel page alloc. Inside HalPageAlloc.cpp. - Made NewFSJournalRunner fields private. - Rework StorageKit for current ticket 14. - :boom: Breaking changes to virtual memory api. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/KernelCheck.cxx2
-rw-r--r--Private/Source/KernelHeap.cxx32
-rw-r--r--Private/Source/NewFS+Journal.cxx6
-rw-r--r--Private/Source/PageAllocator.cxx6
-rw-r--r--Private/Source/PageManager.cxx46
-rw-r--r--Private/Source/Pmm.cxx1
6 files changed, 35 insertions, 58 deletions
diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx
index 593190e1..30c76050 100644
--- a/Private/Source/KernelCheck.cxx
+++ b/Private/Source/KernelCheck.cxx
@@ -47,7 +47,7 @@ void ke_stop(const HCore::Int &id) {
}
case RUNTIME_CHECK_BOOTSTRAP: {
kcout << "*** CAUSE: RUNTIME_CHECK_BOOTSTRAP *** \r\n";
- kcout << "*** WHAT: BAD BOOT. *** \r\n";
+ kcout << "*** WHAT: INVALID BOOT SEQUENCE. *** \r\n";
break;
}
case RUNTIME_CHECK_HANDSHAKE: {
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 359e3cbd..438df005 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -4,8 +4,9 @@
------------------------------------------- */
-#include <NewKit/Crc32.hpp>
+#include <KernelKit/DebugOutput.hpp>
#include <KernelKit/KernelHeap.hpp>
+#include <NewKit/Crc32.hpp>
#include <NewKit/PageManager.hpp>
//! @file KernelHeap.cxx
@@ -14,19 +15,19 @@
#define kHeapMagic 0xD4D7
namespace HCore {
-STATIC SizeT kHeapCount = 0UL;
-STATIC Ref<PTEWrapper> kHeapLastWrapper;
-STATIC PageManager kHeapPageManager;
+STATIC SizeT kHeapCount = 0UL;
+STATIC Ref<PTEWrapper> kHeapLastWrapper;
+STATIC PageManager kHeapPageManager;
namespace Detail {
/// @brief Kernel heap information block.
/// Located before the address bytes.
/// | HIB | ADDRESS |
struct HeapInformationBlock final {
- UInt16 hMagic;
+ UInt16 hMagic;
Boolean hPresent;
- Int32 hCRC32;
- Int64 hSizeAddress;
+ Int32 hCRC32;
+ Int64 hSizeAddress;
UIntPtr hAddress;
};
@@ -44,17 +45,21 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
auto wrapper = kHeapPageManager.Request(rw, user, false);
kHeapLastWrapper = wrapper;
+ kcout << "HCoreKrnl.exe: Populating HIB...\r\n";
+
Detail::HeapInformationBlockPtr heapInfo =
reinterpret_cast<Detail::HeapInformationBlockPtr>(
wrapper.VirtualAddress());
heapInfo->hSizeAddress = sz;
heapInfo->hMagic = kHeapMagic;
- heapInfo->hCRC32 = 0; // dont fill it for now.
+ heapInfo->hCRC32 = 0; // dont fill it for now.
heapInfo->hAddress = wrapper.VirtualAddress();
++kHeapCount;
+ kcout << "HCoreKrnl.exe: Return address...\r\n";
+
return reinterpret_cast<VoidPtr>(wrapper.VirtualAddress() +
sizeof(Detail::HeapInformationBlock));
}
@@ -70,8 +75,10 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) {
if (kHeapLastWrapper && virtualAddress->hMagic == kHeapMagic &&
virtualAddress->hAddress == kHeapLastWrapper.Leak().VirtualAddress()) {
- virtualAddress->hSizeAddress = 0UL;
- virtualAddress->hPresent = false;
+ virtualAddress->hSizeAddress = 0UL;
+ virtualAddress->hPresent = false;
+
+ --kHeapCount;
return true;
}
@@ -84,13 +91,14 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) {
/// @param ptr the pointer
/// @return if it exists.
Boolean ke_is_valid_ptr(VoidPtr ptr) {
+ if (kHeapCount < 1) return false;
+
if (ptr) {
Detail::HeapInformationBlockPtr virtualAddress =
reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr) -
sizeof(Detail::HeapInformationBlock);
- if (virtualAddress->hPresent &&
- virtualAddress->hMagic == kHeapMagic) {
+ if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) {
return true;
}
}
diff --git a/Private/Source/NewFS+Journal.cxx b/Private/Source/NewFS+Journal.cxx
index 472db1fe..ec3c5eb7 100644
--- a/Private/Source/NewFS+Journal.cxx
+++ b/Private/Source/NewFS+Journal.cxx
@@ -19,11 +19,12 @@ typedef Boolean (*NewFSRunnerType)(VoidPtr delegate);
/// @brief Journal thread class.
class NewFSJournalRunner final {
- public:
+ private:
NewFSRunnerType fLoadRoutine{nullptr};
NewFSRunnerType fCacheRoutine{nullptr};
NewFSRunnerType fUnloadRoutine{nullptr};
+ public:
explicit NewFSJournalRunner(NewFSRunnerType load_runner)
: fLoadRoutine(load_runner) {
MUST_PASS(fLoadRoutine);
@@ -44,7 +45,8 @@ class NewFSJournalRunner final {
switch (operation) {
case kNewFSOpLog: {
if (!classPtr) {
- kcout << "HCoreKrnl.exe: Miss for classPtr at NewFSJournalManager::Run(classPtr) "
+ kcout << "HCoreKrnl.exe: Miss for classPtr at "
+ "NewFSJournalManager::Run(classPtr) "
<< __FILE__ << "\n";
return false;
}
diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx
index eb22dd35..209bb9ac 100644
--- a/Private/Source/PageAllocator.cxx
+++ b/Private/Source/PageAllocator.cxx
@@ -8,10 +8,10 @@
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/PageAllocator.hpp>
-// empty for now.
+/// @brief Internal namespace, used internally by kernel.
namespace HCore::Detail {
-UIntPtr create_page_wrapper(Boolean rw, Boolean user) {
- auto addr = HAL::hal_create_page(rw, user);
+VoidPtr create_page_wrapper(Boolean rw, Boolean user) {
+ auto addr = HAL::hal_alloc_page(rw, user);
if (addr == kBadAddress) {
kcout << "[create_page_wrapper] kBadAddress returned\n";
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index 6cedd5b6..67aa9b7f 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -25,40 +25,9 @@ PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable,
m_Shareable(false),
m_Wt(false),
m_Present(true),
- m_Accessed(false) {
- // special case for the null region.
- if (VirtAddr <= kProtectedRegionEnd) {
- m_Wt = false;
- m_Rw = false;
- m_Cache = false;
- m_Shareable = false;
- m_ExecDisable = true;
- }
-}
-
-PTEWrapper::~PTEWrapper() {
- PDE* cr3 = (PDE*)hal_read_cr3();
-
- PTE* raw = (PTE*)&cr3->Pte[(this->m_VirtAddr % kPTESize)];
-
- raw->Present = false;
- raw->Rw = false;
-}
+ m_Accessed(false) {}
-void PTEWrapper::Flush() {
- PDE* cr3 = (PDE*)hal_read_cr3();
-
- kcout << "CR3: " << hex_number((UIntPtr)cr3) << endl;
- kcout << "Index: " << hex_number((this->m_VirtAddr % kPTESize)) << endl;
-
- cr3->Pte[(this->m_VirtAddr % kPTESize)].Wt = m_Wt;
- cr3->Pte[(this->m_VirtAddr % kPTESize)].Rw = m_Rw;
- cr3->Pte[(this->m_VirtAddr % kPTESize)].Cache = m_Cache;
- cr3->Pte[(this->m_VirtAddr % kPTESize)].Present = m_Present;
- cr3->Pte[(this->m_VirtAddr % kPTESize)].ExecDisable = m_ExecDisable;
-
- kcout << "Wrote PTE to PDE: " << hex_number((UIntPtr)cr3) << endl;
-}
+PTEWrapper::~PTEWrapper() {}
void PageManager::FlushTLB(UIntPtr VirtAddr) {
if (VirtAddr == kBadAddress) return;
@@ -75,12 +44,9 @@ bool PTEWrapper::Reclaim() {
return false;
}
-PTEWrapper PageManager::Request(Boolean Rw, Boolean User,
- Boolean ExecDisable) {
+PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable) {
// Store PTE wrapper right after PTE.
- VoidPtr ptr = reinterpret_cast<PTEWrapper *>(
- HCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User));
-
+ VoidPtr ptr = HCore::HAL::hal_alloc_page(Rw, User);
return PTEWrapper{Rw, User, ExecDisable, (UIntPtr)ptr};
}
@@ -94,7 +60,9 @@ bool PageManager::Free(Ref<PTEWrapper *> &wrapper) {
return false;
}
-const UIntPtr PTEWrapper::VirtualAddress() { return (m_VirtAddr + sizeof(PTE) + sizeof(PTEWrapper)); }
+const UIntPtr PTEWrapper::VirtualAddress() {
+ return (m_VirtAddr + sizeof(PTE) + sizeof(PTEWrapper));
+}
bool PTEWrapper::Shareable() { return m_Shareable; }
diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx
index 9112b3d9..97614cfa 100644
--- a/Private/Source/Pmm.cxx
+++ b/Private/Source/Pmm.cxx
@@ -30,7 +30,6 @@ Boolean Pmm::FreePage(Ref<PTEWrapper> PageRef) {
if (!PageRef) return false;
PageRef.Leak().m_Present = false;
- PageRef.Leak().Flush();
return true;
}