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)
14 /* Allow ".name" identifiers */
21 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
24 /* Explicit radix in MASM syntax */
28 #define HEX(x) 0##x##h
30 /* Macro values need not be marked */
33 /* MASM/ML doesn't want explicit [rip] addressing */
36 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
37 #define MACRO(name, ...) name MACRO __VA_ARGS__
39 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
41 __current_function_name EQU %name
50 /* ... and .ENDP, replacing ENDP */
52 %__current_function_name ENDP
56 /* Global labels need an extra colon */
57 GLOBAL_LABEL MACRO label
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)
67 /* MASM doesn't have an ASCII macro */
68 .ASCII MACRO text:VARARG
71 .ascii MACRO text:VARARG
75 /* MASM doesn't have an ASCIZ macro */
76 .ASCIZ MACRO text:VARARG
80 .asciz MACRO text:VARARG
112 .align MACRO alignment
116 .byte MACRO args:VARARG
120 .short MACRO args:VARARG
124 .word MACRO args:VARARG
128 .long MACRO args:VARARG
132 .double MACRO args:VARARG
140 .fill MACRO count, size, value
152 .skip MACRO size, fill:=<0>
156 .space MACRO size, fill:=<0>
160 ljmp MACRO segment, offset
166 ljmp16 MACRO segment, offset
172 data32 MACRO opcode:VARARG
177 UNIMPLEMENTED MACRO name
180 absolute MACRO address
181 __absolute__address__ = address
184 resb MACRO name, size
185 name = __absolute__address__
186 __absolute__address__ = __absolute__address__ + size
190 /* We need this to distinguish repeat from macros */
197 #else /***********************************************************************/
199 /* Force intel syntax */
200 .intel_syntax noprefix
204 /* Explicit radix in GAS syntax */
210 /* Macro values need to be marked */
213 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
214 #define MACRO(...) .macro __VA_ARGS__
217 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
221 /* x86 gas expects a label with _ prefix */
226 .equ cfa_current_offset, -8
230 /* ... and .ENDP, replacing ENDP */
235 #define ENDFUNC .ENDP
237 /* MASM compatible PUBLIC */
242 /* No special marking of global labels */
243 .macro GLOBAL_LABEL label
248 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
251 /* MASM needs an end tag for segments */
255 /* MASM compatible ALIGN */
258 /* MASM compatible REPEAT, additional ENDR */
262 .macro ljmp segment, offset
263 jmp far ptr \segment:\offset
266 .macro ljmp16 segment, offset
267 jmp far ptr \segment:\offset
270 /* MASM compatible EXTERN */
274 /* MASM needs an END tag */
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
290 /* Macros for x64 stack unwind OPs */
292 .macro .allocstack size
293 .cfi_adjust_cfa_offset \size
294 .set cfa_current_offset, cfa_current_offset - \size
298 .macro .pushframe param=0
300 .cfi_adjust_cfa_offset 0x30
301 .set cfa_current_offset, cfa_current_offset - 0x30
303 .cfi_adjust_cfa_offset 0x28
304 .set cfa_current_offset, cfa_current_offset - 0x28
309 .cfi_adjust_cfa_offset 8
310 .equ cfa_current_offset, cfa_current_offset - 8
311 .cfi_offset \reg, cfa_current_offset
314 .macro .savereg reg, offset
316 .cfi_offset \reg, \offset
319 .macro .savexmm128 reg, offset
321 .cfi_offset \reg, \offset
324 .macro .setframe reg, offset
325 .cfi_def_cfa reg, \offset
326 .equ cfa_current_offset, \offset
332 .macro absolute address
333 __absolute__address__ = \address
336 .macro resb name, size
337 \name = __absolute__address__
338 __absolute__address__ = __absolute__address__ + \size
341 .macro UNIMPLEMENTED2 file, line, func
347 lea rcx, MsgUnimplemented[rip]
354 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
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 */
361 #define elseif .elseif
369 /* Common definitions for FPO macro
370 see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
374 #define FRAME_NONFPO 3
376 #endif /* __ASM_INC__ */