]> Zhao Yanbai Git Server - kernel.git/commitdiff
添加rdmsr
authoracevest <zhaoyanbai@126.com>
Sat, 11 May 2024 14:37:44 +0000 (22:37 +0800)
committeracevest <zhaoyanbai@126.com>
Sat, 11 May 2024 14:37:44 +0000 (22:37 +0800)
include/msr.h

index 41ee5cd31de2ab2e1745397b7187e5a38dba6984..7348d7793be86b1271ee51606627d822bc5a55b1 100644 (file)
 #ifndef _MSR_H
 #define _MSR_H
 
+#include <types.h>
+
 #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