summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-12-23 01:43:54 -0500
committerIan Moffett <ian@osmora.org>2025-12-23 01:43:54 -0500
commit172a14db53beb6554e8a8019d08986d466cb68c8 (patch)
tree4d3459afcdea7ddcfafecde737d8873903640b4b
parent722586d120c0bfdafdf74f2f0f93d3635fa36370 (diff)
mos/x86_64: msr: Add wrmsr/rdmsr helpers
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--mos/sys/inc/arch/x86_64/msr.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/mos/sys/inc/arch/x86_64/msr.h b/mos/sys/inc/arch/x86_64/msr.h
index 4ccf3c8..5c3e1d1 100644
--- a/mos/sys/inc/arch/x86_64/msr.h
+++ b/mos/sys/inc/arch/x86_64/msr.h
@@ -6,6 +6,8 @@
#ifndef _MACHINE_MSR_H_
#define _MACHINE_MSR_H_ 1
+#include <sdk/defs.h>
+
#define IA32_APIC_BASE 0x0000001B
#define IA32_GS_BASE 0xC0000101
#define IA32_MTRR_CAP 0x000000FE
@@ -15,4 +17,37 @@
#define IA32_KERNEL_GS_BASE 0xC0000102
#define IA32_EFER 0xC0000080
+#ifndef __ASSEMBLER__
+ALWAYS_INLINE static inline void
+md_wrmsr(ULONG msr, UQUAD v)
+{
+ ULONG lo, hi;
+
+ lo = v & 0xFFFFFFFF;
+ hi = (v >> 32) & 0xFFFFFFFF;
+
+ ASM(
+ "wrmsr"
+ :
+ : "c" (msr), "a" (lo), "d" (hi)
+ : "memory"
+ );
+}
+
+ALWAYS_INLINE static inline UQUAD
+md_rdmsr(ULONG msr)
+{
+ ULONG lo, hi;
+
+ ASM(
+ "rdmsr"
+ : "=a" (lo), "=d" (hi)
+ : "c" (msr)
+ : "memory"
+ );
+
+ return ((UQUAD)hi << 32) | lo;
+}
+
+#endif /* !__ASSEMBLER__ */
#endif /* !_MACHINE_MSR_H_ */