preproc: add %[i]defid support
[nasm.git] / standard.mac
bloba3e8eea3e4507764e48ce52af97e0b943d2f18cd
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.
17 ;;     
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 three need to be defined, though the actual definitions will
54 ; be constantly updated during preprocessing.
55 %define __FILE__
56 %define __LINE__
57 %define __BITS__
59 %define __SECT__                ; it ought to be defined, even if as nothing
61 %imacro section 1+.nolist
62 %define __SECT__ [section %1]
63           __SECT__
64 %endmacro
65 %imacro segment 1+.nolist
66 %define __SECT__ [segment %1]
67           __SECT__
68 %endmacro
70 %imacro absolute 1+.nolist
71 %define __SECT__ [absolute %1]
72           __SECT__
73 %endmacro
75 %imacro struc 1-2.nolist 0
76 %push
77 %define %$strucname %1
78 [absolute %2]
79 %$strucname:                    ; allow definition of `.member' to work sanely
80 %endmacro
81 %imacro endstruc 0.nolist
82 %{$strucname}_size equ ($-%$strucname)
83 %pop
84 __SECT__
85 %endmacro
87 %imacro istruc 1.nolist
88 %push
89 %define %$strucname %1
90 %$strucstart:
91 %endmacro
92 %imacro at 1-2+.nolist
93           times (%1-%$strucname)-($-%$strucstart) db 0
94           %2
95 %endmacro
96 %imacro iend 0.nolist
97           times %{$strucname}_size-($-%$strucstart) db 0
98 %pop
99 %endmacro
101 %imacro align 1-2+.nolist nop
102           times (((%1) - (($-$$) % (%1))) % (%1)) %2
103 %endmacro
104 %imacro alignb 1-2+.nolist
105           %ifempty %2
106                 resb (((%1) - (($-$$) % (%1))) % (%1))
107           %else
108                 times (((%1) - (($-$$) % (%1))) % (%1)) %2
109           %endif
110 %endmacro
112 %imacro extern 1-*.nolist
113 %rep %0
114 [extern %1]
115 %rotate 1
116 %endrep
117 %endmacro
119 %imacro bits 1+.nolist
120 [bits %1]
121 %endmacro
123 %imacro use16 0.nolist
124 [bits 16]
125 %endmacro
126 %imacro use32 0.nolist
127 [bits 32]
128 %endmacro
129 %imacro use64 0.nolist
130 [bits 64]
131 %endmacro
133 %imacro global 1-*.nolist
134 %rep %0
135 [global %1]
136 %rotate 1
137 %endrep
138 %endmacro
140 %imacro common 1-*.nolist
141 %rep %0
142 [common %1]
143 %rotate 1
144 %endrep
145 %endmacro
147 %imacro cpu 1+.nolist
148 [cpu %1]
149 %endmacro
151 %define __FLOAT_DAZ__ nodaz
152 %define __FLOAT_ROUND__ near
153 ; __FLOAT__ contains the whole floating-point configuration so it can
154 ; be saved and restored
155 %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
156 %imacro float 1-*.nolist
157 %rep %0
158 [float %1]
159 %ifidni %1,daz
160 %define __FLOAT_DAZ__ daz
161 %elifidni %1,nodaz
162 %define __FLOAT_DAZ__ nodaz
163 %elifidni %1,near
164 %define __FLOAT_ROUND__ near
165 %elifidni %1,up
166 %define __FLOAT_ROUND__ up
167 %elifidni %1,down
168 %define __FLOAT_ROUND__ down
169 %elifidni %1,zero
170 %define __FLOAT_ROUND__ zero
171 %elifidni %1,default
172 %define __FLOAT_DAZ__ nodaz
173 %define __FLOAT_ROUND__ near
174 %endif
175 %rotate 1
176 %endrep
177 %endmacro
179 %imacro default 1+.nolist
180 [default %1]
181 %endmacro
183 %imacro incbin 1-2+.nolist 0
184 %push
185 %pathsearch %$dep %1
186 %depend %$dep
187         %? %$dep,%2
188 %pop
189 %endmacro