Compile rdmsr and wrmsr

Source: Internet
Author: User
Compile rdmsr and wrmsr

1. MSR Overview

Model specific register (MSR) as the name implies is model specific and may change from processor model number (n) to processor model number (n + 1 ).

MSR is designed to set the CPU working environment and indicate the CPU running status, including temperature control and performance monitoring. Specifically, it is divided into the following items:

1. Thermal

2. Frequency

3. c state

4. microcode

5. eist

6. TM

7. Key features of CPU

8. Voltage

9. Cache Control

10. mtrr

11. DCA (direct cache access)

12. Machine check

13. Online hardware control

14. Other

2. Introduction to assembly instructions

MSR is a set of 64-bit registers of the CPU. Read and Write operations can be performed by using rdmsr and wrmsr commands respectively, provided that the MSR address is written to ECx. MSR commands must be executed in level 0 or real mode.

Rdmsr read mode definition register. For the rdmsr command, 64bit information in the corresponding MSR will be returned to the (EDX: eax) Register.

Wrmsr write mode definition register. For the wrmsr command, save the information to be written to (EDX: eax). After executing the write command, you can save the corresponding information to the MSR specified by ECx.

I used the cpuid command to detect that the instruction set of my processor is 3 and the value is less than 6,
This is definitely unable to use the rdmsr command that appears after 586.
But I did not give up, so I finally found it in the mighty ntddk document.
An API called x86_readrdmsr,
This API has two parameters and I don't know how to use them,
But I tried to call this function in the driver,
Invoke x86_readrdms R, 101 H, offset Buffer
As expected, the call was successful and the address of service no. 101h was read.
It seems that we should try not to use hard encoding in the program, but use the system to provide good
API. Otherwise, the program you write cannot run on another machine. What is the value of the program...
In the randlibk. inc header file in the masm32 SDK, I found the x86_readrdmsr _ ASM {
Movecx, 119 H
Rdmsr
Or eax, 00200000 H
Wrmsr
} Rdmsr-read from model specific register
Description
Loads the contents of a 64-bit model specific register (MSR) specified in the ECX Register
Registers edX: eax. The edX register is loaded with the high-order 32 bits of the MSR and
Eax register is loaded with the low-order 32 bits. If less than 64 bits are implemented in
MSR being read, the values returned to edX: eax in unimplemented bit locations are unde-fined.
This instruction must be executed at privilege level 0 or in real-address mode; otherwise,
General protection exception # GP (0) will be generated. specifying a reserved or unimplemented
MSR address in ECX will also cause a general protection exception.
The MSRs control functions for testability, execution tracing, performance-monitoring and
Machine check errors. Appendix B, model-specific registers (MSRs), In the Intel architecture
Software Developer's manual, Volume 3, lists all the MSRs that can be read with this instruction
And their addresses.
The cpuid instruction shocould be used to determine whether MSRs are supported (EDX [5] = 1)
Before using this instruction.
Intel architecture compatibility
The MSRs and the ability to read them with the rdmsr instruction were introduced into
Intel architecture with the Pentium processor. Execution of this instruction by an Intel archi-tecture processor earlier than the Pentium processor results in an invalid opcode exception # Ud.
Operation
EdX: eax ← MSR [ECx];
Flags affected
None.
Protected Mode exceptions
# GP (0) if the current privilege level is not 0.
If the value in ECx specifies a reserved or unimplemented MSR address.
Real-address mode exceptions
# GP if the value in ECx specifies a reserved or unimplemented MSR address.
Opcode instruction description
0f 32 rdmsr load MSR specified by ECx into edX: eax
3-400
Instruction Set Reference
Rdmsr-read from model specific register (continued)
Virtual-8086 mode exceptions
# GP (0) The rdmsr instruction is not recognized in virtual-8086 mode.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.