ladybird/Kernel/Arch/x86/MSR.h
Gunnar Beutner 04a912f68f Kernel: Hide the implementation detail that MSRs use two registers
When retrieving and setting x86 MSRs two registers are required. The
existing setter and getter for the MSR class made this implementation
detail visible to the caller. This changes the setter and getter to
use u64 instead.
2021-07-04 01:07:28 +02:00

50 lines
870 B
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/Arch/x86/CPUID.h>
namespace Kernel {
class MSR {
uint32_t m_msr;
public:
static bool have()
{
CPUID id(1);
return (id.edx() & (1 << 5)) != 0;
}
MSR(const MSR&) = delete;
MSR& operator=(const MSR&) = delete;
MSR(uint32_t msr)
: m_msr(msr)
{
}
[[nodiscard]] u64 get()
{
u32 low, high;
asm volatile("rdmsr"
: "=a"(low), "=d"(high)
: "c"(m_msr));
return ((u64)high << 32) | low;
}
void set(u64 value)
{
u32 low = value & 0xffffffff;
u32 high = value >> 32;
asm volatile("wrmsr" ::"a"(low), "d"(high), "c"(m_msr));
}
};
}