From 1311cdcfaa7fad132196a615899fd38393f54daf Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 18 Mar 2025 05:20:57 +0100 Subject: feat(AHCI, HAL): Improve AHCI error handling & optimize HAL initialization - Refactored `sk_acquire_ahci_device(Int32 drv_index)` to return `ErrorOr` for proper error handling instead of returning a raw object. - Moved `sk_init_ahci_device(BOOL atapi)` into the `NeOS` namespace for better encapsulation. - Reduced `HbaMem::Ports` array size from `Ports[32]` to `Ports[1]` to optimize memory usage for single-port AHCI controllers. - Removed manual constructor initialization (`__CTOR_LIST__`, `__DTOR_LIST__`) from HAL, simplifying kernel startup. - Updated `hal_real_init()` to initialize AHCI storage (`sk_init_ahci_device(NO)`) before userland execution. - Refactored `hal_get_phys_address(void* virtual_address)` to use `VoidPtr` for type safety. - Fixed incorrect buffer size (`kSzIdent`) in AHCI driver initialization from `kib_cast(1)` to `512`, ensuring correct sector identification. - Removed redundant drive model string parsing logic. - Refactored AHCI PRD iteration loop to use `prd_i` instead of `i`, improving readability. - Optimized `drv_std_input_output` by simplifying wait loop logic. Overall, this commit improves AHCI error handling, reduces redundant initialization, optimizes memory usage, and cleans up HAL and storage code. Signed-off-by: Amlal El Mahrouss --- dev/Kernel/HALKit/AMD64/HalKernelMain.cc | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'dev/Kernel/HALKit/AMD64/HalKernelMain.cc') diff --git a/dev/Kernel/HALKit/AMD64/HalKernelMain.cc b/dev/Kernel/HALKit/AMD64/HalKernelMain.cc index 88d2007c..ef5c93e3 100644 --- a/dev/Kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/Kernel/HALKit/AMD64/HalKernelMain.cc @@ -4,6 +4,7 @@ ------------------------------------------- */ +#include #include #include #include @@ -17,9 +18,6 @@ EXTERN_C NeOS::VoidPtr kInterruptVectorTable[]; EXTERN_C NeOS::VoidPtr mp_user_switch_proc; EXTERN_C NeOS::Char mp_user_switch_proc_stack_begin[]; -EXTERN_C NeOS::rtl_ctor_kind __CTOR_LIST__[]; -EXTERN_C NeOS::VoidPtr __DTOR_LIST__; - STATIC NeOS::Void hal_init_cxx_ctors() { for (NeOS::SizeT i = 0U; i < NeOS::UserProcessScheduler::The().CurrentTeam().AsArray().Count(); ++i) @@ -27,14 +25,6 @@ STATIC NeOS::Void hal_init_cxx_ctors() NeOS::UserProcessScheduler::The().CurrentTeam().AsArray()[i] = NeOS::UserProcess(); NeOS::UserProcessScheduler::The().CurrentTeam().AsArray()[i].Status = NeOS::ProcessStatusKind::kKilled; } - - NeOS::UserProcessScheduler::The().CurrentTeam().mProcessCount = 0UL; - - for (NeOS::SizeT index = 0UL; __CTOR_LIST__[index] != __DTOR_LIST__; ++index) - { - NeOS::rtl_ctor_kind constructor_cxx = (NeOS::rtl_ctor_kind)__CTOR_LIST__[index]; - constructor_cxx(); - } } STATIC NeOS::UInt64 hal_rdtsc_fn() @@ -104,7 +94,7 @@ EXTERN_C void hal_init_platform( EXTERN_C NeOS::Void hal_real_init(NeOS::Void) noexcept { - NeOS::NeFS::fs_init_nefs(); + auto dev = NeOS::sk_init_ahci_device(NO); NeOS::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); @@ -116,7 +106,7 @@ EXTERN_C NeOS::Void hal_real_init(NeOS::Void) noexcept kEnd = hal_rdtsc_fn(); - kout << "Cycles Spent: " << NeOS::number(kEnd - kStart) << kendl; + kout << "Cycles Spent Before Userland: " << NeOS::number(kEnd - kStart) << kendl; idt_loader.Load(idt_reg); -- cgit v1.2.3