Add __PATH__ support
[nasm.git] / standard.mac
blob0c27fe2b0bd7aa071bbf6f39b5aa62505a3cbb9c
1 ;; --------------------------------------------------------------------------
2 ;;   
3 ;;   Copyright 1996-2009 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 before the first include
37 ; directive.
39     %idefine IDEAL
40     %idefine JUMPS
41     %idefine P386
42     %idefine P486
43     %idefine P586
44     %idefine END
46 ; This is a magic token which indicates the end of the TASM macros
47 *END*TASM*MACROS*
49 ; Note that although some user-level forms of directives are defined
50 ; here, not all of them are: the user-level form of a format-specific
51 ; directive should be defined in the module for that directive.
53 ; These need to be defined, though the actual definitions will
54 ; be constantly updated during preprocessing.
55 %define __PATH__
56 %define __FILE__
57 %define __LINE__
58 %define __BITS__
60 %define __SECT__            ; it ought to be defined, even if as nothing
62 %imacro section 1+.nolist
63     %define __SECT__ [section %1]
64     __SECT__
65 %endmacro
67 %imacro segment 1+.nolist
68     %define __SECT__ [segment %1]
69     __SECT__
70 %endmacro
72 %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
73 %imacro sectalign 1.nolist
74     %ifnum %1
75         %if __SECTALIGN_ALIGN_UPDATES_SECTION__ = 1
76             [sectalign %1]
77         %endif
78     %else
79         %ifidni %1,off
80             %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 0
81         %elifidni %1,on
82             %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
83         %endif
84     %endif
85 %endmacro
87 %imacro absolute 1+.nolist
88     %define __SECT__ [absolute %1]
89     __SECT__
90 %endmacro
92 %imacro struc 1-2.nolist 0
93     %push
94         %define %$strucname %1
95         [absolute %2]
96         %$strucname:        ; allow definition of `.member' to work sanely
97     %endmacro
99 %imacro endstruc 0.nolist
100         %{$strucname}_size equ ($-%$strucname)
101     %pop
102     __SECT__
103 %endmacro
105 %imacro istruc 1.nolist
106     %push
107         %define %$strucname %1
108         %$strucstart:
109 %endmacro
111 %imacro at 1-2+.nolist
112     times (%1-%$strucname)-($-%$strucstart) db 0
113     %2
114 %endmacro
116 %imacro iend 0.nolist
117         times %{$strucname}_size-($-%$strucstart) db 0
118     %pop
119 %endmacro
121 %imacro align 1-2+.nolist nop
122     sectalign %1
123     times (((%1) - (($-$$) % (%1))) % (%1)) %2
124 %endmacro
126 %imacro alignb 1-2+.nolist
127     sectalign %1
128     %ifempty %2
129         resb (((%1) - (($-$$) % (%1))) % (%1))
130     %else
131         times (((%1) - (($-$$) % (%1))) % (%1)) %2
132     %endif
133 %endmacro
135 %imacro extern 1-*.nolist
136     %rep %0
137         [extern %1]
138         %rotate 1
139     %endrep
140 %endmacro
142 %imacro bits 1+.nolist
143     [bits %1]
144 %endmacro
146 %imacro use16 0.nolist
147     [bits 16]
148 %endmacro
150 %imacro use32 0.nolist
151     [bits 32]
152 %endmacro
154 %imacro use64 0.nolist
155     [bits 64]
156 %endmacro
158 %imacro global 1-*.nolist
159     %rep %0
160         [global %1]
161         %rotate 1
162     %endrep
163 %endmacro
165 %imacro common 1-*.nolist
166     %rep %0
167         [common %1]
168         %rotate 1
169     %endrep
170 %endmacro
172 %imacro cpu 1+.nolist
173     [cpu %1]
174 %endmacro
176 %define __FLOAT_DAZ__ nodaz
177 %define __FLOAT_ROUND__ near
178 ; __FLOAT__ contains the whole floating-point configuration so it can
179 ; be saved and restored
180 %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
182 %imacro float 1-*.nolist
183     %rep %0
184         [float %1]
185         %ifidni %1,daz
186             %define __FLOAT_DAZ__ daz
187         %elifidni %1,nodaz
188             %define __FLOAT_DAZ__ nodaz
189         %elifidni %1,near
190             %define __FLOAT_ROUND__ near
191         %elifidni %1,up
192             %define __FLOAT_ROUND__ up
193         %elifidni %1,down
194             %define __FLOAT_ROUND__ down
195         %elifidni %1,zero
196             %define __FLOAT_ROUND__ zero
197         %elifidni %1,default
198             %define __FLOAT_DAZ__ nodaz
199             %define __FLOAT_ROUND__ near
200         %endif
201         %rotate 1
202     %endrep
203 %endmacro
205 %imacro default 1+.nolist
206     [default %1]
207 %endmacro
209 %imacro incbin 1-2+.nolist 0
210     %push
211         %pathsearch %$dep %1
212         %depend %$dep
213         %? %$dep,%2
214     %pop
215 %endmacro