From: acevest Date: Sat, 11 May 2024 14:37:44 +0000 (+0800) Subject: 添加rdmsr X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=40a46ae2c7fa62a5e7d1315b8f46010fc0807fbc;p=kernel.git 添加rdmsr --- diff --git a/include/msr.h b/include/msr.h index 41ee5cd..7348d77 100644 --- a/include/msr.h +++ b/include/msr.h @@ -17,13 +17,39 @@ #ifndef _MSR_H #define _MSR_H +#include + #define MSR_SYSENTER_CS 0x174 #define MSR_SYSENTER_ESP 0x175 #define MSR_SYSENTER_EIP 0x176 +#define MSR_IA32_PERF_STATUS 0x198 +#define MSR_IA32_PERF_CRTL 0x199 + +#define rdmsr(msr, lowval, highval) \ + do { \ + asm("rdmsr;" : "=a"(lowval), "=d"(highval) : "c"(msr)); \ + } while (0) + #define wrmsr(msr, lowval, highval) \ do { \ asm("wrmsr;" ::"c"(msr), "a"(lowval), "d"(highval)); \ - } while (0); + } while (0) + +static inline uint64_t read_msr(uint32_t msr) { + uint32_t lowval = 0; + uint32_t highval = 0; + + rdmsr(msr, lowval, highval); + + return ((uint64_t)highval << 32) | lowval; +} + +static inline void write_msr(uint32_t msr, uint64_t value) { + uint32_t lowval = value & 0xFFFFFFFF; + uint32_t highval = value >> 32; + + wrmsr(msr, lowval, highval); +} #endif //_MSR_H