Xen Test Framework
asm_macros.h
Go to the documentation of this file.
1
6#ifndef XTF_X86_ASM_MACROS_H
7#define XTF_X86_ASM_MACROS_H
8
9/* Generate code fragments appropriately for Assembly or C. */
10#ifdef __ASSEMBLY__
11# define __ASM_CODE(x) x
12# define __ASM_CODE_RAW(x) x
13#else
14# define __ASM_CODE(x) " " #x " "
15# define __ASM_CODE_RAW(x) #x
16#endif
17
18#define ALIGN .align 16
19
20/* Select between two variations based on compat or long mode. */
21#ifdef __i386__
22# define __ASM_SEL(c, l) __ASM_CODE(c)
23# define __ASM_SEL_RAW(c, l) __ASM_CODE_RAW(c)
24#else
25# define __ASM_SEL(c, l) __ASM_CODE(l)
26# define __ASM_SEL_RAW(c, l) __ASM_CODE_RAW(l)
27#endif
28
29#define _WORD __ASM_SEL(.long, .quad)
30
31#define __ASM_REG(reg) __ASM_SEL_RAW(e ## reg, r ## reg)
32
33#define _ASM_AX __ASM_REG(ax)
34#define _ASM_CX __ASM_REG(cx)
35#define _ASM_DX __ASM_REG(dx)
36#define _ASM_BX __ASM_REG(bx)
37#define _ASM_SP __ASM_REG(sp)
38#define _ASM_BP __ASM_REG(bp)
39#define _ASM_SI __ASM_REG(si)
40#define _ASM_DI __ASM_REG(di)
41
42#ifdef __ASSEMBLY__
43
44.macro SAVE_ALL
45 cld
46#if defined(__x86_64__)
47 push %rdi
48 push %rsi
49 push %rdx
50 push %rcx
51 push %rax
52 push %r8
53 push %r9
54 push %r10
55 push %r11
56 push %rbx
57 push %rbp
58 push %r12
59 push %r13
60 push %r14
61 push %r15
62#elif defined(__i386__)
63 push %edi
64 push %esi
65 push %edx
66 push %ecx
67 push %eax
68 push %ebx
69 push %ebp
70#else
71# error Bad architecture for SAVE_ALL
72#endif
73.endm
74
75.macro RESTORE_ALL
76#if defined(__x86_64__)
77 pop %r15
78 pop %r14
79 pop %r13
80 pop %r12
81 pop %rbp
82 pop %rbx
83 pop %r11
84 pop %r10
85 pop %r9
86 pop %r8
87 pop %rax
88 pop %rcx
89 pop %rdx
90 pop %rsi
91 pop %rdi
92#elif defined(__i386__)
93 pop %ebp
94 pop %ebx
95 pop %eax
96 pop %ecx
97 pop %edx
98 pop %esi
99 pop %edi
100#else
101# error Bad architecture for RESTORE_ALL
102#endif
103.endm
104
105#endif /* __ASSEMBLY__ */
106
107#endif /* XTF_X86_ASM_MACROS_H */
108
109/*
110 * Local variables:
111 * mode: C
112 * c-file-style: "BSD"
113 * c-basic-offset: 4
114 * tab-width: 4
115 * indent-tabs-mode: nil
116 * End:
117 */