From 06be6d65bb71152be8a28d7bb6b1028b5a588654 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 28 Jan 2024 16:26:33 +0100 Subject: NewKernel: Final things are getting done for the first prototype. NewBoot: Add ARM64 to HEL. SPEC: Update it to include NewFS into it. Signed-off-by: Amlal El Mahrouss --- Private/Source/Json.cxx | 16 ++-- Private/Source/KHeap.cxx | 159 +++++++++++++++++----------------- Private/Source/KMain.cxx | 25 ------ Private/Source/MeBus/Database.cpp | 10 --- Private/Source/MeBus/Database.cxx | 10 +++ Private/Source/NewFS-IO.cxx | 19 ++-- Private/Source/PermissionSelector.cxx | 34 +++++--- Private/Source/ProcessManager.cxx | 12 ++- Private/Source/RuntimeMain.cxx | 35 ++++++++ 9 files changed, 172 insertions(+), 148 deletions(-) delete mode 100644 Private/Source/KMain.cxx delete mode 100644 Private/Source/MeBus/Database.cpp create mode 100644 Private/Source/MeBus/Database.cxx create mode 100644 Private/Source/RuntimeMain.cxx (limited to 'Private/Source') diff --git a/Private/Source/Json.cxx b/Private/Source/Json.cxx index 25987f70..adfd571d 100644 --- a/Private/Source/Json.cxx +++ b/Private/Source/Json.cxx @@ -1,15 +1,15 @@ /* -* ======================================================== -* -* hCore -* Copyright 2024 Mahrouss Logic, all rights reserved. -* -* ======================================================== -*/ + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ #include using namespace hCore; /// @brief Undefined object, is null in length. -JsonType JsonType::kUndefined(0, 0); \ No newline at end of file +INIT(hCore::JsonType::kUndefined, hCore::JsonType); diff --git a/Private/Source/KHeap.cxx b/Private/Source/KHeap.cxx index 5f394e51..c36c6ad7 100644 --- a/Private/Source/KHeap.cxx +++ b/Private/Source/KHeap.cxx @@ -16,114 +16,111 @@ namespace hCore { - static Ref kWrapperList[kMaxWrappers]; - static SizeT kWrapperCount = 0UL; - static Ref kLastWrapper; - static Pmm kPmm; +static Ref kWrapperList[kMaxWrappers]; +static SizeT kWrapperCount = 0UL; +static Ref kLastWrapper; +static Pmm kPmm; - namespace Detail +namespace Detail +{ +static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) +{ + for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) { - static voidPtr try_find_ptr(const SizeT &sz, const bool rw, const bool user) + if (!kWrapperList[indexWrapper]->Present()) { - for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) - { - if (!kWrapperList[indexWrapper]->Present()) - { - kWrapperList[indexWrapper]->Reclaim(); /* very straight-forward as you can see. */ - return reinterpret_cast(kWrapperList[indexWrapper]->VirtualAddress()); - } - } - - return nullptr; + kWrapperList[indexWrapper]->Reclaim(); /* very straight-forward as you can see. */ + return reinterpret_cast(kWrapperList[indexWrapper]->VirtualAddress()); } - } // namespace Detail - - /// @brief manual allocation - /// @param sz size of pointer - /// @param rw read write (true to enable it) - /// @param user is it accesible by user processes? - /// @return the pointer - VoidPtr kernel_new_ptr(const SizeT& sz, const bool rw, const bool user) - { - if (kWrapperCount < sz) - return nullptr; + } - if (auto ptr = Detail::try_find_ptr(sz, rw, user); - ptr) - return ptr; + return nullptr; +} +} // namespace Detail + +/// @brief manual allocation +/// @param sz size of pointer +/// @param rw read write (true to enable it) +/// @param user is it accesible by user processes? +/// @return the pointer +VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user) +{ + if (kWrapperCount < sz) + return nullptr; - Ref wrapper = kPmm.RequestPage(user, rw); + if (auto ptr = Detail::find_ptr(sz, rw, user); ptr) + return ptr; - if (wrapper) - { - kLastWrapper = wrapper; + Ref wrapper = kPmm.RequestPage(user, rw); - kWrapperList[kWrapperCount] = wrapper; - ++kWrapperCount; + if (wrapper) + { + kLastWrapper = wrapper; - return reinterpret_cast(wrapper->VirtualAddress()); - } + kWrapperList[kWrapperCount] = wrapper; + ++kWrapperCount; - return nullptr; + return reinterpret_cast(wrapper->VirtualAddress()); } - /// @brief Declare pointer as free. - /// @param ptr the pointer. - /// @return - Int32 kernel_delete_ptr(voidPtr ptr) + return nullptr; +} + +/// @brief Declare pointer as free. +/// @param ptr the pointer. +/// @return +Int32 kernel_delete_ptr(voidPtr ptr) +{ + if (ptr) { - if (ptr) - { - const UIntPtr virtualAddress = reinterpret_cast(ptr); + const UIntPtr virtualAddress = reinterpret_cast(ptr); - if (kLastWrapper && - virtualAddress == kLastWrapper->VirtualAddress()) - { - return kPmm.FreePage(kLastWrapper); - } + if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) + { + return kPmm.FreePage(kLastWrapper); + } - Ref wrapper; + Ref wrapper; - for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) + for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) + { + if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) { - if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) - { - wrapper = kWrapperList[indexWrapper]; - return kPmm.FreePage(wrapper); - } + wrapper = kWrapperList[indexWrapper]; + return kPmm.FreePage(wrapper); } } - - return -1; } - /// @brief find pointer in kernel heap - /// @param ptr the pointer - /// @return if it exists. - Boolean kernel_valid_ptr(voidPtr ptr) + return -1; +} + +/// @brief find pointer in kernel heap +/// @param ptr the pointer +/// @return if it exists. +Boolean kernel_valid_ptr(voidPtr ptr) +{ + if (ptr) { - if (ptr) - { - const UIntPtr virtualAddress = reinterpret_cast(ptr); + const UIntPtr virtualAddress = reinterpret_cast(ptr); - if (kLastWrapper && - virtualAddress == kLastWrapper->VirtualAddress()) - { - return true; - } + if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) + { + return true; + } - Ref wrapper; + Ref wrapper; - for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) + for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) + { + if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) { - if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) - { - wrapper = kWrapperList[indexWrapper]; - return true; - } + wrapper = kWrapperList[indexWrapper]; + return true; } } - - return false; } + + return false; +} } // namespace hCore diff --git a/Private/Source/KMain.cxx b/Private/Source/KMain.cxx deleted file mode 100644 index d2dac924..00000000 --- a/Private/Source/KMain.cxx +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include - -extern "C" void KMain(hCore::VoidPtr this_image) -{ - MUST_PASS(hCore::initialize_hardware_components()); - - hCore::IFilesystemManager::Mount(new hCore::NewFilesystemManager()); - hCore::PEFLoader img("/System/SeekerSrv.out"); - - if (!hCore::Utils::execute_from_image(img)) - { - hCore::panic(RUNTIME_CHECK_BOOTSTRAP); - } -} diff --git a/Private/Source/MeBus/Database.cpp b/Private/Source/MeBus/Database.cpp deleted file mode 100644 index 3c7594d5..00000000 --- a/Private/Source/MeBus/Database.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ======================================================== - * - * hCore - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -//! Add this unit to compilation. diff --git a/Private/Source/MeBus/Database.cxx b/Private/Source/MeBus/Database.cxx new file mode 100644 index 00000000..3c7594d5 --- /dev/null +++ b/Private/Source/MeBus/Database.cxx @@ -0,0 +1,10 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +//! Add this unit to compilation. diff --git a/Private/Source/NewFS-IO.cxx b/Private/Source/NewFS-IO.cxx index ce81db40..b9ecfd52 100644 --- a/Private/Source/NewFS-IO.cxx +++ b/Private/Source/NewFS-IO.cxx @@ -1,15 +1,14 @@ /* -* ======================================================== -* -* hCore -* Copyright 2024 Mahrouss Logic, all rights reserved. -* -* ======================================================== -*/ + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ #include -#include -#include +#include +#include /// bugs 0 - diff --git a/Private/Source/PermissionSelector.cxx b/Private/Source/PermissionSelector.cxx index a14f146d..04245502 100644 --- a/Private/Source/PermissionSelector.cxx +++ b/Private/Source/PermissionSelector.cxx @@ -5,7 +5,7 @@ * Copyright 2024 Mahrouss Logic, all rights reserved. * * File: PermissionSelector.cpp - * Purpose: Permission primitives and types. + * Purpose: Permission primitive type. * * ======================================================== */ @@ -15,19 +15,29 @@ namespace hCore { - PermissionSelector::PermissionSelector(const Int32& sel) - : fRing((RingKind)sel) - { MUST_PASS(sel > 0); } +PermissionSelector::PermissionSelector(const Int32 &sel) : fRing((RingKind)sel) +{ + MUST_PASS(sel > 0); +} + +PermissionSelector::PermissionSelector(const RingKind &ringKind) : fRing(ringKind) +{ +} - PermissionSelector::PermissionSelector(const RingKind& ringKind) - : fRing(ringKind) - {} +PermissionSelector::~PermissionSelector() = default; - PermissionSelector::~PermissionSelector() = default; +bool PermissionSelector::operator==(const PermissionSelector &lhs) +{ + return lhs.fRing == this->fRing; +} - bool PermissionSelector::operator==(const PermissionSelector& lhs) { return lhs.fRing == this->fRing; } - - bool PermissionSelector::operator!=(const PermissionSelector& lhs) { return lhs.fRing != this->fRing; } +bool PermissionSelector::operator!=(const PermissionSelector &lhs) +{ + return lhs.fRing != this->fRing; +} - const RingKind& PermissionSelector::Ring() noexcept { return this->fRing; } +const RingKind &PermissionSelector::Ring() noexcept +{ + return this->fRing; +} } // namespace hCore diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 5dcc98f2..4679daff 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -7,6 +7,7 @@ * ======================================================== */ +#include "NewKit/Panic.hpp" #include #include #include @@ -121,19 +122,25 @@ const ProcessStatus &Process::GetStatus() return this->Status; } +/** +@brief Affinity is the time slot allowed for the process. +*/ const AffinityKind &Process::GetAffinity() { return this->Affinity; } +/** +@brief Standard exit proc. +*/ void Process::Exit(Int32 exit_code) { if (this->ProcessId != ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId) - return; + panic(RUNTIME_CHECK_PROCESS); if (this->Ring == (Int32)ProcessSelector::kRingKernel && ProcessManager::Shared().Leak().GetCurrent().Leak().Ring > 0) - return; + panic(RUNTIME_CHECK_PROCESS); kExitCode = exit_code; @@ -200,6 +207,7 @@ SizeT ProcessManager::Run() noexcept for (; processIndex < this->m_Headers.Count(); ++processIndex) { auto process = this->m_Headers[processIndex]; + MUST_PASS( process); //! no need for a MUST_PASS(process.Leak());, it is recursive because of the nature of the class; diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx new file mode 100644 index 00000000..4b91bb5f --- /dev/null +++ b/Private/Source/RuntimeMain.cxx @@ -0,0 +1,35 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include "NewKit/Defines.hpp" +#include +#include +#include +#include + +extern void (*__SYSTEM_INIT_END)(); +extern void (**init)(); + +extern "C" void RuntimeMain() +{ + for (hCore::SizeT index_init = 0UL; init[index_init] != __SYSTEM_INIT_END; ++index_init) + { + init[index_init](); + } + + MUST_PASS(hCore::init_hal()); + + hCore::IFilesystemManager::Mount(new hCore::NewFilesystemManager()); + hCore::PEFLoader img("/System/Seeker.cm"); + + if (!hCore::Utils::execute_from_image(img)) + { + hCore::panic(RUNTIME_CHECK_BOOTSTRAP); + } +} -- cgit v1.2.3