diff options
| author | Ada Christine <adachristine18@gmail.com> | 2025-01-31 00:48:54 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2025-01-31 00:48:54 +0000 |
| commit | 2fb3f208bd2e739a8968afb23d22e13b6660ca22 (patch) | |
| tree | 4bf02b06ed27c2726f675f752e064211df934323 /lib/asm/x86_64/msr.c | |
| parent | 0d2ddecc9aeb232746b76b4eebdb1381053a8951 (diff) | |
spread around defs, x86 asm and bits libs
Diffstat (limited to 'lib/asm/x86_64/msr.c')
| -rw-r--r-- | lib/asm/x86_64/msr.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/asm/x86_64/msr.c b/lib/asm/x86_64/msr.c new file mode 100644 index 0000000..2dfdc44 --- /dev/null +++ b/lib/asm/x86_64/msr.c @@ -0,0 +1,30 @@ +#include <asm/x86_64/msr.h> + +void msr_write(uint32_t index, uint64_t value) +{ + uint32_t low = value & 0xffffffff; + uint32_t high = value >> 32; + + __asm__ volatile + ( + "wrmsr\n\t" + : + : "a"(low), "d"(high), "c"(index) + ); +} + +uint64_t msr_read(uint32_t index) +{ + uint32_t low; + uint32_t high; + + __asm__ volatile + ( + "rdmsr\n\t" + : "=a"(low), "=d"(high) + : "c"(index) + ); + + return ((uint64_t)high << 32)|low; +} + |
