1 /// -*- mode: asm; asm-comment-char: ?/ -*-
3 /// Fancy SIMD implementation of Salsa20
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 // Some useful variables.
33 // Literal pools done the hard way.
34 #define _LIT .text .L$_subsec + 1
35 #define _ENDLIT .text .L$_subsec
36 #define _LTORG .L$_subsec = .L$_subsec + 2; .text .L$_subsec
38 // Announcing an external function.
42 .macro ENDFUNC; _ENDFUNC(name); .endm; \
47 // Marking the end of a function.
48 #define _ENDFUNC(name) \
54 // Make a helper function, if necessary.
56 .ifndef .L$_auxfn_def.name; \
58 .macro _ENDAUXFN; _ENDAUXFN_TAIL(name); .endm; \
61 #define _ENDAUXFN_TAIL(name) \
64 .L$_auxfn_def.name = 1
65 #define ENDAUXFN _ENDAUXFN; .endif
67 ///--------------------------------------------------------------------------
68 /// ELF-specific hacking.
72 #if __PIC__ || __PIE__
76 #define TYPE_FUNC(name) .type name, STT_FUNC
78 #define SIZE_OBJ(name) .size name, . - name
82 ///--------------------------------------------------------------------------
83 /// Windows-specific hacking.
88 # define F(name) _##name
93 ///--------------------------------------------------------------------------
94 /// x86- and amd64-specific hacking.
96 /// It's (slightly) easier to deal with both of these in one go.
98 #if CPUFAM_X86 || CPUFAM_AMD64
100 // Set the function hooks.
101 #define FUNC_PREHOOK(_) .balign 16
103 // On Windows, arrange to install stack-unwinding data.
104 #if CPUFAM_AMD64 && ABI_WIN
105 # define FUNC_POSTHOOK(name) .seh_proc name
106 # define ENDFUNC_HOOK(_) .seh_endproc
107 // Procedures are expected to invoke `.seh_setframe' if necessary, and
108 // `.seh_pushreg' and friends, and `.seh_endprologue'.
111 // Don't use the wretched AT&T syntax. It's festooned with pointless
112 // punctuation, and all of the data movement is backwards. Ugh!
113 .intel_syntax noprefix
115 // Call external subroutine at ADDR, possibly via PLT.
124 // Do I need to arrange a spare GOT register?
125 #if WANT_PIC && CPUFAM_X86
128 #define GOTREG ebx // Not needed in AMD64 so don't care.
130 // Maybe load GOT address into GOT.
131 .macro ldgot got
=GOTREG
132 #if WANT_PIC && CPUFAM_X86
138 add \got
, offset _GLOBAL_OFFSET_TABLE_
142 // Load address of external symbol ADDR into REG, maybe using GOT.
143 .macro leaext reg
, addr
, got
=GOTREG
146 mov
\reg
, [\got
+ \addr@GOT
]
149 mov
\reg
, \addr@GOTPCREL
[rip
]
153 mov
\reg
, offset
\addr
161 // Address expression (possibly using a base register, and a displacement)
162 // referring to ADDR, which is within our module, maybe using GOT.
163 #define INTADDR(...) INTADDR__0(__VA_ARGS__, GOTREG, dummy)
164 #define INTADDR__0(addr, got, ...) INTADDR__1(addr, got)
166 # define INTADDR__1(addr, got) addr + rip
168 # define INTADDR__1(addr, got) got + addr@GOTOFF
170 # define INTADDR__1(addr, got) addr
175 ///--------------------------------------------------------------------------
176 /// ARM-specific hacking.
180 // ARM/Thumb mode things. Use ARM by default.
181 #define ARM .arm; .L$_pcoff = 8
182 #define THUMB .thumb; .L$_pcoff = 4
185 // Set the function hooks.
186 #define FUNC_PREHOOK(_) .balign 4
187 #define ENDFUNC_HOOK(name) .ltorg
189 // Call external subroutine at ADDR, possibly via PLT.
190 .macro callext addr
, cond
=
198 // Do I need to arrange a spare GOT register?
204 // Maybe load GOT address into GOT.
205 .macro ldgot cond
=, got
=GOTREG
207 ldr\cond \got
, .L$_ldgot$\@
209 add\cond \got
, pc
, \got
213 .word _GLOBAL_OFFSET_TABLE_
- .L$_ldgot_pc$\@
- .L$_pcoff
218 // Load address of external symbol ADDR into REG, maybe using GOT.
219 .macro leaext reg
, addr
, cond
=, got
=GOTREG
221 ldr\cond
\reg
, .L$_leaext$\@
222 ldr\cond
\reg
, [\got
, \reg
]
229 ldr\cond
\reg
, =\addr
233 // Load address of external symbol ADDR into REG directly.
234 .macro leaextq reg
, addr
, cond
=
236 ldr\cond
\reg
, .L$_leaextq$\@
239 ldr\cond
\reg
, [pc
, \reg
]
242 ldr\cond
\reg
, [\reg
]
247 .word
\addr
(GOT_PREL
) + (. - .L$_leaextq_pc$\@
- .L$_pcoff
)
250 ldr\cond
\reg
, =\addr
256 ///--------------------------------------------------------------------------
259 // Default values for the various hooks.
261 # define FUNC_PREHOOK(name)
263 #ifndef FUNC_POSTHOOK
264 # define FUNC_POSTHOOK(name)
267 # define ENDFUNC_HOOK(name)
271 # define F(name) name
275 # define TYPE_FUNC(name)
279 # define SIZE_OBJ(name)
282 ///----- That's all, folks --------------------------------------------------