Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[x86_64] Add functions to read and write model-specific registers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef _IPXE_MSR_H | ||
#define _IPXE_MSR_H | ||
|
||
/** @file | ||
* | ||
* Model-specific registers | ||
* | ||
*/ | ||
|
||
FILE_LICENCE ( GPL2_OR_LATER ); | ||
|
||
/** | ||
* Read model-specific register | ||
* | ||
* @v msr Model-specific register | ||
* @ret value Value | ||
*/ | ||
static inline __attribute__ (( always_inline )) uint64_t | ||
rdmsr ( unsigned int msr ) { | ||
uint32_t high; | ||
uint32_t low; | ||
|
||
__asm__ __volatile__ ( "rdmsr" : | ||
"=d" ( high ), "=a" ( low ) : "c" ( msr ) ); | ||
return ( ( ( ( uint64_t ) high ) << 32 ) | low ); | ||
} | ||
|
||
/** | ||
* Write model-specific register | ||
* | ||
* @v msr Model-specific register | ||
* @v value Value | ||
*/ | ||
static inline __attribute__ (( always_inline )) void | ||
wrmsr ( unsigned int msr, uint64_t value ) { | ||
uint32_t high = ( value >> 32 ); | ||
uint32_t low = ( value >> 0 ); | ||
|
||
__asm__ __volatile__ ( "wrmsr" : : | ||
"c" ( msr ), "d" ( high ), "a" ( low ) ); | ||
} | ||
|
||
#endif /* _IPXE_MSR_H */ |