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)
12 /* Common definitions for FPO macro
13 see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
17 #define FRAME_NONFPO 3
21 /* Allow ".name" identifiers */
28 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
31 /* Explicit radix in MASM syntax */
35 #define HEX(x) 0##x##h
37 /* Macro values need not be marked */
40 /* MASM/ML doesn't want explicit [rip] addressing */
43 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
44 #define MACRO(name, ...) name MACRO __VA_ARGS__
46 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
48 __current_function_name EQU %name
57 /* ... and .ENDP, replacing ENDP */
59 %__current_function_name ENDP
63 /* Global labels need an extra colon */
64 GLOBAL_LABEL MACRO label
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)
74 /* MASM doesn't have an ASCII macro */
75 .ASCII MACRO text:VARARG
78 .ascii MACRO text:VARARG
82 /* MASM doesn't have an ASCIZ macro */
83 .ASCIZ MACRO text:VARARG
87 .asciz MACRO text:VARARG
119 .align MACRO alignment
123 .byte MACRO args:VARARG
127 .short MACRO args:VARARG
131 .word MACRO args:VARARG
135 .long MACRO args:VARARG
139 .double MACRO args:VARARG
147 .fill MACRO count, size, value
159 .skip MACRO size, fill:=<0>
163 .space MACRO size, fill:=<0>
167 ljmp MACRO segment, offset
173 ljmp16 MACRO segment, offset
179 data32 MACRO opcode:VARARG
184 UNIMPLEMENTED MACRO name
187 absolute MACRO address
188 __absolute__address__ = address
191 resb MACRO name, size
192 name = __absolute__address__
193 __absolute__address__ = __absolute__address__ + size
196 /* We need this to distinguish repeat from macros */
203 /* For compatibility with GAS */
204 #define CFI_STARTPROC
206 #define CFI_ADJUST_CFA_OFFSET
209 #define CFI_DEF_CFA_REGISTER
211 #define CFI_REL_OFFSET
212 #define CFI_SAME_VALUE
213 #define CFI_DEF_CFA_OFFSET
215 #else /***********************************************************************/
217 /* Force intel syntax */
218 .intel_syntax noprefix
222 /* Explicit radix in GAS syntax */
228 /* Macro values need to be marked */
231 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
232 #define MACRO(...) .macro __VA_ARGS__
235 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
239 /* x86 GAS expects a label with _ prefix */
244 .equ cfa_current_offset, -8
248 /* ... and .ENDP, replacing ENDP */
253 #define ENDFUNC .ENDP
255 /* MASM compatible PUBLIC */
260 /* No special marking of global labels */
261 .macro GLOBAL_LABEL label
266 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
269 /* MASM needs an end tag for segments */
273 /* MASM compatible ALIGN */
276 /* MASM compatible REPEAT, additional ENDR */
280 .macro ljmp segment, offset
281 jmp far ptr \segment:\offset
284 .macro ljmp16 segment, offset
285 jmp far ptr \segment:\offset
288 /* MASM compatible EXTERN */
292 /* MASM needs an END tag */
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)
310 /* Macros for x64 stack unwind OPs */
312 .macro .allocstack size
313 .cfi_adjust_cfa_offset \size
314 .set cfa_current_offset, cfa_current_offset - \size
318 .macro .pushframe param=0
320 .cfi_adjust_cfa_offset 0x30
321 .set cfa_current_offset, cfa_current_offset - 0x30
323 .cfi_adjust_cfa_offset 0x28
324 .set cfa_current_offset, cfa_current_offset - 0x28
329 .cfi_adjust_cfa_offset 8
330 .equ cfa_current_offset, cfa_current_offset - 8
331 .cfi_offset \reg, cfa_current_offset
334 .macro .savereg reg, offset
336 .cfi_offset \reg, \offset
339 .macro .savexmm128 reg, offset
341 .cfi_offset \reg, \offset
344 .macro .setframe reg, offset
345 .cfi_def_cfa reg, \offset
346 .equ cfa_current_offset, \offset
352 .macro absolute address
353 __absolute__address__ = \address
356 .macro resb name, size
357 \name = __absolute__address__
358 __absolute__address__ = __absolute__address__ + \size
361 .macro UNIMPLEMENTED2 file, line, func
367 lea rcx, MsgUnimplemented[rip]
374 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
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 */
381 #define elseif .elseif
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
401 #endif /* __ASM_INC__ */