diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-05-11 06:43:54 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-05-11 06:43:54 +0000 |
| commit | ca675beb41dba8d7d16c5793b55d1672f38be3b4 (patch) | |
| tree | c995ada42729ac2059a0ed87a4539d1a7e10b14a /Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | |
| parent | 2b4a4792abf51487ab4a16106f9376f43acf381a (diff) | |
| parent | bc57a29a24b98b00ba17710ba84ec2188ab73504 (diff) | |
Merged in MHR-23 (pull request #12)
MHR-23: Merge work.
Diffstat (limited to 'Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp')
| -rw-r--r-- | Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp new file mode 100644 index 00000000..470a3286 --- /dev/null +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -0,0 +1,123 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include <Builtins/ACPI/ACPIFactoryInterface.hxx> +#include <HALKit/AMD64/Processor.hpp> +#include <NewKit/KernelCheck.hpp> + +/////////////////////////////////////////////////////////////////////////////////////// + +//! NOTE: fGSI stands 'Field Global System Interrupt' + +/////////////////////////////////////////////////////////////////////////////////////// + +namespace NewOS::HAL +{ + constexpr Int32 kThreadAPIC = 0; + constexpr Int32 kThreadLAPIC = 1; + constexpr Int32 kThreadIOAPIC = 2; + constexpr Int32 kThreadAPIC64 = 3; + constexpr Int32 kThreadBoot = 4; + + /* + * + * this is used to store info about the current running thread + * we use this struct to determine if we can use it, or mark it as used or on + * sleep. + * + */ + + struct ProcessorInfoAMD64 final + { + Int32 ThreadType; + UIntPtr JumpAddress; + + struct + { + UInt32 Code; + UInt32 Data; + UInt32 BSS; + } Selector; + }; + + STATIC voidPtr kApicMadt = nullptr; + STATIC const char* kApicSignature = "APIC"; + + /// @brief Multiple APIC Descriptor Table. + struct MadtType final : public SDT + { + struct MadtAddress final + { + Char RecordType; + Char RecordLen; // record length + + UInt32 Address; + UInt32 Flags; // 1 = Dual Legacy PICs installed + } MadtRecords[]; + }; + + struct MadtProcessorLocalApic final + { + Char AcpiProcessorId; + Char Reserved; + UInt32 Flags; + }; + + struct MadtIOApic final + { + Char ApicId; + Char Reserved; + UInt32 Address; + UInt32 SystemInterruptBase; + }; + + struct MadtInterruptSource final + { + Char BusSource; + Char IrqSource; + UInt32 GSI; + UInt16 Flags; + }; + + struct MadtInterruptNmi final + { + Char NmiSource; + Char Reserved; + UInt16 Flags; + UInt32 GSI; + }; + + struct MadtLocalApicAddressOverride final + { + UInt16 Resvered; + UIntPtr Address; + }; + + /////////////////////////////////////////////////////////////////////////////////////// + + STATIC MadtType* kApicInfoBlock = nullptr; + + /////////////////////////////////////////////////////////////////////////////////////// + + void hal_system_get_cores(voidPtr rsdPtr) + { + auto acpi = ACPIFactoryInterface(rsdPtr); + kApicMadt = acpi.Find(kApicSignature).Leak().Leak(); + + if (kApicMadt) + { + kcout << "New OS: APIC is present...\r"; + kApicInfoBlock = (MadtType*)kApicMadt; + } + else + { + kcout << "New OS: APIC is not present! it is a vital component.\r"; + ke_stop(RUNTIME_CHECK_FAILED); + } + } +} // namespace NewOS::HAL + +/////////////////////////////////////////////////////////////////////////////////////// |
