[CLASSPNP] Fix MSVC build. Brought to you by Timo.
[reactos.git] / reactos / include / asm / asm.inc
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: include/asm/asm.inc
5 * PURPOSE: ASM macros for GAS and MASM/ML64
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7 */
8
9 #ifndef __ASM_INC__
10 #define __ASM_INC__
11
12 #ifdef _USE_ML
13
14 /* Allow ".name" identifiers */
15 OPTION DOTNAME
16
17 #ifdef _M_IX86
18 .686P
19 .XMM
20 .MODEL FLAT
21 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
22 #endif
23
24 /* Explicit radix in MASM syntax */
25 #define BIN(x) x##y
26 #define OCT(x) x##q
27 #define DEC(x) x##t
28 #define HEX(x) 0##x##h
29
30 /* Macro values need not be marked */
31 #define VAL(x) x
32
33 /* MASM/ML doesn't want explicit [rip] addressing */
34 rip = 0
35
36 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
37 #define MACRO(name, ...) name MACRO __VA_ARGS__
38
39 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
40 .PROC MACRO name
41 __current_function_name EQU %name
42 #ifdef _M_IX86
43 %name PROC
44 #else
45 %name PROC FRAME
46 #endif
47 ENDM
48 #define FUNC .PROC
49
50 /* ... and .ENDP, replacing ENDP */
51 .ENDP MACRO
52 %__current_function_name ENDP
53 ENDM
54 #define ENDFUNC .ENDP
55
56 /* Global labels need an extra colon */
57 GLOBAL_LABEL MACRO label
58 %label::
59 ENDM
60
61 /* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
62 and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
63 FPO MACRO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
64 .FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame)
65 ENDM
66
67 /* MASM doesn't have an ASCII macro */
68 .ASCII MACRO text:VARARG
69 DB text
70 ENDM
71 .ascii MACRO text:VARARG
72 DB text
73 ENDM
74
75 /* MASM doesn't have an ASCIZ macro */
76 .ASCIZ MACRO text:VARARG
77 DB text
78 DB 0
79 ENDM
80 .asciz MACRO text:VARARG
81 DB text
82 DB 0
83 ENDM
84
85 .code64 MACRO
86 .code
87 ENDM
88
89 .code32 MACRO
90 .code
91 .586P
92 ENDM
93
94 .code16 MACRO
95 ASSUME nothing
96 .text SEGMENT use16
97 .586P
98 ENDM
99
100 .endcode16 MACRO
101 .text ENDS
102 ENDM
103
104 .bss MACRO
105 .DATA?
106 ASSUME nothing
107 ENDM
108
109 //.text MACRO
110 //ENDM
111
112 .align MACRO alignment
113 ALIGN alignment
114 ENDM
115
116 .byte MACRO args:VARARG
117 db args
118 ENDM
119
120 .short MACRO args:VARARG
121 dw args
122 ENDM
123
124 .word MACRO args:VARARG
125 dw args
126 ENDM
127
128 .long MACRO args:VARARG
129 dd args
130 ENDM
131
132 .double MACRO args:VARARG
133 dq args
134 ENDM
135
136 .org MACRO value
137 ORG value
138 ENDM
139
140 .fill MACRO count, size, value
141 REPEAT count
142 if (size EQ 1)
143 DB value
144 elseif (size EQ 2)
145 DW value
146 elseif (size EQ 4)
147 DD value
148 endif
149 ENDM
150 ENDM
151
152 .skip MACRO size, fill:=<0>
153 DB size DUP (fill)
154 ENDM
155
156 .space MACRO size, fill:=<0>
157 .skip size, fill
158 ENDM
159
160 ljmp MACRO segment, offset
161 DB 0EAh
162 DD offset
163 DW segment
164 ENDM
165
166 ljmp16 MACRO segment, offset
167 DB 0EAh
168 DW offset
169 DW segment
170 ENDM
171
172 data32 MACRO opcode:VARARG
173 DB 66h
174 opcode
175 ENDM
176
177 UNIMPLEMENTED MACRO name
178 ENDM
179
180 absolute MACRO address
181 __absolute__address__ = address
182 ENDM
183
184 resb MACRO name, size
185 name = __absolute__address__
186 __absolute__address__ = __absolute__address__ + size
187 ENDM
188
189
190 /* We need this to distinguish repeat from macros */
191 #define ENDR ENDM
192
193 #define CR 13
194 #define LF 10
195 #define NUL 0
196
197 #else /***********************************************************************/
198
199 /* Force intel syntax */
200 .intel_syntax noprefix
201
202 .altmacro
203
204 /* Explicit radix in GAS syntax */
205 #define BIN(x) 0b##x
206 #define OCT(x) 0##x
207 #define DEC(x) x
208 #define HEX(x) 0x##x
209
210 /* Macro values need to be marked */
211 #define VAL(x) \x
212
213 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
214 #define MACRO(...) .macro __VA_ARGS__
215 #define ENDM .endm
216
217 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
218 .macro .PROC name
219 .func \name
220 #ifdef _X86_
221 /* x86 gas expects a label with _ prefix */
222 _\name:
223 #endif
224 \name:
225 .cfi_startproc
226 .equ cfa_current_offset, -8
227 .endm
228 #define FUNC .PROC
229
230 /* ... and .ENDP, replacing ENDP */
231 .macro .ENDP
232 .cfi_endproc
233 .endfunc
234 .endm
235 #define ENDFUNC .ENDP
236
237 /* MASM compatible PUBLIC */
238 .macro PUBLIC symbol
239 .global \symbol
240 .endm
241
242 /* No special marking of global labels */
243 .macro GLOBAL_LABEL label
244 \label:
245 .endm
246
247 /* Dummy ASSUME */
248 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
249 .endm
250
251 /* MASM needs an end tag for segments */
252 .macro .endcode16
253 .endm
254
255 /* MASM compatible ALIGN */
256 #define ALIGN .align
257
258 /* MASM compatible REPEAT, additional ENDR */
259 #define REPEAT .rept
260 #define ENDR .endr
261
262 .macro ljmp segment, offset
263 jmp far ptr \segment:\offset
264 .endm
265
266 .macro ljmp16 segment, offset
267 jmp far ptr \segment:\offset
268 .endm
269
270 /* MASM compatible EXTERN */
271 .macro EXTERN name
272 .endm
273
274 /* MASM needs an END tag */
275 #define END
276
277 .macro .MODEL model
278 .endm
279
280 .macro .code
281 .text
282 .endm
283
284 /* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
285 and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
286 .macro FPO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
287 /* dummy */
288 .endm
289
290 /* Macros for x64 stack unwind OPs */
291
292 .macro .allocstack size
293 .cfi_adjust_cfa_offset \size
294 .set cfa_current_offset, cfa_current_offset - \size
295 .endm
296
297 code = 1
298 .macro .pushframe param=0
299 .if (\param)
300 .cfi_adjust_cfa_offset 0x30
301 .set cfa_current_offset, cfa_current_offset - 0x30
302 .else
303 .cfi_adjust_cfa_offset 0x28
304 .set cfa_current_offset, cfa_current_offset - 0x28
305 .endif
306 .endm
307
308 .macro .pushreg reg
309 .cfi_adjust_cfa_offset 8
310 .equ cfa_current_offset, cfa_current_offset - 8
311 .cfi_offset \reg, cfa_current_offset
312 .endm
313
314 .macro .savereg reg, offset
315 // checkme!!!
316 .cfi_offset \reg, \offset
317 .endm
318
319 .macro .savexmm128 reg, offset
320 // checkme!!!
321 .cfi_offset \reg, \offset
322 .endm
323
324 .macro .setframe reg, offset
325 .cfi_def_cfa reg, \offset
326 .equ cfa_current_offset, \offset
327 .endm
328
329 .macro .endprolog
330 .endm
331
332 .macro absolute address
333 __absolute__address__ = \address
334 .endm
335
336 .macro resb name, size
337 \name = __absolute__address__
338 __absolute__address__ = __absolute__address__ + \size
339 .endm
340
341 .macro UNIMPLEMENTED2 file, line, func
342 jmp 3f
343 1: .asciz "\func"
344 2: .asciz \file
345 3:
346 sub rsp, 0x20
347 lea rcx, MsgUnimplemented[rip]
348 lea rdx, 1b[rip]
349 lea r8, 2b[rip]
350 mov r9, \line
351 call DbgPrint
352 add rsp, 0x20
353 .endm
354 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
355
356 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
357 conditionals. We therefore use "if", too. .if shouldn't be used at all */
358 #define if .if
359 #define endif .endif
360 #define else .else
361 #define elseif .elseif
362
363 #define CR "\r"
364 #define LF "\n"
365 #define NUL "\0"
366
367 #endif
368
369 /* Common definitions for FPO macro
370 see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
371 #define FRAME_FPO 0
372 #define FRAME_TRAP 1
373 #define FRAME_TSS 2
374 #define FRAME_NONFPO 3
375
376 #endif /* __ASM_INC__ */