diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-07-10 01:13:08 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-07-10 01:13:08 +0200 |
| commit | 5f6549b7d46118ba416faa170ff088d98c9144f0 (patch) | |
| tree | 23d19bc039a547f27275065d96c52551d8ca989f /Kernel/HALKit/AMD64/Processor.hpp | |
| parent | dfaf137915094e7ba72f7d7f1f57dc5158d1b6ab (diff) | |
MHR-36: See below.
- Implement MSR functions has_msr, get_msr, set_msr.
- Moved SMP interrupt to interrupt 34 in AMD64.
- Fix syntax error in STB.hxx.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/HALKit/AMD64/Processor.hpp')
| -rw-r--r-- | Kernel/HALKit/AMD64/Processor.hpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hpp index 27c1bfbb..ff7045c2 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hpp @@ -19,6 +19,8 @@ #include <FirmwareKit/Handover.hxx> #include <HALKit/AMD64/HalPageAlloc.hpp> +#include <cpuid.h> + #ifdef kCPUBackendName #undef kCPUBackendName #endif // ifdef kCPUBackendName @@ -230,6 +232,30 @@ namespace Kernel::HAL Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress); Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress); + 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); + } + + inline Void hal_get_msr(UInt32 msr, UInt32* lo, UInt32* hi) noexcept + { + asm volatile("rdmsr" + : "=a"(*lo), "=d"(*hi) + : "c"(msr)); + } + + inline Void hal_set_msr(UInt32 msr, UInt32 lo, UInt32 hi) noexcept + { + asm volatile("wrmsr" + : + : "a"(lo), "d"(hi), "c"(msr)); + } + /// @brief Processor specific structures. namespace Detail { |
