summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Private/HALKit/AMD64/HalDebugOutput.cxx2
-rw-r--r--Private/HALKit/AMD64/HalHardwareInit.cpp2
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.cpp19
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.hpp2
-rw-r--r--Private/HALKit/AMD64/HalPlatformAMD64.cpp1
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx2
-rw-r--r--Private/NewKit/Macros.hpp2
-rw-r--r--Private/NewKit/PageManager.hpp1
-rw-r--r--Private/NewKit/RuntimeCheck.hpp4
-rw-r--r--Private/Source/FileManager.cxx2
-rw-r--r--Private/Source/KernelHeap.cxx16
-rw-r--r--Private/Source/KernelMain.cxx5
-rw-r--r--Private/Source/PageManager.cxx48
-rw-r--r--Private/Source/RuntimeCheck.cxx7
14 files changed, 37 insertions, 76 deletions
diff --git a/Private/HALKit/AMD64/HalDebugOutput.cxx b/Private/HALKit/AMD64/HalDebugOutput.cxx
index 635537ae..f4d81338 100644
--- a/Private/HALKit/AMD64/HalDebugOutput.cxx
+++ b/Private/HALKit/AMD64/HalDebugOutput.cxx
@@ -69,8 +69,6 @@ void ke_io_print(const char *bytes) {
++index;
}
- HAL::Out8(Detail::PORT, '\r');
- HAL::Out8(Detail::PORT, '\n');
Detail::kState = kStateReady;
}
diff --git a/Private/HALKit/AMD64/HalHardwareInit.cpp b/Private/HALKit/AMD64/HalHardwareInit.cpp
index 2a44f696..1c857ff7 100644
--- a/Private/HALKit/AMD64/HalHardwareInit.cpp
+++ b/Private/HALKit/AMD64/HalHardwareInit.cpp
@@ -18,7 +18,7 @@ bool ke_init_hal() {
HCore::HAL::Register64 kIdtRegister;
kIdtRegister.Base = (UIntPtr)__EXEC_IVT;
- kIdtRegister.Limit = sizeof(HAL::Register64) * 256;
+ kIdtRegister.Limit = sizeof(HAL::Register64) * 255;
HAL::IDTLoader idt;
idt.Load(kIdtRegister);
diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp
index d94d994d..8920f295 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.cpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.cpp
@@ -7,33 +7,36 @@
* ========================================================
*/
+#include <ArchKit/ArchKit.hpp>
#include <HALKit/AMD64/HalPageAlloc.hpp>
-#include <NewKit/RuntimeCheck.hpp>
#include <NewKit/Defines.hpp>
+#include <NewKit/RuntimeCheck.hpp>
// this files handles paging.
-static HCore::UIntPtr kPagePtr = 0;
static HCore::SizeT kPageCnt = 0UL;
+#define kPagePad 512
+
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);
+ PageTable64 *pte = reinterpret_cast<PageTable64 *>(
+ (UIntPtr)kKernelVirtualStart + kPageCnt + kPagePad);
pte->Rw = rw;
pte->User = user;
pte->Present = true;
+ kKernelVirtualStart = (VoidPtr)((UIntPtr)kKernelVirtualStart + kPageCnt + sz);
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);
+ PageTable64 *pte = reinterpret_cast<PageTable64 *>(
+ (UIntPtr)kKernelVirtualStart + kPageCnt);
if (!pte->Present) {
pte->User = user;
@@ -53,9 +56,5 @@ auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr {
return reinterpret_cast<UIntPtr>(new_pte);
}
-
-UIntPtr& hal_page_base() noexcept { return kPagePtr; }
-
-void hal_page_base(const UIntPtr& newPagePtr) noexcept { kPagePtr = newPagePtr; }
} // namespace HAL
} // namespace HCore
diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp
index 9ca2c580..8717f3db 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.hpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.hpp
@@ -76,8 +76,6 @@ struct PageDirectory64 final {
};
PageTable64* hal_alloc_page(SizeT sz, Boolean rw, Boolean user);
-UIntPtr& hal_page_base() noexcept;
-void hal_page_base(const UIntPtr& newPagePtr) noexcept;
UIntPtr hal_create_page(Boolean rw, Boolean user);
} // namespace HCore::HAL
diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp
index 6374d06b..71b7542e 100644
--- a/Private/HALKit/AMD64/HalPlatformAMD64.cpp
+++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp
@@ -31,7 +31,6 @@ void GDTLoader::Load(Register64 &gdt) {
void IDTLoader::Load(Register64 &idt) {
Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64();
- MUST_PASS(reg);
reg->base = idt.Base;
reg->limit = idt.Limit;
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index 4dd0c437..65cd1e44 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -125,6 +125,8 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
writer.WriteString(L"HCoreLdr: Booting HCore...\r\n");
+ EFI::ExitBootServices(MapKey, ImageHandle);
+
EFI::Stop();
return kEfiOk;
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index b6ec8268..cafc1cdd 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -90,3 +90,5 @@
#ifndef self
#define self this
#endif
+
+#define STRINGIFY(X) #X
diff --git a/Private/NewKit/PageManager.hpp b/Private/NewKit/PageManager.hpp
index fdde95f8..f76aa6f4 100644
--- a/Private/NewKit/PageManager.hpp
+++ b/Private/NewKit/PageManager.hpp
@@ -27,6 +27,7 @@ class PTEWrapper final {
public:
explicit PTEWrapper(Boolean Rw = false, Boolean User = false,
Boolean ExecDisable = false, UIntPtr Address = 0);
+
~PTEWrapper();
PTEWrapper &operator=(const PTEWrapper &) = default;
diff --git a/Private/NewKit/RuntimeCheck.hpp b/Private/NewKit/RuntimeCheck.hpp
index 7221b3ea..9f37eb8e 100644
--- a/Private/NewKit/RuntimeCheck.hpp
+++ b/Private/NewKit/RuntimeCheck.hpp
@@ -17,7 +17,9 @@ void ke_runtime_check(bool bExpression, const char *file, const char *line);
}
#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG)
-#define MUST_PASS(EXPR) HCore::ke_runtime_check(EXPR, __FILE__, " %d -> ")
+#define __MUST_PASS(EXPR, FILE, LINE) \
+ HCore::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE))
+#define MUST_PASS(EXPR) __MUST_PASS(EXPR, __FILE__, __LINE__)
#define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION)
enum RUNTIME_CHECK {
diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx
index 860a8808..ba5d6bfd 100644
--- a/Private/Source/FileManager.cxx
+++ b/Private/Source/FileManager.cxx
@@ -33,7 +33,7 @@ IFilesystemManager* IFilesystemManager::Unmount() {
}
bool IFilesystemManager::Mount(IFilesystemManager* pMount) {
- if (pMount) {
+ if (kMounted == nullptr) {
kMounted = pMount;
return true;
}
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index a967b003..358330f0 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.
@@ -47,16 +49,12 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
Ref<PTEWrapper *> wrapper = kPageManager.Request(user, rw, false);
- if (wrapper) {
- kLastWrapper = wrapper;
-
- kWrapperList[kWrapperCount] = wrapper;
- ++kWrapperCount;
+ kLastWrapper = wrapper;
- return reinterpret_cast<voidPtr>(wrapper->VirtualAddress());
- }
+ kWrapperList[kWrapperCount] = wrapper;
+ ++kWrapperCount;
- return nullptr;
+ return reinterpret_cast<voidPtr>(wrapper->VirtualAddress());
}
/// @brief Declare pointer as free.
@@ -124,7 +122,5 @@ Boolean kernel_valid_ptr(voidPtr ptr) {
Void ke_init_ke_heap() noexcept {
kWrapperCount = 0UL;
Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper *>(nullptr);
-
- kcout << "KernelHeap: Init [OK]\r\n";
}
} // namespace HCore
diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx
index ea6e0c1d..171deff1 100644
--- a/Private/Source/KernelMain.cxx
+++ b/Private/Source/KernelMain.cxx
@@ -24,9 +24,6 @@ EXTERN_C void RuntimeMain(
kKernelPhysicalSize = HandoverHeader->f_VirtualSize;
kKernelPhysicalStart = HandoverHeader->f_VirtualStart;
- /// Setup base page.
- HCore::HAL::hal_page_base((HCore::UIntPtr)kKernelVirtualStart);
-
/// Init memory managers.
HCore::ke_init_ke_heap();
HCore::ke_init_heap();
@@ -35,7 +32,7 @@ EXTERN_C void RuntimeMain(
MUST_PASS(HCore::ke_init_hal());
/// Mount a New partition.
- HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
+ // HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
HCore::PEFLoader img("/System/HCoreShell.exe");
/// Run the shell.
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index b3a168d3..c520da78 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -10,8 +10,6 @@
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/PageManager.hpp>
-#include "NewKit/String.hpp"
-
#ifdef __x86_64__
#include <HALKit/AMD64/HalPageAlloc.hpp>
#endif // ifdef __x86_64__
@@ -45,7 +43,8 @@ PTEWrapper::~PTEWrapper() {
PTE *raw = reinterpret_cast<PTE *>(m_VirtAddr);
MUST_PASS(raw);
- if (raw->Present) raw->Present = false;
+ raw->Present = false;
+ raw->Rw = false;
}
void PTEWrapper::FlushTLB(Ref<PageManager> &pm) {
@@ -80,14 +79,14 @@ PTEWrapper *PageManager::Request(Boolean Rw, Boolean User,
HCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User));
if (PageTableEntry == nullptr) {
- kcout << "PTEWrapper : Page table is nullptr!, ke_new_ke_heap failed!";
+ kcout << "PTEWrapper : Page table is nullptr!, ke_new_ke_heap failed!\n";
return nullptr;
}
PageTableEntry->NoExecute(ExecDisable);
- *PageTableEntry =
- PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)};
+ *PageTableEntry = PTEWrapper{Rw, User, ExecDisable,
+ reinterpret_cast<UIntPtr>(PageTableEntry)};
return PageTableEntry;
}
@@ -116,42 +115,11 @@ const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; }
////////////////////////////
-bool PTEWrapper::Shareable() {
- auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
-
- if (raw->Present) {
- m_Shareable = raw->Rw;
- kcout << m_Shareable ? "[PTEWrapper::Shareable] page is sharable!\n"
- : "[PTEWrapper::Shareable] page is not sharable!\n";
-
- return m_Shareable;
- } else {
- kcout << "[PTEWrapper::Shareable] page is not present!\n";
- return false;
- }
-}
-
-bool PTEWrapper::Present() {
- auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
+bool PTEWrapper::Shareable() { return m_Shareable; }
- if (raw->Present) {
- m_Present = raw->Present;
- return m_Present;
- } else {
- kcout << "[PTEWrapper::Present] page is not present!";
- return false;
- }
-}
-
-bool PTEWrapper::Access() {
- auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
+bool PTEWrapper::Present() { return m_Present; }
- if (raw->Present) {
- m_Accessed = raw->Accessed;
- }
-
- return m_Accessed;
-}
+bool PTEWrapper::Access() { return m_Accessed; }
////////////////////////////
diff --git a/Private/Source/RuntimeCheck.cxx b/Private/Source/RuntimeCheck.cxx
index 664e3d75..03660076 100644
--- a/Private/Source/RuntimeCheck.cxx
+++ b/Private/Source/RuntimeCheck.cxx
@@ -25,7 +25,7 @@ extern "C" [[noreturn]] void ke_wait_for_debugger() {
namespace HCore {
void ke_stop(const HCore::Int &id) {
kcout << "*** STOP *** \r\n";
- kcout << "*** HCoreKrnl.exe has trigerred a runtime breakpoint. *** \r\n";
+ kcout << "*** HCoreKrnl.exe has trigerred a runtime stop. *** \r\n";
switch (id) {
case RUNTIME_CHECK_PROCESS: {
@@ -72,9 +72,8 @@ void ke_stop(const HCore::Int &id) {
void ke_runtime_check(bool expr, const char *file, const char *line) {
if (!expr) {
#ifdef __DEBUG__
- kcout << "[KERNEL] Check Failed!\n";
- kcout << "[KERNEL] File: " << file << "\n";
- kcout << "[KERNEL] Where: " << line << "\n";
+ kcout << "Krnl: File: " << file << "\n";
+ kcout << "Krnl: Line: " << line << "\n";
#endif // __DEBUG__