Skip to contentSkip to conversation

x86: define macros CPUINFO_features and CPUINFO_FEATURE_OFFSET

PATCH Superseded Feng Wu 1 participant 1 message May 5, 2014

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Feng Wu

author
#0 lore raw

PATCH v4 1/10 x86: define macros CPUINFO_features and CPUINFO_FEATURE_OFFSET

This patch defines macros CPUINFO_features and CPUINFO_FEATURE_OFFSET. CPUINFO_features can be used as the base of the offset for cpu features, while CPUINFO_FEATURE_OFFSET is used to define the right offset for specific CPU feature.

---
 xen/arch/x86/boot/head.S          | 3 ++-
 xen/arch/x86/x86_64/asm-offsets.c | 2 +-
 xen/include/asm-x86/asm_defns.h   | 6 ++++++
 xen/include/asm-x86/cpufeature.h  | 4 ++++
 4 files changed, 13 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +2 -1
index 1777c17..a2eabb9 100644
@@ -6,6 +6,7 @@
 #include <asm/fixmap.h>
 #include <asm/page.h>
 #include <asm/msr.h>
+#include <asm/cpufeature.h>
 
         .text
         .code32
@@ -131,7 +132,7 @@ __start:
         mov     $0x80000001,%eax
         cpuid
 1:      mov     %edx,sym_phys(cpuid_ext_features)
-        mov     %edx,sym_phys(boot_cpu_data)+CPUINFO86_ext_features
+        mov     %edx,sym_phys(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM)
 
         /* Check for availability of long mode. */
         bt      $29,%edx
xen/arch/x86/x86_64/asm-offsets.c +1 -1
index b0098b3..76fafb9 100644
@@ -159,7 +159,7 @@ void __dummy__(void)
     OFFSET(IRQSTAT_softirq_pending, irq_cpustat_t, __softirq_pending);
     BLANK();
 
-    OFFSET(CPUINFO86_ext_features, struct cpuinfo_x86, x86_capability[1]);
+    OFFSET(CPUINFO_features, struct cpuinfo_x86, x86_capability[0]);
     BLANK();
 
     OFFSET(MB_flags, multiboot_info_t, flags);
xen/include/asm-x86/asm_defns.h +6 -0
index a4601ba..3babbe2 100644
@@ -77,6 +77,9 @@ void ret_from_intr(void);
 #define ASSERT_NOT_IN_ATOMIC
 #endif
 
+#define CPUINFO_FEATURE_OFFSET(feature)           \
+        (((feature >> 3) & ~3) + CPUINFO_features)
+
 #else
 
 #ifdef __clang__ /* clang's builtin assember can't do .subsection */
@@ -101,6 +104,9 @@ void ret_from_intr(void);
         UNLIKELY_END_SECTION "\n"          \
         ".Llikely%=.tag:"
 
+#define CPUINFO_FEATURE_OFFSET(feature)                  \
+        "(((" __stringify(feature) ">> 3) & ~3) + "      \
+        __stringify(CPUINFO_features)")"
 #endif
 
 #endif /* __X86_ASM_DEFNS_H__ */
xen/include/asm-x86/cpufeature.h +4 -0
index 0c4d6c1..3dfb875 100644
@@ -7,7 +7,9 @@
 #ifndef __ASM_I386_CPUFEATURE_H
 #define __ASM_I386_CPUFEATURE_H
 
+#ifndef __ASSEMBLY__
 #include <xen/bitops.h>
+#endif
 
 #define NCAPINTS	8	/* N 32-bit words worth of info */
 
@@ -151,6 +153,7 @@
 #define X86_FEATURE_ADX		(7*32+19) /* ADCX, ADOX instructions */
 #define X86_FEATURE_SMAP	(7*32+20) /* Supervisor Mode Access Prevention */
 
+#ifndef __ASSEMBLY__
 #define cpu_has(c, bit)		test_bit(bit, (c)->x86_capability)
 #define boot_cpu_has(bit)	test_bit(bit, boot_cpu_data.x86_capability)
 #define cpufeat_mask(idx)       (1u << ((idx) & 31))
@@ -209,6 +212,7 @@
 #define cpu_has_vmx		boot_cpu_has(X86_FEATURE_VMXE)
 
 #define cpu_has_cpuid_faulting	boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
+#endif
 
 #endif /* __ASM_I386_CPUFEATURE_H */
 
Signature · 1 line
1.8.3.1