From 2a7a9825fd275d6d999b94614fe87c1d705c7f8f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 1 Apr 2025 08:30:44 +0200 Subject: boot, kernel, modules: unify gfx headers, fix AHCI LBA48, standardize ModuleMain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Consolidated CoreGfx headers: * Renamed `FBMgr.h` to `CoreGfx.h` * Renamed `TextMgr.h` → `TextGfx.h`, `MathMgr.h` → `MathGfx.h`, and `AccessibilityMgr.h` → `CoreAccess.h` * Updated all includes across bootloader, HAL, and kernel to use new names - Standardized EFI entrypoint: * Replaced `Main` with `ModuleMain` in EFI boot sources and linker flags * Updated GDB and build scripts accordingly - Improved AHCI identify logic: * Added full 48-bit LBA extraction (words 100–102) * Fallback to 28-bit if LBA48 not supported * Refactored `drv_get_size` and `drv_std_detected` into separate `#ifdef __AHCI__` region - DiskImage framework improvements: * Namespaced API into `DI` namespace * Split implementation: `DiskImage+EPM.cc` and `DiskImage+NeFS.cc` * Updated CLI tool accordingly - KernelTest framework: * Namespaced macros and classes with `KT_` * Changed test result to use `MUST_PASS` and boolean return - Misc: * Corrected minor logic in `NetworkDevice::Name()` * Bumped down KernelKit and NewKit versions to 0.0.1 * Renamed `HalUtils.asm` → `HalUtilsAPI.asm` Signed-off-by: Amlal El Mahrouss --- dev/kernel/FirmwareKit/EFI/API.h | 2 +- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 2 +- dev/kernel/HALKit/AMD64/HalDebugOutput.cc | 4 +- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/AMD64/HalKernelPanic.cc | 4 +- dev/kernel/HALKit/AMD64/HalUtils.asm | 26 ---- dev/kernel/HALKit/AMD64/HalUtilsAPI.asm | 26 ++++ dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 146 +++++++++++---------- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/ARM64/HalKernelPanic.cc | 4 +- dev/kernel/KernelKit/Defines.h | 4 +- dev/kernel/NewKit/Defines.h | 4 +- dev/kernel/amd64-ci.make | 2 +- dev/kernel/amd64-desktop.make | 2 +- dev/kernel/src/Network/NetworkDevice.cc | 13 +- 15 files changed, 127 insertions(+), 116 deletions(-) delete mode 100644 dev/kernel/HALKit/AMD64/HalUtils.asm create mode 100644 dev/kernel/HALKit/AMD64/HalUtilsAPI.asm (limited to 'dev/kernel') diff --git a/dev/kernel/FirmwareKit/EFI/API.h b/dev/kernel/FirmwareKit/EFI/API.h index 67ff19bc..403e017e 100644 --- a/dev/kernel/FirmwareKit/EFI/API.h +++ b/dev/kernel/FirmwareKit/EFI/API.h @@ -22,7 +22,7 @@ class BootTextWriter; #define __BOOTKIT_NO_INCLUDE__ 1 #include -#include +#include #endif // ifdef __BOOTZ__ inline EfiSystemTable* ST = nullptr; diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index f839884e..10361d8e 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc index 9bd45efe..e79b6b09 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -8,8 +8,8 @@ #include #include #include -#include -#include +#include +#include namespace Kernel { diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 0371bde4..f4dbc16e 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -12,7 +12,7 @@ #include #include #include -#include +#include EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; EXTERN_C Kernel::VoidPtr mp_user_switch_proc; diff --git a/dev/kernel/HALKit/AMD64/HalKernelPanic.cc b/dev/kernel/HALKit/AMD64/HalKernelPanic.cc index 770fac2b..3703692c 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelPanic.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelPanic.cc @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include /* Each error code is attributed with an ID, which will prompt a string onto the diff --git a/dev/kernel/HALKit/AMD64/HalUtils.asm b/dev/kernel/HALKit/AMD64/HalUtils.asm deleted file mode 100644 index ab639992..00000000 --- a/dev/kernel/HALKit/AMD64/HalUtils.asm +++ /dev/null @@ -1,26 +0,0 @@ -;; /* -;; * ======================================================== -;; * -;; * NeKernel -;; * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -;; * -;; * ======================================================== -;; */ - -[bits 64] - -[global rt_install_tib] - -section .text - -;; changed: rs, fs -;; expected: rcx, rdx - -rt_install_tib: - mov rcx, gs ;; TIB -> Thread Information Block - mov rdx, fs ;; PIB -> Process Information Block - ret - -;; //////////////////////////////////////////////////// ;; - -[extern kApicMadtAddressesCount] diff --git a/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm b/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm new file mode 100644 index 00000000..ab639992 --- /dev/null +++ b/dev/kernel/HALKit/AMD64/HalUtilsAPI.asm @@ -0,0 +1,26 @@ +;; /* +;; * ======================================================== +;; * +;; * NeKernel +;; * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +;; * +;; * ======================================================== +;; */ + +[bits 64] + +[global rt_install_tib] + +section .text + +;; changed: rs, fs +;; expected: rcx, rdx + +rt_install_tib: + mov rcx, gs ;; TIB -> Thread Information Block + mov rdx, fs ;; PIB -> Process Information Block + ret + +;; //////////////////////////////////////////////////// ;; + +[extern kApicMadtAddressesCount] diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 7dac018d..e5f10db3 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -77,16 +77,26 @@ STATIC Void drv_compute_disk_ahci() noexcept static UInt8 identify_data[kSzIdent] ATTRIBUTE(aligned(4096)) = {0}; HAL::mm_map_page((void*)mib_cast(1), (void*)mib_cast(1), HAL::kMMFlagsWr); - + rt_set_memory(identify_data, 0, kSzIdent); /// Send AHCI command for identification. drv_std_input_output_ahci(0, identify_data, kAHCISectorSize, kSzIdent); /// Extract 48-bit LBA. - kSATASectorCount = (identify_data[61] << 16) | identify_data[60]; + + UInt64 lba48_sectors = 0; + lba48_sectors |= (UInt64)identify_data[100]; + lba48_sectors |= (UInt64)identify_data[101] << 16; + lba48_sectors |= (UInt64)identify_data[102] << 32; + + if (lba48_sectors == 0) + kSATASectorCount = (identify_data[61] << 16) | identify_data[60]; + else + kSATASectorCount = lba48_sectors; /// Show what we got. + kout << "Disk Model: " << kCurrentDiskModel << kendl; kout << "Disk Size: " << number(drv_get_size()) << kendl; kout << "Disk Sector Count: " << number(kSATASectorCount) << kendl; @@ -142,7 +152,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz MUST_PASS(command_header); - constexpr UInt32 kMaxPRDSize = 0x400000; + constexpr const UInt32 kMaxPRDSize = mib_cast(4); command_header->Cfl = sizeof(FisRegH2D) / sizeof(UInt32); command_header->Write = Write; @@ -392,6 +402,71 @@ Bool drv_std_detected_ahci() return kSATADev.DeviceId() != (UShort)PCI::PciConfigKind::Invalid && kSATADev.Bar(kSATABar5) != 0; } +// ================================================================================================ + +// +// This applies only if we compile with AHCI as a default disk driver. +// + +// ================================================================================================ + +#ifdef __AHCI__ + +//////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////// +Void drv_std_write(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) +{ + drv_std_input_output_ahci(lba, reinterpret_cast(buffer), sector_sz, size_buffer); +} + +//////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////// +Void drv_std_read(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) +{ + drv_std_input_output_ahci(lba, reinterpret_cast(buffer), sector_sz, size_buffer); +} + +//////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////// +Bool drv_std_init(UInt16& pi) +{ + BOOL atapi = NO; + return drv_std_init_ahci(pi, atapi); +} + +//////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////// +Bool drv_std_detected(Void) +{ + return drv_std_detected_ahci(); +} + +//////////////////////////////////////////////////// +/** + @brief Gets the number of sectors inside the drive. + @return Sector size in bytes. + */ +//////////////////////////////////////////////////// +SizeT drv_get_sector_count() +{ + return drv_get_sector_count_ahci(); +} + +//////////////////////////////////////////////////// +/// @brief Get the drive size. +/// @return Disk size in bytes. +//////////////////////////////////////////////////// +SizeT drv_get_size() +{ + return drv_get_size_ahci(); +} + +#endif // ifdef __AHCI__ + namespace Kernel { /// @brief Initialize an AHCI device (StorageKit) @@ -471,68 +546,3 @@ namespace Kernel return ErrorOr(device); } } // namespace Kernel - -// ================================================================================================ - -// -// This applies only if we compile with AHCI as a default disk driver. -// - -// ================================================================================================ - -#ifdef __AHCI__ - -//////////////////////////////////////////////////// -/// -//////////////////////////////////////////////////// -Void drv_std_write(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) -{ - drv_std_input_output_ahci(lba, reinterpret_cast(buffer), sector_sz, size_buffer); -} - -//////////////////////////////////////////////////// -/// -//////////////////////////////////////////////////// -Void drv_std_read(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) -{ - drv_std_input_output_ahci(lba, reinterpret_cast(buffer), sector_sz, size_buffer); -} - -//////////////////////////////////////////////////// -/// -//////////////////////////////////////////////////// -Bool drv_std_init(UInt16& pi) -{ - BOOL atapi = NO; - return drv_std_init_ahci(pi, atapi); -} - -//////////////////////////////////////////////////// -/// -//////////////////////////////////////////////////// -Bool drv_std_detected(Void) -{ - return drv_std_detected_ahci(); -} - -//////////////////////////////////////////////////// -/** - @brief Gets the number of sectors inside the drive. - @return Sector size in bytes. - */ -//////////////////////////////////////////////////// -SizeT drv_get_sector_count() -{ - return drv_get_sector_count_ahci(); -} - -//////////////////////////////////////////////////// -/// @brief Get the drive size. -/// @return Disk size in bytes. -//////////////////////////////////////////////////// -SizeT drv_get_size() -{ - return drv_get_size_ahci(); -} - -#endif // ifdef __AHCI__ diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 14781151..d9f3eb85 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include #include #include diff --git a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc index 4a632564..1e008c0f 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc @@ -11,8 +11,8 @@ #include #include #include -#include -#include +#include +#include #include /* Each error code is attributed with an ID, which will prompt a string onto the diff --git a/dev/kernel/KernelKit/Defines.h b/dev/kernel/KernelKit/Defines.h index 9977462d..ca258f58 100644 --- a/dev/kernel/KernelKit/Defines.h +++ b/dev/kernel/KernelKit/Defines.h @@ -8,8 +8,8 @@ #include -#define KERNELKIT_VERSION "1.0.2" -#define KERNELKIT_VERSION_BCD 0x01020 +#define KERNELKIT_VERSION "0.0.1" +#define KERNELKIT_VERSION_BCD 0x0001 class UserProcessScheduler; class IDylibObject; diff --git a/dev/kernel/NewKit/Defines.h b/dev/kernel/NewKit/Defines.h index 85654a52..72e3c552 100644 --- a/dev/kernel/NewKit/Defines.h +++ b/dev/kernel/NewKit/Defines.h @@ -8,8 +8,8 @@ #include -#define NEWKIT_VERSION_STR "1.1.0" -#define NEWKIT_VERSION_BCD 0x01100 +#define NEWKIT_VERSION_STR "0.0.1" +#define NEWKIT_VERSION_BCD 0x0001 #ifndef __cplusplus #error Kernel compiles with a C++ compiler. diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make index d71f3a6f..a03c8fdd 100644 --- a/dev/kernel/amd64-ci.make +++ b/dev/kernel/amd64-ci.make @@ -54,7 +54,7 @@ newos-amd64-epm: clean $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalCommonAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBootHeader.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtils.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtilsAPI.asm $(MOVEALL) OBJCOPY=x86_64-w64-mingw32-objcopy diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index d71f3a6f..a03c8fdd 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -54,7 +54,7 @@ newos-amd64-epm: clean $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalCommonAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBootHeader.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtils.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtilsAPI.asm $(MOVEALL) OBJCOPY=x86_64-w64-mingw32-objcopy diff --git a/dev/kernel/src/Network/NetworkDevice.cc b/dev/kernel/src/Network/NetworkDevice.cc index 79fb66d1..d7d78c28 100644 --- a/dev/kernel/src/Network/NetworkDevice.cc +++ b/dev/kernel/src/Network/NetworkDevice.cc @@ -10,25 +10,26 @@ namespace Kernel { /// \brief Getter for fNetworkName. + /// \return Network device name. const Char* NetworkDevice::Name() const { return this->fNetworkName; } /// \brief Setter for fNetworkName. - Boolean NetworkDevice::Name(const Char* devnam) + Boolean NetworkDevice::Name(const Char* name) { - if (devnam == nullptr) + if (name == nullptr) return NO; - if (*devnam == 0) + if (*name == 0) return NO; - if (rt_string_len(devnam) > cNetworkNameLen) + if (rt_string_len(name) > cNetworkNameLen) return NO; - rt_copy_memory((VoidPtr)devnam, - (VoidPtr)this->fNetworkName, rt_string_len(devnam)); + rt_copy_memory((VoidPtr)name, + (VoidPtr)this->fNetworkName, rt_string_len(name)); return YES; } -- cgit v1.2.3