Debian Codegraph @

macros/standard.mac

raw
1 ;; SPDX-License-Identifier: BSD-2-Clause
2 ;; Copyright 1996-2025 The NASM Authors - All Rights Reserved
3
4 ; Standard macro set for NASM -*- nasm -*-
5
6 ; Macros to make NASM ignore some TASM directives
7 STD: tasm
8 %idefine IDEAL
9 %idefine JUMPS
10 %idefine P386
11 %idefine P486
12 %idefine P586
13 %idefine END
14
15 ; The normal standard macros
16 STD: nasm
17
18 ; Note that although some user-level forms of directives are defined
19 ; here, not all of them are: the user-level form of a format-specific
20 ; directive should be defined in the module for that directive.
21
22 %define __?SECT?__ ; it ought to be defined, even if as nothing
23 %defalias __SECT__ __?SECT?__
24
25 %imacro section 1+.nolist
26 %define __?SECT?__ [section %1]
27 __?SECT?__
28 %endmacro
29
30 %imacro segment 1+.nolist
31 %define __?SECT?__ [segment %1]
32 __?SECT?__
33 %endmacro
34
35 %define __?SECTALIGN_ALIGN_UPDATES_SECTION?__ 1
36 %imacro sectalign 1+.nolist
37 %ifidni %1,off
38 %define __?SECTALIGN_ALIGN_UPDATES_SECTION?__ 0
39 %elifidni %1,on
40 %define __?SECTALIGN_ALIGN_UPDATES_SECTION?__ 1
41 %else
42 [sectalign %1]
43 %endif
44 %endmacro
45 %defalias __SECTALIGN_ALIGN_UPDATES_SECTION__ __?SECTALIGN_ALIGN_UPDATES_SECTION?__
46
47 %imacro absolute 1+.nolist
48 %define __?SECT?__ [absolute %1]
49 __?SECT?__
50 %endmacro
51
52 %imacro struc 1-2.nolist 0
53 %push
54 %define %$strucname %1
55 [absolute %2]
56 %$strucname: ; allow definition of `.member' to work sanely
57 %endmacro
58
59 %imacro endstruc 0.nolist
60 %{$strucname}_size equ ($-%$strucname)
61 %pop
62 [warning push]
63 [warning -other]
64 __?SECT?__
65 [warning pop]
66 %endmacro
67
68 %imacro istruc 1.nolist
69 %push
70 %define %$strucname %1
71 %$strucstart:
72 %endmacro
73
74 %imacro at 1-2+.nolist
75 %defstr %$member %1
76 %substr %$member1 %$member 1
77 %ifidn %$member1, '.'
78 times (%$strucname%1-%$strucname)-($-%$strucstart) db 0
79 %else
80 times (%1-%$strucname)-($-%$strucstart) db 0
81 %endif
82 %2
83 %endmacro
84
85 %imacro iend 0.nolist
86 times %{$strucname}_size-($-%$strucstart) db 0
87 %pop
88 %endmacro
89
90 %imacro align 1-2+.nolist nop
91 %if __?SECTALIGN_ALIGN_UPDATES_SECTION?__
92 sectalign %1
93 %endif
94 times (((%1) - (($-$$) % (%1))) % (%1)) %2
95 %endmacro
96
97 %imacro alignb 1-2+.nolist
98 %if __?SECTALIGN_ALIGN_UPDATES_SECTION?__
99 sectalign %1
100 %endif
101 %ifempty %2
102 [warning push]
103 [warning -zeroing]
104 resb (((%1) - (($-$$) % (%1))) % (%1))
105 [warning pop]
106 %else
107 times (((%1) - (($-$$) % (%1))) % (%1)) %2
108 %endif
109 %endmacro
110
111 %imacro bits 1+.nolist
112 [bits %1]
113 %endmacro
114
115 %imacro use16 0.nolist
116 [bits 16]
117 %endmacro
118
119 %imacro use32 0.nolist
120 [bits 32]
121 %endmacro
122
123 %imacro use64 0.nolist
124 [bits 64]
125 %endmacro
126
127 %imacro extern 1-*.nolist
128 %rep %0
129 [extern %1]
130 %rotate 1
131 %endrep
132 %endmacro
133
134 %imacro static 1-*.nolist
135 %rep %0
136 [static %1]
137 %rotate 1
138 %endrep
139 %endmacro
140
141 %imacro global 1-*.nolist
142 %rep %0
143 [global %1]
144 %rotate 1
145 %endrep
146 %endmacro
147
148 %imacro required 1-*.nolist
149 %rep %0
150 [required %1]
151 %rotate 1
152 %endrep
153 %endmacro
154
155 %imacro common 1-*.nolist
156 %rep %0
157 [common %1]
158 %rotate 1
159 %endrep
160 %endmacro
161
162 %imacro cpu 1+.nolist
163 [cpu %1]
164 %endmacro
165
166 %define __?FLOAT_DAZ?__ nodaz
167 %define __?FLOAT_ROUND?__ near
168 ; __?FLOAT?__ contains the whole floating-point configuration so it can
169 ; be saved and restored
170 %define __?FLOAT?__ __?FLOAT_DAZ?__,__?FLOAT_ROUND?__
171
172 %defalias __FLOAT_DAZ__ __?FLOAT_DAZ?__
173 %defalias __FLOAT_ROUND__ __?FLOAT_ROUND?__
174 %defalias __FLOAT__ __?FLOAT?__
175
176 %imacro float 1-*.nolist
177 %rep %0
178 [float %1]
179 %ifidni %1,daz
180 %define __?FLOAT_DAZ?__ daz
181 %elifidni %1,nodaz
182 %define __?FLOAT_DAZ?__ nodaz
183 %elifidni %1,near
184 %define __?FLOAT_ROUND?__ near
185 %elifidni %1,up
186 %define __?FLOAT_ROUND?__ up
187 %elifidni %1,down
188 %define __?FLOAT_ROUND?__ down
189 %elifidni %1,zero
190 %define __?FLOAT_ROUND?__ zero
191 %elifidni %1,default
192 %define __?FLOAT_DAZ?__ nodaz
193 %define __?FLOAT_ROUND?__ near
194 %endif
195 %rotate 1
196 %endrep
197 %endmacro
198
199 %imacro default 1+.nolist
200 [default %1]
201 %endmacro
202
203 %imacro userel 0.nolist
204 [default rel]
205 %endmacro
206 %imacro useabs 0.nolist
207 [default abs]
208 %endmacro
209 %imacro usebnd 0.nolist
210 [default bnd]
211 %endmacro
212 %imacro usenobnd 0.nolist
213 [default nobnd]
214 %endmacro
215
216 %imacro incbin 1-2+.nolist 0
217 %? %depend(%pathsearch(%1)),%2
218 %endmacro
219
220 ; Compatibility macro aliases
221 %defalias __NASM_MAJOR__ __?NASM_MAJOR?__
222 %defalias __NASM_MINOR__ __?NASM_MINOR?__
223 %defalias __NASM_SUBMINOR__ __?NASM_SUBMINOR?__
224 %defalias __NASM_PATCHLEVEL__ __?NASM_PATCHLEVEL?__
225 %defalias __NASM_SNAPSHOT__ __?NASM_SNAPSHOT?__
226 %defalias __NASM_VERSION_ID__ __?NASM_VERSION_ID?__
227 %defalias __NASM_VER__ __?NASM_VER?__
228
229 %defalias __OUTPUT_FORMAT__ __?OUTPUT_FORMAT?__
230 %defalias __DEBUG_FORMAT__ __?DEBUG_FORMAT?__
231
232 %defalias __DATE__ __?DATE?__
233 %defalias __DATE_NUM__ __?DATE_NUM?__
234 %defalias __TIME__ __?TIME?__
235 %defalias __TIME_NUM__ __?TIME_NUM?__
236 %defalias __UTC_DATE__ __?UTC_DATE?__
237 %defalias __UTC_DATE_NUM__ __?UTC_DATE_NUM?__
238 %defalias __UTC_TIME__ __?UTC_TIME?__
239 %defalias __UTC_TIME_NUM__ __?UTC_TIME_NUM?__
240 %defalias __POSIX_TIME__ __?POSIX_TIME?__
241
242 %defalias __FILE__ __?FILE?__
243 %defalias __LINE__ __?LINE?__
244 %defalias __BITS__ __?BITS?__
245 %defalias __PTR__ __?PTR?__
246 %defalias __PASS__ __?PASS?__
247
248 ; Backwards compatibility aliases for tokens. The extra level of
249 ; indirection here means %aliases on|off will do the right thing for
250 ; these as well.
251 %idefine __?infinity?__ %?
252 %idefine __?nan?__ %?
253 %idefine __?qnan?__ %?
254 %idefine __?snan?__ %?
255
256 %idefine __?float8?__ %?
257 %idefine __?float16?__ %?
258 %idefine __?float32?__ %?
259 %idefine __?float64?__ %?
260 %idefine __?float80m?__ %?
261 %idefine __?float80e?__ %?
262 %idefine __?float128l?__ %?
263 %idefine __?float128h?__ %?
264
265 %idefine __?utf16?__ %?
266 %idefine __?utf16le?__ %?
267 %idefine __?utf16be?__ %?
268 %idefine __?utf32?__ %?
269 %idefine __?utf32le?__ %?
270 %idefine __?utf32be?__ %?
271
272 %idefine __?ilog2e?__ %?
273 %idefine __?ilog2w?__ %?
274 %idefine __?ilog2f?__ %?
275 %idefine __?ilog2c?__ %?
276
277 %idefalias __infinity__ __?infinity?__
278 %idefalias __nan__ __?nan?__
279 %idefalias __qnan__ __?qnan?__
280 %idefalias __snan__ __?snan?__
281
282 %idefalias __float8__ __?float8?__
283 %idefalias __float16__ __?float16?__
284 %idefalias __float32__ __?float32?__
285 %idefalias __float64__ __?float64?__
286 %idefalias __float80m__ __?float80m?__
287 %idefalias __float80e__ __?float80e?__
288 %idefalias __float128l__ __?float128l?__
289 %idefalias __float128h__ __?float128h?__
290
291 %idefalias __utf16__ __?utf16?__
292 %idefalias __utf16le__ __?utf16le?__
293 %idefalias __utf16be__ __?utf16be?__
294 %idefalias __utf32__ __?utf32?__
295 %idefalias __utf32le__ __?utf32le?__
296 %idefalias __utf32be__ __?utf32be?__
297
298 %idefalias __ilog2e__ __?ilog2e?__
299 %idefalias __ilog2w__ __?ilog2w?__
300 %idefalias __ilog2f__ __?ilog2f?__
301 %idefalias __ilog2c__ __?ilog2c?__
302
303 ; Declare that %ifdirective is supported
304 %define __?NASM_HAS_IFDIRECTIVE?__ 1