2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/include/amd64/asmmacro.S
5 * PURPOSE: ASM macros for for GAS and MASM/ML64
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
11 /* Allow ".name" identifiers */
18 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
21 /* Hex numbers need to be in 01ABh format */
22 #define HEX(x) 0##x##h
24 /* Macro values need to be marked */
27 /* MASM/ML doesn't want explicit [rip] addressing */
30 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
31 #define MACRO(name, ...) name MACRO __VA_ARGS__
33 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
35 __current_function_name EQU %name
44 /* ... and .ENDP, replacing ENDP */
46 %__current_function_name ENDP
50 /* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
51 and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
52 FPO MACRO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
53 .FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame)
56 /* MASM doesn't have an ASCII macro */
57 .ASCII MACRO text:VARARG
60 .ascii MACRO text:VARARG
64 /* MASM doesn't have an ASCIZ macro */
65 .ASCIZ MACRO text:VARARG
69 .asciz MACRO text:VARARG
101 .align MACRO alignment
105 .byte MACRO args:VARARG
109 .short MACRO args:VARARG
113 .word MACRO args:VARARG
117 .long MACRO args:VARARG
121 .double MACRO args:VARARG
129 .fill MACRO count, size, value
145 ljmp MACRO segment, offset
151 ljmp16 MACRO segment, offset
157 data32 MACRO opcode:VARARG
162 UNIMPLEMENTED MACRO name
165 absolute MACRO address
166 __absolute__address__ = address
169 resb MACRO name, size
170 name = __absolute__address__
171 __absolute__address__ = __absolute__address__ + size
175 /* We need this to distinguish repeat from macros */
182 #else /***********************************************************************/
184 /* Force intel syntax */
185 .intel_syntax noprefix
189 /* Hex numbers need to be in 0x1AB format */
192 /* Macro values need to be marked */
195 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
196 #define MACRO(...) .macro __VA_ARGS__
199 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
203 /* x86 gas expects a label with _ prefix */
208 .equ cfa_current_offset, -8
212 /* ... and .ENDP, replacing ENDP */
217 #define ENDFUNC .ENDP
219 /* MASM compatible PUBLIC */
225 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
228 /* MASM needs an end tag for segments */
232 /* MASM compatible ALIGN */
235 /* MASM compatible REPEAT, additional ENDR */
239 .macro ljmp segment, offset
240 jmp far ptr \segment:\offset
243 .macro ljmp16 segment, offset
244 jmp far ptr \segment:\offset
247 /* MASM compatible EXTERN */
251 /* MASM needs an END tag */
261 /* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
262 and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
263 .macro FPO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
267 /* Macros for x64 stack unwind OPs */
269 .macro .allocstack size
270 .cfi_adjust_cfa_offset \size
271 .set cfa_current_offset, cfa_current_offset - \size
275 .macro .pushframe param=0
277 .cfi_adjust_cfa_offset 0x30
278 .set cfa_current_offset, cfa_current_offset - 0x30
280 .cfi_adjust_cfa_offset 0x28
281 .set cfa_current_offset, cfa_current_offset - 0x28
286 .cfi_adjust_cfa_offset 8
287 .equ cfa_current_offset, cfa_current_offset - 8
288 .cfi_offset \reg, cfa_current_offset
291 .macro .savereg reg, offset
293 .cfi_offset \reg, \offset
296 .macro .savexmm128 reg, offset
298 .cfi_offset \reg, \offset
301 .macro .setframe reg, offset
302 .cfi_def_cfa reg, \offset
303 .equ cfa_current_offset, \offset
309 .macro absolute address
310 __absolute__address__ = \address
313 .macro resb name, size
314 \name = __absolute__address__
315 __absolute__address__ = __absolute__address__ + \size
318 .macro UNIMPLEMENTED2 file, line, func
325 lea rcx, MsgUnimplemented[rip]
332 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
334 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
335 conditionals. We therefore use "if", too. .if shouldn't be used at all */
339 #define elseif .elseif
347 /* Common definitions for FPO macro
348 see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
352 #define FRAME_NONFPO 3