From 54a0f4c49d9bfb955174c87dae2f442d7f5a8b25 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 May 2025 11:12:31 +0200 Subject: feat!(Kernel): Improvements on the BitMapMgr, HTS, and UPS. other: - Add ZXD header file. - Reworking AMD64 interrupts. - Improved HTS's design implementation. - Improved UPS's balancing implementation. breaking changes: - Rename MemoryMgr to HeapMgr. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/FileMgr.h | 11 ++-- dev/kernel/KernelKit/HardwareThreadScheduler.h | 1 - dev/kernel/KernelKit/HeapMgr.h | 58 +++++++++++++++++++ dev/kernel/KernelKit/HeapMgr.inl | 35 ++++++++++++ dev/kernel/KernelKit/MemoryMgr.h | 78 -------------------------- dev/kernel/KernelKit/Zxd.h | 37 ++++++++++++ 6 files changed, 136 insertions(+), 84 deletions(-) create mode 100644 dev/kernel/KernelKit/HeapMgr.h create mode 100644 dev/kernel/KernelKit/HeapMgr.inl delete mode 100644 dev/kernel/KernelKit/MemoryMgr.h create mode 100644 dev/kernel/KernelKit/Zxd.h (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 86354d7f..21b8b96e 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -28,8 +28,8 @@ #include #include +#include #include -#include #include #include #include @@ -324,7 +324,7 @@ class FileStream final { Char* MIME() noexcept { return const_cast(fMime); } enum { - kFileMgrRestrictRead, + kFileMgrRestrictRead = 100, kFileMgrRestrictReadBinary, kFileMgrRestrictWrite, kFileMgrRestrictWriteBinary, @@ -338,7 +338,8 @@ class FileStream final { const Char* fMime{kFileMimeGeneric}; }; -using FileStreamUTF8 = FileStream; +using FileStreamASCII = FileStream; +using FileStreamUTF8 = FileStream; using FileStreamUTF16 = FileStream; typedef UInt64 CursorType; @@ -346,7 +347,7 @@ typedef UInt64 CursorType; inline static const auto kRestrictStrLen = 8U; /// @brief restrict information about the file descriptor. -struct FileRestrictKind final { +struct FILEMGR_RESTRICT final { Char fRestrict[kRestrictStrLen]; Int32 fMappedTo; }; @@ -356,7 +357,7 @@ template inline FileStream::FileStream(const Encoding* path, const Encoding* restrict_type) : fFile(Class::GetMounted()->Open(path, restrict_type)) { SizeT kRestrictCount = kRestrictMax; - const FileRestrictKind kRestrictList[] = {{ + const FILEMGR_RESTRICT kRestrictList[] = {{ .fRestrict = kRestrictR, .fMappedTo = kFileMgrRestrictRead, }, diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index a10d3a9e..76327a93 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -71,7 +71,6 @@ class HardwareThread final { HAL::StackFramePtr fStack{nullptr}; ThreadKind fKind{ThreadKind::kAPStandard}; ThreadID fID{0}; - ThreadID fPID{0}; Bool fWakeup{NO}; Bool fBusy{NO}; UInt64 fPTime{0}; diff --git a/dev/kernel/KernelKit/HeapMgr.h b/dev/kernel/KernelKit/HeapMgr.h new file mode 100644 index 00000000..3271dd03 --- /dev/null +++ b/dev/kernel/KernelKit/HeapMgr.h @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef INC_KERNEL_HEAP_H +#define INC_KERNEL_HEAP_H + +/// @date 30/01/24 +/// @file: HeapMgr.h +/// @brief: Memory allocation support for the NeKernel. + +#include +#include +#include + +namespace Kernel { +/// @brief Declare pointer as free. +/// @param heap_ptr the pointer. +/// @return a status code regarding the deallocation. +Int32 mm_delete_ptr(VoidPtr heap_ptr); + +/// @brief Check if pointer is a valid Kernel pointer. +/// @param heap_ptr the pointer +/// @return if it exists it returns true. +Boolean mm_is_valid_ptr(VoidPtr heap_ptr); + +/// @brief Allocate chunk of memory. +/// @param sz Size of pointer +/// @param wr Read Write bit. +/// @param user User enable bit. +/// @return The newly allocated pointer, or nullptr. +VoidPtr mm_new_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount = 0); + +/// @brief Protect the heap with a CRC value. +/// @param heap_ptr pointer. +/// @return if it valid: point has crc now., otherwise fail. +Boolean mm_protect_ptr(VoidPtr heap_ptr); + +/// @brief Makes a Kernel page. +/// @param heap_ptr the page pointer. +/// @return status code +Int32 mm_make_page(VoidPtr heap_ptr); + +/// @brief Overwrites and set the flags of a heap header. +/// @param heap_ptr the pointer to update. +/// @param flags the flags to set. +Int32 mm_make_ptr_flags(VoidPtr heap_ptr, UInt64 flags); + +/// @brief Gets the flags of a heap header. +/// @param heap_ptr the pointer to get. +UInt64 mm_get_ptr_flags(VoidPtr heap_ptr); +} // namespace Kernel + +#include + +#endif // !INC_KERNEL_HEAP_H diff --git a/dev/kernel/KernelKit/HeapMgr.inl b/dev/kernel/KernelKit/HeapMgr.inl new file mode 100644 index 00000000..6371012e --- /dev/null +++ b/dev/kernel/KernelKit/HeapMgr.inl @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#ifndef INC_KERNEL_HEAP_H +#include +#endif // !INC_KERNEL_HEAP_H + +namespace Kernel { +/// @brief Allocate C++ class. +/// @param cls The class to allocate. +/// @param args The args to pass. +template +inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) { + if (*cls) { + err_global_get() = Kernel::kErrorInvalidData; + return NO; + } + + *cls = new T(move(args)...); + return *cls; +} + +/// @brief Delete and nullify C++ class. +/// @param cls The class to delete. +template +inline Void mm_delete_class(_Input _Output T** cls) { + delete *cls; + *cls = nullptr; +} +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/KernelKit/MemoryMgr.h b/dev/kernel/KernelKit/MemoryMgr.h deleted file mode 100644 index 7ca7da90..00000000 --- a/dev/kernel/KernelKit/MemoryMgr.h +++ /dev/null @@ -1,78 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#ifndef INC_KERNEL_HEAP_H -#define INC_KERNEL_HEAP_H - -/// @date 30/01/24 -/// @file: MemoryMgr.h -/// @brief: Memory allocation support for the NeKernel. - -#include -#include -#include - -namespace Kernel { -/// @brief Declare pointer as free. -/// @param heap_ptr the pointer. -/// @return a status code regarding the deallocation. -Int32 mm_delete_ptr(VoidPtr heap_ptr); - -/// @brief Check if pointer is a valid Kernel pointer. -/// @param heap_ptr the pointer -/// @return if it exists it returns true. -Boolean mm_is_valid_ptr(VoidPtr heap_ptr); - -/// @brief Allocate chunk of memory. -/// @param sz Size of pointer -/// @param wr Read Write bit. -/// @param user User enable bit. -/// @return The newly allocated pointer, or nullptr. -VoidPtr mm_new_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount = 0); - -/// @brief Protect the heap with a CRC value. -/// @param heap_ptr pointer. -/// @return if it valid: point has crc now., otherwise fail. -Boolean mm_protect_ptr(VoidPtr heap_ptr); - -/// @brief Makes a Kernel page. -/// @param heap_ptr the page pointer. -/// @return status code -Int32 mm_make_page(VoidPtr heap_ptr); - -/// @brief Overwrites and set the flags of a heap header. -/// @param heap_ptr the pointer to update. -/// @param flags the flags to set. -Int32 mm_make_ptr_flags(VoidPtr heap_ptr, UInt64 flags); - -/// @brief Gets the flags of a heap header. -/// @param heap_ptr the pointer to get. -UInt64 mm_get_ptr_flags(VoidPtr heap_ptr); - -/// @brief Allocate C++ class. -/// @param cls The class to allocate. -/// @param args The args to pass. -template -inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) { - if (*cls) { - err_global_get() = Kernel::kErrorInvalidData; - return NO; - } - - *cls = new T(move(args)...); - return *cls; -} - -/// @brief Delete and nullify C++ class. -/// @param cls The class to delete. -template -inline Void mm_delete_class(_Input _Output T** cls) { - delete *cls; - *cls = nullptr; -} -} // namespace Kernel - -#endif // !INC_KERNEL_HEAP_H diff --git a/dev/kernel/KernelKit/Zxd.h b/dev/kernel/KernelKit/Zxd.h new file mode 100644 index 00000000..d2456f51 --- /dev/null +++ b/dev/kernel/KernelKit/Zxd.h @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace ZXD { +using namespace Kernel; + +struct ZXD_EXEC_HEADER; +struct ZXD_STUB_HEADER; + +/// @brief ZXD executable header +/// @details This header is used to identify ZXD executable files. +struct ZXD_EXEC_HEADER { + UInt32 fMagic; + UInt32 fVersion; + UInt32 fFlags; + UInt32 fHdrSize; + UInt32 fCRC32; + UInt32 fAssigneeSignature; + UInt32 fIssuerSingature; +}; + +/// @brief ZXD stub header +/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the +/// offset of the stub, and the CRC32 checksum of the stub. +struct ZXD_STUB_HEADER : public ZXD_EXEC_HEADER { + UInt32 fStubSize; + UInt32 fStubOffset; + UInt32 fStubCRC32; +}; +} // namespace ZXD \ No newline at end of file -- cgit v1.2.3