diff options
Diffstat (limited to 'Private/KernelKit')
| -rw-r--r-- | Private/KernelKit/DebugOutput.hpp | 2 | ||||
| -rw-r--r-- | Private/KernelKit/KernelHeap.hpp | 19 | ||||
| -rw-r--r-- | Private/KernelKit/LockDelegate.hpp | 64 | ||||
| -rw-r--r-- | Private/KernelKit/ProcessScheduler.hpp | 4 | ||||
| -rw-r--r-- | Private/KernelKit/UserHeap.hpp | 40 |
5 files changed, 127 insertions, 2 deletions
diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index 88ed2448..0eb59da2 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -83,6 +83,8 @@ inline TerminalDevice _write_number_hex(const Long &x, TerminalDevice& term) { inline TerminalDevice hex_number(const Long &x) { TerminalDevice selfTerm = TerminalDevice::Shared(); + + selfTerm << "0x"; Detail::_write_number_hex(x, selfTerm); return selfTerm; diff --git a/Private/KernelKit/KernelHeap.hpp b/Private/KernelKit/KernelHeap.hpp new file mode 100644 index 00000000..974cf0f3 --- /dev/null +++ b/Private/KernelKit/KernelHeap.hpp @@ -0,0 +1,19 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +// last-rev 30/01/24 +// file: KernelHeap.hpp +// description: heap allocation for the kernel. + +#include <NewKit/Defines.hpp> + +namespace HCore { +Int32 ke_delete_ke_heap(voidPtr allocatedPtr); +Boolean ke_is_valid_ptr(VoidPtr ptr); +voidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user); +} // namespace HCore diff --git a/Private/KernelKit/LockDelegate.hpp b/Private/KernelKit/LockDelegate.hpp new file mode 100644 index 00000000..0fd9ba63 --- /dev/null +++ b/Private/KernelKit/LockDelegate.hpp @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Atom.hpp> +#include <NewKit/Defines.hpp> + +#define kLockDone (200U) /* job is done */ +#define kLockTimedOut (100U) /* job has timed out */ + +namespace HCore +{ +/// @brief Lock condition pointer. +typedef Boolean* LockPtr; + +/// @brief Locking delegate class, hangs until limit. +/// @tparam N the amount of cycles to wait. +template <SizeT N> +class LockDelegate final +{ + public: + LockDelegate() = delete; + + public: + explicit LockDelegate(LockPtr expr) + { + auto spin = 0U; + + while (spin != N) + { + if (*expr) + { + m_LockStatus | kLockDone; + break; + } + } + + if (spin == N) + m_LockStatus | kLockTimedOut; + } + + ~LockDelegate() = default; + + LockDelegate &operator=(const LockDelegate &) = delete; + LockDelegate(const LockDelegate &) = delete; + + bool Done() + { + return m_LockStatus[kLockDone] == kLockDone; + } + + bool HasTimedOut() + { + return m_LockStatus[kLockTimedOut] != kLockTimedOut; + } + + private: + Atom<UInt> m_LockStatus; +}; +} // namespace HCore diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp index e3cbbe86..caff1125 100644 --- a/Private/KernelKit/ProcessScheduler.hpp +++ b/Private/KernelKit/ProcessScheduler.hpp @@ -10,9 +10,9 @@ #include <ArchKit/ArchKit.hpp> #include <KernelKit/FileManager.hpp> #include <KernelKit/PermissionSelector.hxx> -#include <NewKit/LockDelegate.hpp> +#include <KernelKit/LockDelegate.hpp> #include <NewKit/MutableArray.hpp> -#include <NewKit/UserHeap.hpp> +#include <KernelKit/UserHeap.hpp> #define kMinMicroTime AffinityKind::kHartStandard #define kPIDInvalid (-1) diff --git a/Private/KernelKit/UserHeap.hpp b/Private/KernelKit/UserHeap.hpp new file mode 100644 index 00000000..d66eb356 --- /dev/null +++ b/Private/KernelKit/UserHeap.hpp @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Array.hpp> +#include <NewKit/ArrayList.hpp> +#include <NewKit/ErrorOr.hpp> +#include <NewKit/PageManager.hpp> +#include <NewKit/Ref.hpp> +#include <NewKit/Pmm.hpp> + +/// @version 5/11/23 +/// @file UserHeap.hpp +/// @brief memory heap for user programs. + +#define kUserHeapMaxSz (4096) +#define kUserHeapMag (0x5500A1) + +namespace HCore { +typedef enum { + kUserHeapHypervisor = 0x2, + kUserHeapShared = 0x4, + kUserHeapUser = 0x6, + kUserHeapRw = 0x8, +} kUserHeapFlags; + +/// @brief Allocate a process heap, no zero out is done here. +/// @param flags +/// @return The process's heap. +VoidPtr rt_new_heap(Int32 flags); + +/// @brief Frees the process heap. +/// @param pointer The process heap pointer. +/// @return +Int32 rt_free_heap(voidPtr pointer); +} // namespace HCore |
