1 /// -*- mode: asm; asm-comment-char: ?/ -*-
3 /// Common definitions for asesembler source files
5 /// (c) 2015 Straylight/Edgeware
8 ///----- Licensing notice ---------------------------------------------------
10 /// This file is part of Catacomb.
12 /// Catacomb is free software; you can redistribute it and/or modify
13 /// it under the terms of the GNU Library General Public License as
14 /// published by the Free Software Foundation; either version 2 of the
15 /// License, or (at your option) any later version.
17 /// Catacomb is distributed in the hope that it will be useful,
18 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 /// GNU Library General Public License for more details.
22 /// You should have received a copy of the GNU Library General Public
23 /// License along with Catacomb; if not, write to the Free
24 /// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 /// MA 02111-1307, USA.
27 ///--------------------------------------------------------------------------
28 /// General definitions.
30 // Preprocessor hacks.
31 #define STRINGY(x) _STRINGY(x, y)
32 #define _STRINGY(x) #x
33 #define GLUE(x, y) _GLUE(x, y)
34 #define _GLUE(x, y) x##y
37 // Some useful variables.
40 // Literal pools done the hard way.
41 #define _LIT .text .L$_subsec + 1
42 #define _ENDLIT .text .L$_subsec
43 #define _LTORG .L$_subsec = .L$_subsec + 2; .text .L$_subsec
48 # define _SECTTY(ty) %ty
50 # define _SECTTY(ty) @ty
55 #define TEXT .text .L$_subsec
57 # define RODATA .section .rdata, "dr"
59 # define RODATA .section .rodata, "a", _SECTTY(progbits)
65 // Announcing an internal function.
66 #define INTFUNC(name) \
68 .macro ENDFUNC; _ENDFUNC(name); .endm; \
69 .L$_prologue_p = 0; .L$_frameptr_p = 0; \
74 // Announcing an external function.
79 // Marking the end of a function.
80 #define _ENDFUNC(name) \
81 .if ~ .L$_prologue_p; .error "Missing `endprologue'"; .endif; \
82 .if .L$_frameptr_p; .purgem dropfp; .endif; \
88 // Make a helper function, if necessary.
90 .ifndef .L$_auxfn_def.name; \
92 .macro _ENDAUXFN; _ENDAUXFN_TAIL(name); .endm; \
95 #define _ENDAUXFN_TAIL(name) \
98 .L$_auxfn_def.name = 1
99 #define ENDAUXFN _ENDAUXFN; .endif
101 ///--------------------------------------------------------------------------
102 /// ELF-specific hacking.
106 #if __PIC__ || __PIE__
110 #define TYPE_FUNC(name) .type name, STT_FUNC
112 #define SIZE_OBJ(name) .size name, . - name
116 ///--------------------------------------------------------------------------
117 /// Windows-specific hacking.
122 # define F(name) _##name
127 ///--------------------------------------------------------------------------
128 /// x86- and amd64-specific hacking.
130 /// It's (slightly) easier to deal with both of these in one go.
132 #if CPUFAM_X86 || CPUFAM_AMD64
142 // Set the function hooks.
143 #define FUNC_PREHOOK(_) .balign 16
145 // On Windows, arrange to install stack-unwinding data.
146 #if CPUFAM_AMD64 && ABI_WIN
147 # define FUNC_POSTHOOK(name) .seh_proc name
148 # define ENDFUNC_HOOK(_) .seh_endproc
149 // Procedures are expected to invoke `.seh_setframe' if necessary, and
150 // `.seh_pushreg' and friends, and `.seh_endprologue'.
154 # define FUNC_POSTHOOK(_) .cfi_startproc
155 # define ENDFUNC_HOOK(_) .cfi_endproc
158 // Don't use the wretched AT&T syntax. It's festooned with pointless
159 // punctuation, and all of the data movement is backwards. Ugh!
160 .intel_syntax noprefix
162 // Call external subroutine at ADDR, possibly via PLT.
171 // Do I need to arrange a spare GOT register?
172 #if WANT_PIC && CPUFAM_X86
175 #define GOTREG ebx // Not needed in AMD64 so don't care.
177 // Maybe load GOT address into GOT.
178 .macro ldgot got=GOTREG
179 #if WANT_PIC && CPUFAM_X86
185 add \got, offset _GLOBAL_OFFSET_TABLE_
189 // Load address of external symbol ADDR into REG, maybe using GOT.
190 .macro leaext reg, addr, got=GOTREG
193 mov \reg, [\got + \addr@GOT]
196 mov \reg, \addr@GOTPCREL[rip]
200 mov \reg, offset \addr
208 // Address expression (possibly using a base register, and a displacement)
209 // referring to ADDR, which is within our module, maybe using GOT.
210 #define INTADDR(...) INTADDR__0(__VA_ARGS__, GOTREG, dummy)
211 #define INTADDR__0(addr, got, ...) INTADDR__1(addr, got)
213 # define INTADDR__1(addr, got) addr + rip
215 # define INTADDR__1(addr, got) got + addr@GOTOFF
217 # define INTADDR__1(addr, got) addr
220 // Permutations for SIMD instructions. SHUF(A, B, C, D) is an immediate,
221 // suitable for use in `pshufd' or `shufpd', which copies element A
222 // (0 <= A < 4) of the source to element 0 of the destination, element B to
223 // element 1, element C to element 2, and element D to element 3.
224 #define SHUF(a, b, c, d) ((a) + 4*(b) + 16*(c) + 64*(d))
226 // Map register names to their individual pieces.
228 // Apply decoration decor to (internal) register name reg of type ty.
230 // See `R_...' for internal register names. Decorations are as follows.
232 // b low byte (e.g., `al', `r8b')
233 // h high byte (e.g., `ah')
234 // w word (e.g., `ax', `r8w')
235 // d doubleword (e.g., `eax', `r8d')
236 // q quadword (e.g., `rax', `r8')
237 // r whole register (doubleword on x86, quadword on amd64)
239 // And types are as follows.
241 // abcd the four traditional registers `a', `b', `c', `d'
242 // xp the four pointer registers `si', `di', `bp', `sp'
243 // ip the instruction pointer `ip'
244 // rn the AMD64 numbered registers `r8'--`r15'
245 #define _DECOR(ty, decor, reg) _DECOR_##ty##_##decor(reg)
247 // Internal macros: _DECOR_ty_decor(reg) applies decoration decor to
248 // (internal) register name reg of type ty.
250 #define _DECOR_abcd_b(reg) reg##l
251 #define _DECOR_abcd_h(reg) reg##h
252 #define _DECOR_abcd_w(reg) reg##x
253 #define _DECOR_abcd_d(reg) e##reg##x
255 # define _DECOR_abcd_q(reg) r##reg##x
258 #define _DECOR_xp_b(reg) reg##l
259 #define _DECOR_xp_w(reg) reg
260 #define _DECOR_xp_d(reg) e##reg
262 # define _DECOR_xp_q(reg) r##reg
265 #define _DECOR_ip_w(reg) reg
266 #define _DECOR_ip_d(reg) e##reg
268 # define _DECOR_ip_q(reg) r##reg
272 # define _DECOR_rn_b(reg) reg##b
273 # define _DECOR_rn_w(reg) reg##w
274 # define _DECOR_rn_d(reg) reg##d
275 # define _DECOR_rn_q(reg) reg
276 # define _DECOR_rn_r(reg) reg
280 # define _DECOR_abcd_r(reg) e##reg##x
281 # define _DECOR_xp_r(reg) e##reg
282 # define _DECOR_ip_r(reg) e##reg
285 # define _DECOR_abcd_r(reg) r##reg##x
286 # define _DECOR_xp_r(reg) r##reg
287 # define _DECOR_ip_r(reg) r##reg
290 #define _DECOR_mem_b(addr) byte ptr addr
291 #define _DECOR_mem_w(addr) word ptr addr
292 #define _DECOR_mem_d(addr) dword ptr addr
294 # define _DECOR_mem_q(addr) qword ptr addr
297 // R_r(decor) applies decoration decor to register r, which is an internal
298 // register name. The internal register names are: `ip', `a', `b', `c', `d',
299 // `si', `di', `bp', `sp', `r8'--`r15'.
300 #define R_ip(decor) _DECOR(ip, decor, ip)
301 #define R_a(decor) _DECOR(abcd, decor, a)
302 #define R_b(decor) _DECOR(abcd, decor, b)
303 #define R_c(decor) _DECOR(abcd, decor, c)
304 #define R_d(decor) _DECOR(abcd, decor, d)
305 #define R_si(decor) _DECOR(xp, decor, si)
306 #define R_di(decor) _DECOR(xp, decor, di)
307 #define R_bp(decor) _DECOR(xp, decor, bp)
308 #define R_sp(decor) _DECOR(xp, decor, sp)
310 # define R_r8(decor) _DECOR(rn, decor, r8)
311 # define R_r9(decor) _DECOR(rn, decor, r9)
312 # define R_r10(decor) _DECOR(rn, decor, r10)
313 # define R_r11(decor) _DECOR(rn, decor, r11)
314 # define R_r12(decor) _DECOR(rn, decor, r12)
315 # define R_r13(decor) _DECOR(rn, decor, r13)
316 # define R_r14(decor) _DECOR(rn, decor, r14)
317 # define R_r15(decor) _DECOR(rn, decor, r15)
320 // Refer to an in-memory datum of the type implied by decor residing at
321 // address addr (which should supply its own square-brackets).
322 #define MEM(decor, addr) _DECOR(mem, decor, addr)
324 // Applies decoration decor to assembler-level register name reg.
325 #define _REGFORM(reg, decor) _GLUE(_REGFORM_, reg)(decor)
327 // Internal macros: _REGFORM_r(decor) applies decoration decor to an
328 // assembler-level register name, in place of any decoration that register
331 #define _REGFORM_ip(decor) R_ip(decor)
332 #define _REGFORM_eip(decor) R_ip(decor)
334 #define _REGFORM_a(decor) R_a(decor)
335 #define _REGFORM_al(decor) R_a(decor)
336 #define _REGFORM_ah(decor) R_a(decor)
337 #define _REGFORM_ax(decor) R_a(decor)
338 #define _REGFORM_eax(decor) R_a(decor)
340 #define _REGFORM_b(decor) R_b(decor)
341 #define _REGFORM_bl(decor) R_b(decor)
342 #define _REGFORM_bh(decor) R_b(decor)
343 #define _REGFORM_bx(decor) R_b(decor)
344 #define _REGFORM_ebx(decor) R_b(decor)
346 #define _REGFORM_c(decor) R_c(decor)
347 #define _REGFORM_cl(decor) R_c(decor)
348 #define _REGFORM_ch(decor) R_c(decor)
349 #define _REGFORM_cx(decor) R_c(decor)
350 #define _REGFORM_ecx(decor) R_c(decor)
352 #define _REGFORM_d(decor) R_d(decor)
353 #define _REGFORM_dl(decor) R_d(decor)
354 #define _REGFORM_dh(decor) R_d(decor)
355 #define _REGFORM_dx(decor) R_d(decor)
356 #define _REGFORM_edx(decor) R_d(decor)
358 #define _REGFORM_si(decor) R_si(decor)
359 #define _REGFORM_sil(decor) R_si(decor)
360 #define _REGFORM_esi(decor) R_si(decor)
362 #define _REGFORM_di(decor) R_di(decor)
363 #define _REGFORM_dil(decor) R_di(decor)
364 #define _REGFORM_edi(decor) R_di(decor)
366 #define _REGFORM_bp(decor) R_bp(decor)
367 #define _REGFORM_bpl(decor) R_bp(decor)
368 #define _REGFORM_ebp(decor) R_bp(decor)
370 #define _REGFORM_sp(decor) R_sp(decor)
371 #define _REGFORM_spl(decor) R_sp(decor)
372 #define _REGFORM_esp(decor) R_sp(decor)
376 # define _REGFORM_rip(decor) R_ip(decor)
377 # define _REGFORM_rsp(decor) R_sp(decor)
378 # define _REGFORM_rbp(decor) R_bp(decor)
379 # define _REGFORM_rdi(decor) R_di(decor)
380 # define _REGFORM_rsi(decor) R_si(decor)
381 # define _REGFORM_rdx(decor) R_d(decor)
382 # define _REGFORM_rcx(decor) R_c(decor)
383 # define _REGFORM_rbx(decor) R_b(decor)
384 # define _REGFORM_rax(decor) R_a(decor)
386 # define _REGFORM_r8(decor) R_r8(decor)
387 # define _REGFORM_r8b(decor) R_r8(decor)
388 # define _REGFORM_r8w(decor) R_r8(decor)
389 # define _REGFORM_r8d(decor) R_r8(decor)
391 # define _REGFORM_r9(decor) R_r9(decor)
392 # define _REGFORM_r9b(decor) R_r9(decor)
393 # define _REGFORM_r9w(decor) R_r9(decor)
394 # define _REGFORM_r9d(decor) R_r9(decor)
396 # define _REGFORM_r10(decor) R_r10(decor)
397 # define _REGFORM_r10b(decor) R_r10(decor)
398 # define _REGFORM_r10w(decor) R_r10(decor)
399 # define _REGFORM_r10d(decor) R_r10(decor)
401 # define _REGFORM_r11(decor) R_r11(decor)
402 # define _REGFORM_r11b(decor) R_r11(decor)
403 # define _REGFORM_r11w(decor) R_r11(decor)
404 # define _REGFORM_r11d(decor) R_r11(decor)
406 # define _REGFORM_r12(decor) R_r12(decor)
407 # define _REGFORM_r12b(decor) R_r12(decor)
408 # define _REGFORM_r12w(decor) R_r12(decor)
409 # define _REGFORM_r12d(decor) R_r12(decor)
411 # define _REGFORM_r13(decor) R_r13(decor)
412 # define _REGFORM_r13b(decor) R_r13(decor)
413 # define _REGFORM_r13w(decor) R_r13(decor)
414 # define _REGFORM_r13d(decor) R_r13(decor)
416 # define _REGFORM_r14(decor) R_r14(decor)
417 # define _REGFORM_r14b(decor) R_r14(decor)
418 # define _REGFORM_r14w(decor) R_r14(decor)
419 # define _REGFORM_r14d(decor) R_r14(decor)
421 # define _REGFORM_r15(decor) R_r15(decor)
422 # define _REGFORM_r15b(decor) R_r15(decor)
423 # define _REGFORM_r15w(decor) R_r15(decor)
424 # define _REGFORM_r15d(decor) R_r15(decor)
428 // Macros for converting register names.
429 #define BYTE(reg) _REGFORM(reg, b)
430 #define HIBYTE(reg) _REGFORM(reg, h)
431 #define WORD(reg) _REGFORM(reg, w)
432 #define DWORD(reg) _REGFORM(reg, d)
434 # define QWORD(reg) _REGFORM(reg, q)
436 #define WHOLE(reg) _REGFORM(reg, r)
438 // Stack management and unwinding.
439 .macro setfp fp, offset = 0
443 .cfi_def_cfa_register \fp
445 #if ABI_WIN && CPUFAM_AMD64
449 lea \fp, [R_sp(r) + \offset]
451 .cfi_def_cfa_register \fp
452 .cfi_adjust_cfa_offset -\offset
454 #if ABI_WIN && CPUFAM_AMD64
455 .seh_setframe \fp, \offset
459 .macro dropfp; _dropfp \fp, \offset; .endm
462 .macro _dropfp fp, offset = 0
466 .cfi_def_cfa_register R_sp(r)
469 lea R_sp(r), [\fp - \offset]
471 .cfi_def_cfa_register R_sp(r)
472 .cfi_adjust_cfa_offset +\offset
482 .cfi_adjust_cfa_offset +\n
484 #if ABI_WIN && CPUFAM_AMD64
492 .cfi_adjust_cfa_offset -\n
499 .cfi_adjust_cfa_offset +WORDSZ
500 .cfi_rel_offset \r, 0
502 #if ABI_WIN && CPUFAM_AMD64
510 .cfi_adjust_cfa_offset -WORDSZ
515 .macro savexmm r, offset
516 movdqa [R_sp(r) + \offset], \r
517 #if ABI_WIN && CPUFAM_AMD64
518 .seh_savexmm \r, \offset
522 .macro rstrxmm r, offset
523 movdqa \r, [R_sp(r) + \offset]
527 #if ABI_WIN && CPUFAM_AMD64
538 // Stash GP registers and establish temporary stack frame.
557 // Print FMT and the other established arguments.
558 lea eax, .L$_reg$msg.\@
598 _reg.3 "\msg: \r = %08x"
606 pshufd xmm0, xmm0, 0x1b
609 _reg.3 "\msg: \r = %08x %08x %08x %08x"
619 _reg.3 "\msg: \r = %08x %08x"
627 fldt [esp + 32 + 16*\i]
630 _reg.3 "\msg: st(\i) = %.20Lg"
638 fldt [esp + 32 + 16*\i]
641 _reg.3 "\msg: st(\i) = %La"
646 ///--------------------------------------------------------------------------
647 /// ARM-specific hacking.
651 // ARM/Thumb mode things. Use ARM by default.
652 #define ARM .arm; .L$_pcoff = 8
653 #define THUMB .thumb; .L$_pcoff = 4
656 // Set the function hooks.
657 #define FUNC_PREHOOK(_) .balign 4; .fnstart
658 #define ENDFUNC_HOOK(_) .fnend; .ltorg
660 // Call external subroutine at ADDR, possibly via PLT.
661 .macro callext addr, cond=
669 // Do I need to arrange a spare GOT register?
675 // Maybe load GOT address into GOT.
676 .macro ldgot cond=, got=GOTREG
678 ldr\cond \got, .L$_ldgot$\@
680 add\cond \got, pc, \got
684 .word _GLOBAL_OFFSET_TABLE_ - .L$_ldgot_pc$\@ - .L$_pcoff
689 // Load address of external symbol ADDR into REG, maybe using GOT.
690 .macro leaext reg, addr, cond=, got=GOTREG
692 ldr\cond \reg, .L$_leaext$\@
693 ldr\cond \reg, [\got, \reg]
700 ldr\cond \reg, =\addr
704 // Load address of external symbol ADDR into REG directly.
705 .macro leaextq reg, addr, cond=
707 ldr\cond \reg, .L$_leaextq$\@
710 ldr\cond \reg, [pc, \reg]
713 ldr\cond \reg, [\reg]
718 .word \addr(GOT_PREL) + (. - .L$_leaextq_pc$\@ - .L$_pcoff)
721 ldr\cond \reg, =\addr
725 // Apply decoration decor to register name reg.
726 #define _REGFORM(reg, decor) _GLUE(_REGFORM_, reg)(decor)
728 // Internal macros: `_REGFORM_r(decor)' applies decoration decor to register
731 #define _REGFORM_s0(decor) _DECOR(s, decor, 0)
732 #define _REGFORM_s1(decor) _DECOR(s, decor, 1)
733 #define _REGFORM_s2(decor) _DECOR(s, decor, 2)
734 #define _REGFORM_s3(decor) _DECOR(s, decor, 3)
735 #define _REGFORM_s4(decor) _DECOR(s, decor, 4)
736 #define _REGFORM_s5(decor) _DECOR(s, decor, 5)
737 #define _REGFORM_s6(decor) _DECOR(s, decor, 6)
738 #define _REGFORM_s7(decor) _DECOR(s, decor, 7)
739 #define _REGFORM_s8(decor) _DECOR(s, decor, 8)
740 #define _REGFORM_s9(decor) _DECOR(s, decor, 9)
741 #define _REGFORM_s10(decor) _DECOR(s, decor, 10)
742 #define _REGFORM_s11(decor) _DECOR(s, decor, 11)
743 #define _REGFORM_s12(decor) _DECOR(s, decor, 12)
744 #define _REGFORM_s13(decor) _DECOR(s, decor, 13)
745 #define _REGFORM_s14(decor) _DECOR(s, decor, 14)
746 #define _REGFORM_s15(decor) _DECOR(s, decor, 15)
747 #define _REGFORM_s16(decor) _DECOR(s, decor, 16)
748 #define _REGFORM_s17(decor) _DECOR(s, decor, 17)
749 #define _REGFORM_s18(decor) _DECOR(s, decor, 18)
750 #define _REGFORM_s19(decor) _DECOR(s, decor, 19)
751 #define _REGFORM_s20(decor) _DECOR(s, decor, 20)
752 #define _REGFORM_s21(decor) _DECOR(s, decor, 21)
753 #define _REGFORM_s22(decor) _DECOR(s, decor, 22)
754 #define _REGFORM_s23(decor) _DECOR(s, decor, 23)
755 #define _REGFORM_s24(decor) _DECOR(s, decor, 24)
756 #define _REGFORM_s25(decor) _DECOR(s, decor, 25)
757 #define _REGFORM_s26(decor) _DECOR(s, decor, 26)
758 #define _REGFORM_s27(decor) _DECOR(s, decor, 27)
759 #define _REGFORM_s28(decor) _DECOR(s, decor, 28)
760 #define _REGFORM_s29(decor) _DECOR(s, decor, 29)
761 #define _REGFORM_s30(decor) _DECOR(s, decor, 30)
762 #define _REGFORM_s31(decor) _DECOR(s, decor, 31)
764 #define _REGFORM_d0(decor) _DECOR(d, decor, 0)
765 #define _REGFORM_d1(decor) _DECOR(d, decor, 1)
766 #define _REGFORM_d2(decor) _DECOR(d, decor, 2)
767 #define _REGFORM_d3(decor) _DECOR(d, decor, 3)
768 #define _REGFORM_d4(decor) _DECOR(d, decor, 4)
769 #define _REGFORM_d5(decor) _DECOR(d, decor, 5)
770 #define _REGFORM_d6(decor) _DECOR(d, decor, 6)
771 #define _REGFORM_d7(decor) _DECOR(d, decor, 7)
772 #define _REGFORM_d8(decor) _DECOR(d, decor, 8)
773 #define _REGFORM_d9(decor) _DECOR(d, decor, 9)
774 #define _REGFORM_d10(decor) _DECOR(d, decor, 10)
775 #define _REGFORM_d11(decor) _DECOR(d, decor, 11)
776 #define _REGFORM_d12(decor) _DECOR(d, decor, 12)
777 #define _REGFORM_d13(decor) _DECOR(d, decor, 13)
778 #define _REGFORM_d14(decor) _DECOR(d, decor, 14)
779 #define _REGFORM_d15(decor) _DECOR(d, decor, 15)
780 #define _REGFORM_d16(decor) _DECOR(d, decor, 16)
781 #define _REGFORM_d17(decor) _DECOR(d, decor, 17)
782 #define _REGFORM_d18(decor) _DECOR(d, decor, 18)
783 #define _REGFORM_d19(decor) _DECOR(d, decor, 19)
784 #define _REGFORM_d20(decor) _DECOR(d, decor, 20)
785 #define _REGFORM_d21(decor) _DECOR(d, decor, 21)
786 #define _REGFORM_d22(decor) _DECOR(d, decor, 22)
787 #define _REGFORM_d23(decor) _DECOR(d, decor, 23)
788 #define _REGFORM_d24(decor) _DECOR(d, decor, 24)
789 #define _REGFORM_d25(decor) _DECOR(d, decor, 25)
790 #define _REGFORM_d26(decor) _DECOR(d, decor, 26)
791 #define _REGFORM_d27(decor) _DECOR(d, decor, 27)
792 #define _REGFORM_d28(decor) _DECOR(d, decor, 28)
793 #define _REGFORM_d29(decor) _DECOR(d, decor, 29)
794 #define _REGFORM_d30(decor) _DECOR(d, decor, 30)
795 #define _REGFORM_d31(decor) _DECOR(d, decor, 31)
797 #define _REGFORM_q0(decor) _DECOR(q, decor, 0)
798 #define _REGFORM_q1(decor) _DECOR(q, decor, 1)
799 #define _REGFORM_q2(decor) _DECOR(q, decor, 2)
800 #define _REGFORM_q3(decor) _DECOR(q, decor, 3)
801 #define _REGFORM_q4(decor) _DECOR(q, decor, 4)
802 #define _REGFORM_q5(decor) _DECOR(q, decor, 5)
803 #define _REGFORM_q6(decor) _DECOR(q, decor, 6)
804 #define _REGFORM_q7(decor) _DECOR(q, decor, 7)
805 #define _REGFORM_q8(decor) _DECOR(q, decor, 8)
806 #define _REGFORM_q9(decor) _DECOR(q, decor, 9)
807 #define _REGFORM_q10(decor) _DECOR(q, decor, 10)
808 #define _REGFORM_q11(decor) _DECOR(q, decor, 11)
809 #define _REGFORM_q12(decor) _DECOR(q, decor, 12)
810 #define _REGFORM_q13(decor) _DECOR(q, decor, 13)
811 #define _REGFORM_q14(decor) _DECOR(q, decor, 14)
812 #define _REGFORM_q15(decor) _DECOR(q, decor, 15)
814 // `_LOPART(n)' and `_HIPART(n)' return the numbers of the register halves of
815 // register n, i.e., 2*n and 2*n + 1 respectively.
816 #define _LOPART(n) _GLUE(_LOPART_, n)
817 #define _HIPART(n) _GLUE(_HIPART_, n)
819 // Internal macros: `_LOPART_n' and `_HIPART_n' return the numbers of the
820 // register halves of register n, i.e., 2*n and 2*n + 1 respectively.
842 #define _LOPART_10 20
843 #define _HIPART_10 21
844 #define _LOPART_11 22
845 #define _HIPART_11 23
846 #define _LOPART_12 24
847 #define _HIPART_12 25
848 #define _LOPART_13 26
849 #define _HIPART_13 27
850 #define _LOPART_14 28
851 #define _HIPART_14 29
852 #define _LOPART_15 30
853 #define _HIPART_15 31
855 // Return the register number of the pair containing register n, i.e.,
857 #define _PAIR(n) _GLUE(_PAIR_, n)
859 // Internal macros: `_PAIR_n' returns the register number of the pair
860 // containing register n, i.e., floor(n/2).
894 // Apply decoration decor to register number n of type ty. Decorations are
897 // decor types meaning
898 // Q s, d the NEON qN register containing this one
899 // D s the NEON dN register containing this one
900 // D0 q the low 64-bit half of this one
901 // D1 q the high 64-bit half of this one
902 // S0 d, q the first 32-bit piece of this one
903 // S1 d, q the second 32-bit piece of this one
904 // S2 q the third 32-bit piece of this one
905 // S3 q the fourth 32-bit piece of this one
906 // Bn q the nth byte of this register, as a scalar
907 // Hn q the nth halfword of this register, as a scalar
908 // Wn q the nth word of this register, as a scalar
909 #define _DECOR(ty, decor, n) _DECOR_##ty##_##decor(n)
911 // Internal macros: `_DECOR_ty_decor(n)' applies decoration decor to register
912 // number n of type ty.
914 #define _DECOR_s_Q(n) GLUE(q, _PAIR(_PAIR(n)))
915 #define _DECOR_s_D(n) GLUE(d, _PAIR(n))
917 #define _DECOR_d_Q(n) GLUE(q, _PAIR(n))
918 #define _DECOR_d_S0(n) GLUE(s, _LOPART(n))
919 #define _DECOR_d_S1(n) GLUE(s, _LOPART(n))
921 #define _DECOR_q_D0(n) GLUE(d, _LOPART(n))
922 #define _DECOR_q_D1(n) GLUE(d, _HIPART(n))
923 #define _DECOR_q_S0(n) GLUE(s, _LOPART(_LOPART(n)))
924 #define _DECOR_q_S1(n) GLUE(s, _HIPART(_LOPART(n)))
925 #define _DECOR_q_S2(n) GLUE(s, _LOPART(_HIPART(n)))
926 #define _DECOR_q_S3(n) GLUE(s, _HIPART(_HIPART(n)))
927 #define _DECOR_q_W0(n) GLUE(d, _LOPART(n))[0]
928 #define _DECOR_q_W1(n) GLUE(d, _LOPART(n))[1]
929 #define _DECOR_q_W2(n) GLUE(d, _HIPART(n))[0]
930 #define _DECOR_q_W3(n) GLUE(d, _HIPART(n))[1]
931 #define _DECOR_q_H0(n) GLUE(d, _LOPART(n))[0]
932 #define _DECOR_q_H1(n) GLUE(d, _LOPART(n))[1]
933 #define _DECOR_q_H2(n) GLUE(d, _LOPART(n))[2]
934 #define _DECOR_q_H3(n) GLUE(d, _LOPART(n))[3]
935 #define _DECOR_q_H4(n) GLUE(d, _HIPART(n))[0]
936 #define _DECOR_q_H5(n) GLUE(d, _HIPART(n))[1]
937 #define _DECOR_q_H6(n) GLUE(d, _HIPART(n))[2]
938 #define _DECOR_q_H7(n) GLUE(d, _HIPART(n))[3]
939 #define _DECOR_q_B0(n) GLUE(d, _LOPART(n))[0]
940 #define _DECOR_q_B1(n) GLUE(d, _LOPART(n))[1]
941 #define _DECOR_q_B2(n) GLUE(d, _LOPART(n))[2]
942 #define _DECOR_q_B3(n) GLUE(d, _LOPART(n))[3]
943 #define _DECOR_q_B4(n) GLUE(d, _LOPART(n))[4]
944 #define _DECOR_q_B5(n) GLUE(d, _LOPART(n))[5]
945 #define _DECOR_q_B6(n) GLUE(d, _LOPART(n))[6]
946 #define _DECOR_q_B7(n) GLUE(d, _LOPART(n))[7]
947 #define _DECOR_q_B8(n) GLUE(d, _HIPART(n))[0]
948 #define _DECOR_q_B9(n) GLUE(d, _HIPART(n))[1]
949 #define _DECOR_q_B10(n) GLUE(d, _HIPART(n))[2]
950 #define _DECOR_q_B11(n) GLUE(d, _HIPART(n))[3]
951 #define _DECOR_q_B12(n) GLUE(d, _HIPART(n))[4]
952 #define _DECOR_q_B13(n) GLUE(d, _HIPART(n))[5]
953 #define _DECOR_q_B14(n) GLUE(d, _HIPART(n))[6]
954 #define _DECOR_q_B15(n) GLUE(d, _HIPART(n))[7]
956 // Macros for navigating the NEON register hierarchy.
957 #define S0(reg) _REGFORM(reg, S0)
958 #define S1(reg) _REGFORM(reg, S1)
959 #define S2(reg) _REGFORM(reg, S2)
960 #define S3(reg) _REGFORM(reg, S3)
961 #define D(reg) _REGFORM(reg, D)
962 #define D0(reg) _REGFORM(reg, D0)
963 #define D1(reg) _REGFORM(reg, D1)
964 #define Q(reg) _REGFORM(reg, Q)
966 // Macros for indexing quadword registers.
967 #define QB(reg, i) _REGFORM(reg, B##i)
968 #define QH(reg, i) _REGFORM(reg, H##i)
969 #define QW(reg, i) _REGFORM(reg, W##i)
971 // Macros for converting vldm/vstm ranges.
972 #define QQ(qlo, qhi) D0(qlo)-D1(qhi)
974 // Stack management and unwinding.
975 .macro setfp fp, offset = 0
980 add \fp, sp, #\offset
981 .setfp \fp, sp, #\offset
983 .macro dropfp; _dropfp \fp, \offset; .endm
987 .macro _dropfp fp, offset = 0
991 sub sp, \fp, #\offset
1007 .macro pushreg rr:vararg
1012 .macro popreg rr:vararg
1016 .macro pushvfp rr:vararg
1021 .macro popvfp rr:vararg
1028 // No need for prologue markers on ARM.
1029 #define FUNC_POSTHOOK(_) .L$_prologue_p = -1
1033 ///--------------------------------------------------------------------------
1034 /// AArch64-specific hacking.
1038 // Set the function hooks.
1039 #define FUNC_PREHOOK(_) .balign 4
1040 #define FUNC_POSTHOOK(_) .cfi_startproc; .L$_prologue_p = -1
1041 #define ENDFUNC_HOOK(_) .cfi_endproc
1043 // Call external subroutine at ADDR, possibly via PLT.
1048 // Load address of external symbol ADDR into REG.
1049 .macro leaext reg, addr
1051 adrp \reg, :got:\addr
1052 ldr \reg, [\reg, #:got_lo12:\addr]
1055 add \reg, \reg, #:lo12:\addr
1059 // Stack management and unwinding.
1060 .macro setfp fp, offset = 0
1061 // If you're just going through the motions with a fixed-size stack frame,
1062 // then you want to say `add x29, sp, #OFFSET' directly, which will avoid
1063 // pointlessly restoring sp later.
1066 .cfi_def_cfa_register \fp
1068 add \fp, sp, #\offset
1069 .cfi_def_cfa_register \fp
1070 .cfi_adjust_cfa_offset -\offset
1072 .macro dropfp; _dropfp \fp, \offset; .endm
1076 .macro _dropfp fp, offset = 0
1079 .cfi_def_cfa_register sp
1081 sub sp, \fp, #\offset
1082 .cfi_def_cfa_register sp
1083 .cfi_adjust_cfa_offset +\offset
1091 .cfi_adjust_cfa_offset +\n
1096 .cfi_adjust_cfa_offset -\n
1099 .macro pushreg x, y=
1102 .cfi_adjust_cfa_offset +16
1103 .cfi_rel_offset \x, 0
1105 stp \x, \y, [sp, #-16]!
1106 .cfi_adjust_cfa_offset +16
1107 .cfi_rel_offset \x, 0
1108 .cfi_rel_offset \y, 8
1116 .cfi_adjust_cfa_offset -16
1118 ldp \x, \y, [sp], #16
1121 .cfi_adjust_cfa_offset -16
1125 .macro savereg x, y, z=
1128 .cfi_rel_offset \x, \y
1130 stp \x, \y, [sp, #\z]
1131 .cfi_rel_offset \x, \z
1132 .cfi_rel_offset \y, \z + 8
1136 .macro rstrreg x, y, z=
1141 ldp \x, \y, [sp, #\z]
1152 ///--------------------------------------------------------------------------
1155 // Default values for the various hooks.
1156 #ifndef FUNC_PREHOOK
1157 # define FUNC_PREHOOK(_)
1159 #ifndef FUNC_POSTHOOK
1160 # define FUNC_POSTHOOK(_)
1162 #ifndef ENDFUNC_HOOK
1163 # define ENDFUNC_HOOK(_)
1167 # define F(name) name
1171 # define TYPE_FUNC(name)
1175 # define SIZE_OBJ(name)
1178 #if __ELF__ && !defined(WANT_EXECUTABLE_STACK)
1179 .pushsection .note.GNU-stack, "", _SECTTY(progbits)
1183 ///----- That's all, folks --------------------------------------------------