summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-21 19:48:01 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-21 19:48:56 +0100
commit1b072a1dc14d67c9a64028d515f60c715544fcd4 (patch)
treea853dfac6fd35a0f66d23381245149eea25d7b2b /Private/Source
parent5cc05e3f40267ff30c0191f7c53a62d9c791102b (diff)
Kernel: Got it up and running.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/KernelHeap.cxx13
-rw-r--r--Private/Source/KernelMain.cxx (renamed from Private/Source/RuntimeMain.cxx)4
-rw-r--r--Private/Source/PageManager.cxx11
-rw-r--r--Private/Source/Pmm.cxx18
4 files changed, 32 insertions, 14 deletions
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 72aa2d67..38b279a7 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -9,6 +9,8 @@
#include <NewKit/KernelHeap.hpp>
+#include "KernelKit/DebugOutput.hpp"
+
//! @file KernelHeap.cpp
//! @brief Kernel allocator.
@@ -18,7 +20,7 @@ namespace HCore {
static Ref<PTEWrapper *> kWrapperList[kMaxWrappers];
static SizeT kWrapperCount = 0UL;
static Ref<PTEWrapper *> kLastWrapper;
-static Pmm kPmm;
+static PageManager kPageManager;
namespace Detail {
STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) {
@@ -45,7 +47,7 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
if (auto ptr = Detail::ke_find_heap(sz, rw, user); ptr) return ptr;
- Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw);
+ Ref<PTEWrapper *> wrapper = kPageManager.Request(user, rw, false);
if (wrapper) {
kLastWrapper = wrapper;
@@ -67,7 +69,7 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
- if (kPmm.FreePage(kLastWrapper)) {
+ if (kPageManager.Free(kLastWrapper)) {
kLastWrapper->NoExecute(false);
return true;
}
@@ -82,7 +84,7 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
wrapper = kWrapperList[indexWrapper];
// if page is no more, then mark it also as non executable.
- if (kPmm.FreePage(wrapper)) {
+ if (kPageManager.Free(wrapper)) {
wrapper->NoExecute(false);
return true;
}
@@ -124,6 +126,7 @@ Boolean kernel_valid_ptr(voidPtr ptr) {
Void ke_init_ke_heap() noexcept {
kWrapperCount = 0UL;
Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper *>(nullptr);
- Pmm kPmm = Pmm();
+
+ kcout << "KernelHeap: Init [OK]\r\n";
}
} // namespace HCore
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/KernelMain.cxx
index abbfb749..1d52967d 100644
--- a/Private/Source/RuntimeMain.cxx
+++ b/Private/Source/KernelMain.cxx
@@ -15,7 +15,9 @@
#include <NewKit/KernelHeap.hpp>
#include <NewKit/UserHeap.hpp>
-extern "C" void RuntimeMain(
+#include "NewKit/Utils.hpp"
+
+EXTERN_C void RuntimeMain(
HCore::HEL::HandoverInformationHeader* HandoverHeader) {
/// Setup kernel globals.
kKernelVirtualSize = HandoverHeader->f_VirtualSize;
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index b4d9ed8e..b3a168d3 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -10,6 +10,8 @@
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/PageManager.hpp>
+#include "NewKit/String.hpp"
+
#ifdef __x86_64__
#include <HALKit/AMD64/HalPageAlloc.hpp>
#endif // ifdef __x86_64__
@@ -47,6 +49,13 @@ PTEWrapper::~PTEWrapper() {
}
void PTEWrapper::FlushTLB(Ref<PageManager> &pm) {
+ volatile PTE *virtAddr = static_cast<volatile PTE *>(virtAddr);
+
+ virtAddr->Present = this->m_Present;
+ virtAddr->ExecDisable = this->m_ExecDisable;
+ virtAddr->Rw = this->m_Rw;
+ virtAddr->User = this->m_User;
+
pm.Leak().FlushTLB(this->m_VirtAddr);
}
@@ -75,6 +84,8 @@ PTEWrapper *PageManager::Request(Boolean Rw, Boolean User,
return nullptr;
}
+ PageTableEntry->NoExecute(ExecDisable);
+
*PageTableEntry =
PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)};
return PageTableEntry;
diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx
index 7eb6875e..58f3e4a2 100644
--- a/Private/Source/Pmm.cxx
+++ b/Private/Source/Pmm.cxx
@@ -11,22 +11,24 @@
#include <NewKit/Pmm.hpp>
namespace HCore {
-Pmm::Pmm() : m_PageManager() {
- kcout << "[PMM] Allocate PageMemoryManager\r\n";
-}
+Pmm::Pmm() : m_PageManager() { kcout << "[PMM] Allocate PageMemoryManager"; }
Pmm::~Pmm() = default;
/* If this returns Null pointer, enter emergency mode */
Ref<PTEWrapper *> Pmm::RequestPage(Boolean user, Boolean readWrite) {
- if (m_PageManager) {
- PTEWrapper *pt = m_PageManager.Leak().Request(user, readWrite, true);
+ PTEWrapper *pt = m_PageManager.Leak().Request(user, readWrite, false);
+
+ if (pt) {
+ pt->m_Present = true;
+ pt->FlushTLB(m_PageManager);
+
+ kcout << "[PMM]: Allocation was successful.";
- if (pt) return Ref<PTEWrapper *>(pt);
+ return Ref<PTEWrapper *>(pt);
}
- kcout << "[Pmm::RequestPage] Ref<PTEWrapper*> could not be created! "
- "m_PageManager is nullptr!\r\n";
+ kcout << "[PMM]: Allocation failure.";
return {};
}