x86: add and use *_BIT constants for CR0, CR4, EFLAGS
The "BIT" macro cannot be used in top-level assembly statements
(it can be used in functions through the "i" constraint), because
old binutils such as the one in CentOS 7 do not support the "1UL"
syntax for numerals.
To avoid having to hard-code EFLAGS.AC being bit 18, define the constants
for CR0, CR4 and EFLAGS bits in terms of new macros for just the bit
number.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index fb87198..0324220 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -31,67 +31,119 @@
#define AC_VECTOR 17
#define CP_VECTOR 21
-#define X86_CR0_PE BIT(0)
-#define X86_CR0_MP BIT(1)
-#define X86_CR0_EM BIT(2)
-#define X86_CR0_TS BIT(3)
-#define X86_CR0_ET BIT(4)
-#define X86_CR0_NE BIT(5)
-#define X86_CR0_WP BIT(16)
-#define X86_CR0_AM BIT(18)
-#define X86_CR0_NW BIT(29)
-#define X86_CR0_CD BIT(30)
-#define X86_CR0_PG BIT(31)
+#define X86_CR0_PE_BIT (0)
+#define X86_CR0_PE BIT(X86_CR0_PE_BIT)
+#define X86_CR0_MP_BIT (1)
+#define X86_CR0_MP BIT(X86_CR0_MP_BIT)
+#define X86_CR0_EM_BIT (2)
+#define X86_CR0_EM BIT(X86_CR0_EM_BIT)
+#define X86_CR0_TS_BIT (3)
+#define X86_CR0_TS BIT(X86_CR0_TS_BIT)
+#define X86_CR0_ET_BIT (4)
+#define X86_CR0_ET BIT(X86_CR0_ET_BIT)
+#define X86_CR0_NE_BIT (5)
+#define X86_CR0_NE BIT(X86_CR0_NE_BIT)
+#define X86_CR0_WP_BIT (16)
+#define X86_CR0_WP BIT(X86_CR0_WP_BIT)
+#define X86_CR0_AM_BIT (18)
+#define X86_CR0_AM BIT(X86_CR0_AM_BIT)
+#define X86_CR0_NW_BIT (29)
+#define X86_CR0_NW BIT(X86_CR0_NW_BIT)
+#define X86_CR0_CD_BIT (30)
+#define X86_CR0_CD BIT(X86_CR0_CD_BIT)
+#define X86_CR0_PG_BIT (31)
+#define X86_CR0_PG BIT(X86_CR0_PG_BIT)
#define X86_CR3_PCID_MASK GENMASK(11, 0)
-#define X86_CR4_VME BIT(0)
-#define X86_CR4_PVI BIT(1)
-#define X86_CR4_TSD BIT(2)
-#define X86_CR4_DE BIT(3)
-#define X86_CR4_PSE BIT(4)
-#define X86_CR4_PAE BIT(5)
-#define X86_CR4_MCE BIT(6)
-#define X86_CR4_PGE BIT(7)
-#define X86_CR4_PCE BIT(8)
-#define X86_CR4_OSFXSR BIT(9)
-#define X86_CR4_OSXMMEXCPT BIT(10)
-#define X86_CR4_UMIP BIT(11)
-#define X86_CR4_LA57 BIT(12)
-#define X86_CR4_VMXE BIT(13)
-#define X86_CR4_SMXE BIT(14)
-/* UNUSED BIT(15) */
-#define X86_CR4_FSGSBASE BIT(16)
-#define X86_CR4_PCIDE BIT(17)
-#define X86_CR4_OSXSAVE BIT(18)
-#define X86_CR4_KL BIT(19)
-#define X86_CR4_SMEP BIT(20)
-#define X86_CR4_SMAP BIT(21)
-#define X86_CR4_PKE BIT(22)
-#define X86_CR4_CET BIT(23)
-#define X86_CR4_PKS BIT(24)
+#define X86_CR4_VME_BIT (0)
+#define X86_CR4_VME BIT(X86_CR4_VME_BIT)
+#define X86_CR4_PVI_BIT (1)
+#define X86_CR4_PVI BIT(X86_CR4_PVI_BIT)
+#define X86_CR4_TSD_BIT (2)
+#define X86_CR4_TSD BIT(X86_CR4_TSD_BIT)
+#define X86_CR4_DE_BIT (3)
+#define X86_CR4_DE BIT(X86_CR4_DE_BIT)
+#define X86_CR4_PSE_BIT (4)
+#define X86_CR4_PSE BIT(X86_CR4_PSE_BIT)
+#define X86_CR4_PAE_BIT (5)
+#define X86_CR4_PAE BIT(X86_CR4_PAE_BIT)
+#define X86_CR4_MCE_BIT (6)
+#define X86_CR4_MCE BIT(X86_CR4_MCE_BIT)
+#define X86_CR4_PGE_BIT (7)
+#define X86_CR4_PGE BIT(X86_CR4_PGE_BIT)
+#define X86_CR4_PCE_BIT (8)
+#define X86_CR4_PCE BIT(X86_CR4_PCE_BIT)
+#define X86_CR4_OSFXSR_BIT (9)
+#define X86_CR4_OSFXSR BIT(X86_CR4_OSFXSR_BIT)
+#define X86_CR4_OSXMMEXCPT_BIT (10)
+#define X86_CR4_OSXMMEXCPT BIT(X86_CR4_OSXMMEXCPT_BIT)
+#define X86_CR4_UMIP_BIT (11)
+#define X86_CR4_UMIP BIT(X86_CR4_UMIP_BIT)
+#define X86_CR4_LA57_BIT (12)
+#define X86_CR4_LA57 BIT(X86_CR4_LA57_BIT)
+#define X86_CR4_VMXE_BIT (13)
+#define X86_CR4_VMXE BIT(X86_CR4_VMXE_BIT)
+#define X86_CR4_SMXE_BIT (14)
+#define X86_CR4_SMXE BIT(X86_CR4_SMXE_BIT)
+/* UNUSED (15) */
+#define X86_CR4_FSGSBASE_BIT (16)
+#define X86_CR4_FSGSBASE BIT(X86_CR4_FSGSBASE_BIT)
+#define X86_CR4_PCIDE_BIT (17)
+#define X86_CR4_PCIDE BIT(X86_CR4_PCIDE_BIT)
+#define X86_CR4_OSXSAVE_BIT (18)
+#define X86_CR4_OSXSAVE BIT(X86_CR4_OSXSAVE_BIT)
+#define X86_CR4_KL_BIT (19)
+#define X86_CR4_KL BIT(X86_CR4_KL_BIT)
+#define X86_CR4_SMEP_BIT (20)
+#define X86_CR4_SMEP BIT(X86_CR4_SMEP_BIT)
+#define X86_CR4_SMAP_BIT (21)
+#define X86_CR4_SMAP BIT(X86_CR4_SMAP_BIT)
+#define X86_CR4_PKE_BIT (22)
+#define X86_CR4_PKE BIT(X86_CR4_PKE_BIT)
+#define X86_CR4_CET_BIT (23)
+#define X86_CR4_CET BIT(X86_CR4_CET_BIT)
+#define X86_CR4_PKS_BIT (24)
+#define X86_CR4_PKS BIT(X86_CR4_PKS_BIT)
-#define X86_EFLAGS_CF BIT(0)
-#define X86_EFLAGS_FIXED BIT(1)
-#define X86_EFLAGS_PF BIT(2)
-/* RESERVED 0 BIT(3) */
-#define X86_EFLAGS_AF BIT(4)
-/* RESERVED 0 BIT(5) */
-#define X86_EFLAGS_ZF BIT(6)
-#define X86_EFLAGS_SF BIT(7)
-#define X86_EFLAGS_TF BIT(8)
-#define X86_EFLAGS_IF BIT(9)
-#define X86_EFLAGS_DF BIT(10)
-#define X86_EFLAGS_OF BIT(11)
+#define X86_EFLAGS_CF_BIT (0)
+#define X86_EFLAGS_CF BIT(X86_EFLAGS_CF_BIT)
+#define X86_EFLAGS_FIXED_BIT (1)
+#define X86_EFLAGS_FIXED BIT(X86_EFLAGS_FIXED_BIT)
+#define X86_EFLAGS_PF_BIT (2)
+#define X86_EFLAGS_PF BIT(X86_EFLAGS_PF_BIT)
+/* RESERVED 0 (3) */
+#define X86_EFLAGS_AF_BIT (4)
+#define X86_EFLAGS_AF BIT(X86_EFLAGS_AF_BIT)
+/* RESERVED 0 (5) */
+#define X86_EFLAGS_ZF_BIT (6)
+#define X86_EFLAGS_ZF BIT(X86_EFLAGS_ZF_BIT)
+#define X86_EFLAGS_SF_BIT (7)
+#define X86_EFLAGS_SF BIT(X86_EFLAGS_SF_BIT)
+#define X86_EFLAGS_TF_BIT (8)
+#define X86_EFLAGS_TF BIT(X86_EFLAGS_TF_BIT)
+#define X86_EFLAGS_IF_BIT (9)
+#define X86_EFLAGS_IF BIT(X86_EFLAGS_IF_BIT)
+#define X86_EFLAGS_DF_BIT (10)
+#define X86_EFLAGS_DF BIT(X86_EFLAGS_DF_BIT)
+#define X86_EFLAGS_OF_BIT (11)
+#define X86_EFLAGS_OF BIT(X86_EFLAGS_OF_BIT)
#define X86_EFLAGS_IOPL GENMASK(13, 12)
-#define X86_EFLAGS_NT BIT(14)
-/* RESERVED 0 BIT(15) */
-#define X86_EFLAGS_RF BIT(16)
-#define X86_EFLAGS_VM BIT(17)
-#define X86_EFLAGS_AC BIT(18)
-#define X86_EFLAGS_VIF BIT(19)
-#define X86_EFLAGS_VIP BIT(20)
-#define X86_EFLAGS_ID BIT(21)
+#define X86_EFLAGS_NT_BIT (14)
+#define X86_EFLAGS_NT BIT(X86_EFLAGS_NT_BIT)
+/* RESERVED 0 (15) */
+#define X86_EFLAGS_RF_BIT (16)
+#define X86_EFLAGS_RF BIT(X86_EFLAGS_RF_BIT)
+#define X86_EFLAGS_VM_BIT (17)
+#define X86_EFLAGS_VM BIT(X86_EFLAGS_VM_BIT)
+#define X86_EFLAGS_AC_BIT (18)
+#define X86_EFLAGS_AC BIT(X86_EFLAGS_AC_BIT)
+#define X86_EFLAGS_VIF_BIT (19)
+#define X86_EFLAGS_VIF BIT(X86_EFLAGS_VIF_BIT)
+#define X86_EFLAGS_VIP_BIT (20)
+#define X86_EFLAGS_VIP BIT(X86_EFLAGS_VIP_BIT)
+#define X86_EFLAGS_ID_BIT (21)
+#define X86_EFLAGS_ID BIT(X86_EFLAGS_ID_BIT)
#define X86_EFLAGS_ALU (X86_EFLAGS_CF | X86_EFLAGS_PF | X86_EFLAGS_AF | \
X86_EFLAGS_ZF | X86_EFLAGS_SF | X86_EFLAGS_OF)
diff --git a/x86/smap.c b/x86/smap.c
index 0994c29..9a823a5 100644
--- a/x86/smap.c
+++ b/x86/smap.c
@@ -39,7 +39,7 @@
#endif
"add $"S", %"R "sp\n"
#ifdef __x86_64__
- "orl $" xstr(X86_EFLAGS_AC) ", 2*"S"(%"R "sp)\n" // set EFLAGS.AC and retry
+ "orl $(1 << " xstr(X86_EFLAGS_AC_BIT) "), 2*"S"(%"R "sp)\n" // set EFLAGS.AC and retry
#endif
"iret"W" \n\t"
"jmp pf_tss\n\t");