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