summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
Diffstat (limited to 'Private')
-rw-r--r--Private/EFIKit/Handover.hxx5
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.cpp2
-rw-r--r--Private/NewBoot/Source/FileReader.cxx4
-rw-r--r--Private/NewBoot/Source/bundle.mk2
-rw-r--r--Private/NewKit/KernelCheck.hpp (renamed from Private/NewKit/RuntimeCheck.hpp)0
-rw-r--r--Private/NewKit/KernelHeap.hpp1
-rw-r--r--Private/NewKit/NewKit.hpp20
-rw-r--r--Private/NewKit/OwnPtr.hpp2
-rw-r--r--Private/NewKit/Ref.hpp2
-rw-r--r--Private/NewKit/String.hpp2
-rw-r--r--Private/NewKit/UserHeap.hpp1
-rw-r--r--Private/Source/CxxAbi.cxx26
-rw-r--r--Private/Source/KernelCheck.cxx (renamed from Private/Source/RuntimeCheck.cxx)2
-rw-r--r--Private/Source/KernelHeap.cxx76
-rw-r--r--Private/Source/KernelMain.cxx6
-rw-r--r--Private/Source/NewFS+FileManager.cxx6
-rw-r--r--Private/Source/PEFCodeManager.cxx2
-rw-r--r--Private/Source/PermissionSelector.cxx2
-rw-r--r--Private/Source/ProcessManager.cxx2
-rw-r--r--Private/Source/ThreadLocalStorage.cxx6
-rw-r--r--Private/Source/UserHeap.cxx7
21 files changed, 83 insertions, 93 deletions
diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx
index 42926a3e..b668dd60 100644
--- a/Private/EFIKit/Handover.hxx
+++ b/Private/EFIKit/Handover.hxx
@@ -11,8 +11,8 @@
* @file Handover.hxx
* @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
* @brief Handover protocol.
- * @version 0.1
- * @date 2024-02-02
+ * @version 0.2
+ * @date 2024-02-23
*
* @copyright Copyright (c) 2024, Mahrouss Logic
*
@@ -26,7 +26,6 @@
#define kHandoverMagic 0xBADCC
-#define kHandoverStartKernel 0xffffffff10000000
#define kHandoverStructSz sizeof(HEL::HandoverHeader)
namespace HCore::HEL {
diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp
index 64752520..fd691be2 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.cpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.cpp
@@ -10,7 +10,7 @@
#include <ArchKit/ArchKit.hpp>
#include <HALKit/AMD64/HalPageAlloc.hpp>
#include <NewKit/Defines.hpp>
-#include <NewKit/RuntimeCheck.hpp>
+#include <NewKit/KernelCheck.hpp>
// this files handles paging.
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index d81248ea..6696a1b4 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -99,6 +99,8 @@ BFileReader::~BFileReader() {
BSetMem(this->mPath, 0, kPathLen);
}
+#define hTransferBufferAddress 0xffffffff10000000
+
/**
@brief this reads all of the buffer.
@param ImageHandle used internally.
@@ -107,7 +109,7 @@ Void BFileReader::ReadAll() {
/// Allocate Handover page.
if (mBlob == nullptr) {
- UInt8* blob = (UInt8*)kHandoverStartKernel;
+ UInt8* blob = (UInt8*)hTransferBufferAddress;
if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1,
(EfiPhysicalAddress*)&blob) != kEfiOk) {
diff --git a/Private/NewBoot/Source/bundle.mk b/Private/NewBoot/Source/bundle.mk
index c5a83ffb..cf4ac376 100644
--- a/Private/NewBoot/Source/bundle.mk
+++ b/Private/NewBoot/Source/bundle.mk
@@ -28,7 +28,7 @@ bootloader-amd64:
.PHONY: run-efi-amd64
run-efi-amd64:
wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
- qemu-system-x86_64 -net none -smp 2 -m 8G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
+ qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
.PHONY: clean
clean:
diff --git a/Private/NewKit/RuntimeCheck.hpp b/Private/NewKit/KernelCheck.hpp
index 9f37eb8e..9f37eb8e 100644
--- a/Private/NewKit/RuntimeCheck.hpp
+++ b/Private/NewKit/KernelCheck.hpp
diff --git a/Private/NewKit/KernelHeap.hpp b/Private/NewKit/KernelHeap.hpp
index 80934caf..fba25b70 100644
--- a/Private/NewKit/KernelHeap.hpp
+++ b/Private/NewKit/KernelHeap.hpp
@@ -17,7 +17,6 @@
#include <NewKit/Pmm.hpp>
namespace HCore {
-Void ke_init_ke_heap() noexcept;
Int32 ke_delete_ke_heap(voidPtr allocatedPtr);
voidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user);
} // namespace HCore
diff --git a/Private/NewKit/NewKit.hpp b/Private/NewKit/NewKit.hpp
index 8e560914..fc18a900 100644
--- a/Private/NewKit/NewKit.hpp
+++ b/Private/NewKit/NewKit.hpp
@@ -10,18 +10,16 @@
#pragma once
-#include <NewKit/OwnPtr.hpp>
-#include <NewKit/New.hpp>
-#include <NewKit/Json.hpp>
-#include <NewKit/UserHeap.hpp>
-#include <NewKit/ErrorOr.hpp>
-#include <NewKit/ArrayList.hpp>
#include <NewKit/Array.hpp>
+#include <NewKit/ArrayList.hpp>
+#include <NewKit/ErrorOr.hpp>
+#include <NewKit/Json.hpp>
+#include <NewKit/KernelCheck.hpp>
+#include <NewKit/LockDelegate.hpp>
+#include <NewKit/MutableArray.hpp>
+#include <NewKit/New.hpp>
+#include <NewKit/OwnPtr.hpp>
#include <NewKit/Ref.hpp>
-#include <NewKit/RuntimeCheck.hpp>
#include <NewKit/Stream.hpp>
+#include <NewKit/UserHeap.hpp>
#include <NewKit/Utils.hpp>
-#include <NewKit/MutableArray.hpp>
-#include <NewKit/LockDelegate.hpp>
-
-
diff --git a/Private/NewKit/OwnPtr.hpp b/Private/NewKit/OwnPtr.hpp
index e24eba3e..69e3389f 100644
--- a/Private/NewKit/OwnPtr.hpp
+++ b/Private/NewKit/OwnPtr.hpp
@@ -11,8 +11,8 @@
#pragma once
#include <NewKit/Defines.hpp>
+#include <NewKit/KernelCheck.hpp>
#include <NewKit/Ref.hpp>
-#include <NewKit/RuntimeCheck.hpp>
namespace HCore {
template <typename T>
diff --git a/Private/NewKit/Ref.hpp b/Private/NewKit/Ref.hpp
index 9988c213..f97e3a90 100644
--- a/Private/NewKit/Ref.hpp
+++ b/Private/NewKit/Ref.hpp
@@ -11,7 +11,7 @@
#pragma once
#include <NewKit/Defines.hpp>
-#include <NewKit/RuntimeCheck.hpp>
+#include <NewKit/KernelCheck.hpp>
namespace HCore {
template <typename T>
diff --git a/Private/NewKit/String.hpp b/Private/NewKit/String.hpp
index e6bc745e..6979739a 100644
--- a/Private/NewKit/String.hpp
+++ b/Private/NewKit/String.hpp
@@ -11,7 +11,7 @@
#include <NewKit/Defines.hpp>
#include <NewKit/ErrorOr.hpp>
-#include <NewKit/RuntimeCheck.hpp>
+#include <NewKit/KernelCheck.hpp>
namespace HCore {
class StringView final {
diff --git a/Private/NewKit/UserHeap.hpp b/Private/NewKit/UserHeap.hpp
index 05430bf4..5c0b7134 100644
--- a/Private/NewKit/UserHeap.hpp
+++ b/Private/NewKit/UserHeap.hpp
@@ -38,7 +38,6 @@ struct HeapHeader final {
UIntPtr Pad;
};
-Void ke_init_heap();
VoidPtr ke_new_heap(Int32 flags);
Int32 ke_free_heap(voidPtr pointer);
} // namespace HCore
diff --git a/Private/Source/CxxAbi.cxx b/Private/Source/CxxAbi.cxx
index c062219b..41c8587b 100644
--- a/Private/Source/CxxAbi.cxx
+++ b/Private/Source/CxxAbi.cxx
@@ -9,16 +9,16 @@
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/CxxAbi.hpp>
-#include <NewKit/RuntimeCheck.hpp>
-
-#ifdef __GNUC__
+#include <NewKit/KernelCheck.hpp>
void *__dso_handle;
atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS];
uarch_t __atexit_func_count;
-extern "C" void __cxa_pure_virtual() { HCore::kcout << "[C++] Placeholder\n"; }
+extern "C" void __cxa_pure_virtual() {
+ HCore::kcout << "Krnl\\Abi: Placeholder method.\n";
+}
extern "C" void ___chkstk_ms() {}
@@ -67,21 +67,3 @@ extern "C" int __cxa_guard_release(__guard *g) {
extern "C" void __cxa_guard_abort(__guard *g) { (void)g; }
} // namespace cxxabiv1
-
-#else
-
-namespace cxxkit {
-extern "C" void __unwind(void (**finis)(void), int cnt) {
- for (int i = 0; i < cnt; ++i) (finis[i])();
-}
-
-extern "C" void __init_local(void (**init)(void), int cnt) {
- for (int i = 0; i < cnt; ++i) (init[i])();
-}
-
-extern "C" void __fini_local(void (**finis)(void), int cnt) {
- for (int i = 0; i < cnt; ++i) (finis[i])();
-}
-} // namespace cxxkit
-
-#endif
diff --git a/Private/Source/RuntimeCheck.cxx b/Private/Source/KernelCheck.cxx
index 03660076..4fc24918 100644
--- a/Private/Source/RuntimeCheck.cxx
+++ b/Private/Source/KernelCheck.cxx
@@ -9,7 +9,7 @@
#include <ArchKit/ArchKit.hpp>
#include <KernelKit/DebugOutput.hpp>
-#include <NewKit/RuntimeCheck.hpp>
+#include <NewKit/KernelCheck.hpp>
#include <NewKit/String.hpp>
extern "C" [[noreturn]] void ke_wait_for_debugger() {
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 10d3fdd2..fdc4dc4f 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -7,22 +7,34 @@
* ========================================================
*/
+#include <NewKit/Crc32.hpp>
#include <NewKit/KernelHeap.hpp>
//! @file KernelHeap.cpp
//! @brief Kernel allocator.
-#define kMaxWrappers (4096 * 8)
+#define kHeapMaxWrappers (4096 * 8)
+#define kHeapMagic 0xAA55
namespace HCore {
-static Ref<PTEWrapper *> kWrapperList[kMaxWrappers];
-static SizeT kWrapperCount = 0UL;
-static Ref<PTEWrapper *> kLastWrapper;
-static PageManager kPageManager;
+STATIC Ref<PTEWrapper *> kWrapperList[kHeapMaxWrappers];
+STATIC SizeT kHeapCount = 0UL;
+STATIC Ref<PTEWrapper *> kLastWrapper;
+STATIC PageManager kPageManager;
namespace Detail {
+/// @brief
+struct HeapInformationBlock final {
+ Int16 hMagic;
+ Boolean hPresent;
+ Int64 hSize;
+ Int32 hCRC32;
+ VoidPtr hPtr;
+};
+
STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) {
- for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) {
+ for (SizeT indexWrapper = 0; indexWrapper < kHeapMaxWrappers;
+ ++indexWrapper) {
if (!kWrapperList[indexWrapper]->Present()) {
kWrapperList[indexWrapper]
->Reclaim(); /* very straight-forward as you can see. */
@@ -35,7 +47,7 @@ STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) {
}
} // namespace Detail
-/// @brief Page allocation routine.
+/// @brief Allocate pointer.
/// @param sz size of pointer
/// @param rw read write (true to enable it)
/// @param user is it accesible by user processes?
@@ -49,10 +61,20 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
kLastWrapper = wrapper;
- kWrapperList[kWrapperCount] = wrapper;
- ++kWrapperCount;
+ Detail::HeapInformationBlock *heapInfo =
+ reinterpret_cast<Detail::HeapInformationBlock *>(
+ wrapper->VirtualAddress());
+
+ heapInfo->hSize = sz;
+ heapInfo->hMagic = kHeapMagic;
+ heapInfo->hCRC32 = ke_calculate_crc32((Char *)wrapper->VirtualAddress(), sz);
+ heapInfo->hPtr = (VoidPtr)wrapper->VirtualAddress();
+
+ kWrapperList[kHeapCount] = wrapper;
+ ++kHeapCount;
- return reinterpret_cast<voidPtr>(wrapper->VirtualAddress());
+ return reinterpret_cast<voidPtr>(wrapper->VirtualAddress() +
+ sizeof(Detail::HeapInformationBlock));
}
/// @brief Declare pointer as free.
@@ -60,10 +82,15 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
/// @return
Int32 ke_delete_ke_heap(voidPtr ptr) {
if (ptr) {
- const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
+ Detail::HeapInformationBlock *virtualAddress =
+ reinterpret_cast<Detail::HeapInformationBlock *>(ptr) -
+ sizeof(Detail::HeapInformationBlock);
- if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
+ if (kLastWrapper &&
+ (UIntPtr)virtualAddress->hPtr == kLastWrapper->VirtualAddress()) {
if (kPageManager.Free(kLastWrapper)) {
+ virtualAddress->hSize = 0UL;
+ virtualAddress->hPresent = false;
kLastWrapper->NoExecute(false);
return true;
}
@@ -73,13 +100,18 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
Ref<PTEWrapper *> wrapper{nullptr};
- for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) {
- if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) {
+ for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) {
+ if (kWrapperList[indexWrapper]->VirtualAddress() ==
+ (UIntPtr)virtualAddress->hPtr) {
wrapper = kWrapperList[indexWrapper];
// if page is no more, then mark it also as non executable.
if (kPageManager.Free(wrapper)) {
+ virtualAddress->hSize = 0UL;
+ virtualAddress->hPresent = false;
+
wrapper->NoExecute(false);
+
return true;
}
@@ -98,14 +130,17 @@ Boolean kernel_valid_ptr(voidPtr ptr) {
if (ptr) {
const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
- if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
+ if (kLastWrapper &&
+ virtualAddress == (kLastWrapper->VirtualAddress() +
+ sizeof(Detail::HeapInformationBlock))) {
return true;
}
Ref<PTEWrapper *> wrapper;
- for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) {
- if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) {
+ for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) {
+ if ((kLastWrapper->VirtualAddress() +
+ sizeof(Detail::HeapInformationBlock)) == virtualAddress) {
wrapper = kWrapperList[indexWrapper];
return true;
}
@@ -114,11 +149,4 @@ Boolean kernel_valid_ptr(voidPtr ptr) {
return false;
}
-
-/// @brief The Kernel heap initializer function.
-/// @return
-Void ke_init_ke_heap() noexcept {
- kWrapperCount = 0UL;
- Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper *>(nullptr);
-}
} // namespace HCore
diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx
index 171deff1..e293cbf2 100644
--- a/Private/Source/KernelMain.cxx
+++ b/Private/Source/KernelMain.cxx
@@ -24,16 +24,12 @@ EXTERN_C void RuntimeMain(
kKernelPhysicalSize = HandoverHeader->f_VirtualSize;
kKernelPhysicalStart = HandoverHeader->f_VirtualStart;
- /// Init memory managers.
- HCore::ke_init_ke_heap();
- HCore::ke_init_heap();
-
/// Init the HAL.
MUST_PASS(HCore::ke_init_hal());
/// Mount a New partition.
// HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
- HCore::PEFLoader img("/System/HCoreShell.exe");
+ HCore::PEFLoader img("C:/System/HCoreShell.exe");
/// Run the shell.
if (!HCore::Utils::execute_from_image(img)) {
diff --git a/Private/Source/NewFS+FileManager.cxx b/Private/Source/NewFS+FileManager.cxx
index d1ea58f6..51959d0b 100644
--- a/Private/Source/NewFS+FileManager.cxx
+++ b/Private/Source/NewFS+FileManager.cxx
@@ -11,6 +11,7 @@
#ifdef __FSKIT_NEWFS__
+/// @brief NewFS File manager.
/// BUGS: 0
namespace HCore {
@@ -18,11 +19,6 @@ NewFilesystemManager::NewFilesystemManager() = default;
NewFilesystemManager::~NewFilesystemManager() = default;
-/**
- * Unallocates a file from disk.
- * @param node_name it's path.
- * @return operation status boolean.
- */
bool NewFilesystemManager::Remove(const char* node_name) {
if (node_name == nullptr || *node_name == 0) return false;
diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx
index 68c5b556..ee535057 100644
--- a/Private/Source/PEFCodeManager.cxx
+++ b/Private/Source/PEFCodeManager.cxx
@@ -13,9 +13,9 @@
#include <KernelKit/ProcessManager.hpp>
#include <NewKit/Defines.hpp>
#include <NewKit/ErrorID.hpp>
+#include <NewKit/KernelCheck.hpp>
#include <NewKit/KernelHeap.hpp>
#include <NewKit/OwnPtr.hpp>
-#include <NewKit/RuntimeCheck.hpp>
#include <NewKit/String.hpp>
#include "KernelKit/PEF.hpp"
diff --git a/Private/Source/PermissionSelector.cxx b/Private/Source/PermissionSelector.cxx
index 34760b8f..87680b06 100644
--- a/Private/Source/PermissionSelector.cxx
+++ b/Private/Source/PermissionSelector.cxx
@@ -11,7 +11,7 @@
*/
#include <KernelKit/PermissionSelector.hxx>
-#include <NewKit/RuntimeCheck.hpp>
+#include <NewKit/KernelCheck.hpp>
/// bugs 0
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index ccf037ae..46533f00 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -18,8 +18,6 @@
#include <NewKit/KernelHeap.hpp>
#include <NewKit/String.hpp>
-#include "NewKit/RuntimeCheck.hpp"
-
///! bugs = 0
/***********************************************************************************/
diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx
index 8aeb0431..9a9c8477 100644
--- a/Private/Source/ThreadLocalStorage.cxx
+++ b/Private/Source/ThreadLocalStorage.cxx
@@ -29,7 +29,7 @@ Boolean hcore_tls_check(VoidPtr ptr) {
const char* _ptr = (const char*)ptr;
- kcout << "TLS: Checking for cookie...\n";
+ kcout << "Krnl\\TLS: Checking for cookie...\n";
return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 &&
_ptr[2] == kCookieMag2;
@@ -42,9 +42,9 @@ Boolean hcore_tls_check(VoidPtr ptr) {
*/
Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept {
if (!hcore_tls_check(ptr.Cookie)) {
- kcout << "TLS: Verification failure, Crashing...\n";
+ kcout << "Krnl\\TLS: Verification failure, Crashing...\n";
ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}
- kcout << "TLS: Verification succeeded! Keeping on...\n";
+ kcout << "Krnl\\TLS: Verification succeeded! Keeping on...\n";
}
diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx
index d3d60f6b..cc243904 100644
--- a/Private/Source/UserHeap.cxx
+++ b/Private/Source/UserHeap.cxx
@@ -182,11 +182,4 @@ Int32 ke_free_heap(VoidPtr ptr) {
return -1;
}
-
-/// @brief Init HeapManager, set Count to zero and IsEnabled to true.
-/// @return
-Void ke_init_heap() {
- HeapManager::Count() = 0UL;
- HeapManager::IsEnabled() = true;
-}
} // namespace HCore