Model Specific Registers: Difference between revisions

Jump to navigation Jump to search
m
Minor cleanup
[unchecked revision][unchecked revision]
m (Fixed link)
m (Minor cleanup)
Line 1:
Processors from the P6 family onwards (including Pentium PROPentiumPro, Pentium 3II, &III, 4 and Intel Core) have a collection of registers that allowsallow configuration of variousOS-relevant things such as memory type-range, sysenter/sysexit, local APIC, etc.
These '''MSRs''' are accessed using special instructions such as RDMSR (Read MSR), WRMSR (Write MSR), and RDTSC.
 
== Accessing Model Specific Registers ==
 
Each MSR hasthat ais singleaccessed 32-bitby identificationthe numberRDMSR thatand willWRMSR begroup givenof toinstructions RDMSRis oridentified WRMSRby assemblya instructions to operate32-bit itinteger. MSRs are 64-bit wide. The presence of MSRs on your processor is indicated by [[CPUID]].01h:EDX[bit 5].
 
<source lang="c">
 
const uint32_t CPUID_FLAG_MSR = 1 << 5;
 
bool cpuHasMSR()
{
uint32_t a, d; // eax, edx
cpuid(1, &a, &d);
return d & CPUID_FLAG_MSR;
Line 15 ⟶ 19:
void cpuGetMSR(uint32_t msr, uint32_t *lo, uint32_t *hi)
{
asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
}
 
void cpuSetMSR(uint32_t msr, uint32_t lo, uint32_t hi)
{
asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
}
</source>
 
===Other accessway to access MSRs===
 
As <code>rdmsr</code> and <code>wrmsr</code> are privelegedprivileged instructions. However, there are a few MSRs whichthat arecan deemedbe safeaccessed forfrom non-privelegedprivileged accesscode using special instructions. For example, the <code>rdtsc</code> instruction is a non priveleged-privileged instruction whichthat will readreads the timestamp counter, which is actually situated in an MSR (index 10h).
 
==See Also==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu