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
37 // Announcing an external function.
41 .macro ENDFUNC; _ENDFUNC(name); .endm; \
46 // Marking the end of a function.
47 #define _ENDFUNC(name) \
51 .L$_subsec = .L$_subsec + 2; \
54 ///--------------------------------------------------------------------------
55 /// ELF-specific hacking.
59 #if __PIC__ || __PIE__
63 #define TYPE_FUNC(name) .type name, STT_FUNC
65 #define SIZE_OBJ(name) .size name, . - name
69 ///--------------------------------------------------------------------------
70 /// Windows-specific hacking.
75 # define F(name) _##name
80 ///--------------------------------------------------------------------------
81 /// x86- and amd64-specific hacking.
83 /// It's (slightly) easier to deal with both of these in one go.
85 #if CPUFAM_X86 || CPUFAM_AMD64
87 // Set the function hooks.
88 #define FUNC_PREHOOK(_) .balign 16
90 // Don't use the wretched AT&T syntax. It's festooned with pointless
91 // punctuation, and all of the data movement is backwards. Ugh!
92 .intel_syntax noprefix
94 // Call external subroutine at ADDR, possibly via PLT.
103 // Do I need to arrange a spare GOT register?
104 #if WANT_PIC && CPUFAM_X86
107 #define GOTREG ebx // Not needed in AMD64 so don't care.
109 // Maybe load GOT address into GOT.
110 .macro ldgot got
=GOTREG
111 #if WANT_PIC && CPUFAM_X86
112 call _where_am_i
.\got
113 add \got
, offset _GLOBAL_OFFSET_TABLE_
117 // Maybe build a helper subroutine for `ldgot GOT'.
118 .macro gotaux got
=GOTREG
119 #if WANT_PIC && CPUFAM_X86
127 // Load address of external symbol ADDR into REG, maybe using GOT.
128 .macro leaext reg
, addr
, got
=GOTREG
131 mov
\reg
, [\got
+ \addr@GOT
]
134 mov
\reg
, \addr@GOTPCREL
[rip
]
138 mov
\reg
, offset
\addr
146 // Address expression (possibly using a base register, and a displacement)
147 // referring to ADDR, which is within our module, maybe using GOT.
148 #define INTADDR(...) INTADDR__0(__VA_ARGS__, GOTREG, dummy)
149 #define INTADDR__0(addr, got, ...) INTADDR__1(addr, got)
151 # define INTADDR__1(addr, got) addr + rip
153 # define INTADDR__1(addr, got) got + addr@GOTOFF
155 # define INTADDR__1(addr, got) addr
160 ///--------------------------------------------------------------------------
161 /// ARM-specific hacking.
165 // ARM/Thumb mode things. Use ARM by default.
166 #define ARM .arm; .L$_pcoff = 8
167 #define THUMB .thumb; .L$_pcoff = 4
170 // Set the function hooks.
171 #define FUNC_PREHOOK(_) .balign 4
172 #define ENDFUNC_HOOK(name) .ltorg
174 // Call external subroutine at ADDR, possibly via PLT.
175 .macro callext addr
, cond
=
183 // Do I need to arrange a spare GOT register?
189 // Maybe load GOT address into GOT.
190 .macro ldgot cond
=, got
=GOTREG
192 ldr\cond \got
, .L$_ldgot$\@
194 add\cond \got
, pc
, \got
198 .word _GLOBAL_OFFSET_TABLE_
- .L$_ldgot_pc$\@
- .L$_pcoff
203 // Load address of external symbol ADDR into REG, maybe using GOT.
204 .macro leaext reg
, addr
, cond
=, got
=GOTREG
206 ldr\cond
\reg
, .L$_leaext$\@
207 ldr\cond
\reg
, [\got
, \reg
]
214 ldr\cond
\reg
, =\addr
218 // Load address of external symbol ADDR into REG directly.
219 .macro leaextq reg
, addr
, cond
=
221 ldr\cond
\reg
, .L$_leaextq$\@
224 ldr\cond
\reg
, [pc
, \reg
]
227 ldr\cond
\reg
, [\reg
]
232 .word
\addr
(GOT_PREL
) + (. - .L$_leaextq_pc$\@
- .L$_pcoff
)
235 ldr\cond
\reg
, =\addr
241 ///--------------------------------------------------------------------------
244 // Default values for the various hooks.
246 # define FUNC_PREHOOK(name)
248 #ifndef FUNC_POSTHOOK
249 # define FUNC_POSTHOOK(name)
252 # define ENDFUNC_HOOK(name)
256 # define F(name) name
260 # define TYPE_FUNC(name)
264 # define SIZE_OBJ(name)
267 ///----- That's all, folks --------------------------------------------------