Model Specific Registers: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(code was wrong didnot compile)
Line 3: Line 3:
== Accessing Model Specific Registers ==
== Accessing Model Specific Registers ==


Each MSR has a single 32-bit identification number that will be given to RDMSR or WRMSR assembly instructions to operate it. MSRs are 64-bit wide. The presence of MSRs on your processor is indicated by bit 5 of CPUID features.
Each MSR has a single 32-bit identification number that will be given to RDMSR or WRMSR assembly instructions to operate it. MSRs are 64-bit wide. The presence of MSRs on your processor is indicated by [[CPUID]].01h:EDX[bit 5].


<source lang="c">
<pre>
boolean cpuHasMSR()
boolean cpuHasMSR()
{
{
Line 22: Line 22:
asm volatile("wrmsr"::"a"(lo),"d"(hi),"c"(msr));
asm volatile("wrmsr"::"a"(lo),"d"(hi),"c"(msr));
}
}
</pre>
</source>


==See Also==
==See Also==

Revision as of 18:12, 19 January 2011

Processors from P6 family (including Pentium PRO, Pentium 3 & 4) have a collection of registers that allows configuration of various things such as memory type-range, sysenter/sysexit, local APIC, etc.

Accessing Model Specific Registers

Each MSR has a single 32-bit identification number that will be given to RDMSR or WRMSR assembly instructions to operate it. MSRs are 64-bit wide. The presence of MSRs on your processor is indicated by CPUID.01h:EDX[bit 5].

boolean cpuHasMSR()
{
   dword a,d;
   cpuid(1,&a,&d);
   return d&CPUID_FLAG_MSR;
}

void cpuGetMSR(dword msr, dword *lo, dword *hi)
{
   asm volatile("rdmsr":"=a"(*lo),"=d"(*hi):"c"(msr));
}

void cpuSetMSR(dword msr, dword lo, dword hi)
{
   asm volatile("wrmsr"::"a"(lo),"d"(hi),"c"(msr));
}

See Also

Articles

External Links