From fc0d38259fd6670966b916b1f28a11f3cb2a4c45 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 1 Jun 2024 09:29:31 +0200 Subject: MHR-23: SMP: Add hal_send_start_ipi and hal_send_end_ipi, as well as DMA utilities. Signed-off-by: Amlal El Mahrouss --- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx') diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index ff5372f4..f92554f8 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -7,6 +7,8 @@ #include #include #include +#include +#include namespace NewOS { @@ -73,28 +75,37 @@ namespace NewOS return ErrorOr{-4}; } - SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xFFF)); + /// FIXME + RSDT* xsdt = (RSDT*)rsdPtr->XsdtAddress; - SizeT num = -(xsdt->Length - sizeof(SDT)) / 8; + if (NewOS::HAL::ke_map_address((PDE*)hal_read_cr3(), rsdPtr->XsdtAddress, (UIntPtr)xsdt, NewOS::HAL::eFlagsRw)) + return ErrorOr{-5}; + + Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt64); + + if (num < 1) + { + return ErrorOr{-6}; + } this->fEntries = num; - kcout << "ACPI: Number of entries: " << number(num) << endl; + kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl; kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; - constexpr short ACPI_SIGNATURE_LENGTH = 4; + const short cAcpiSignatureLength = 4; for (Size index = 0; index < this->fEntries; ++index) { - SDT& sdt = xsdt[index]; + SDT* sdt = (SDT*)(xsdt->AddressArr[index]); - for (short signature_index = 0; signature_index < ACPI_SIGNATURE_LENGTH; ++signature_index) + for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index) { - if (sdt.Signature[signature_index] != signature[signature_index]) + if (sdt->Signature[signature_index] != signature[signature_index]) break; - if (signature_index == 4) - return ErrorOr(reinterpret_cast(&sdt)); + if (signature_index == (cAcpiSignatureLength - 1)) + return ErrorOr(reinterpret_cast(sdt)); } } -- cgit v1.2.3 From 5bc5e4de0d4dcfc52c192315ca5c59a066d678d8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 1 Jun 2024 23:59:03 +0200 Subject: MHR-23: Fix ACPI and APIC probe. Signed-off-by: Amlal El Mahrouss --- Kernel/Builtins/ACPI/ACPI.hxx | 2 +- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 18 +++++----- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 42 ++++++---------------- Kernel/HALKit/AMD64/Processor.hpp | 30 ++++++++-------- SDK/Libraries/CoreSystem/Headers/File.h | 5 +++ SDK/Libraries/CoreSystem/Sources/File.c | 13 ++++++- 6 files changed, 54 insertions(+), 56 deletions(-) (limited to 'Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx') diff --git a/Kernel/Builtins/ACPI/ACPI.hxx b/Kernel/Builtins/ACPI/ACPI.hxx index d9bfeaca..430a39f4 100644 --- a/Kernel/Builtins/ACPI/ACPI.hxx +++ b/Kernel/Builtins/ACPI/ACPI.hxx @@ -81,7 +81,7 @@ namespace NewOS UInt32 OemRev; UInt32 CreatorID; UInt32 CreatorRevision; - UInt64 AddressArr[]; + UInt32 AddressArr[]; }; } // namespace NewOS diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index f92554f8..adeeb10d 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -76,36 +76,38 @@ namespace NewOS } /// FIXME - RSDT* xsdt = (RSDT*)rsdPtr->XsdtAddress; + RSDT* xsdt = (RSDT*)(rsdPtr->RsdtAddress); - if (NewOS::HAL::ke_map_address((PDE*)hal_read_cr3(), rsdPtr->XsdtAddress, (UIntPtr)xsdt, NewOS::HAL::eFlagsRw)) - return ErrorOr{-5}; - - Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt64); + Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt32); if (num < 1) { + kcout << "ACPI: No entries." << endl; return ErrorOr{-6}; } this->fEntries = num; kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl; + kcout << "ACPI: Revision: " << number(xsdt->Revision) << endl; + kcout << "ACPI: XSDT: " << xsdt->Signature << endl; kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; const short cAcpiSignatureLength = 4; for (Size index = 0; index < this->fEntries; ++index) { - SDT* sdt = (SDT*)(xsdt->AddressArr[index]); + SDT& sdt = *(SDT*)xsdt->AddressArr[index]; + + kcout << "ACPI: Revision: " << number(sdt.CreatorID) << endl; for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index) { - if (sdt->Signature[signature_index] != signature[signature_index]) + if (sdt.Signature[signature_index] != signature[signature_index]) break; if (signature_index == (cAcpiSignatureLength - 1)) - return ErrorOr(reinterpret_cast(sdt)); + return ErrorOr(reinterpret_cast(&sdt)); } } diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 287b1882..5ab40532 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -137,37 +137,17 @@ namespace NewOS::HAL if (kApicMadt != nullptr) { - auto madt = (SDT*)kApicMadt; - - const UInt8* madt_end = (const UInt8*)madt + madt->Length; - const UInt8* entry_ptr = (const UInt8*)(madt + 1); - - while (entry_ptr < madt_end) - { - const MadtType::MadtAddress* entry_header = (const MadtType::MadtAddress*)entry_ptr; - - switch (entry_header->Flags) - { - case 0: { - const MadtProcessorLocalApic* local_apic = (const MadtProcessorLocalApic*)entry_ptr; - if (local_apic->Flags & 1) - { - // Processor is enabled - kcout << "Processor ID: %d, APIC ID: %d\n" - << number(local_apic->AcpiProcessorId) << number(local_apic->ApicId); - } - break; - } - default: - break; - } - - entry_ptr += entry_header->RecordLen; - } - - while (true) - { - } + MadtType* madt = (MadtType*)kApicMadt; + + constexpr auto cMaxProbableCores = 4; + + for (SizeT i = 0; i < cMaxProbableCores; ++i) + { + if (madt->MadtRecords[i].Flags == 0x01) // if local apic. + { + // then register as a core for scheduler. + } + } } else { diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hpp index 608a502f..4916d845 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hpp @@ -74,24 +74,27 @@ namespace NewOS::HAL if (!pde->Pte[pml4_index].Present) { pde->Pte[pml4_index].Present = true; - kcout << "PM: It is present now.\r"; + kcout << "PM is present now.\r"; + + pde->Pte[pml4_index].PhysicalAddress = phys_addr; + pde->Pte[pml4_index].Rw = flags & eFlagsRw; + pde->Pte[pml4_index].User = flags & eFlagsUser; + pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable; + + return 0; } else { - kcout << "PM: It is already present.\r"; - kcout << "Address? " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl; - kcout << "User? " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r"; - kcout << "RW? " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r"; + kcout << "PM is already present.\r"; - return 1; - } + kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl; + kcout << "User: " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r"; + kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r"; - pde->Pte[pml4_index].PhysicalAddress = phys_addr; - pde->Pte[pml4_index].Rw = flags & eFlagsRw; - pde->Pte[pml4_index].User = flags & eFlagsUser; - pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable; + return 1; + } - return 0; + return 0; } /// @brief Map address to PDE. @@ -102,9 +105,6 @@ namespace NewOS::HAL inline void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags) { UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; - UInt16 pdpt_index = (virt_addr >> 30) & 0x1FF; - UInt16 pd_index = (virt_addr >> 21) & 0x1FF; - UInt16 pt_index = (virt_addr >> 12) & 0x1FF; if (pde->Pte[pml4_index].Present) { diff --git a/SDK/Libraries/CoreSystem/Headers/File.h b/SDK/Libraries/CoreSystem/Headers/File.h index 0013b074..cfd9ee30 100644 --- a/SDK/Libraries/CoreSystem/Headers/File.h +++ b/SDK/Libraries/CoreSystem/Headers/File.h @@ -49,4 +49,9 @@ CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); /// @return if not return false, or true. CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); +/// @brief Flush file +/// @param refCS the file reference. +/// @return +CS_EXTERN_C VoidType CSFlushFile(FSRef refCS); + /// END OF FILE diff --git a/SDK/Libraries/CoreSystem/Sources/File.c b/SDK/Libraries/CoreSystem/Sources/File.c index 7547e7f2..6e0e810a 100644 --- a/SDK/Libraries/CoreSystem/Sources/File.c +++ b/SDK/Libraries/CoreSystem/Sources/File.c @@ -38,10 +38,21 @@ CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) { CS_MUST_PASS(kSharedApplication); - kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); + CSFlushFile(refCS); + kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); } +/// @brief Flush file +/// @param refCS the file reference. +/// @return +CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) +{ + CS_MUST_PASS(kSharedApplication); + + kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); +} + /// @brief Check if filesystem path is valid. /// @param path /// @return -- cgit v1.2.3 From c34c46598c12b04b2877aa7290dd401cc40a29e3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 2 Jun 2024 09:00:18 +0200 Subject: ACPI: even error codes. Signed-off-by: Amlal El Mahrouss --- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 17 ++++++++--------- SDK/Libraries/CoreSystem/Headers/Defines.h | 4 ++-- SDK/Libraries/CoreSystem/Headers/Math.h | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx') diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index adeeb10d..7bdec117 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -63,17 +63,15 @@ namespace NewOS MUST_PASS(fRsdp); if (!signature) - return ErrorOr{-2}; + return ErrorOr{-1}; if (*signature == 0) - return ErrorOr{-3}; + return ErrorOr{-1}; RSDP* rsdPtr = reinterpret_cast(this->fRsdp); if (rsdPtr->Revision <= 1) - { - return ErrorOr{-4}; - } + return ErrorOr{-1}; /// FIXME RSDT* xsdt = (RSDT*)(rsdPtr->RsdtAddress); @@ -82,15 +80,16 @@ namespace NewOS if (num < 1) { - kcout << "ACPI: No entries." << endl; - return ErrorOr{-6}; + /// stop here, we should have entries... + ke_stop(RUNTIME_CHECK_ACPI); + return ErrorOr{-1}; } this->fEntries = num; kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl; kcout << "ACPI: Revision: " << number(xsdt->Revision) << endl; - kcout << "ACPI: XSDT: " << xsdt->Signature << endl; + kcout << "ACPI: Signature: " << xsdt->Signature << endl; kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; const short cAcpiSignatureLength = 4; @@ -111,7 +110,7 @@ namespace NewOS } } - return ErrorOr{nullptr}; + return ErrorOr{-1}; } /*** diff --git a/SDK/Libraries/CoreSystem/Headers/Defines.h b/SDK/Libraries/CoreSystem/Headers/Defines.h index a7e46234..713d6df8 100644 --- a/SDK/Libraries/CoreSystem/Headers/Defines.h +++ b/SDK/Libraries/CoreSystem/Headers/Defines.h @@ -32,6 +32,8 @@ #endif +#include + struct ApplicationInterface; struct GUID; @@ -231,5 +233,3 @@ typedef CharacterTypeUTF8 StrType255[255]; #ifndef kInvalidRef #define kInvalidRef 0 #endif - -#include diff --git a/SDK/Libraries/CoreSystem/Headers/Math.h b/SDK/Libraries/CoreSystem/Headers/Math.h index 0a13e86f..0079803e 100644 --- a/SDK/Libraries/CoreSystem/Headers/Math.h +++ b/SDK/Libraries/CoreSystem/Headers/Math.h @@ -9,7 +9,7 @@ #include /////////////////////////////////////////////////////////////////////// -/// Random functions /// +/// Random number generators functions /// /////////////////////////////////////////////////////////////////////// /// @brief Number generator helper. -- cgit v1.2.3 From 2cecacfe4f0cbbd8869cbd2c93a2f943aabd44ad Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 3 Jun 2024 00:14:06 +0200 Subject: MHR-23: remove FIXME. Signed-off-by: Amlal El Mahrouss --- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 1 - Kernel/KernelKit/ProcessScheduler.hxx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx') diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index 7bdec117..14241f60 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -73,7 +73,6 @@ namespace NewOS if (rsdPtr->Revision <= 1) return ErrorOr{-1}; - /// FIXME RSDT* xsdt = (RSDT*)(rsdPtr->RsdtAddress); Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt32); diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 33c9f313..bd8cb628 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -14,7 +14,7 @@ #include #include -#define kSchedMinMicroTime AffinityKind::kHartStandard +#define kSchedMinMicroTime (AffinityKind::kHartStandard) #define kSchedInvalidPID (-1) #define kSchedProcessLimitPerTeam (100U) -- cgit v1.2.3