Просмотр исходного кода

[x86_64] Add functions to read and write model-specific registers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 лет назад
Родитель
Сommit
5888c887a4
1 измененных файлов: 43 добавлений и 0 удалений
  1. 43
    0
      src/arch/x86_64/include/ipxe/msr.h

+ 43
- 0
src/arch/x86_64/include/ipxe/msr.h Просмотреть файл

@@ -0,0 +1,43 @@
1
+#ifndef _IPXE_MSR_H
2
+#define _IPXE_MSR_H
3
+
4
+/** @file
5
+ *
6
+ * Model-specific registers
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+/**
13
+ * Read model-specific register
14
+ *
15
+ * @v msr		Model-specific register
16
+ * @ret value		Value
17
+ */
18
+static inline __attribute__ (( always_inline )) uint64_t
19
+rdmsr ( unsigned int msr ) {
20
+	uint32_t high;
21
+	uint32_t low;
22
+
23
+	__asm__ __volatile__ ( "rdmsr" :
24
+			       "=d" ( high ), "=a" ( low ) : "c" ( msr ) );
25
+	return ( ( ( ( uint64_t ) high ) << 32 ) | low );
26
+}
27
+
28
+/**
29
+ * Write model-specific register
30
+ *
31
+ * @v msr		Model-specific register
32
+ * @v value		Value
33
+ */
34
+static inline __attribute__ (( always_inline )) void
35
+wrmsr ( unsigned int msr, uint64_t value ) {
36
+	uint32_t high = ( value >> 32 );
37
+	uint32_t low = ( value >> 0 );
38
+
39
+	__asm__ __volatile__ ( "wrmsr" : :
40
+			       "c" ( msr ), "d" ( high ), "a" ( low ) );
41
+}
42
+
43
+#endif /* _IPXE_MSR_H */

Загрузка…
Отмена
Сохранить