1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#include <asm/dwarf2.h>
50
51
52
53
54
55
56#define R15 0
57#define R14 8
58#define R13 16
59#define R12 24
60#define RBP 32
61#define RBX 40
62
63
64#define R11 48
65#define R10 56
66#define R9 64
67#define R8 72
68#define RAX 80
69#define RCX 88
70#define RDX 96
71#define RSI 104
72#define RDI 112
73#define ORIG_RAX 120
74
75
76
77#define RIP 128
78#define CS 136
79#define EFLAGS 144
80#define RSP 152
81#define SS 160
82
83#define ARGOFFSET R11
84#define SWFRAME ORIG_RAX
85
86 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
87 subq $9*8+\addskip, %rsp
88 CFI_ADJUST_CFA_OFFSET 9*8+\addskip
89 movq_cfi rdi, 8*8
90 movq_cfi rsi, 7*8
91 movq_cfi rdx, 6*8
92
93 .if \save_rcx
94 movq_cfi rcx, 5*8
95 .endif
96
97 movq_cfi rax, 4*8
98
99 .if \save_r891011
100 movq_cfi r8, 3*8
101 movq_cfi r9, 2*8
102 movq_cfi r10, 1*8
103 movq_cfi r11, 0*8
104 .endif
105
106 .endm
107
108#define ARG_SKIP (9*8)
109
110 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
111 rstor_r8910=1, rstor_rdx=1
112 .if \rstor_r11
113 movq_cfi_restore 0*8, r11
114 .endif
115
116 .if \rstor_r8910
117 movq_cfi_restore 1*8, r10
118 movq_cfi_restore 2*8, r9
119 movq_cfi_restore 3*8, r8
120 .endif
121
122 .if \rstor_rax
123 movq_cfi_restore 4*8, rax
124 .endif
125
126 .if \rstor_rcx
127 movq_cfi_restore 5*8, rcx
128 .endif
129
130 .if \rstor_rdx
131 movq_cfi_restore 6*8, rdx
132 .endif
133
134 movq_cfi_restore 7*8, rsi
135 movq_cfi_restore 8*8, rdi
136
137 .if ARG_SKIP+\addskip > 0
138 addq $ARG_SKIP+\addskip, %rsp
139 CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
140 .endif
141 .endm
142
143 .macro LOAD_ARGS offset, skiprax=0
144 movq \offset(%rsp), %r11
145 movq \offset+8(%rsp), %r10
146 movq \offset+16(%rsp), %r9
147 movq \offset+24(%rsp), %r8
148 movq \offset+40(%rsp), %rcx
149 movq \offset+48(%rsp), %rdx
150 movq \offset+56(%rsp), %rsi
151 movq \offset+64(%rsp), %rdi
152 .if \skiprax
153 .else
154 movq \offset+72(%rsp), %rax
155 .endif
156 .endm
157
158#define REST_SKIP (6*8)
159
160 .macro SAVE_REST
161 subq $REST_SKIP, %rsp
162 CFI_ADJUST_CFA_OFFSET REST_SKIP
163 movq_cfi rbx, 5*8
164 movq_cfi rbp, 4*8
165 movq_cfi r12, 3*8
166 movq_cfi r13, 2*8
167 movq_cfi r14, 1*8
168 movq_cfi r15, 0*8
169 .endm
170
171 .macro RESTORE_REST
172 movq_cfi_restore 0*8, r15
173 movq_cfi_restore 1*8, r14
174 movq_cfi_restore 2*8, r13
175 movq_cfi_restore 3*8, r12
176 movq_cfi_restore 4*8, rbp
177 movq_cfi_restore 5*8, rbx
178 addq $REST_SKIP, %rsp
179 CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
180 .endm
181
182 .macro SAVE_ALL
183 SAVE_ARGS
184 SAVE_REST
185 .endm
186
187 .macro RESTORE_ALL addskip=0
188 RESTORE_REST
189 RESTORE_ARGS 1, \addskip
190 .endm
191
192 .macro icebp
193 .byte 0xf1
194 .endm
195
196.macro UNWIND_END_OF_STACK
197 417:
198 .pushsection __unwind_end_of_stack, "a"
199 .quad 417b
200 .popsection
201.endm
202
203.macro UNWIND_UNSAFE_STACK
204 417:
205 .pushsection __unwind_unsafe_stack, "a"
206 .quad 417b
207 .popsection
208.endm
209