BR 3392218: Disassemble 82h opcodes
[nasm/nasm.git] / standard.mac
blobb2dff8d6467b2f171c39f4343b3bd62031b26ecf
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 %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
72 %imacro sectalign 1.nolist
73     %ifnum %1
74         %if __SECTALIGN_ALIGN_UPDATES_SECTION__ = 1
75             [sectalign %1]
76         %endif
77     %else
78         %ifidni %1,off
79             %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 0
80         %elifidni %1,on
81             %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
82         %endif
83     %endif
84 %endmacro
86 %imacro absolute 1+.nolist
87     %define __SECT__ [absolute %1]
88     __SECT__
89 %endmacro
91 %imacro struc 1-2.nolist 0
92     %push
93         %define %$strucname %1
94         [absolute %2]
95         %$strucname:        ; allow definition of `.member' to work sanely
96     %endmacro
98 %imacro endstruc 0.nolist
99         %{$strucname}_size equ ($-%$strucname)
100     %pop
101     __SECT__
102 %endmacro
104 %imacro istruc 1.nolist
105     %push
106         %define %$strucname %1
107         %$strucstart:
108 %endmacro
110 %imacro at 1-2+.nolist
111     times (%1-%$strucname)-($-%$strucstart) db 0
112     %2
113 %endmacro
115 %imacro iend 0.nolist
116         times %{$strucname}_size-($-%$strucstart) db 0
117     %pop
118 %endmacro
120 %imacro align 1-2+.nolist nop
121     sectalign %1
122     times (((%1) - (($-$$) % (%1))) % (%1)) %2
123 %endmacro
125 %imacro alignb 1-2+.nolist
126     sectalign %1
127     %ifempty %2
128         resb (((%1) - (($-$$) % (%1))) % (%1))
129     %else
130         times (((%1) - (($-$$) % (%1))) % (%1)) %2
131     %endif
132 %endmacro
134 %imacro extern 1-*.nolist
135     %rep %0
136         [extern %1]
137         %rotate 1
138     %endrep
139 %endmacro
141 %imacro bits 1+.nolist
142     [bits %1]
143 %endmacro
145 %imacro use16 0.nolist
146     [bits 16]
147 %endmacro
149 %imacro use32 0.nolist
150     [bits 32]
151 %endmacro
153 %imacro use64 0.nolist
154     [bits 64]
155 %endmacro
157 %imacro global 1-*.nolist
158     %rep %0
159         [global %1]
160         %rotate 1
161     %endrep
162 %endmacro
164 %imacro common 1-*.nolist
165     %rep %0
166         [common %1]
167         %rotate 1
168     %endrep
169 %endmacro
171 %imacro cpu 1+.nolist
172     [cpu %1]
173 %endmacro
175 %define __FLOAT_DAZ__ nodaz
176 %define __FLOAT_ROUND__ near
177 ; __FLOAT__ contains the whole floating-point configuration so it can
178 ; be saved and restored
179 %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
181 %imacro float 1-*.nolist
182     %rep %0
183         [float %1]
184         %ifidni %1,daz
185             %define __FLOAT_DAZ__ daz
186         %elifidni %1,nodaz
187             %define __FLOAT_DAZ__ nodaz
188         %elifidni %1,near
189             %define __FLOAT_ROUND__ near
190         %elifidni %1,up
191             %define __FLOAT_ROUND__ up
192         %elifidni %1,down
193             %define __FLOAT_ROUND__ down
194         %elifidni %1,zero
195             %define __FLOAT_ROUND__ zero
196         %elifidni %1,default
197             %define __FLOAT_DAZ__ nodaz
198             %define __FLOAT_ROUND__ near
199         %endif
200         %rotate 1
201     %endrep
202 %endmacro
204 %imacro default 1+.nolist
205     [default %1]
206 %endmacro
208 %imacro incbin 1-2+.nolist 0
209     %push
210         %pathsearch %$dep %1
211         %depend %$dep
212         %? %$dep,%2
213     %pop
214 %endmacro