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/src/HeapMgr.cc | 260 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 dev/kernel/src/HeapMgr.cc (limited to 'dev/kernel/src/HeapMgr.cc') diff --git a/dev/kernel/src/HeapMgr.cc b/dev/kernel/src/HeapMgr.cc new file mode 100644 index 00000000..6cd8fb24 --- /dev/null +++ b/dev/kernel/src/HeapMgr.cc @@ -0,0 +1,260 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include + +/* ------------------------------------------- + + Revision History: + 10/8/24: FIX: Fix useless long name, alongside a new WR (WriteRead) field. + 20/10/24: FIX: Fix mm_new_ and mm_delete_ APIs inside HeapMgr.h header. (amlal) + 27/01/25: REFACTOR: Reworked code as the memory manager. + 25/03/25: REFACTOR: Refactor HeapMgr code and log freed address location. + + ------------------------------------------- */ + +//! @file HeapMgr.cc +//! @brief Heap system that serves as the main memory manager. + +#define kMemoryMgrMagic (0xD4D75) +#define kMemoryMgrAlignSz (4U) + +namespace Kernel { +/// @brief Implementation details. +namespace Detail { + struct PACKED MM_INFORMATION_BLOCK; + + /// @brief Kernel heap information block. + /// Located before the address bytes. + /// | HIB | CLASS/STRUCT/DATA TYPES... | + struct PACKED MM_INFORMATION_BLOCK final { + ///! @brief 32-bit value which contains the magic number of the heap. + UInt32 fMagic : 24; + + ///! @brief Is the heap present? + UInt8 fPresent : 1; + + /// @brief Is this value writable? + UInt8 fWriteRead : 1; + + /// @brief Is this value owned by the user? + UInt8 fUser : 1; + + /// @brief Is this a page pointer? + UInt8 fPage : 1; + + /// @brief 32-bit CRC checksum. + UInt32 fCRC32; + + /// @brief 64-bit Allocation flags. + UInt16 fFlags; + + /// @brief 64-bit pointer size. + SizeT fSize; + + /// @brief 64-bit target offset pointer. + UIntPtr fOffset; + + /// @brief Padding. + UInt32 fPad; + + /// @brief Padding bytes for header. + UInt8 fPadding[kMemoryMgrAlignSz]; + }; + + /// @brief Check for heap address validity. + /// @param heap_ptr The address_ptr to check. + /// @return Bool if the pointer is valid or not. + _Output auto mm_check_ptr_address(VoidPtr heap_ptr) -> Bool { + if (!heap_ptr) return false; + + IntPtr base_ptr = ((IntPtr) heap_ptr) - sizeof(Detail::MM_INFORMATION_BLOCK); + + /// Add that check in case we're having an integer underflow. /// + + if (base_ptr < 0) { + return false; + } + + return true; + } + + typedef MM_INFORMATION_BLOCK* MM_INFORMATION_BLOCK_PTR; +} // namespace Detail + +STATIC PageMgr kPageMgr; + +/// @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. +_Output VoidPtr mm_new_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { + auto sz_fix = sz; + + if (sz_fix == 0) return nullptr; + + sz_fix += sizeof(Detail::MM_INFORMATION_BLOCK); + + auto wrapper = kPageMgr.Request(wr, user, No, sz_fix, pad_amount); + + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast(wrapper.VirtualAddress() + + sizeof(Detail::MM_INFORMATION_BLOCK)); + + heap_info_ptr->fSize = sz_fix; + heap_info_ptr->fMagic = kMemoryMgrMagic; + heap_info_ptr->fCRC32 = 0U; // dont fill it for now. + heap_info_ptr->fOffset = + reinterpret_cast(heap_info_ptr) + sizeof(Detail::MM_INFORMATION_BLOCK); + heap_info_ptr->fPage = No; + heap_info_ptr->fWriteRead = wr; + heap_info_ptr->fUser = user; + heap_info_ptr->fPresent = Yes; + heap_info_ptr->fPad = pad_amount; + + rt_set_memory(heap_info_ptr->fPadding, 0, kMemoryMgrAlignSz); + + auto result = reinterpret_cast(heap_info_ptr->fOffset); + + (Void)(kout << "HeapMgr: Registered heap address: " + << hex_number(reinterpret_cast(heap_info_ptr)) << kendl); + + return result; +} + +/// @brief Makes a page heap. +/// @param heap_ptr the pointer to make a page heap. +/// @return kErrorSuccess if successful, otherwise an error code. +_Output Int32 mm_make_page(VoidPtr heap_ptr) { + if (Detail::mm_check_ptr_address(heap_ptr) == No) return kErrorHeapNotPresent; + + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast((UIntPtr) heap_ptr - + sizeof(Detail::MM_INFORMATION_BLOCK)); + + if (!heap_info_ptr) return kErrorHeapNotPresent; + + heap_info_ptr->fPage = true; + + (Void)(kout << "HeapMgr: Registered page from heap address: " + << hex_number(reinterpret_cast(heap_info_ptr)) << kendl); + + return kErrorSuccess; +} + +/// @brief Overwrites and set the flags of a heap header. +/// @param heap_ptr the pointer to update. +/// @param flags the flags to set. +_Output Int32 mm_make_ptr_flags(VoidPtr heap_ptr, UInt64 flags) { + if (Detail::mm_check_ptr_address(heap_ptr) == No) return kErrorHeapNotPresent; + + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast((UIntPtr) heap_ptr - + sizeof(Detail::MM_INFORMATION_BLOCK)); + + if (!heap_info_ptr) return kErrorHeapNotPresent; + + heap_info_ptr->fFlags = flags; + + return kErrorSuccess; +} + +/// @brief Gets the flags of a heap header. +/// @param heap_ptr the pointer to get. +_Output UInt64 mm_get_ptr_flags(VoidPtr heap_ptr) { + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast((UIntPtr) heap_ptr - + sizeof(Detail::MM_INFORMATION_BLOCK)); + + if (!heap_info_ptr) return kErrorHeapNotPresent; + + return heap_info_ptr->fFlags; +} + +/// @brief Declare pointer as free. +/// @param heap_ptr the pointer. +/// @return +_Output Int32 mm_delete_ptr(VoidPtr heap_ptr) { + if (Detail::mm_check_ptr_address(heap_ptr) == No) return kErrorHeapNotPresent; + + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast((UIntPtr) (heap_ptr) - + sizeof(Detail::MM_INFORMATION_BLOCK)); + + if (heap_info_ptr && heap_info_ptr->fMagic == kMemoryMgrMagic) { + if (!heap_info_ptr->fPresent) { + return kErrorHeapNotPresent; + } + + heap_info_ptr->fSize = 0UL; + heap_info_ptr->fPresent = No; + heap_info_ptr->fOffset = 0; + heap_info_ptr->fCRC32 = 0; + heap_info_ptr->fWriteRead = No; + heap_info_ptr->fUser = No; + heap_info_ptr->fMagic = 0; + heap_info_ptr->fPad = 0; + + (Void)(kout << "HeapMgr: Freed heap address: " + << hex_number(reinterpret_cast(heap_info_ptr)) << kendl); + + PTEWrapper page_wrapper( + No, No, No, + reinterpret_cast(heap_info_ptr) - sizeof(Detail::MM_INFORMATION_BLOCK)); + + Ref pte_address{page_wrapper}; + + kPageMgr.Free(pte_address); + + return kErrorSuccess; + } + + return kErrorInternal; +} + +/// @brief Check if pointer is a valid Kernel pointer. +/// @param heap_ptr the pointer +/// @return if it exists. +_Output Boolean mm_is_valid_ptr(VoidPtr heap_ptr) { + if (heap_ptr && HAL::mm_is_bitmap(heap_ptr)) { + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast((UIntPtr) (heap_ptr) - + sizeof(Detail::MM_INFORMATION_BLOCK)); + + return (heap_info_ptr && heap_info_ptr->fPresent && heap_info_ptr->fMagic == kMemoryMgrMagic); + } + + return No; +} + +/// @brief Protect the heap with a CRC value. +/// @param heap_ptr HIB pointer. +/// @return if it valid: point has crc now., otherwise fail. +_Output Boolean mm_protect_ptr(VoidPtr heap_ptr) { + if (heap_ptr) { + Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = + reinterpret_cast((UIntPtr) heap_ptr - + sizeof(Detail::MM_INFORMATION_BLOCK)); + + /// if valid, present and is heap header, then compute crc32 + if (heap_info_ptr && heap_info_ptr->fPresent && kMemoryMgrMagic == heap_info_ptr->fMagic) { + heap_info_ptr->fCRC32 = + ke_calculate_crc32((Char*) heap_info_ptr->fOffset, heap_info_ptr->fSize); + + return Yes; + } + } + + return No; +} +} // namespace Kernel -- cgit v1.2.3 From 80f5f9dfdaaf68d9e63a7bc3ba1187ca447eadc9 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 May 2025 13:04:05 +0200 Subject: refactor(kernel): Refactor HeapMgr functions. what: - mm_new_ptr is now mm_alloc_ptr. - mm_delete_ptr is now mm_free_ptr. Signed-off-by: Amlal El Mahrouss --- dev/ddk/src/ddk_alloc.c | 4 +-- dev/kernel/KernelKit/FileMgr.h | 2 +- dev/kernel/KernelKit/HeapMgr.h | 4 +-- dev/kernel/KernelKit/UserProcessScheduler.inl | 4 +-- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 42 +++++++++++++-------------- dev/kernel/src/FS/NeFS+FileSystemParser.cc | 4 +-- dev/kernel/src/HeapMgr.cc | 4 +-- dev/kernel/src/New+Delete.cc | 12 ++++---- dev/kernel/src/PEFCodeMgr.cc | 16 +++++----- dev/kernel/src/UserProcessScheduler.cc | 14 ++++----- 10 files changed, 53 insertions(+), 53 deletions(-) (limited to 'dev/kernel/src/HeapMgr.cc') diff --git a/dev/ddk/src/ddk_alloc.c b/dev/ddk/src/ddk_alloc.c index 1354bce4..0b428b15 100644 --- a/dev/ddk/src/ddk_alloc.c +++ b/dev/ddk/src/ddk_alloc.c @@ -16,7 +16,7 @@ DDK_EXTERN void* kalloc(size_t sz) { if (!sz) ++sz; - void* ptr = ke_call("mm_new_ptr", 1, &sz, sizeof(size_t)); + void* ptr = ke_call("mm_alloc_ptr", 1, &sz, sizeof(size_t)); return ptr; } @@ -28,5 +28,5 @@ DDK_EXTERN void* kalloc(size_t sz) { DDK_EXTERN void kfree(void* ptr) { if (!ptr) return; - ke_call("mm_delete_ptr", 1, ptr, 0); + ke_call("mm_free_ptr", 1, ptr, 0); } diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 21b8b96e..dcce787f 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -392,7 +392,7 @@ inline FileStream::FileStream(const Encoding* path, const Encod /// @brief destructor of the file stream. template inline FileStream::~FileStream() { - mm_delete_ptr(fFile); + mm_free_ptr(fFile); } } // namespace Kernel diff --git a/dev/kernel/KernelKit/HeapMgr.h b/dev/kernel/KernelKit/HeapMgr.h index 3271dd03..851f3095 100644 --- a/dev/kernel/KernelKit/HeapMgr.h +++ b/dev/kernel/KernelKit/HeapMgr.h @@ -19,7 +19,7 @@ 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); +Int32 mm_free_ptr(VoidPtr heap_ptr); /// @brief Check if pointer is a valid Kernel pointer. /// @param heap_ptr the pointer @@ -31,7 +31,7 @@ Boolean mm_is_valid_ptr(VoidPtr heap_ptr); /// @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); +VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount = 0); /// @brief Protect the heap with a CRC value. /// @param heap_ptr pointer. diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index 236262e1..156aa0b5 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -36,13 +36,13 @@ Boolean USER_PROCESS::Delete(ErrorOr ptr) { hal_write_cr3(this->VMRegister); - auto ret = mm_delete_ptr(entry->Entry); + auto ret = mm_free_ptr(entry->Entry); hal_write_cr3(pd); return ret == kErrorSuccess; #else - Bool ret = mm_delete_ptr(ptr.Leak().Leak()); + Bool ret = mm_free_ptr(ptr.Leak().Leak()); return ret == kErrorSuccess; #endif diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 0f6e7355..155c9b9f 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -262,7 +262,7 @@ namespace Detail { const BOOL delete_or_create) { if (mnt) { HEFS_INDEX_NODE_DIRECTORY* tmpdir = - (HEFS_INDEX_NODE_DIRECTORY*) mm_new_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); + (HEFS_INDEX_NODE_DIRECTORY*) mm_alloc_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); auto start = boot->fStartIND; auto prev_location = start; @@ -294,7 +294,7 @@ namespace Detail { if (expr) { HEFS_INDEX_NODE_DIRECTORY* dirent = - (HEFS_INDEX_NODE_DIRECTORY*) mm_new_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); + (HEFS_INDEX_NODE_DIRECTORY*) mm_alloc_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); rt_set_memory(dirent, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); @@ -412,8 +412,8 @@ namespace Detail { err_global_get() = kErrorSuccess; - mm_delete_ptr(dirent); - mm_delete_ptr(tmpdir); + mm_free_ptr(dirent); + mm_free_ptr(tmpdir); if (!delete_or_create) ++boot->fINDCount; @@ -438,7 +438,7 @@ namespace Detail { } err_global_get() = kErrorDisk; - mm_delete_ptr(tmpdir); + mm_free_ptr(tmpdir); return NO; } @@ -467,7 +467,7 @@ namespace Detail { HEFS_INDEX_NODE* node = new HEFS_INDEX_NODE(); HEFS_INDEX_NODE_DIRECTORY* dir = - (HEFS_INDEX_NODE_DIRECTORY*) mm_new_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); + (HEFS_INDEX_NODE_DIRECTORY*) mm_alloc_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); while (YES) { if (err_global_get() == kErrorDiskIsCorrupted) { @@ -543,7 +543,7 @@ namespace Detail { if (mnt) { HEFS_INDEX_NODE_DIRECTORY* dir = - (HEFS_INDEX_NODE_DIRECTORY*) mm_new_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); + (HEFS_INDEX_NODE_DIRECTORY*) mm_alloc_ptr(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); auto hash_file = node->fHashPath; @@ -596,7 +596,7 @@ namespace Detail { mnt->fOutput(mnt->fPacket); - mm_delete_ptr(dir); + mm_free_ptr(dir); return YES; } else if (dir->fINSlices[inode_index] != 0 && delete_or_create) { @@ -646,7 +646,7 @@ namespace Detail { mnt->fOutput(mnt->fPacket); - mm_delete_ptr(dir); + mm_free_ptr(dir); return YES; } @@ -657,7 +657,7 @@ namespace Detail { if (start > boot->fEndIND || start == 0) break; } - mm_delete_ptr(dir); + mm_free_ptr(dir); err_global_get() = kErrorFileNotFound; return NO; } @@ -902,7 +902,7 @@ _Output Bool HeFileSystemParser::INodeDirectoryCtlManip(_Input DriveTrait* mnt, return NO; } - HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) mm_new_ptr(sizeof(HEFS_BOOT_NODE), Yes, No); + HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) mm_alloc_ptr(sizeof(HEFS_BOOT_NODE), Yes, No); rt_copy_memory((VoidPtr) "fs/hefs-packet", mnt->fPacket.fPacketMime, rt_string_len("fs/hefs-packet")); @@ -938,11 +938,11 @@ _Output Bool HeFileSystemParser::INodeDirectoryCtlManip(_Input DriveTrait* mnt, // todo: make it smarter for high-throughput. Detail::hefsi_balance_ind(boot, mnt); - mm_delete_ptr((VoidPtr) boot); + mm_free_ptr((VoidPtr) boot); return YES; } - mm_delete_ptr((VoidPtr) boot); + mm_free_ptr((VoidPtr) boot); return NO; } @@ -983,7 +983,7 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc return NO; } - HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) mm_new_ptr(sizeof(HEFS_BOOT_NODE), Yes, No); + HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) mm_alloc_ptr(sizeof(HEFS_BOOT_NODE), Yes, No); if (!boot) { err_global_get() = kErrorInvalidData; @@ -1001,7 +1001,7 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc if (!KStringBuilder::Equals(boot->fMagic, kHeFSMagic) || boot->fVersion != kHeFSVersion) { (Void)(kout << "Invalid Boot Node, HeFS partition is invalid." << kendl); - mm_delete_ptr((VoidPtr) boot); + mm_free_ptr((VoidPtr) boot); err_global_get() = kErrorDisk; return NO; } @@ -1021,7 +1021,7 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc mnt->fInput(mnt->fPacket); } else { if (start->fFlags & kHeFSFlagsReadOnly) { - mm_delete_ptr((VoidPtr) boot); + mm_free_ptr((VoidPtr) boot); delete start; kout << "Error: File is read-only\r"; @@ -1034,7 +1034,7 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc } } - mm_delete_ptr((VoidPtr) boot); + mm_free_ptr((VoidPtr) boot); delete start; return YES; } @@ -1058,7 +1058,7 @@ _Output Bool HeFileSystemParser::INodeCtlManip(_Input DriveTrait* mnt, _Input co return NO; } - HEFS_INDEX_NODE* node = (HEFS_INDEX_NODE*) mm_new_ptr(sizeof(HEFS_INDEX_NODE), Yes, No); + HEFS_INDEX_NODE* node = (HEFS_INDEX_NODE*) mm_alloc_ptr(sizeof(HEFS_INDEX_NODE), Yes, No); if (!node) { err_global_get() = kErrorInvalidData; @@ -1070,7 +1070,7 @@ _Output Bool HeFileSystemParser::INodeCtlManip(_Input DriveTrait* mnt, _Input co HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) RTL_ALLOCA(sizeof(HEFS_BOOT_NODE)); if (!boot) { - mm_delete_ptr((VoidPtr) node); + mm_free_ptr((VoidPtr) node); err_global_get() = kErrorInvalidData; return NO; @@ -1124,7 +1124,7 @@ _Output Bool HeFileSystemParser::INodeCtlManip(_Input DriveTrait* mnt, _Input co node->fHashPath = Detail::hefsi_hash_64(name); if (Detail::hefsi_update_in_status(boot, mnt, dir, node, delete_or_create)) { - mm_delete_ptr((VoidPtr) node); + mm_free_ptr((VoidPtr) node); Detail::hefsi_balance_ind(boot, mnt); @@ -1132,7 +1132,7 @@ _Output Bool HeFileSystemParser::INodeCtlManip(_Input DriveTrait* mnt, _Input co return YES; } - mm_delete_ptr((VoidPtr) node); + mm_free_ptr((VoidPtr) node); err_global_get() = kErrorDirectoryNotFound; return NO; diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index bd6a1aee..f1746a58 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -240,7 +240,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char return nullptr; } - Char* parent_name = (Char*) mm_new_ptr(sizeof(Char) * rt_string_len(name), Yes, No); + Char* parent_name = (Char*) mm_alloc_ptr(sizeof(Char) * rt_string_len(name), Yes, No); /// Locate parent catalog, to then allocate right after it. @@ -269,7 +269,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char NEFS_CATALOG_STRUCT* catalog = this->FindCatalog(parent_name, out_lba); - mm_delete_ptr(parent_name); + mm_free_ptr(parent_name); auto& drive = kMountpoint.A(); diff --git a/dev/kernel/src/HeapMgr.cc b/dev/kernel/src/HeapMgr.cc index 6cd8fb24..5280bcc3 100644 --- a/dev/kernel/src/HeapMgr.cc +++ b/dev/kernel/src/HeapMgr.cc @@ -98,7 +98,7 @@ STATIC PageMgr kPageMgr; /// @param wr Read Write bit. /// @param user User enable bit. /// @return The newly allocated pointer. -_Output VoidPtr mm_new_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { +_Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { auto sz_fix = sz; if (sz_fix == 0) return nullptr; @@ -184,7 +184,7 @@ _Output UInt64 mm_get_ptr_flags(VoidPtr heap_ptr) { /// @brief Declare pointer as free. /// @param heap_ptr the pointer. /// @return -_Output Int32 mm_delete_ptr(VoidPtr heap_ptr) { +_Output Int32 mm_free_ptr(VoidPtr heap_ptr) { if (Detail::mm_check_ptr_address(heap_ptr) == No) return kErrorHeapNotPresent; Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = diff --git a/dev/kernel/src/New+Delete.cc b/dev/kernel/src/New+Delete.cc index 29bbfbbf..da705f26 100644 --- a/dev/kernel/src/New+Delete.cc +++ b/dev/kernel/src/New+Delete.cc @@ -10,25 +10,25 @@ void* operator new[](size_t sz) { if (sz == 0) ++sz; - return Kernel::mm_new_ptr(sz, true, false); + return Kernel::mm_alloc_ptr(sz, true, false); } void* operator new(size_t sz) { if (sz == 0) ++sz; - return Kernel::mm_new_ptr(sz, true, false); + return Kernel::mm_alloc_ptr(sz, true, false); } void operator delete[](void* ptr) { if (ptr == nullptr) return; - Kernel::mm_delete_ptr(ptr); + Kernel::mm_free_ptr(ptr); } void operator delete(void* ptr) { if (ptr == nullptr) return; - Kernel::mm_delete_ptr(ptr); + Kernel::mm_free_ptr(ptr); } void operator delete(void* ptr, size_t sz) { @@ -36,7 +36,7 @@ void operator delete(void* ptr, size_t sz) { NE_UNUSED(sz); - Kernel::mm_delete_ptr(ptr); + Kernel::mm_free_ptr(ptr); } void operator delete[](void* ptr, size_t sz) { @@ -44,5 +44,5 @@ void operator delete[](void* ptr, size_t sz) { NE_UNUSED(sz); - Kernel::mm_delete_ptr(ptr); + Kernel::mm_free_ptr(ptr); } diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index 9ea9b5b1..e810651a 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -78,7 +78,7 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) fBad = true; - if (fCachedBlob) mm_delete_ptr(fCachedBlob); + if (fCachedBlob) mm_free_ptr(fCachedBlob); kout << "PEFLoader: Warning: Executable format error!\r"; @@ -89,7 +89,7 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) /// @brief PEF destructor. /***********************************************************************************/ PEFLoader::~PEFLoader() { - if (fCachedBlob) mm_delete_ptr(fCachedBlob); + if (fCachedBlob) mm_free_ptr(fCachedBlob); fFile.Delete(); } @@ -147,7 +147,7 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { if (container_header->Kind == kind) { if (container_header->Cpu != Detail::ldr_get_platform()) { if (!this->fFatBinary) { - mm_delete_ptr(blob); + mm_free_ptr(blob); return ErrorOr{kErrorInvalidData}; } } @@ -156,7 +156,7 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { rt_copy_memory((VoidPtr) ((Char*) blob + sizeof(PEFCommandHeader)), container_blob_value, container_header->Size); - mm_delete_ptr(blob); + mm_free_ptr(blob); kout << "PEFLoader: Information: Loaded stub: " << container_header->Name << "!\r"; @@ -165,7 +165,7 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { HAL::kMMFlagsPresent | HAL::kMMFlagsUser); if (ret != kErrorSuccess) { - mm_delete_ptr(container_blob_value); + mm_free_ptr(container_blob_value); return ErrorOr{kErrorInvalidData}; } @@ -174,7 +174,7 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { } } - mm_delete_ptr(blob); + mm_free_ptr(blob); return ErrorOr{kErrorInvalidData}; } @@ -236,7 +236,7 @@ namespace Utils { UserProcessScheduler::The().Spawn(reinterpret_cast(symname.Leak().Leak()), errOrStart.Leak().Leak(), exec.GetBlob().Leak().Leak()); - mm_delete_ptr(symname.Leak().Leak()); + mm_free_ptr(symname.Leak().Leak()); if (id != kSchedInvalidPID) { auto stacksym = exec.FindSymbol(kPefStackSizeSymbol, kPefData); @@ -253,7 +253,7 @@ namespace Utils { UserProcessScheduler::The().TheCurrentTeam().AsArray()[id].StackSize = *(UIntPtr*) stacksym.Leak().Leak(); - mm_delete_ptr(stacksym.Leak().Leak()); + mm_free_ptr(stacksym.Leak().Leak()); } return id; diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 3251e0dc..5996adca 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -129,11 +129,11 @@ ErrorOr USER_PROCESS::New(SizeT sz, SizeT pad_amount) { auto vm_register = kKernelVM; hal_write_cr3(this->VMRegister); - auto ptr = mm_new_ptr(sz, Yes, Yes, pad_amount); + auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); hal_write_cr3(vm_register); #else - auto ptr = mm_new_ptr(sz, Yes, Yes, pad_amount); + auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); #endif if (!this->HeapTree) { @@ -241,12 +241,12 @@ STATIC Void sched_free_ptr_tree(PROCESS_HEAP_TREE* memory_ptr_list) { // Deleting memory lists. Make sure to free all of them. while (memory_ptr_list) { if (memory_ptr_list->Entry) { - MUST_PASS(mm_delete_ptr(memory_ptr_list->Entry)); + MUST_PASS(mm_free_ptr(memory_ptr_list->Entry)); } auto next = memory_ptr_list->Next; - mm_delete_ptr(memory_ptr_list); + mm_free_ptr(memory_ptr_list); if (memory_ptr_list->Child) sched_free_ptr_tree(memory_ptr_list->Child); @@ -288,14 +288,14 @@ Void USER_PROCESS::Exit(const Int32& exit_code) { #endif //! Delete image if not done already. - if (this->Image.fCode && mm_is_valid_ptr(this->Image.fCode)) mm_delete_ptr(this->Image.fCode); + if (this->Image.fCode && mm_is_valid_ptr(this->Image.fCode)) mm_free_ptr(this->Image.fCode); //! Delete blob too. - if (this->Image.fBlob && mm_is_valid_ptr(this->Image.fBlob)) mm_delete_ptr(this->Image.fBlob); + if (this->Image.fBlob && mm_is_valid_ptr(this->Image.fBlob)) mm_free_ptr(this->Image.fBlob); //! Delete stack frame. if (this->StackFrame && mm_is_valid_ptr(this->StackFrame)) - mm_delete_ptr((VoidPtr) this->StackFrame); + mm_free_ptr((VoidPtr) this->StackFrame); //! Avoid use after free. this->Image.fBlob = nullptr; -- cgit v1.2.3 From 5b30cacacf0f0ca6fb06bb34389f04b05ceb2b15 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 25 May 2025 09:56:46 +0200 Subject: kernel!: lots of changes, see commit details. refactor(hal): unify file naming and drop redundant architecture suffixes feat(build): rename kernel and bootloader to 'ne_kernel' and 'ne_bootz' refactor(memory): replace mm_get_phys_address with mm_get_page_addr feat(bitmap): track bitmap allocator usage and add out-of-memory error fix(heap): correct heap magic naming and alignment logic chore(fs): downgrade HeFS disk size check to warning chore(tools): clean up formatting in 'ping' and 'manual' docs(design): update OS_DESIGN.drawio to reflect Hypr86 and new layout Signed-off-by: Amlal El Mahrouss --- .gitignore | 3 + dev/boot/BootKit/Support.h | 4 +- dev/boot/amd64-ci.make | 6 +- dev/boot/amd64-desktop.make | 6 +- dev/boot/arm64-desktop.make | 6 +- dev/boot/src/BootloaderRsrc.rsrc | 2 +- dev/boot/src/HEL/AMD64/BootEFI.cc | 4 +- dev/boot/src/HEL/ARM64/BootEFI.cc | 2 +- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 1 + dev/kernel/HALKit/AMD64/HalControlRegister.s | 45 ------ dev/kernel/HALKit/AMD64/HalControlRegisterAPI.s | 45 ++++++ dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc | 159 ++++++++++++++++++++ .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 159 -------------------- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 10 +- dev/kernel/HALKit/AMD64/HalPagingMgr.cc | 164 +++++++++++++++++++++ dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc | 164 --------------------- dev/kernel/HALKit/AMD64/HalProcessor.cc | 89 +++++++++++ dev/kernel/HALKit/AMD64/HalProcessorAMD64.cc | 80 ---------- .../HALKit/AMD64/HalSchedulerCorePrimitives.cc | 47 ++++++ .../AMD64/HalSchedulerCorePrimitivesAMD64.cc | 47 ------ dev/kernel/HALKit/AMD64/HalTimer.cc | 97 ++++++++++++ dev/kernel/HALKit/AMD64/HalTimerAMD64.cc | 97 ------------ dev/kernel/HALKit/AMD64/HalUtilsAPI.asm | 2 - .../HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 2 +- dev/kernel/HALKit/AMD64/Processor.h | 13 +- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 4 +- dev/kernel/HALKit/ARM64/HalPagingMgr.cc | 28 ++++ dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc | 28 ---- dev/kernel/HALKit/ARM64/HalSchedulerCore.cc | 21 +++ dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc | 21 --- .../HALKit/ARM64/HalSchedulerCorePrimitives.cc | 30 ++++ .../ARM64/HalSchedulerCorePrimitivesARM64.cc | 30 ---- dev/kernel/HALKit/ARM64/HalTimer.cc | 15 ++ dev/kernel/HALKit/ARM64/HalTimerARM64.cc | 15 -- dev/kernel/HALKit/ARM64/Processor.h | 2 +- dev/kernel/KernelKit/KPC.h | 3 +- dev/kernel/KernelKit/LockDelegate.h | 4 +- dev/kernel/KernelKit/ZXD.h | 24 +-- dev/kernel/amd64-ci.make | 2 +- dev/kernel/amd64-desktop.make | 2 +- dev/kernel/arm64-desktop.make | 2 +- dev/kernel/kernel_rsrc.rsrc | 2 +- dev/kernel/src/BitMapMgr.cc | 18 ++- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 5 +- dev/kernel/src/HeapMgr.cc | 16 +- dev/kernel/src/PEFCodeMgr.cc | 2 +- dev/kernel/src/UserProcessScheduler.cc | 4 +- docs/drawio/OS_DESIGN.drawio | 30 ++-- public/tools/manual/src/CommandLine.cc | 4 +- public/tools/ping/src/CommandLine.cc | 8 +- 50 files changed, 798 insertions(+), 776 deletions(-) delete mode 100644 dev/kernel/HALKit/AMD64/HalControlRegister.s create mode 100644 dev/kernel/HALKit/AMD64/HalControlRegisterAPI.s create mode 100644 dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc delete mode 100644 dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc create mode 100644 dev/kernel/HALKit/AMD64/HalPagingMgr.cc delete mode 100644 dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc create mode 100644 dev/kernel/HALKit/AMD64/HalProcessor.cc delete mode 100644 dev/kernel/HALKit/AMD64/HalProcessorAMD64.cc create mode 100644 dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc delete mode 100644 dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc create mode 100644 dev/kernel/HALKit/AMD64/HalTimer.cc delete mode 100644 dev/kernel/HALKit/AMD64/HalTimerAMD64.cc create mode 100644 dev/kernel/HALKit/ARM64/HalPagingMgr.cc delete mode 100644 dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc create mode 100644 dev/kernel/HALKit/ARM64/HalSchedulerCore.cc delete mode 100644 dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc create mode 100644 dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc delete mode 100644 dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc create mode 100644 dev/kernel/HALKit/ARM64/HalTimer.cc delete mode 100644 dev/kernel/HALKit/ARM64/HalTimerARM64.cc (limited to 'dev/kernel/src/HeapMgr.cc') diff --git a/.gitignore b/.gitignore index 01c18138..9722f662 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ public/frameworks/*/dist/* *.pdf *.aux +ne_kernel +ne_bootz + neoskrnl/neoskrnl.xcodeproj/project.xcworkspace/xcshareddata/ tooling/dist/mkfs.* diff --git a/dev/boot/BootKit/Support.h b/dev/boot/BootKit/Support.h index 6e1407c2..b4129abc 100644 --- a/dev/boot/BootKit/Support.h +++ b/dev/boot/BootKit/Support.h @@ -9,7 +9,7 @@ /// @file Support.h /// @brief Purpose of this file is to help port libs into the bootloader. -#ifndef __aarch64__ +#ifndef __NE_ARM64__ #include #endif @@ -38,7 +38,9 @@ EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight); #else +#ifndef __NE_ARM64__ #include +#endif #endif // __BOOTZ__ diff --git a/dev/boot/amd64-ci.make b/dev/boot/amd64-ci.make index d711abde..0715151c 100644 --- a/dev/boot/amd64-ci.make +++ b/dev/boot/amd64-ci.make @@ -69,8 +69,8 @@ FLAG_GNU=-fshort-wchar -Wall -Wpedantic -Wextra -Werror -D__EFI_x86_64__ -mno-re -DEFI_FUNCTION_WRAPPER -I./ -I../kernel $(DEBUG_MACRO) $(DISK_DRV) -I../ -c -nostdlib -fno-rtti -fno-exceptions \ -std=c++20 -DBOOTZ_GPT_SUPPORT -DBOOTZ_EPM_SUPPORT -D__HAVE_NE_APIS__ -DZBA_USE_FB -D__NE_AMD64__ -D__NE__ -DNE_AUTO_FORMAT -BOOTLOADER=bootz.efi -KERNEL=krnl.efi +BOOTLOADER=ne_bootz +KERNEL=ne_kernel SYSCHK=chk.efi BOOTNET=net.efi SCIKIT=libSystem.sys @@ -130,7 +130,7 @@ efi: $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd BINS=*.bin -EXECUTABLES=bootz.efi krnl.efi OVMF.fd +EXECUTABLES=ne_bootz ne_kernel OVMF.fd TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 05ac5db8..113c6295 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -71,8 +71,8 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -Wall -Wpedantic -Wextra -mno-red-zone - -DEFI_FUNCTION_WRAPPER -I./ -I../kernel $(DISK_DRV) -I../ -c -nostdlib -fno-rtti -fno-exceptions \ -std=c++20 -DBOOTZ_GPT_SUPPORT -D__HAVE_NE_APIS__ -DZBA_USE_FB -D__NE_AMD64__ -D__NE__ -DNE_AUTO_FORMAT -Wl,--disable-reloc-section -BOOTLOADER=bootz.efi -KERNEL=krnl.efi +BOOTLOADER=ne_bootz +KERNEL=ne_kernel SYSCHK=chk.efi BOOTNET=net.efi SCIKIT=libSystem.sys @@ -140,7 +140,7 @@ efi: $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd BINS=*.bin -EXECUTABLES=bootz.efi krnl.efi OVMF.fd +EXECUTABLES=ne_bootz ne_kernel OVMF.fd TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) diff --git a/dev/boot/arm64-desktop.make b/dev/boot/arm64-desktop.make index 114d2e7e..409975a4 100644 --- a/dev/boot/arm64-desktop.make +++ b/dev/boot/arm64-desktop.make @@ -47,8 +47,8 @@ FLAG_GNU=-fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__NE_ARM64__ -fno- -target aarch64-unknown-windows \ -std=c++20 -DBOOTZ_EPM_SUPPORT -DZBA_USE_FB -D__FSKIT_USE_NEFS__ -D__BOOTZ_STANDALONE__ -D__NEOSKRNL__ -D__BOOTZ__ -D__HAVE_NE_APIS__ -D__NE__ -I../ -I../kernel -BOOT_LOADER=bootz.efi -KERNEL=krnl.efi +BOOT_LOADER=ne_bootz +KERNEL=ne_kernel SYSCHK=chk.efi STARTUP=startup.efi @@ -94,7 +94,7 @@ efi: $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGAARCH64_QEMU_EFI.fd -O OVMF.fd BINS=*.bin -EXECUTABLES=bootz.efi krnl.efi OVMF.fd +EXECUTABLES=ne_bootz ne_kernel OVMF.fd TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) diff --git a/dev/boot/src/BootloaderRsrc.rsrc b/dev/boot/src/BootloaderRsrc.rsrc index c634a8f6..33bce7f7 100644 --- a/dev/boot/src/BootloaderRsrc.rsrc +++ b/dev/boot/src/BootloaderRsrc.rsrc @@ -13,7 +13,7 @@ BEGIN VALUE "FileVersion", BOOTLOADER_VERSION VALUE "InternalName", "bootz" VALUE "LegalCopyright", "Copyright (C) 2024, Amlal El Mahrouss all rights reserved." - VALUE "OriginalFilename", "bootz.efi" + VALUE "OriginalFilename", "ne_bootz" VALUE "ProductName", "bootz" VALUE "ProductVersion", BOOTLOADER_VERSION END diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 58610c39..e1dd5d9e 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -193,8 +193,8 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); // Assign to global 'kHandoverHeader'. - WideChar kernel_path[256U] = L"krnl.efi"; - UInt32 kernel_path_sz = StrLen("krnl.efi"); + WideChar kernel_path[256U] = L"ne_kernel"; + UInt32 kernel_path_sz = StrLen("ne_kernel"); UInt32 sz_ver = sizeof(UInt64); UInt64 ver = KERNEL_VERSION_BCD; diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index be2d8acd..413edd5b 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -210,7 +210,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); - Boot::BootFileReader reader_kernel(L"krnl.efi", image_handle); + Boot::BootFileReader reader_kernel(L"ne_kernel", image_handle); reader_kernel.ReadAll(0); diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 7926289f..2ce05e7c 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -128,6 +128,7 @@ EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ProcessID thrdid) /// @brief Is the current config SMP aware? /// @return True if YES, False if not. /***********************************************************************************/ + Bool mp_is_smp(Void) noexcept { return kSMPAware; } diff --git a/dev/kernel/HALKit/AMD64/HalControlRegister.s b/dev/kernel/HALKit/AMD64/HalControlRegister.s deleted file mode 100644 index 631d1d55..00000000 --- a/dev/kernel/HALKit/AMD64/HalControlRegister.s +++ /dev/null @@ -1,45 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -.globl hal_write_cr3 -.globl hal_write_cr0 -.globl hal_read_cr2 -.globl hal_read_cr3 -.globl hal_read_cr0 -.globl hal_flush_tlb -.globl hal_invl_tlb - -.text - -hal_invl_tlb: - invlpg (%rcx) - retq - -hal_flush_tlb: - call hal_read_cr3 - mov %rax, %rcx - call hal_write_cr3 - retq - -hal_read_cr3: - movq %cr3, %rax - retq - -hal_read_cr0: - movq %cr0, %rax - retq - -hal_read_cr2: - movq %cr2, %rax - retq - -hal_write_cr3: - movq %rcx, %cr3 - retq - -hal_write_cr0: - movq %rcx, %cr0 - retq diff --git a/dev/kernel/HALKit/AMD64/HalControlRegisterAPI.s b/dev/kernel/HALKit/AMD64/HalControlRegisterAPI.s new file mode 100644 index 00000000..631d1d55 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalControlRegisterAPI.s @@ -0,0 +1,45 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +.globl hal_write_cr3 +.globl hal_write_cr0 +.globl hal_read_cr2 +.globl hal_read_cr3 +.globl hal_read_cr0 +.globl hal_flush_tlb +.globl hal_invl_tlb + +.text + +hal_invl_tlb: + invlpg (%rcx) + retq + +hal_flush_tlb: + call hal_read_cr3 + mov %rax, %rcx + call hal_write_cr3 + retq + +hal_read_cr3: + movq %cr3, %rax + retq + +hal_read_cr0: + movq %cr0, %rax + retq + +hal_read_cr2: + movq %cr2, %rax + retq + +hal_write_cr3: + movq %rcx, %cr3 + retq + +hal_write_cr0: + movq %rcx, %cr0 + retq diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc new file mode 100644 index 00000000..01456ae5 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc @@ -0,0 +1,159 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include +#include + +EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip); + +EXTERN_C Kernel::UIntPtr kApicBaseAddress; + +STATIC BOOL kIsRunning = NO; + +/// @brief Notify APIC and PIC that we're done with the interrupt. +/// @note +STATIC void hal_idt_send_eoi(UInt8 vector) { + ((volatile UInt32*) kApicBaseAddress)[0xB0 / 4] = 0; + + if (vector >= kPICCommand && vector <= 0x2F) { + if (vector >= 0x28) { + Kernel::HAL::rt_out8(kPIC2Command, kPICCommand); + } + Kernel::HAL::rt_out8(kPICCommand, kPICCommand); + } +} + +/// @brief Handle GPF fault. +/// @param rsp +EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp) { + auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); + + hal_idt_send_eoi(13); + + process.Leak().Signal.SignalArg = rsp; + process.Leak().Signal.SignalID = SIGKILL; + process.Leak().Signal.Status = process.Leak().Status; +} + +/// @brief Handle page fault. +/// @param rsp +EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { + auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); + + hal_idt_send_eoi(14); + + process.Leak().Signal.SignalArg = rsp; + process.Leak().Signal.SignalID = SIGKILL; + process.Leak().Signal.Status = process.Leak().Status; +} + +/// @brief Handle scheduler interrupt. +EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { + NE_UNUSED(rsp); + + hal_idt_send_eoi(32); + + while (kIsRunning) + ; + + kIsRunning = YES; + + Kernel::UserProcessHelper::StartScheduling(); + + kIsRunning = NO; +} + +/// @brief Handle math fault. +/// @param rsp +EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { + auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); + + hal_idt_send_eoi(8); + + process.Leak().Signal.SignalArg = rsp; + process.Leak().Signal.SignalID = SIGKILL; + process.Leak().Signal.Status = process.Leak().Status; +} + +/// @brief Handle any generic fault. +/// @param rsp +EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { + auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); + + hal_idt_send_eoi(30); + + Kernel::kout << "Kernel: Generic Process Fault.\r"; + + process.Leak().Signal.SignalArg = rsp; + process.Leak().Signal.SignalID = SIGKILL; + process.Leak().Signal.Status = process.Leak().Status; + + Kernel::kout << "Kernel: SIGKILL status.\r"; +} + +EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) { + auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + + hal_idt_send_eoi(3); + + process.Leak().Signal.SignalArg = rip; + process.Leak().Signal.SignalID = SIGTRAP; + + process.Leak().Signal.Status = process.Leak().Status; + + process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; +} + +/// @brief Handle #UD fault. +/// @param rsp +EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { + auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); + + hal_idt_send_eoi(6); + + process.Leak().Signal.SignalArg = rsp; + process.Leak().Signal.SignalID = SIGKILL; + process.Leak().Signal.Status = process.Leak().Status; +} + +/// @brief Enter syscall from assembly. +/// @param stack the stack pushed from assembly routine. +/// @return nothing. +EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx_syscall_index, + Kernel::UIntPtr rdx_syscall_struct) { + hal_idt_send_eoi(50); + + if (rcx_syscall_index < kSysCalls.Count()) { + if (kSysCalls[rcx_syscall_index].fHooked) { + if (kSysCalls[rcx_syscall_index].fProc) { + (kSysCalls[rcx_syscall_index].fProc)((Kernel::VoidPtr) rdx_syscall_struct); + } + } + } +} + +/// @brief Enter Kernel call from assembly (DDK only). +/// @param stack the stack pushed from assembly routine. +/// @return nothing. +EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, + Kernel::UIntPtr rdx_kerncall_struct) { + hal_idt_send_eoi(51); + + if (rcx_kerncall_index < kKernCalls.Count()) { + if (kKernCalls[rcx_kerncall_index].fHooked) { + if (kKernCalls[rcx_kerncall_index].fProc) { + (kKernCalls[rcx_kerncall_index].fProc)((Kernel::VoidPtr) rdx_kerncall_struct); + } + } + } +} diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc deleted file mode 100644 index b70cd51f..00000000 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ /dev/null @@ -1,159 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include -#include -#include - -EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip); - -EXTERN_C Kernel::UIntPtr kApicBaseAddress; - -STATIC BOOL kIsRunning = NO; - -/// @brief Notify APIC and PIC that we're done with the interrupt. -/// @note -STATIC void hal_idt_send_eoi(UInt8 vector) { - ((volatile UInt32*) kApicBaseAddress)[0xB0 / 4] = 0; - - if (vector >= kPICCommand && vector <= 0x2F) { - if (vector >= 0x28) { - Kernel::HAL::rt_out8(kPIC2Command, kPICCommand); - } - Kernel::HAL::rt_out8(kPICCommand, kPICCommand); - } -} - -/// @brief Handle GPF fault. -/// @param rsp -EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp) { - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - process.Leak().Crash(); - - hal_idt_send_eoi(13); - - process.Leak().Signal.SignalArg = rsp; - process.Leak().Signal.SignalID = SIGKILL; - process.Leak().Signal.Status = process.Leak().Status; -} - -/// @brief Handle page fault. -/// @param rsp -EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - process.Leak().Crash(); - - hal_idt_send_eoi(14); - - process.Leak().Signal.SignalArg = rsp; - process.Leak().Signal.SignalID = SIGKILL; - process.Leak().Signal.Status = process.Leak().Status; -} - -/// @brief Handle scheduler interrupt. -EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { - NE_UNUSED(rsp); - - hal_idt_send_eoi(32); - - while (kIsRunning) - ; - - kIsRunning = YES; - - Kernel::UserProcessHelper::StartScheduling(); - - kIsRunning = NO; -} - -/// @brief Handle math fault. -/// @param rsp -EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - process.Leak().Crash(); - - hal_idt_send_eoi(8); - - process.Leak().Signal.SignalArg = rsp; - process.Leak().Signal.SignalID = SIGKILL; - process.Leak().Signal.Status = process.Leak().Status; -} - -/// @brief Handle any generic fault. -/// @param rsp -EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - process.Leak().Crash(); - - hal_idt_send_eoi(30); - - Kernel::kout << "Kernel: Generic Process Fault.\r"; - - process.Leak().Signal.SignalArg = rsp; - process.Leak().Signal.SignalID = SIGKILL; - process.Leak().Signal.Status = process.Leak().Status; - - Kernel::kout << "Kernel: SIGKILL status.\r"; -} - -EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) { - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - - hal_idt_send_eoi(3); - - process.Leak().Signal.SignalArg = rip; - process.Leak().Signal.SignalID = SIGTRAP; - - process.Leak().Signal.Status = process.Leak().Status; - - process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; -} - -/// @brief Handle #UD fault. -/// @param rsp -EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - process.Leak().Crash(); - - hal_idt_send_eoi(6); - - process.Leak().Signal.SignalArg = rsp; - process.Leak().Signal.SignalID = SIGKILL; - process.Leak().Signal.Status = process.Leak().Status; -} - -/// @brief Enter syscall from assembly. -/// @param stack the stack pushed from assembly routine. -/// @return nothing. -EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx_syscall_index, - Kernel::UIntPtr rdx_syscall_struct) { - hal_idt_send_eoi(50); - - if (rcx_syscall_index < kSysCalls.Count()) { - if (kSysCalls[rcx_syscall_index].fHooked) { - if (kSysCalls[rcx_syscall_index].fProc) { - (kSysCalls[rcx_syscall_index].fProc)((Kernel::VoidPtr) rdx_syscall_struct); - } - } - } -} - -/// @brief Enter Kernel call from assembly (DDK only). -/// @param stack the stack pushed from assembly routine. -/// @return nothing. -EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, - Kernel::UIntPtr rdx_kerncall_struct) { - hal_idt_send_eoi(51); - - if (rcx_kerncall_index < kKernCalls.Count()) { - if (kKernCalls[rcx_kerncall_index].fHooked) { - if (kKernCalls[rcx_kerncall_index].fProc) { - (kKernCalls[rcx_kerncall_index].fProc)((Kernel::VoidPtr) rdx_kerncall_struct); - } - } - } -} diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index c1558892..edbe058a 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -146,17 +146,19 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); #ifdef __FSKIT_INCLUDES_HEFS__ - if (HeFS::fs_init_hefs()) { - goto hal_spin_kernel; + if (!HeFS::fs_init_hefs()) { + kout << "HeFS cannot be formated on disk. Aborting\r"; + DBG_TRAP(); } #endif +#ifdef __FSKIT_INCLUDES_NEFS__ if (!NeFS::fs_init_nefs()) { - kout << "NeFS cannot be formated on the disk. Aborting\r"; + kout << "NeFS cannot be formated on disk. Aborting\r"; DBG_TRAP(); } +#endif -hal_spin_kernel: HAL::Register64 idt_reg; idt_reg.Base = reinterpret_cast(kInterruptVectorTable); diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgr.cc b/dev/kernel/HALKit/AMD64/HalPagingMgr.cc new file mode 100644 index 00000000..048cb7c2 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalPagingMgr.cc @@ -0,0 +1,164 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + + File: HalPagingMgr.cc + Purpose: Platform Paging Manager. + +------------------------------------------- */ + +#include +#include + +namespace Kernel::HAL { +namespace Detail { + /// @brief Page Table Entry for AMD64. + struct PTE { + UInt64 Present : 1; + UInt64 Wr : 1; + UInt64 User : 1; + UInt64 Pwt : 1; // Page-level Write-Through + UInt64 Pcd : 1; // Page-level Cache Disable + UInt64 Accessed : 1; + UInt64 Dirty : 1; + UInt64 Pat : 1; // Page Attribute Table (or PS for PDE) + UInt64 Global : 1; + UInt64 Ignored1 : 3; // Available to software + UInt64 PhysicalAddress : 40; // Physical page frame address (bits 12–51) + UInt64 Ignored2 : 7; // More software bits / reserved + UInt64 ProtectionKey : 4; // Optional (if PKU enabled) + UInt64 Reserved : 1; // Usually reserved + UInt64 Nx : 1; // No Execute + }; +} // namespace Detail + +/***********************************************************************************/ +/// \brief Retrieve the page status of a PTE. +/// \param pte Page Table Entry pointer. +/***********************************************************************************/ +STATIC Void mmi_page_status(Detail::PTE* pte) { + NE_UNUSED(pte); + +#ifdef __NE_VERBOSE_BITMAP__ + (Void)(kout << "Flag: " << (pte->Present ? "Present" : "Not Present") << kendl); + (Void)(kout << "Flag: " << (pte->Wr ? "W/R" : "Not W/R") << kendl); + (Void)(kout << "Flag: " << (pte->Nx ? "NX" : "Not NX") << kendl); + (Void)(kout << "Flag: " << pte->User ? "User" : "Not User") << kendl); + (Void)(kout << "Flag: " << (pte->Pcd ? "Not Cached" : "Cached") << kendl); + (Void)(kout << "Flag: " << (pte->Accessed ? "Accessed" : "Not Accessed") << kendl); + (Void)(kout << "Flag: " << (pte->ProtectionKey ? "Protected" : "Not Protected/PKU Disabled") + << kendl); + (Void)(kout << "Physical Address: " << hex_number(pte->PhysicalAddress) << kendl); +#endif +} + +/***********************************************************************************/ +/// @brief Gets a physical address from a virtual address. +/// @param virt a valid virtual address. +/// @return Physical address. +/***********************************************************************************/ +EXTERN_C UIntPtr mm_get_page_addr(VoidPtr virt) { + const UInt64 kVMAddr = (UInt64) virt; + const UInt64 kMask9Bits = 0x1FFULL; + const UInt64 kPageOffsetMask = 0xFFFULL; + + UInt64 cr3 = (UInt64) hal_read_cr3() & ~kPageOffsetMask; + + // Level 4 + auto pml4 = reinterpret_cast(cr3); + UInt64 pml4e = pml4[(kVMAddr >> 39) & kMask9Bits]; + + if (!(pml4e & 1)) return 0; + + // Level 3 + auto pdpt = reinterpret_cast(pml4e & ~kPageOffsetMask); + UInt64 pdpte = pdpt[(kVMAddr >> 30) & kMask9Bits]; + + if (!(pdpte & 1)) return 0; + + // Level 2 + auto pd = reinterpret_cast(pdpte & ~kPageOffsetMask); + UInt64 pde = pd[(kVMAddr >> 21) & kMask9Bits]; + + if (!(pde & 1)) return 0; + + // 1 GiB page support + if (pde & (1 << 7)) { + return (pde & ~((1ULL << 30) - 1)) | (kVMAddr & ((1ULL << 30) - 1)); + } + + // Level 1 + auto pt = reinterpret_cast(pde & ~kPageOffsetMask); + Detail::PTE* pte = (Detail::PTE*) pt[(kVMAddr >> 12) & kMask9Bits]; + + if (!pte->Present) return 0; + + mmi_page_status((Detail::PTE*) pte); + + return (pte->PhysicalAddress << 12) | (kVMAddr & 0xFFF); +} + +/***********************************************************************************/ +/// @brief clflush+mfence helper function. +/***********************************************************************************/ +EXTERN_C Int32 mm_memory_fence(VoidPtr virtual_address) { + if (!virtual_address || !mm_get_page_addr(virtual_address)) return kErrorInvalidData; + + asm volatile("clflush (%0)" : : "r"(virtual_address) : "memory"); + asm volatile("mfence" ::: "memory"); + + return kErrorSuccess; +} + +/***********************************************************************************/ +/// @brief Maps or allocates a page from virtual_address. +/// @param virtual_address a valid virtual address. +/// @param phys_addr point to physical address. +/// @param flags the flags to put on the page. +/// @return Status code of page manipulation process. +/***********************************************************************************/ +EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) { + if (physical_address == 0) return kErrorInvalidData; + + const UInt64 kVMAddr = (UInt64) virtual_address; + constexpr UInt64 kMask9 = 0x1FF; + constexpr UInt64 kPageMask = 0xFFF; + + UInt64 cr3 = (UIntPtr) hal_read_cr3() & ~kPageMask; + + auto pml4 = reinterpret_cast(cr3); + UInt64 pml4e = pml4[(kVMAddr >> 39) & kMask9]; + + if (!(pml4e & 1)) return kErrorInvalidData; + + UInt64* pdpt = reinterpret_cast(pml4e & ~kPageMask); + UInt64 pdpte = pdpt[(kVMAddr >> 30) & kMask9]; + + if (!(pdpte & 1)) return kErrorInvalidData; + + UInt64* pd = reinterpret_cast(pdpte & ~kPageMask); + UInt64 pde = pd[(kVMAddr >> 21) & kMask9]; + + if (!(pde & 1)) return kErrorInvalidData; + + UInt64* pt = reinterpret_cast(pde & ~kPageMask); + Detail::PTE* pte = (Detail::PTE*) pt[(kVMAddr >> 12) & kMask9]; + + pte->Present = !!(flags & kMMFlagsPresent); + pte->Wr = !!(flags & kMMFlagsWr); + pte->User = !!(flags & kMMFlagsUser); + pte->Nx = !!(flags & kMMFlagsNX); + pte->Pcd = !!(flags & kMMFlagsPCD); + pte->Pwt = !!(flags & kMMFlagsPwt); + + pte->PhysicalAddress = ((UIntPtr) (physical_address)) >> 12; + + hal_invl_tlb(virtual_address); + + mm_memory_fence(virtual_address); + + mmi_page_status(pte); + + return kErrorSuccess; +} +} // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc deleted file mode 100644 index 4681b5e5..00000000 --- a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc +++ /dev/null @@ -1,164 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - - File: HalPagingMgr.cc - Purpose: Platform Paging Manager. - -------------------------------------------- */ - -#include -#include - -namespace Kernel::HAL { -namespace Detail { - /// @brief Page Table Entry for AMD64. - struct PTE { - UInt64 Present : 1; - UInt64 Wr : 1; - UInt64 User : 1; - UInt64 Pwt : 1; // Page-level Write-Through - UInt64 Pcd : 1; // Page-level Cache Disable - UInt64 Accessed : 1; - UInt64 Dirty : 1; - UInt64 Pat : 1; // Page Attribute Table (or PS for PDE) - UInt64 Global : 1; - UInt64 Ignored1 : 3; // Available to software - UInt64 PhysicalAddress : 40; // Physical page frame address (bits 12–51) - UInt64 Ignored2 : 7; // More software bits / reserved - UInt64 ProtectionKey : 4; // Optional (if PKU enabled) - UInt64 Reserved : 1; // Usually reserved - UInt64 Nx : 1; // No Execute - }; -} // namespace Detail - -/***********************************************************************************/ -/// \brief Retrieve the page status of a PTE. -/// \param pte Page Table Entry pointer. -/***********************************************************************************/ -STATIC Void mmi_page_status(Detail::PTE* pte) { - NE_UNUSED(pte); - -#ifdef __NE_VERBOSE_BITMAP__ - (Void)(kout << "Flag: " << (pte->Present ? "Present" : "Not Present") << kendl); - (Void)(kout << "Flag: " << (pte->Wr ? "W/R" : "Not W/R") << kendl); - (Void)(kout << "Flag: " << (pte->Nx ? "NX" : "Not NX") << kendl); - (Void)(kout << "Flag: " << pte->User ? "User" : "Not User") << kendl); - (Void)(kout << "Flag: " << (pte->Pcd ? "Not Cached" : "Cached") << kendl); - (Void)(kout << "Flag: " << (pte->Accessed ? "Accessed" : "Not Accessed") << kendl); - (Void)(kout << "Flag: " << (pte->ProtectionKey ? "Protected" : "Not Protected/PKU Disabled") - << kendl); - (Void)(kout << "Physical Address: " << hex_number(pte->PhysicalAddress) << kendl); -#endif -} - -/***********************************************************************************/ -/// @brief Gets a physical address from a virtual address. -/// @param virt a valid virtual address. -/// @return Physical address. -/***********************************************************************************/ -UIntPtr mm_get_phys_address(VoidPtr virt) { - const UInt64 kVMAddr = (UInt64) virt; - const UInt64 kMask9Bits = 0x1FFULL; - const UInt64 kPageOffsetMask = 0xFFFULL; - - UInt64 cr3 = (UInt64) hal_read_cr3() & ~kPageOffsetMask; - - // Level 4 - auto pml4 = reinterpret_cast(cr3); - UInt64 pml4e = pml4[(kVMAddr >> 39) & kMask9Bits]; - - if (!(pml4e & 1)) return 0; - - // Level 3 - auto pdpt = reinterpret_cast(pml4e & ~kPageOffsetMask); - UInt64 pdpte = pdpt[(kVMAddr >> 30) & kMask9Bits]; - - if (!(pdpte & 1)) return 0; - - // Level 2 - auto pd = reinterpret_cast(pdpte & ~kPageOffsetMask); - UInt64 pde = pd[(kVMAddr >> 21) & kMask9Bits]; - - if (!(pde & 1)) return 0; - - // 1 GiB page support - if (pde & (1 << 7)) { - return (pde & ~((1ULL << 30) - 1)) | (kVMAddr & ((1ULL << 30) - 1)); - } - - // Level 1 - auto pt = reinterpret_cast(pde & ~kPageOffsetMask); - Detail::PTE* pte = (Detail::PTE*) pt[(kVMAddr >> 12) & kMask9Bits]; - - if (!pte->Present) return 0; - - mmi_page_status((Detail::PTE*) pte); - - return (pte->PhysicalAddress << 12) | (kVMAddr & 0xFFF); -} - -/***********************************************************************************/ -/// @brief clflush+mfence helper function. -/***********************************************************************************/ -EXTERN_C Int32 mm_memory_fence(VoidPtr virtual_address) { - if (!virtual_address || !mm_get_phys_address(virtual_address)) return kErrorInvalidData; - - asm volatile("clflush (%0)" : : "r"(virtual_address) : "memory"); - asm volatile("mfence" ::: "memory"); - - return kErrorSuccess; -} - -/***********************************************************************************/ -/// @brief Maps or allocates a page from virtual_address. -/// @param virtual_address a valid virtual address. -/// @param phys_addr point to physical address. -/// @param flags the flags to put on the page. -/// @return Status code of page manipulation process. -/***********************************************************************************/ -EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) { - if (physical_address == 0) return kErrorInvalidData; - - const UInt64 kVMAddr = (UInt64) virtual_address; - constexpr UInt64 kMask9 = 0x1FF; - constexpr UInt64 kPageMask = 0xFFF; - - UInt64 cr3 = (UIntPtr) hal_read_cr3() & ~kPageMask; - - auto pml4 = reinterpret_cast(cr3); - UInt64 pml4e = pml4[(kVMAddr >> 39) & kMask9]; - - if (!(pml4e & 1)) return kErrorInvalidData; - - UInt64* pdpt = reinterpret_cast(pml4e & ~kPageMask); - UInt64 pdpte = pdpt[(kVMAddr >> 30) & kMask9]; - - if (!(pdpte & 1)) return kErrorInvalidData; - - UInt64* pd = reinterpret_cast(pdpte & ~kPageMask); - UInt64 pde = pd[(kVMAddr >> 21) & kMask9]; - - if (!(pde & 1)) return kErrorInvalidData; - - UInt64* pt = reinterpret_cast(pde & ~kPageMask); - Detail::PTE* pte = (Detail::PTE*) pt[(kVMAddr >> 12) & kMask9]; - - pte->Present = !!(flags & kMMFlagsPresent); - pte->Wr = !!(flags & kMMFlagsWr); - pte->User = !!(flags & kMMFlagsUser); - pte->Nx = !!(flags & kMMFlagsNX); - pte->Pcd = !!(flags & kMMFlagsPCD); - pte->Pwt = !!(flags & kMMFlagsPwt); - - pte->PhysicalAddress = ((UIntPtr) (physical_address)) >> 12; - - hal_invl_tlb(virtual_address); - - mm_memory_fence(virtual_address); - - mmi_page_status(pte); - - return kErrorSuccess; -} -} // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/HalProcessor.cc b/dev/kernel/HALKit/AMD64/HalProcessor.cc new file mode 100644 index 00000000..6ebbea08 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalProcessor.cc @@ -0,0 +1,89 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + + File: HalCPU.cc + Purpose: Platform processor routines. + +------------------------------------------- */ + +#include +#include + +/** + * @file HalCPU.cc + * @brief Common CPU API. + */ + +namespace Kernel::HAL { +inline Bool hal_has_msr() noexcept { + static UInt32 eax, unused, edx; // eax, edx + + __get_cpuid(1, &eax, &unused, &unused, &edx); + + // edx returns the flag for MSR (which is 1 shifted to 5.) + return edx & (1 << 5); +} + +Void hal_get_msr(UInt32 msr, UInt32* lo, UInt32* hi) noexcept { + if (!lo || !hi) return; + asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr)); +} + +Void hal_set_msr(UInt32 msr, UInt32 lo, UInt32 hi) noexcept { + asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr)); +} + +Void lrt_hal_out8(UInt16 port, UInt8 value) { + asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +Void lrt_hal_out16(UInt16 port, UInt16 value) { + asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +Void lrt_hal_out32(UInt16 port, UInt32 value) { + asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +UInt8 lrt_hal_in8(UInt16 port) { + UInt8 value = 0UL; + asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +UInt16 lrt_hal_in16(UInt16 port) { + UInt16 value = 0UL; + asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +UInt32 lrt_hal_in32(UInt16 port) { + UInt32 value = 0UL; + asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +Void rt_halt() { + asm volatile("hlt"); +} + +Void rt_cli() { + asm volatile("cli"); +} + +Void rt_sti() { + asm volatile("sti"); +} + +Void rt_cld() { + asm volatile("cld"); +} + +Void rt_std() { + asm volatile("std"); +} +} // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/HalProcessorAMD64.cc b/dev/kernel/HALKit/AMD64/HalProcessorAMD64.cc deleted file mode 100644 index 2fc18e2f..00000000 --- a/dev/kernel/HALKit/AMD64/HalProcessorAMD64.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - - File: HalCPU.cc - Purpose: Platform processor routines. - -------------------------------------------- */ - -#include -#include - -/** - * @file HalCPU.cc - * @brief Common CPU API. - */ - -namespace Kernel::HAL { -Void hal_get_msr(UInt32 msr, UInt32* lo, UInt32* hi) noexcept { - if (!lo || !hi) return; - asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr)); -} - -Void hal_set_msr(UInt32 msr, UInt32 lo, UInt32 hi) noexcept { - asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr)); -} - -Void lrt_hal_out8(UInt16 port, UInt8 value) { - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -Void lrt_hal_out16(UInt16 port, UInt16 value) { - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -Void lrt_hal_out32(UInt16 port, UInt32 value) { - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -UInt8 lrt_hal_in8(UInt16 port) { - UInt8 value = 0UL; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -UInt16 lrt_hal_in16(UInt16 port) { - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -UInt32 lrt_hal_in32(UInt16 port) { - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -Void rt_halt() { - asm volatile("hlt"); -} - -Void rt_cli() { - asm volatile("cli"); -} - -Void rt_sti() { - asm volatile("sti"); -} - -Void rt_cld() { - asm volatile("cld"); -} - -Void rt_std() { - asm volatile("std"); -} -} // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc new file mode 100644 index 00000000..0c468e14 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +namespace Kernel { +/***********************************************************************************/ +/// @brief Unimplemented function (crashes by default) +/// @param +/***********************************************************************************/ + +EXTERN_C Void __zka_pure_call(USER_PROCESS* process) { + if (process) process->Crash(); +} + +/***********************************************************************************/ +/// @brief Validate user stack. +/// @param stack_ptr the frame pointer. +/***********************************************************************************/ + +EXTERN_C Bool hal_check_stack(HAL::StackFramePtr stack_ptr) { + if (!stack_ptr) return No; + + return stack_ptr->SP != 0 && stack_ptr->IP != 0; +} + +/// @brief Wakes up thread. +/// Wakes up thread from the hang state. +Void mp_wakeup_thread(HAL::StackFrame* stack) { + NE_UNUSED(stack); + Kernel::UserProcessHelper::StartScheduling(); +} + +/// @brief makes the thread sleep on a loop. +/// hooks and hangs thread to prevent code from executing. +Void mp_hang_thread(HAL::StackFrame* stack) { + NE_UNUSED(stack); + + while (Yes) { + /* Nothing to do, code is spinning */ + } +} +} // namespace Kernel diff --git a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc deleted file mode 100644 index 0c468e14..00000000 --- a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -namespace Kernel { -/***********************************************************************************/ -/// @brief Unimplemented function (crashes by default) -/// @param -/***********************************************************************************/ - -EXTERN_C Void __zka_pure_call(USER_PROCESS* process) { - if (process) process->Crash(); -} - -/***********************************************************************************/ -/// @brief Validate user stack. -/// @param stack_ptr the frame pointer. -/***********************************************************************************/ - -EXTERN_C Bool hal_check_stack(HAL::StackFramePtr stack_ptr) { - if (!stack_ptr) return No; - - return stack_ptr->SP != 0 && stack_ptr->IP != 0; -} - -/// @brief Wakes up thread. -/// Wakes up thread from the hang state. -Void mp_wakeup_thread(HAL::StackFrame* stack) { - NE_UNUSED(stack); - Kernel::UserProcessHelper::StartScheduling(); -} - -/// @brief makes the thread sleep on a loop. -/// hooks and hangs thread to prevent code from executing. -Void mp_hang_thread(HAL::StackFrame* stack) { - NE_UNUSED(stack); - - while (Yes) { - /* Nothing to do, code is spinning */ - } -} -} // namespace Kernel diff --git a/dev/kernel/HALKit/AMD64/HalTimer.cc b/dev/kernel/HALKit/AMD64/HalTimer.cc new file mode 100644 index 00000000..13573880 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalTimer.cc @@ -0,0 +1,97 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + + File: HalTimer.cc + Purpose: HAL timer + + Revision History: + + 07/07/24: Added file (amlel) + +------------------------------------------- */ + +#include +#include +#include + +// timer slot 0 + +#define kHPETSignature ("HPET") + +#define kHPETCounterRegValue (0x00) +#define kHPETConfigRegValue (0x20) +#define kHPETCompRegValue (0x24) +#define kHPETInterruptRegValue (0x2C) + +///! BUGS: 0 +///! @file HalTimer.cc +///! @brief Hardware Timer (HPET) + +namespace Kernel::Detail { +struct HPET_BLOCK : public Kernel::SDT { + Kernel::UInt8 hardware_rev_id; + Kernel::UInt8 comparator_count : 5; + Kernel::UInt8 counter_size : 1; + Kernel::UInt8 reserved : 1; + Kernel::UInt8 legacy_replacement : 1; + Kernel::UInt16 pci_vendor_id; + ACPI_ADDRESS address; + Kernel::UInt8 hpet_number; + Kernel::UInt16 minimum_tick; + Kernel::UInt8 page_protection; +} PACKED; +} // namespace Kernel::Detail + +using namespace Kernel; + +HardwareTimer::HardwareTimer(UInt64 ms) : fWaitFor(ms) { + auto power = PowerFactoryInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr); + + auto hpet = (Detail::HPET_BLOCK*) power.Find(kHPETSignature).Leak().Leak(); + MUST_PASS(hpet); + + fDigitalTimer = (UInt8*) hpet->address.Address; + + if (hpet->page_protection) { + HAL::mm_map_page((VoidPtr) fDigitalTimer, (VoidPtr) fDigitalTimer, + HAL::kMMFlagsWr | HAL::kMMFlagsPCD | HAL::kMMFlagsPwt); + } + + // if not enabled yet. + if (!(*((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) & (1 << 0))) { + *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) = + *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | + (1 << 0); // enable timer + *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) = + *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | + (1 << 3); // one shot conf + } +} + +HardwareTimer::~HardwareTimer() { + fDigitalTimer = nullptr; + fWaitFor = 0; +} + +/***********************************************************************************/ +/// @brief Wait for the timer to stop spinning. +/***********************************************************************************/ + +BOOL HardwareTimer::Wait() noexcept { + if (fWaitFor < 1) return NO; + + UInt64 hpet_cap = *((volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue)); + UInt64 femtoseconds_per_tick = (hpet_cap >> 32); + + if (femtoseconds_per_tick == 0) return NO; + + volatile UInt64* timer = (volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue); + + UInt64 now = *timer; + UInt64 prev = now + (fWaitFor / femtoseconds_per_tick); + + while (*timer < (prev)) asm volatile("pause"); + + return YES; +} diff --git a/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc b/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc deleted file mode 100644 index 13573880..00000000 --- a/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - - File: HalTimer.cc - Purpose: HAL timer - - Revision History: - - 07/07/24: Added file (amlel) - -------------------------------------------- */ - -#include -#include -#include - -// timer slot 0 - -#define kHPETSignature ("HPET") - -#define kHPETCounterRegValue (0x00) -#define kHPETConfigRegValue (0x20) -#define kHPETCompRegValue (0x24) -#define kHPETInterruptRegValue (0x2C) - -///! BUGS: 0 -///! @file HalTimer.cc -///! @brief Hardware Timer (HPET) - -namespace Kernel::Detail { -struct HPET_BLOCK : public Kernel::SDT { - Kernel::UInt8 hardware_rev_id; - Kernel::UInt8 comparator_count : 5; - Kernel::UInt8 counter_size : 1; - Kernel::UInt8 reserved : 1; - Kernel::UInt8 legacy_replacement : 1; - Kernel::UInt16 pci_vendor_id; - ACPI_ADDRESS address; - Kernel::UInt8 hpet_number; - Kernel::UInt16 minimum_tick; - Kernel::UInt8 page_protection; -} PACKED; -} // namespace Kernel::Detail - -using namespace Kernel; - -HardwareTimer::HardwareTimer(UInt64 ms) : fWaitFor(ms) { - auto power = PowerFactoryInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr); - - auto hpet = (Detail::HPET_BLOCK*) power.Find(kHPETSignature).Leak().Leak(); - MUST_PASS(hpet); - - fDigitalTimer = (UInt8*) hpet->address.Address; - - if (hpet->page_protection) { - HAL::mm_map_page((VoidPtr) fDigitalTimer, (VoidPtr) fDigitalTimer, - HAL::kMMFlagsWr | HAL::kMMFlagsPCD | HAL::kMMFlagsPwt); - } - - // if not enabled yet. - if (!(*((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) & (1 << 0))) { - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) = - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | - (1 << 0); // enable timer - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) = - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | - (1 << 3); // one shot conf - } -} - -HardwareTimer::~HardwareTimer() { - fDigitalTimer = nullptr; - fWaitFor = 0; -} - -/***********************************************************************************/ -/// @brief Wait for the timer to stop spinning. -/***********************************************************************************/ - -BOOL HardwareTimer::Wait() noexcept { - if (fWaitFor < 1) return NO; - - UInt64 hpet_cap = *((volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue)); - UInt64 femtoseconds_per_tick = (hpet_cap >> 32); - - if (femtoseconds_per_tick == 0) return NO; - - volatile UInt64* timer = (volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue); - - UInt64 now = *timer; - UInt64 prev = now + (fWaitFor / femtoseconds_per_tick); - - while (*timer < (prev)) asm volatile("pause"); - - return YES; -} diff --git a/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm b/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm index ab639992..11336229 100644 --- a/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm +++ b/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm @@ -22,5 +22,3 @@ rt_install_tib: ret ;; //////////////////////////////////////////////////// ;; - -[extern kApicMadtAddressesCount] diff --git a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc index 7c611c26..3ccbfa24 100644 --- a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc +++ b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc @@ -79,7 +79,7 @@ EXTERN_C void rtl_rtl8139_interrupt_handler() { // While we receive data. while ((rt_in8(kRTLIOBase + 0x37) & 0x01) == 0) { // We grab an offset from the RX buffer. - UInt32 offset = kRXOffset % kRXBufferSize; + UInt32 offset = kRXOffset % kRXBufferSize; // If the offset is too high, we reset it. if (offset >= (kRXBufferSize - 16)) { diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index 5a70b465..80dc7a1d 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -174,16 +174,7 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept; /// @retval true it does exists. /// @retval false it doesn't. /***********************************************************************************/ -inline Bool hal_has_msr() noexcept { - static UInt32 eax, unused, edx; // eax, edx - - __get_cpuid(1, &eax, &unused, &unused, &edx); - - // edx returns the flag for MSR (which is 1 shifted to 5.) - return edx & (1 << 5); -} - -UIntPtr mm_get_phys_address(VoidPtr virtual_address); +Bool hal_has_msr() noexcept; /***********************************************************************************/ /// @brief Get Model specific register inside core. @@ -271,6 +262,8 @@ EXTERN_C Void rt_sti(); EXTERN_C Void rt_cld(); EXTERN_C Void rt_std(); +EXTERN_C UIntPtr mm_get_page_addr(VoidPtr virtual_address); + EXTERN_C Int32 mm_memory_fence(VoidPtr virtual_address); } // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index b530a730..b30bfc32 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -359,7 +359,7 @@ STATIC Bool drv_init_command_structures_ahci() { return NO; } - UIntPtr clb_phys = HAL::mm_get_phys_address(clb_mem); + UIntPtr clb_phys = HAL::mm_get_page_addr(clb_mem); kSATAHba->Ports[kSATAIndex].Clb = (UInt32) (clb_phys & 0xFFFFFFFF); kSATAHba->Ports[kSATAIndex].Clbu = (UInt32) (clb_phys >> 32); @@ -379,7 +379,7 @@ STATIC Bool drv_init_command_structures_ahci() { return NO; } - UIntPtr ct_phys = HAL::mm_get_phys_address(ct_mem); + UIntPtr ct_phys = HAL::mm_get_page_addr(ct_mem); header[i].Ctba = (UInt32) (ct_phys & 0xFFFFFFFF); header[i].Ctbau = (UInt32) (ct_phys >> 32); diff --git a/dev/kernel/HALKit/ARM64/HalPagingMgr.cc b/dev/kernel/HALKit/ARM64/HalPagingMgr.cc new file mode 100644 index 00000000..faad6778 --- /dev/null +++ b/dev/kernel/HALKit/ARM64/HalPagingMgr.cc @@ -0,0 +1,28 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + + File: HalPagingMgr.cc + Purpose: Platform Paging Manager. + +------------------------------------------- */ + +#include +#include + +namespace Kernel::HAL { +typedef UInt32 PageTableIndex; + +/// @brief Maps or allocates a page from virtual_address. +/// @param virtual_address a valid virtual address. +/// @param phys_addr point to physical address. +/// @param flags the flags to put on the page. +/// @return Status code of page manipulation process. +EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) { + if (!virtual_address || !flags) return kErrorInvalidData; + + NE_UNUSED(physical_address); + + return kErrorSuccess; +} +} // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc b/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc deleted file mode 100644 index faad6778..00000000 --- a/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc +++ /dev/null @@ -1,28 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - - File: HalPagingMgr.cc - Purpose: Platform Paging Manager. - -------------------------------------------- */ - -#include -#include - -namespace Kernel::HAL { -typedef UInt32 PageTableIndex; - -/// @brief Maps or allocates a page from virtual_address. -/// @param virtual_address a valid virtual address. -/// @param phys_addr point to physical address. -/// @param flags the flags to put on the page. -/// @return Status code of page manipulation process. -EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) { - if (!virtual_address || !flags) return kErrorInvalidData; - - NE_UNUSED(physical_address); - - return kErrorSuccess; -} -} // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCore.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCore.cc new file mode 100644 index 00000000..b3f1b62a --- /dev/null +++ b/dev/kernel/HALKit/ARM64/HalSchedulerCore.cc @@ -0,0 +1,21 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include + +namespace Kernel { +/// @brief Wakes up thread. +/// Wakes up thread from the hang state. +Void mp_wakeup_thread(HAL::StackFrame* stack) { + NE_UNUSED(stack); +} + +/// @brief makes the thread sleep on a loop. +/// hooks and hangs thread to prevent code from executing. +Void mp_hang_thread(HAL::StackFrame* stack) { + NE_UNUSED(stack); +} +} // namespace Kernel diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc deleted file mode 100644 index b3f1b62a..00000000 --- a/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc +++ /dev/null @@ -1,21 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include - -namespace Kernel { -/// @brief Wakes up thread. -/// Wakes up thread from the hang state. -Void mp_wakeup_thread(HAL::StackFrame* stack) { - NE_UNUSED(stack); -} - -/// @brief makes the thread sleep on a loop. -/// hooks and hangs thread to prevent code from executing. -Void mp_hang_thread(HAL::StackFrame* stack) { - NE_UNUSED(stack); -} -} // namespace Kernel diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc new file mode 100644 index 00000000..ee286639 --- /dev/null +++ b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +namespace Kernel { +/***********************************************************************************/ +/// @brief Unimplemented function (crashes by default) +/// @param void +/***********************************************************************************/ + +EXTERN_C Void __zka_pure_call(USER_PROCESS* process) { + if (process) process->Crash(); +} + +/***********************************************************************************/ +/// @brief Validate user stack. +/// @param stack_ptr the frame pointer. +/***********************************************************************************/ + +EXTERN_C Bool hal_check_stack(HAL::StackFramePtr stack_ptr) { + if (!stack_ptr) return No; + + return stack_ptr->SP != 0 && stack_ptr->IP != 0; +} +} // namespace Kernel diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc deleted file mode 100644 index ee286639..00000000 --- a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -namespace Kernel { -/***********************************************************************************/ -/// @brief Unimplemented function (crashes by default) -/// @param void -/***********************************************************************************/ - -EXTERN_C Void __zka_pure_call(USER_PROCESS* process) { - if (process) process->Crash(); -} - -/***********************************************************************************/ -/// @brief Validate user stack. -/// @param stack_ptr the frame pointer. -/***********************************************************************************/ - -EXTERN_C Bool hal_check_stack(HAL::StackFramePtr stack_ptr) { - if (!stack_ptr) return No; - - return stack_ptr->SP != 0 && stack_ptr->IP != 0; -} -} // namespace Kernel diff --git a/dev/kernel/HALKit/ARM64/HalTimer.cc b/dev/kernel/HALKit/ARM64/HalTimer.cc new file mode 100644 index 00000000..2a595f11 --- /dev/null +++ b/dev/kernel/HALKit/ARM64/HalTimer.cc @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + + File: HalTimer.cc + Purpose: HAL timer + + Revision History: + + 07/07/24: Added file (amlel) + +------------------------------------------- */ + +#include +#include \ No newline at end of file diff --git a/dev/kernel/HALKit/ARM64/HalTimerARM64.cc b/dev/kernel/HALKit/ARM64/HalTimerARM64.cc deleted file mode 100644 index 2a595f11..00000000 --- a/dev/kernel/HALKit/ARM64/HalTimerARM64.cc +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - - File: HalTimer.cc - Purpose: HAL timer - - Revision History: - - 07/07/24: Added file (amlel) - -------------------------------------------- */ - -#include -#include \ No newline at end of file diff --git a/dev/kernel/HALKit/ARM64/Processor.h b/dev/kernel/HALKit/ARM64/Processor.h index 38669b2f..068b798d 100644 --- a/dev/kernel/HALKit/ARM64/Processor.h +++ b/dev/kernel/HALKit/ARM64/Processor.h @@ -38,7 +38,7 @@ enum { /// @return Status code of page manip. EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags); -EXTERN_C UIntPtr mm_get_phys_address(VoidPtr virtual_address); +EXTERN_C UIntPtr mm_get_page_addr(VoidPtr virtual_address); typedef UIntPtr Reg; typedef Register64 Register; diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index 944c8efc..811d7f5d 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -64,7 +64,8 @@ inline constexpr KPCError kErrorUnrecoverableDisk = 63; inline constexpr KPCError kErrorFileLocked = 64; inline constexpr KPCError kErrorDiskIsTooTiny = 65; /// Kernel errors. -inline constexpr KPCError kErrorDmaExhausted = 101; +inline constexpr KPCError kErrorDmaExhausted = 101; +inline constexpr KPCError kErrorOutOfBitMapMemory = 102; /// Generic errors. inline constexpr KPCError kErrorUnimplemented = -1; diff --git a/dev/kernel/KernelKit/LockDelegate.h b/dev/kernel/KernelKit/LockDelegate.h index a8162897..b5977c92 100644 --- a/dev/kernel/KernelKit/LockDelegate.h +++ b/dev/kernel/KernelKit/LockDelegate.h @@ -11,8 +11,8 @@ namespace Kernel { enum { - kLockInvalid, - kLockDone = 200, + kLockInvalid = 0, + kLockDone = 200, kLockTimedOut, kLockCount = 3, }; diff --git a/dev/kernel/KernelKit/ZXD.h b/dev/kernel/KernelKit/ZXD.h index 2c5a33c4..10af568b 100644 --- a/dev/kernel/KernelKit/ZXD.h +++ b/dev/kernel/KernelKit/ZXD.h @@ -17,25 +17,25 @@ 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; + UInt32 fMagic; + UInt32 fVersion; + UInt32 fFlags; + UInt32 fHdrSize; + UInt32 fCRC32; + UInt32 fAssigneeSignature; + UInt32 fIssuerSingature; UIntPtr fExecOffset; - SizeT fExecSize; + SizeT fExecSize; UIntPtr fStubOffset; - SizeT fStubSize; - SizeT fStubAlign; - SizeT fStubCount; + SizeT fStubSize; + SizeT fStubAlign; + SizeT fStubCount; }; /// @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 { +struct ZXD_STUB_HEADER { UInt32 fStubSize; UInt32 fStubOffset; UInt32 fStubCRC32; diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make index 38021901..c728b29c 100644 --- a/dev/kernel/amd64-ci.make +++ b/dev/kernel/amd64-ci.make @@ -35,7 +35,7 @@ LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000 LDOBJ = obj/*.obj # This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. -KERNEL_IMG = krnl.efi +KERNEL_IMG = ne_kernel .PHONY: error error: diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index ae2307fd..49593101 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -37,7 +37,7 @@ LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000 LDOBJ = obj/*.obj # This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. -KERNEL_IMG = krnl.efi +KERNEL_IMG = ne_kernel .PHONY: error error: diff --git a/dev/kernel/arm64-desktop.make b/dev/kernel/arm64-desktop.make index 31d8f49e..423391af 100644 --- a/dev/kernel/arm64-desktop.make +++ b/dev/kernel/arm64-desktop.make @@ -23,7 +23,7 @@ LDFLAGS = -subsystem:efi_application -entry:hal_init_platform /nodefaultlib LDOBJ = obj/*.obj # This file is the Kernel, responsible of task management and memory. -KERNEL = krnl.efi +KERNEL = ne_kernel .PHONY: error error: diff --git a/dev/kernel/kernel_rsrc.rsrc b/dev/kernel/kernel_rsrc.rsrc index 8d0093e4..5b1cb14f 100644 --- a/dev/kernel/kernel_rsrc.rsrc +++ b/dev/kernel/kernel_rsrc.rsrc @@ -13,7 +13,7 @@ BEGIN VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "krnl" VALUE "LegalCopyright", "(c) 2024-2025 Amlal El Mahrouss, all rights reserved." - VALUE "OriginalFilename", "krnl.efi" + VALUE "OriginalFilename", "ne_kernel" VALUE "ProductName", "NeKernel" VALUE "ProductVersion", KERNEL_VERSION END diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc index 4301ce5b..df678d41 100644 --- a/dev/kernel/src/BitMapMgr.cc +++ b/dev/kernel/src/BitMapMgr.cc @@ -22,6 +22,8 @@ namespace Kernel { namespace HAL { namespace Detail { + STATIC SizeT kBitMapCursor = 0UL; + /***********************************************************************************/ /// \brief Proxy Interface to manage a bitmap allocator. /***********************************************************************************/ @@ -47,6 +49,8 @@ namespace HAL { UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr); + kBitMapCursor += ptr_bit_set[kBitMapSizeIdx]; + ptr_bit_set[kBitMapMagIdx] = kBitMapMagic; ptr_bit_set[kBitMapUsedIdx] = No; @@ -59,7 +63,6 @@ namespace HAL { UInt32 flags = kMMFlagsPresent; if (wr) flags |= kMMFlagsWr; - if (user) flags |= kMMFlagsUser; return flags; @@ -77,11 +80,18 @@ namespace HAL { auto FindBitMap(VoidPtr base_ptr, SizeT size, Bool wr, Bool user, SizeT pad) -> VoidPtr { if (!size) return nullptr; + if (kBitMapCursor > kKernelBitMpSize) { + err_global_get() = kErrorOutOfBitMapMemory; + + (Void)(kout << "Bitmap limit reached, can't allocate more bitmaps." << kendl); + return nullptr; + } + VoidPtr base = reinterpret_cast((UIntPtr) base_ptr); MUST_PASS(base); - static SizeT biggest = 0UL; + STATIC SizeT biggest = 0UL; while (YES) { UIntPtr* ptr_bit_set = reinterpret_cast(base); @@ -99,6 +109,8 @@ namespace HAL { if (biggest < (size + pad)) biggest = size + pad; + kBitMapCursor += size + pad; + return (VoidPtr) ptr_bit_set; } } else if (ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) { @@ -113,6 +125,8 @@ namespace HAL { if (biggest < (size + pad)) biggest = (size + pad); + kBitMapCursor += size + pad; + return (VoidPtr) ptr_bit_set; } diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index a18abaf8..893f43ef 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -758,9 +758,8 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c } if (drv_std_get_size() < kHeFSMinimumDiskSize) { - (Void)(kout << "HeFS requires at least 128 GiB of free space." << kendl); - err_global_get() = kErrorDisk; - return NO; + (Void)(kout << "HeFS recommends at least 128 GiB of free space." << kendl); + (Void)(kout << "The OS will still try to format a HeFS disk here." << kendl); } HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) RTL_ALLOCA(sizeof(HEFS_BOOT_NODE)); diff --git a/dev/kernel/src/HeapMgr.cc b/dev/kernel/src/HeapMgr.cc index 5280bcc3..2fdfe748 100644 --- a/dev/kernel/src/HeapMgr.cc +++ b/dev/kernel/src/HeapMgr.cc @@ -25,8 +25,8 @@ //! @file HeapMgr.cc //! @brief Heap system that serves as the main memory manager. -#define kMemoryMgrMagic (0xD4D75) -#define kMemoryMgrAlignSz (4U) +#define kHeapMgrMagic (0xD4D75) +#define kHeapMgrAlignSz (4U) namespace Kernel { /// @brief Implementation details. @@ -68,7 +68,7 @@ namespace Detail { UInt32 fPad; /// @brief Padding bytes for header. - UInt8 fPadding[kMemoryMgrAlignSz]; + UInt8 fPadding[kHeapMgrAlignSz]; }; /// @brief Check for heap address validity. @@ -112,7 +112,7 @@ _Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { sizeof(Detail::MM_INFORMATION_BLOCK)); heap_info_ptr->fSize = sz_fix; - heap_info_ptr->fMagic = kMemoryMgrMagic; + heap_info_ptr->fMagic = kHeapMgrMagic; heap_info_ptr->fCRC32 = 0U; // dont fill it for now. heap_info_ptr->fOffset = reinterpret_cast(heap_info_ptr) + sizeof(Detail::MM_INFORMATION_BLOCK); @@ -122,7 +122,7 @@ _Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { heap_info_ptr->fPresent = Yes; heap_info_ptr->fPad = pad_amount; - rt_set_memory(heap_info_ptr->fPadding, 0, kMemoryMgrAlignSz); + rt_set_memory(heap_info_ptr->fPadding, 0, kHeapMgrAlignSz); auto result = reinterpret_cast(heap_info_ptr->fOffset); @@ -191,7 +191,7 @@ _Output Int32 mm_free_ptr(VoidPtr heap_ptr) { reinterpret_cast((UIntPtr) (heap_ptr) - sizeof(Detail::MM_INFORMATION_BLOCK)); - if (heap_info_ptr && heap_info_ptr->fMagic == kMemoryMgrMagic) { + if (heap_info_ptr && heap_info_ptr->fMagic == kHeapMgrMagic) { if (!heap_info_ptr->fPresent) { return kErrorHeapNotPresent; } @@ -231,7 +231,7 @@ _Output Boolean mm_is_valid_ptr(VoidPtr heap_ptr) { reinterpret_cast((UIntPtr) (heap_ptr) - sizeof(Detail::MM_INFORMATION_BLOCK)); - return (heap_info_ptr && heap_info_ptr->fPresent && heap_info_ptr->fMagic == kMemoryMgrMagic); + return (heap_info_ptr && heap_info_ptr->fPresent && heap_info_ptr->fMagic == kHeapMgrMagic); } return No; @@ -247,7 +247,7 @@ _Output Boolean mm_protect_ptr(VoidPtr heap_ptr) { sizeof(Detail::MM_INFORMATION_BLOCK)); /// if valid, present and is heap header, then compute crc32 - if (heap_info_ptr && heap_info_ptr->fPresent && kMemoryMgrMagic == heap_info_ptr->fMagic) { + if (heap_info_ptr && heap_info_ptr->fPresent && kHeapMgrMagic == heap_info_ptr->fMagic) { heap_info_ptr->fCRC32 = ke_calculate_crc32((Char*) heap_info_ptr->fOffset, heap_info_ptr->fSize); diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index e810651a..ed72473f 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -161,7 +161,7 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { kout << "PEFLoader: Information: Loaded stub: " << container_header->Name << "!\r"; auto ret = HAL::mm_map_page((VoidPtr) container_header->VMAddress, - (VoidPtr) HAL::mm_get_phys_address(container_blob_value), + (VoidPtr) HAL::mm_get_page_addr(container_blob_value), HAL::kMMFlagsPresent | HAL::kMMFlagsUser); if (ret != kErrorSuccess) { diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 77421f5f..f900f984 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -403,10 +403,10 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im #ifdef __NE_VIRTUAL_MEMORY_SUPPORT__ HAL::mm_map_page((VoidPtr) process.StackFrame->IP, - (VoidPtr) HAL::mm_get_phys_address((VoidPtr) process.StackFrame->IP), + (VoidPtr) HAL::mm_get_page_addr((VoidPtr) process.StackFrame->IP), HAL::kMMFlagsUser | HAL::kMMFlagsPresent); HAL::mm_map_page((VoidPtr) process.StackFrame->SP, - (VoidPtr) HAL::mm_get_phys_address((VoidPtr) process.StackFrame->SP), + (VoidPtr) HAL::mm_get_page_addr((VoidPtr) process.StackFrame->SP), HAL::kMMFlagsUser | HAL::kMMFlagsPresent); #endif // ifdef __NE_VIRTUAL_MEMORY_SUPPORT__ diff --git a/docs/drawio/OS_DESIGN.drawio b/docs/drawio/OS_DESIGN.drawio index 3a03540c..c428d137 100644 --- a/docs/drawio/OS_DESIGN.drawio +++ b/docs/drawio/OS_DESIGN.drawio @@ -8,37 +8,37 @@ - + - + - - + + - - + + - + - - + + - - + + - - + + - - + + diff --git a/public/tools/manual/src/CommandLine.cc b/public/tools/manual/src/CommandLine.cc index 0d9c4136..a1cd9094 100644 --- a/public/tools/manual/src/CommandLine.cc +++ b/public/tools/manual/src/CommandLine.cc @@ -5,8 +5,8 @@ SInt32 _NeMain(SInt32 argc, Char* argv[]) { SCI_UNUSED(argv); if (argc < 2) { - PrintOut(nullptr, "HELP: manual \n"); - return EXIT_FAILURE; + PrintOut(nullptr, "HELP: manual \n"); + return EXIT_FAILURE; } return EXIT_SUCCESS; diff --git a/public/tools/ping/src/CommandLine.cc b/public/tools/ping/src/CommandLine.cc index 9aae0ea9..7ef58e81 100644 --- a/public/tools/ping/src/CommandLine.cc +++ b/public/tools/ping/src/CommandLine.cc @@ -18,11 +18,11 @@ SInt32 _NeMain(SInt32 argc, Char* argv[]) { return EXIT_FAILURE; } - SInt32 bytes = 64; // Simulated response size - SInt32 time = 100 + (i * 10); // Simulated response time - SInt32 ttl = 64; + SInt32 bytes = 64; // Simulated response size + SInt32 time = 100 + (i * 10); // Simulated response time + SInt32 ttl = 64; - PrintOut(nullptr, "Reply from %s: bytes=%i time=%ims TTL=%i\n", argv[1], bytes, time, ttl); + PrintOut(nullptr, "Reply from %s: bytes=%i time=%ims TTL=%i\n", argv[1], bytes, time, ttl); } return EXIT_SUCCESS; -- cgit v1.2.3 From 5fdab4a1c9c3df049e8e31a42784c05799ef44cd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 27 May 2025 11:19:10 +0200 Subject: refactor: rename mm_make_ptr_flags to mm_set_ptr_flags. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/HeapMgr.h | 2 +- dev/kernel/src/HeapMgr.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/kernel/src/HeapMgr.cc') diff --git a/dev/kernel/KernelKit/HeapMgr.h b/dev/kernel/KernelKit/HeapMgr.h index 851f3095..dacdfa5d 100644 --- a/dev/kernel/KernelKit/HeapMgr.h +++ b/dev/kernel/KernelKit/HeapMgr.h @@ -46,7 +46,7 @@ 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); +Int32 mm_set_ptr_flags(VoidPtr heap_ptr, UInt64 flags); /// @brief Gets the flags of a heap header. /// @param heap_ptr the pointer to get. diff --git a/dev/kernel/src/HeapMgr.cc b/dev/kernel/src/HeapMgr.cc index 2fdfe748..eb86f378 100644 --- a/dev/kernel/src/HeapMgr.cc +++ b/dev/kernel/src/HeapMgr.cc @@ -155,7 +155,7 @@ _Output 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. -_Output Int32 mm_make_ptr_flags(VoidPtr heap_ptr, UInt64 flags) { +_Output Int32 mm_set_ptr_flags(VoidPtr heap_ptr, UInt64 flags) { if (Detail::mm_check_ptr_address(heap_ptr) == No) return kErrorHeapNotPresent; Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = -- cgit v1.2.3