aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox/macro.S
blob: f213f15f9d67efa94cbdc9c58b955741b10c0226 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "platform_config.h"

#if !defined(HAVE_SLASHMACRO) && !defined(HAVE_DOLLARMACRO)
	#error Unknown gnu as macro parameter convention! Run ./configure
#endif

#if defined(__MACH__)
	.macro FN name
	#if defined(HAVE_SLASHMACRO)
		\name:
		_\name:
	#elif defined(HAVE_DOLLARMACRO)
		$0:
		_$0:
	#endif
	.endm

	.macro FN_EXT name, args, xmmused
	#if defined(HAVE_SLASHMACRO)
		FN \name
	#elif defined(HAVE_DOLLARMACRO)
		FN $0
	#endif
	.endm

	.macro FN_END name
	.endm

	.macro HIDDEN name
	#if defined(HAVE_AS_PRIVATE_EXTERN)
	#if defined(HAVE_SLASHMACRO)
		.private_extern \name
		.private_extern _\name
	#elif defined(HAVE_DOLLARMACRO)
		.private_extern $0
		.private_extern _$0
	#endif
	#endif
	.endm
#else
	.macro FN name
		\name:
		_\name:
	.endm

	.macro FN_EXT name, args, xmmused
		FN \name
	.endm

	.macro FN_END name
		.size \name, .-\name
		.size _\name, .-_\name
		.type \name, @function
	 	.type _\name, @function
	.endm

	.macro HIDDEN name
	#if defined(HAVE_AS_HIDDEN)
		.hidden \name
		.hidden _\name
	#endif
	.endm

	/* set NX for stack */
	.section .note.GNU-stack,"",@progbits
#endif
#if defined(__MACH__)
	.macro SECTION_TEXT
		.section __TEXT,__text,regular
	.endm

	.macro SECTION_RODATA
		.section __TEXT,__text,regular
	.endm
#else
	/* put everything in the code segment to simplify things */
	.macro SECTION_TEXT
		.text
	.endm

	.macro SECTION_RODATA
		.text
	.endm
#endif

/* declare a global function */
.macro GLOBAL name
#if defined(HAVE_SLASHMACRO)
	.globl \name
	.globl _\name
#elif defined(HAVE_DOLLARMACRO)
	.globl $0
	.globl _$0
#endif
.endm

.macro FN_LOCAL_PREFIX name
#if defined(HAVE_SLASHMACRO)
	FN LOCAL_PREFIX(\name)
#elif defined(HAVE_DOLLARMACRO)
	FN LOCAL_PREFIX($0)
#endif
.endm

.macro FN_EXT_LOCAL_PREFIX name, args, xmmused
#if defined(HAVE_SLASHMACRO)
	FN_EXT LOCAL_PREFIX(\name), \args, \xmmused
#elif defined(HAVE_DOLLARMACRO)
	FN_EXT LOCAL_PREFIX($0), $1, $2
#endif
.endm

.macro FN_END_LOCAL_PREFIX name
#if defined(HAVE_SLASHMACRO)
	FN_END LOCAL_PREFIX(\name)
#elif defined(HAVE_DOLLARMACRO)
	FN_END LOCAL_PREFIX($0)
#endif
.endm

.macro GLOBAL_LOCAL_PREFIX name
#if defined(HAVE_SLASHMACRO)
	GLOBAL LOCAL_PREFIX(\name)
	HIDDEN LOCAL_PREFIX(\name)
#elif defined(HAVE_DOLLARMACRO)
	GLOBAL LOCAL_PREFIX($0)
	HIDDEN LOCAL_PREFIX($0)
#endif
.endm

.macro GLOBAL_HIDDEN_FN name
#if defined(HAVE_SLASHMACRO)
	GLOBAL \name
	HIDDEN \name
	FN \name
#elif defined(HAVE_DOLLARMACRO)
	GLOBAL $0
	HIDDEN $0
	FN $0
#endif
.endm

.macro GLOBAL_HIDDEN_FN_EXT name, args, xmmused
#if defined(HAVE_SLASHMACRO)
	GLOBAL \name
	HIDDEN \name
	FN_EXT \name, \args, \xmmused
#elif defined(HAVE_DOLLARMACRO)
	GLOBAL $0
	HIDDEN $0
	FN_EXT $0, $1, $2
#endif
.endm

/* pic support */
.macro LOAD_VAR_PIC var, reg
#if !defined(__LP64__)
	#if defined(HAVE_SLASHMACRO)
		call 1f
		1:
		popl \reg
		leal \var - 1b(\reg), \reg
	#elif defined(HAVE_DOLLARMACRO)
		call 1f
		1:
		popl $1
		leal $0 - 1b($1), $1
	#endif
#else
	#if defined(HAVE_SLASHMACRO)
		leaq \var(%rip), \reg
	#elif defined(HAVE_DOLLARMACRO)
		leaq $0(%rip), $1
	#endif
#endif
.endm