]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Introduce _ASM_{{A,C,D,B}X,{B,S}P,{S,D}I} to aid common asm code
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 3 Mar 2017 14:35:49 +0000 (14:35 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 6 Mar 2017 10:55:40 +0000 (10:55 +0000)
This removes the need to #ifdef around code requiring a word-sized register.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/boot/head_pv.S
arch/x86/include/arch/asm_macros.h
arch/x86/pv/traps.c
tests/pv-iopl/asm.S

index aa62b40018725c2b152d8e76928b8eb4d355000c..df4b608d13469aa8e0cf11d9818468316108860d 100644 (file)
@@ -28,11 +28,7 @@ ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz "yes")
 GLOBAL(_start)
 
         /* Stash start_info_t pointer from domain build. */
-#ifdef __x86_64__
-        mov %rsi, start_info
-#else
-        mov %esi, start_info
-#endif
+        mov %_ASM_SI, start_info
 
         /* Move onto own stack. */
         mov $boot_stack + PAGE_SIZE, %esp
index 4acce80037fc69d4fd0ce01f9371452de9d3a9c6..e12e1ba2bc4fc425eb77cff3e819fff6148bd26e 100644 (file)
@@ -6,21 +6,37 @@
 #ifndef XTF_X86_ASM_MACROS_H
 #define XTF_X86_ASM_MACROS_H
 
+/* Generate code fragments appropriately for Assembly or C. */
 #ifdef __ASSEMBLY__
-/* Declare data at the architectures width. */
-# if defined(__x86_64__)
-#  define _WORD .quad
-# elif defined(__i386__)
-#  define _WORD .long
-# endif
+# define __ASM_CODE(x)     x
+# define __ASM_CODE_RAW(x) x
 #else
-# if defined(__x86_64__)
-#  define _WORD ".quad "
-# elif defined(__i386__)
-#  define _WORD ".long "
-# endif
+# define __ASM_CODE(x)     " " #x " "
+# define __ASM_CODE_RAW(x) #x
 #endif
 
+/* Select between two variations based on compat or long mode. */
+#ifdef __i386__
+# define __ASM_SEL(c, l)     __ASM_CODE(c)
+# define __ASM_SEL_RAW(c, l) __ASM_CODE_RAW(c)
+#else
+# define __ASM_SEL(c, l)     __ASM_CODE(l)
+# define __ASM_SEL_RAW(c, l) __ASM_CODE_RAW(l)
+#endif
+
+#define _WORD __ASM_SEL(.long, .quad)
+
+#define __ASM_REG(reg) __ASM_SEL_RAW(e ## reg, r ## reg)
+
+#define _ASM_AX __ASM_REG(ax)
+#define _ASM_CX __ASM_REG(cx)
+#define _ASM_DX __ASM_REG(dx)
+#define _ASM_BX __ASM_REG(bx)
+#define _ASM_SP __ASM_REG(sp)
+#define _ASM_BP __ASM_REG(bp)
+#define _ASM_SI __ASM_REG(si)
+#define _ASM_DI __ASM_REG(di)
+
 #ifdef __ASSEMBLY__
 
 .macro SAVE_ALL
index 894d69927a0e9da24d3a62f9571fe87741ca56e4..9561cbaab7b320bc21204dce015a4defefdeed8b 100644 (file)
@@ -228,11 +228,7 @@ void __noreturn arch_crash_hard(void)
      * the domain.
      */
     asm volatile(
-#ifdef __i386__
-        "mov %0, %%esp;"
-#else
-        "movabs %0, %%rsp;"
-#endif
+        "mov %0, %%" _ASM_SP ";"
         "pushf"
         ::
 #ifdef __i386__
index 1a1f1d0bb0c8ab119edeb609a9ce3f46606e260b..3ef8fbffea69060cbfc3127a9c21b2f5f0ad52c0 100644 (file)
@@ -15,13 +15,12 @@ ENTRY(exec_user_with_iopl)      /* void (*fn)(void), unsigned int iopl */
         pushf                   /* EFLAGS */
 
                                 /* PV guests see the real interrupt flag. Clobber it. */
+        andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_IF), (%_ASM_SP)
 #ifdef __i386__
-        andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_IF), (%esp)
         mov  5*4(%esp), %eax
         shl  $12, %eax
         or   %eax, (%esp)
 #else
-        andl $~(X86_EFLAGS_IOPL | X86_EFLAGS_IF), (%rsp)
         shl  $12, %esi
         or   %esi, (%rsp)
 #endif