Use fallthrough() to placate compiler
[nasm.git] / macros / standard.mac
blob5fe9eb6c337658e1bb01630b7e57cc118d370473
1 ;; --------------------------------------------------------------------------
2 ;;   
3 ;;   Copyright 1996-2016 The NASM Authors - All Rights Reserved
4 ;;   See the file AUTHORS included with the NASM distribution for
5 ;;   the specific copyright holders.
6 ;;
7 ;;   Redistribution and use in source and binary forms, with or without
8 ;;   modification, are permitted provided that the following
9 ;;   conditions are met:
11 ;;   * Redistributions of source code must retain the above copyright
12 ;;     notice, this list of conditions and the following disclaimer.
13 ;;   * Redistributions in binary form must reproduce the above
14 ;;     copyright notice, this list of conditions and the following
15 ;;     disclaimer in the documentation and/or other materials provided
16 ;;     with the distribution.
18 ;;     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 ;;     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 ;;     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 ;;     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 ;;     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 ;;     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 ;;     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 ;;     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 ;;     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 ;;     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 ;;     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 ;;     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 ;;     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ;; --------------------------------------------------------------------------
34 ; Standard macro set for NASM -*- nasm -*-
36 ; Macros to make NASM ignore some TASM directives
37 STD: tasm
38     %idefine IDEAL
39     %idefine JUMPS
40     %idefine P386
41     %idefine P486
42     %idefine P586
43     %idefine END
45 ; The normal standard macros
46 STD: nasm
48 ; Note that although some user-level forms of directives are defined
49 ; here, not all of them are: the user-level form of a format-specific
50 ; directive should be defined in the module for that directive.
52 ; These three need to be defined, though the actual definitions will
53 ; be constantly updated during preprocessing.
54 %define __FILE__
55 %define __LINE__
56 %define __BITS__
58 %define __SECT__            ; it ought to be defined, even if as nothing
60 %imacro section 1+.nolist
61     %define __SECT__ [section %1]
62     __SECT__
63 %endmacro
65 %imacro segment 1+.nolist
66     %define __SECT__ [segment %1]
67     __SECT__
68 %endmacro
70 %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
71 %imacro sectalign 1.nolist
72     %ifnum %1
73         %if __SECTALIGN_ALIGN_UPDATES_SECTION__ = 1
74             [sectalign %1]
75         %endif
76     %else
77         %ifidni %1,off
78             %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 0
79         %elifidni %1,on
80             %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
81         %endif
82     %endif
83 %endmacro
85 %imacro absolute 1+.nolist
86     %define __SECT__ [absolute %1]
87     __SECT__
88 %endmacro
90 %imacro struc 1-2.nolist 0
91     %push
92         %define %$strucname %1
93         [absolute %2]
94         %$strucname:        ; allow definition of `.member' to work sanely
95 %endmacro
97 %imacro endstruc 0.nolist
98         %{$strucname}_size equ ($-%$strucname)
99     %pop
100     __SECT__
101 %endmacro
103 %imacro istruc 1.nolist
104     %push
105         %define %$strucname %1
106         %$strucstart:
107 %endmacro
109 %imacro at 1-2+.nolist
110     times (%1-%$strucname)-($-%$strucstart) db 0
111     %2
112 %endmacro
114 %imacro iend 0.nolist
115         times %{$strucname}_size-($-%$strucstart) db 0
116     %pop
117 %endmacro
119 %imacro align 1-2+.nolist nop
120     sectalign %1
121     times (((%1) - (($-$$) % (%1))) % (%1)) %2
122 %endmacro
124 %imacro alignb 1-2+.nolist
125     sectalign %1
126     %ifempty %2
127         resb (((%1) - (($-$$) % (%1))) % (%1))
128     %else
129         times (((%1) - (($-$$) % (%1))) % (%1)) %2
130     %endif
131 %endmacro
133 %imacro extern 1-*.nolist
134     %rep %0
135         [extern %1]
136         %rotate 1
137     %endrep
138 %endmacro
140 %imacro bits 1+.nolist
141     [bits %1]
142 %endmacro
144 %imacro use16 0.nolist
145     [bits 16]
146 %endmacro
148 %imacro use32 0.nolist
149     [bits 32]
150 %endmacro
152 %imacro use64 0.nolist
153     [bits 64]
154 %endmacro
156 %imacro global 1-*.nolist
157     %rep %0
158         [global %1]
159         %rotate 1
160     %endrep
161 %endmacro
163 %imacro common 1-*.nolist
164     %rep %0
165         [common %1]
166         %rotate 1
167     %endrep
168 %endmacro
170 %imacro cpu 1+.nolist
171     [cpu %1]
172 %endmacro
174 %define __FLOAT_DAZ__ nodaz
175 %define __FLOAT_ROUND__ near
176 ; __FLOAT__ contains the whole floating-point configuration so it can
177 ; be saved and restored
178 %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
180 %imacro float 1-*.nolist
181     %rep %0
182         [float %1]
183         %ifidni %1,daz
184             %define __FLOAT_DAZ__ daz
185         %elifidni %1,nodaz
186             %define __FLOAT_DAZ__ nodaz
187         %elifidni %1,near
188             %define __FLOAT_ROUND__ near
189         %elifidni %1,up
190             %define __FLOAT_ROUND__ up
191         %elifidni %1,down
192             %define __FLOAT_ROUND__ down
193         %elifidni %1,zero
194             %define __FLOAT_ROUND__ zero
195         %elifidni %1,default
196             %define __FLOAT_DAZ__ nodaz
197             %define __FLOAT_ROUND__ near
198         %endif
199         %rotate 1
200     %endrep
201 %endmacro
203 %imacro default 1+.nolist
204     [default %1]
205 %endmacro
207 %imacro userel 0.nolist
208     [default rel]
209 %endmacro
210 %imacro useabs 0.nolist
211     [default abs]
212 %endmacro
213 %imacro usebnd 0.nolist
214     [default bnd]
215 %endmacro
216 %imacro usenobnd 0.nolist
217     [default nobnd]
218 %endmacro
220 %imacro incbin 1-2+.nolist 0
221     %push
222         %pathsearch %$dep %1
223         %depend %$dep
224         %? %$dep,%2
225     %pop
226 %endmacro