Page 1 of 1

Detecting Model-Specific Registers

Posted: Fri Jan 03, 2025 2:32 pm
by chicken
When setting up paging I decided to utilize the No-eXecute feature if available. To do so I first check if the cpuid instruction is available. If so, I use it to check for the MSR feature (CPUID.01h:EDX[bit 5]). This give me information of whether MSRs are supported at all, but it doesnt give me a specific overview of which registers are available on the current CPU. In order to check if EFER is supported I use cpuid again (CPUID.01h:EDX[bit 20]) this time to see if NX is enabled.

I was wondering, whether there is some way to list the available MSRs of the current CPU or if it is only described in online specifications, therefore making a check with cpuid (like for NX and EFER) needed.

Thanks for the support! :D

Re: Detecting Model-Specific Registers

Posted: Fri Jan 03, 2025 2:56 pm
by CodePoet2005
Some model specific registers are architectual (see amd64 system programming manual appendix a(msr cross-reference).
Others are model specific, you can use CPUID to get the cpu vendor string, famlily model etc.
If i rembember correctly you can get this values with CPUID EAX = 1.
Also some msrs are pressent if your cpu has certain features (for example apic), you can also detect this with cpuid. As far that i know there is no cpuid function to detect model specific registers. You have to detect the cpu model (and features).

Happy programming :)

Re: Detecting Model-Specific Registers

Posted: Fri Jan 03, 2025 3:14 pm
by Octocontrabass
You always need to check CPUID. A list of available MSRs doesn't tell you what any of those MSRs do.

If you really want a list of MSRs, you could try reading all of them and see which ones don't cause #GP.