From b052cb4fbb7b83c1292a3098ee7d00e9f3f3fba1 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 08:26:34 +0100 Subject: New commit: see below. - Add Internal directory. - Add Drivers directory. - Add DDKit in Kits directory. Signed-off-by: Amlal El Mahrouss --- Drivers/.gitkeep | 0 Drivers/AHCI/.gitkeep | 0 Drivers/Ethernet/.gitkeep | 0 Drivers/WiFi/.gitkeep | 0 Drivers/XHCI/.gitkeep | 0 Internal/Tools/.gitkeep | 0 Internal/Tools/NewFSPartTool.cxx | 26 ++++ Private/KernelKit/ProcessManager.hpp | 266 ++++++++++++++++------------------ Private/NewBoot/Source/makefile | 1 - Private/Source/ProcessManager.cxx | 5 +- Private/Source/ThreadLocalStorage.cxx | 2 +- Public/DDK/.gitkeep | 0 Public/DDK/README.TXT | 3 - Public/Kits/DDKit/.gitkeep | 0 Public/Kits/DDKit/README.TXT | 3 + Public/Tools/.gitkeep | 0 Public/Tools/MakeNewFS.cxx | 19 --- 17 files changed, 157 insertions(+), 168 deletions(-) create mode 100644 Drivers/.gitkeep create mode 100644 Drivers/AHCI/.gitkeep create mode 100644 Drivers/Ethernet/.gitkeep create mode 100644 Drivers/WiFi/.gitkeep create mode 100644 Drivers/XHCI/.gitkeep create mode 100644 Internal/Tools/.gitkeep create mode 100644 Internal/Tools/NewFSPartTool.cxx delete mode 100644 Public/DDK/.gitkeep delete mode 100644 Public/DDK/README.TXT create mode 100644 Public/Kits/DDKit/.gitkeep create mode 100644 Public/Kits/DDKit/README.TXT delete mode 100644 Public/Tools/.gitkeep delete mode 100644 Public/Tools/MakeNewFS.cxx diff --git a/Drivers/.gitkeep b/Drivers/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Drivers/AHCI/.gitkeep b/Drivers/AHCI/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Drivers/Ethernet/.gitkeep b/Drivers/Ethernet/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Drivers/WiFi/.gitkeep b/Drivers/WiFi/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Drivers/XHCI/.gitkeep b/Drivers/XHCI/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Internal/Tools/.gitkeep b/Internal/Tools/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Internal/Tools/NewFSPartTool.cxx b/Internal/Tools/NewFSPartTool.cxx new file mode 100644 index 00000000..41bdd392 --- /dev/null +++ b/Internal/Tools/NewFSPartTool.cxx @@ -0,0 +1,26 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: MakeNewFS.cpp + Purpose: Partition a drive with a NewFS/EPM filesystem in it. + + Revision History: + + 31/01/24: Added file (amlel) + +------------------------------------------- */ + +/***********************************************************************************/ +/// @file MakeNewFS.cxx +/// @brief NewFS partition program. +/***********************************************************************************/ + +#include + +int main() { + std::cout + << "NewFSPartTool: Make a NewFS partition image from a directory!\n" + << "Copyright Mahrouss Logic, all rights reserved. (INTERNAL TOOL)\n"; + return 0; +} diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp index 724dd34a..dbcd08b2 100644 --- a/Private/KernelKit/ProcessManager.hpp +++ b/Private/KernelKit/ProcessManager.hpp @@ -9,20 +9,20 @@ #pragma once -#include "NewKit/Defines.hpp" #include #include #include -#include #include #include +#include + +#include "NewKit/Defines.hpp" #define kMinMicroTime AffinityKind::kStandard //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -namespace HCore -{ +namespace HCore { //! @brief Process identifier. typedef Int64 ProcessID; @@ -35,59 +35,53 @@ class ProcessManager; class ProcessHelper; //! @brief Process status enum. -enum class ProcessStatus : Int32 -{ - kStarting, - kRunning, - kKilled, - kFrozen, - kDead +enum class ProcessStatus : Int32 { + kStarting, + kRunning, + kKilled, + kFrozen, + kDead }; //! @brief Affinity is the amount of nano-seconds this process is going //! to run. -enum class AffinityKind : Int32 -{ - kInvalid = 300, - kVeryHigh = 250, - kHigh = 200, - kStandard = 150, - kLowUsage = 100, - kVeryLowUsage = 50, +enum class AffinityKind : Int32 { + kInvalid = 300, + kVeryHigh = 250, + kHigh = 200, + kStandard = 150, + kLowUsage = 100, + kVeryLowUsage = 50, }; // operator overloading. -inline bool operator<(AffinityKind lhs, AffinityKind rhs) -{ - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); +inline bool operator<(AffinityKind lhs, AffinityKind rhs) { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); - return lhs_int < rhs_int; + return lhs_int < rhs_int; } -inline bool operator>(AffinityKind lhs, AffinityKind rhs) -{ - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); +inline bool operator>(AffinityKind lhs, AffinityKind rhs) { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); - return lhs_int > rhs_int; + return lhs_int > rhs_int; } -inline bool operator<=(AffinityKind lhs, AffinityKind rhs) -{ - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); +inline bool operator<=(AffinityKind lhs, AffinityKind rhs) { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); - return lhs_int <= rhs_int; + return lhs_int <= rhs_int; } -inline bool operator>=(AffinityKind lhs, AffinityKind rhs) -{ - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); +inline bool operator>=(AffinityKind lhs, AffinityKind rhs) { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); - return lhs_int >= rhs_int; + return lhs_int >= rhs_int; } // end of operator overloading. @@ -97,11 +91,10 @@ using ProcessTime = UInt64; using PID = Int64; // for permission manager, tells where we run the code. -enum class ProcessSelector : Int -{ - kRingUser, /* user ring (or ring 3 in x86) */ - kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ - kRingKernel, /* machine privileges */ +enum class ProcessSelector : Int { + kRingUser, /* user ring (or ring 3 in x86) */ + kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ + kRingKernel, /* machine privileges */ }; // Helper types. @@ -109,126 +102,113 @@ using ImagePtr = VoidPtr; using HeapPtr = VoidPtr; // @brief Process header structure. -class Process final -{ - public: - explicit Process(VoidPtr startImage = nullptr) : Image(startImage) - { - MUST_PASS(startImage); - } - ~Process() = default; - - HCORE_COPY_DEFAULT(Process) - - public: - void AssignStart(UIntPtr &imageStart) noexcept; - - public: - Char Name[kProcessLen] = {"HCore Process"}; - ProcessSubsystem SubSystem; - ProcessSelector Selector; - HAL::StackFrame *StackFrame{nullptr}; - AffinityKind Affinity; - ProcessStatus Status; - - // Memory, images. - HeapPtr PoolCursor{nullptr}; - ImagePtr Image{nullptr}; - HeapPtr Pool{nullptr}; - - // memory usage - SizeT UsedMemory{0}; - SizeT FreeMemory{0}; - - ProcessTime PTime; - PID ProcessId{-1}; - Int32 Ring{3}; - - public: - //! @brief boolean operator, check status. - operator bool() - { - return Status != ProcessStatus::kDead; - } - - //! @brief Crash program, exits with code ~0. - void Crash(); - - //! @brief Exits program. - void Exit(Int32 exit_code = 0); - - //! @brief TLS new - VoidPtr New(const SizeT &sz); - - //! @brief TLS delete. - Boolean Delete(VoidPtr ptr, const SizeT &sz); - - //! @brief Process name getter, example: "C RunTime" - const Char *GetName(); - - //! @brief Wakes up threads. - void Wake(const bool wakeup = false); - - public: - const ProcessSelector &GetSelector(); - const ProcessStatus &GetStatus(); - const AffinityKind &GetAffinity(); - - private: - friend ProcessManager; - friend ProcessHelper; +class Process final { + public: + explicit Process(VoidPtr startImage = nullptr) : Image(startImage) { + MUST_PASS(startImage); + } + ~Process() = default; + + HCORE_COPY_DEFAULT(Process) + + public: + void AssignStart(UIntPtr &imageStart) noexcept; + + public: + Char Name[kProcessLen] = {"HCore Process"}; + ProcessSubsystem SubSystem; + ProcessSelector Selector; + HAL::StackFrame *StackFrame{nullptr}; + AffinityKind Affinity; + ProcessStatus Status; + + // Memory, images. + HeapPtr PoolCursor{nullptr}; + ImagePtr Image{nullptr}; + HeapPtr Pool{nullptr}; + + // memory usage + SizeT UsedMemory{0}; + SizeT FreeMemory{0}; + + ProcessTime PTime; + PID ProcessId{-1}; + Int32 Ring{3}; + + public: + //! @brief boolean operator, check status. + operator bool() { return Status != ProcessStatus::kDead; } + + //! @brief Crash program, exits with code ~0. + void Crash(); + + //! @brief Exits program. + void Exit(Int32 exit_code = 0); + + //! @brief TLS Allocate + VoidPtr New(const SizeT &sz); + + //! @brief TLS Free. + Boolean Delete(VoidPtr ptr, const SizeT &sz); + + //! @brief Process name getter, example: "C RunTime" + const Char *GetName(); + + //! @brief Wakes up threads. + void Wake(const bool wakeup = false); + + public: + const ProcessSelector &GetSelector(); + const ProcessStatus &GetStatus(); + const AffinityKind &GetAffinity(); + + private: + friend ProcessManager; + friend ProcessHelper; }; using ProcessPtr = Process *; //! @brief Kernel scheduler.. -class ProcessManager final -{ - private: - explicit ProcessManager() = default; +class ProcessManager final { + private: + explicit ProcessManager() = default; - public: - ~ProcessManager() = default; + public: + ~ProcessManager() = default; - HCORE_COPY_DEFAULT(ProcessManager) + HCORE_COPY_DEFAULT(ProcessManager) - operator bool() - { - return m_Headers.Count() > 0; - } - bool operator!() - { - return m_Headers.Count() == 0; - } + operator bool() { return m_Headers.Count() > 0; } + bool operator!() { return m_Headers.Count() == 0; } - bool Add(Ref &Header); - bool Remove(SizeT Header); + bool Add(Ref &Header); + bool Remove(SizeT Header); - Ref &GetCurrent(); - SizeT Run() noexcept; + Ref &GetCurrent(); + SizeT Run() noexcept; - static Ref Shared(); + static Ref Shared(); - private: - MutableArray> m_Headers; - Ref m_CurrentProcess; + private: + MutableArray> m_Headers; + Ref m_CurrentProcess; }; /* * Just a helper class, which contains some utilities for the scheduler. */ -class ProcessHelper final -{ - public: - static bool Switch(HAL::StackFrame *newStack, const PID &newPid); - static bool CanBeScheduled(Ref &process); - static PID &GetCurrentPID(); - static bool StartScheduling(); +class ProcessHelper final { + public: + static bool Switch(HAL::StackFrame *newStack, const PID &newPid); + static bool CanBeScheduled(Ref &process); + static PID &GetCurrentPID(); + static bool StartScheduling(); }; const Int32 &rt_get_exit_code() noexcept; -} // namespace HCore +} // namespace HCore #include diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 4e8f17d2..0a2e1d91 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -17,7 +17,6 @@ bootloader-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx $(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI - cp -r ../../Root ./CDROM/MAHROUSS .PHONY: run-efi-debug run-efi-debug: diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index fce7a58f..a8a03b52 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -39,7 +39,10 @@ const Int32 &rt_get_exit_code() noexcept { return kExitCode; } /***********************************************************************************/ void Process::Crash() { - kcout << this->Name << ": Crashed\n"; + kcout << this->Name << ": Crashed, ExitCode: -1\n"; + + // TODO: Bug check the system. + this->Exit(-1); } diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index edb5faa5..8aeb0431 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -42,7 +42,7 @@ 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 << "TLS: Verification failure, Crashing...\n"; ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } diff --git a/Public/DDK/.gitkeep b/Public/DDK/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/DDK/README.TXT b/Public/DDK/README.TXT deleted file mode 100644 index fec20a60..00000000 --- a/Public/DDK/README.TXT +++ /dev/null @@ -1,3 +0,0 @@ -Device Driver Kit - -A Common framework for Device driver development. diff --git a/Public/Kits/DDKit/.gitkeep b/Public/Kits/DDKit/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Public/Kits/DDKit/README.TXT b/Public/Kits/DDKit/README.TXT new file mode 100644 index 00000000..fec20a60 --- /dev/null +++ b/Public/Kits/DDKit/README.TXT @@ -0,0 +1,3 @@ +Device Driver Kit + +A Common framework for Device driver development. diff --git a/Public/Tools/.gitkeep b/Public/Tools/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Public/Tools/MakeNewFS.cxx b/Public/Tools/MakeNewFS.cxx deleted file mode 100644 index 8871d627..00000000 --- a/Public/Tools/MakeNewFS.cxx +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - - File: MakeNewFS.cpp - Purpose: - - Revision History: - - 31/01/24: Added file (amlel) - -------------------------------------------- */ - -/***********************************************************************************/ -/// @file MakeNewFS.cxx -/// @brief NewFS partition program. -/***********************************************************************************/ - -int main() { return 0; } -- cgit v1.2.3