standart.mac: Style nitfix
[nasm.git] / standard.mac
blob0b79896222b620acc070f8a32bc13d624ee8d8d0
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 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
66 %imacro segment 1+.nolist
67     %define __SECT__ [segment %1]
68     __SECT__
69 %endmacro
71 %imacro sectalign 1.nolist
72     [sectalign %1]
73 %endmacro
75 %imacro absolute 1+.nolist
76     %define __SECT__ [absolute %1]
77     __SECT__
78 %endmacro
80 %imacro struc 1-2.nolist 0
81     %push
82         %define %$strucname %1
83         [absolute %2]
84         %$strucname:        ; allow definition of `.member' to work sanely
85     %endmacro
87 %imacro endstruc 0.nolist
88         %{$strucname}_size equ ($-%$strucname)
89     %pop
90     __SECT__
91 %endmacro
93 %imacro istruc 1.nolist
94     %push
95         %define %$strucname %1
96         %$strucstart:
97 %endmacro
99 %imacro at 1-2+.nolist
100     times (%1-%$strucname)-($-%$strucstart) db 0
101     %2
102 %endmacro
104 %imacro iend 0.nolist
105         times %{$strucname}_size-($-%$strucstart) db 0
106     %pop
107 %endmacro
109 %imacro align 1-2+.nolist nop
110     sectalign %1
111     times (((%1) - (($-$$) % (%1))) % (%1)) %2
112 %endmacro
114 %imacro alignb 1-2+.nolist
115     sectalign %1
116     %ifempty %2
117         resb (((%1) - (($-$$) % (%1))) % (%1))
118     %else
119         times (((%1) - (($-$$) % (%1))) % (%1)) %2
120     %endif
121 %endmacro
123 %imacro extern 1-*.nolist
124     %rep %0
125         [extern %1]
126         %rotate 1
127     %endrep
128 %endmacro
130 %imacro bits 1+.nolist
131     [bits %1]
132 %endmacro
134 %imacro use16 0.nolist
135     [bits 16]
136 %endmacro
138 %imacro use32 0.nolist
139     [bits 32]
140 %endmacro
142 %imacro use64 0.nolist
143     [bits 64]
144 %endmacro
146 %imacro global 1-*.nolist
147     %rep %0
148         [global %1]
149         %rotate 1
150     %endrep
151 %endmacro
153 %imacro common 1-*.nolist
154     %rep %0
155         [common %1]
156         %rotate 1
157     %endrep
158 %endmacro
160 %imacro cpu 1+.nolist
161     [cpu %1]
162 %endmacro
164 %define __FLOAT_DAZ__ nodaz
165 %define __FLOAT_ROUND__ near
166 ; __FLOAT__ contains the whole floating-point configuration so it can
167 ; be saved and restored
168 %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
170 %imacro float 1-*.nolist
171     %rep %0
172         [float %1]
173         %ifidni %1,daz
174             %define __FLOAT_DAZ__ daz
175         %elifidni %1,nodaz
176             %define __FLOAT_DAZ__ nodaz
177         %elifidni %1,near
178             %define __FLOAT_ROUND__ near
179         %elifidni %1,up
180             %define __FLOAT_ROUND__ up
181         %elifidni %1,down
182             %define __FLOAT_ROUND__ down
183         %elifidni %1,zero
184             %define __FLOAT_ROUND__ zero
185         %elifidni %1,default
186             %define __FLOAT_DAZ__ nodaz
187             %define __FLOAT_ROUND__ near
188         %endif
189         %rotate 1
190     %endrep
191 %endmacro
193 %imacro default 1+.nolist
194     [default %1]
195 %endmacro
197 %imacro incbin 1-2+.nolist 0
198     %push
199         %pathsearch %$dep %1
200         %depend %$dep
201         %? %$dep,%2
202     %pop
203 %endmacro