summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-24 09:04:34 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-24 09:04:34 +0100
commit917eae9453ecac6d9aeb04254d5d5c97e5a6c9e1 (patch)
tree767f6aeabb24f02c119e073e3efd2c710aabed5d /Private/Source
parent5563deabd8f7ce3fc713ea23f8cf5bbac33b4024 (diff)
Kernel: MS-1: Microkernel and bootloader.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/HError.cxx2
-rw-r--r--Private/Source/KernelHeap.cxx44
-rw-r--r--Private/Source/KernelMain.cxx22
-rw-r--r--Private/Source/NewFS+IO.cxx2
-rw-r--r--Private/Source/ProcessManager.cxx6
5 files changed, 44 insertions, 32 deletions
diff --git a/Private/Source/HError.cxx b/Private/Source/HError.cxx
index 6722e9d8..b82d4296 100644
--- a/Private/Source/HError.cxx
+++ b/Private/Source/HError.cxx
@@ -12,5 +12,5 @@
using namespace HCore;
namespace HCore {
-Boolean ke_bug_check(void) noexcept { return true; }
+Boolean ke_bug_check(void) noexcept { return false; }
} // namespace HCore
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index fdc4dc4f..a1032394 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -23,22 +23,26 @@ STATIC Ref<PTEWrapper *> kLastWrapper;
STATIC PageManager kPageManager;
namespace Detail {
-/// @brief
+/// @brief Kernel heap information block.
+/// Located before the address.
+/// | HIB | ADDRESS |
struct HeapInformationBlock final {
- Int16 hMagic;
+ UInt16 hMagic;
Boolean hPresent;
- Int64 hSize;
Int32 hCRC32;
- VoidPtr hPtr;
+ Int64 hSizeAddress;
+ VoidPtr hAddress;
};
-STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) {
+typedef HeapInformationBlock *HeapInformationBlockPtr;
+
+STATIC VoidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) {
for (SizeT indexWrapper = 0; indexWrapper < kHeapMaxWrappers;
++indexWrapper) {
if (!kWrapperList[indexWrapper]->Present()) {
kWrapperList[indexWrapper]
->Reclaim(); /* very straight-forward as you can see. */
- return reinterpret_cast<voidPtr>(
+ return reinterpret_cast<VoidPtr>(
kWrapperList[indexWrapper]->VirtualAddress());
}
}
@@ -61,35 +65,35 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
kLastWrapper = wrapper;
- Detail::HeapInformationBlock *heapInfo =
- reinterpret_cast<Detail::HeapInformationBlock *>(
+ Detail::HeapInformationBlockPtr heapInfo =
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(
wrapper->VirtualAddress());
- heapInfo->hSize = sz;
+ heapInfo->hSizeAddress = sz;
heapInfo->hMagic = kHeapMagic;
heapInfo->hCRC32 = ke_calculate_crc32((Char *)wrapper->VirtualAddress(), sz);
- heapInfo->hPtr = (VoidPtr)wrapper->VirtualAddress();
+ heapInfo->hAddress = (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.
/// @param ptr the pointer.
/// @return
-Int32 ke_delete_ke_heap(voidPtr ptr) {
+Int32 ke_delete_ke_heap(VoidPtr ptr) {
if (ptr) {
- Detail::HeapInformationBlock *virtualAddress =
- reinterpret_cast<Detail::HeapInformationBlock *>(ptr) -
+ Detail::HeapInformationBlockPtr virtualAddress =
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr) -
sizeof(Detail::HeapInformationBlock);
- if (kLastWrapper &&
- (UIntPtr)virtualAddress->hPtr == kLastWrapper->VirtualAddress()) {
+ if (kLastWrapper && virtualAddress->hMagic == kHeapMagic &&
+ (UIntPtr)virtualAddress->hAddress == kLastWrapper->VirtualAddress()) {
if (kPageManager.Free(kLastWrapper)) {
- virtualAddress->hSize = 0UL;
+ virtualAddress->hSizeAddress = 0UL;
virtualAddress->hPresent = false;
kLastWrapper->NoExecute(false);
return true;
@@ -102,12 +106,12 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) {
if (kWrapperList[indexWrapper]->VirtualAddress() ==
- (UIntPtr)virtualAddress->hPtr) {
+ (UIntPtr)virtualAddress->hAddress) {
wrapper = kWrapperList[indexWrapper];
// if page is no more, then mark it also as non executable.
if (kPageManager.Free(wrapper)) {
- virtualAddress->hSize = 0UL;
+ virtualAddress->hSizeAddress = 0UL;
virtualAddress->hPresent = false;
wrapper->NoExecute(false);
@@ -126,7 +130,7 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
/// @brief find pointer in kernel heap
/// @param ptr the pointer
/// @return if it exists.
-Boolean kernel_valid_ptr(voidPtr ptr) {
+Boolean kernel_valid_ptr(VoidPtr ptr) {
if (ptr) {
const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx
index e293cbf2..6050c95f 100644
--- a/Private/Source/KernelMain.cxx
+++ b/Private/Source/KernelMain.cxx
@@ -17,6 +17,9 @@
EXTERN_C void RuntimeMain(
HCore::HEL::HandoverInformationHeader* HandoverHeader) {
+ HCore::kcout << "HCoreKrnl: (R) Version 1.00, (C) MahroussLogic all rights "
+ "reserved.\n";
+
/// Setup kernel globals.
kKernelVirtualSize = HandoverHeader->f_VirtualSize;
kKernelVirtualStart = HandoverHeader->f_VirtualStart;
@@ -27,12 +30,19 @@ EXTERN_C void RuntimeMain(
/// Init the HAL.
MUST_PASS(HCore::ke_init_hal());
- /// Mount a New partition.
- // HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
- HCore::PEFLoader img("C:/System/HCoreShell.exe");
+ if (!HandoverHeader->f_LiteEdition) {
+ /// Mount a New partition.
+ HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
+
+ // Open file from first hard-drive.
+ HCore::PEFLoader img("A:/System/HCoreShell.exe");
- /// Run the shell.
- if (!HCore::Utils::execute_from_image(img)) {
- HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+ /// Run the shell.
+ if (!HCore::Utils::execute_from_image(img)) {
+ HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+ }
+ } else {
+ HCore::kcout << "HCoreKrnl: Setup is starting...\n";
+ HCore::kcout << "HCoreKrnl: Mounting drive A:...\n";
}
}
diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx
index a4299f72..681b198a 100644
--- a/Private/Source/NewFS+IO.cxx
+++ b/Private/Source/NewFS+IO.cxx
@@ -20,6 +20,6 @@
/// @brief This implements NewFS with Device Abstraction in mind.
-/// bugs 0
+/// BUGS: 0
#endif // ifdef __FSKIT_NEWFS__
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index 46533f00..4a51acc0 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -21,9 +21,7 @@
///! bugs = 0
/***********************************************************************************/
-/* This file handles
- * The preemptive multitasking of the OS.
- * For MT see SMPManager. */
+/* This file handles the process scheduling.
/***********************************************************************************/
namespace HCore {
@@ -39,7 +37,7 @@ const Int32 &rt_get_exit_code() noexcept { return kExitCode; }
void Process::Crash() {
kcout << this->Name << ": Crashed, ExitCode: -1\n";
- MUST_PASS(ke_bug_check());
+ MUST_PASS(!ke_bug_check());
this->Exit(-1);
}