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 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 /* Hex numbers need to be in 01ABh format */
25 #define HEX(x) 0##x##h
27 /* Macro values need to be marked */
30 /* MASM/ML doesn't want explicit [rip] addressing */
33 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
34 #define MACRO(name, ...) name MACRO __VA_ARGS__
36 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
38 __current_function_name EQU %name
47 /* ... and .ENDP, replacing ENDP */
49 %__current_function_name ENDP
53 /* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
54 and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
55 FPO MACRO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
56 .FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame)
59 /* MASM doesn't have an ASCII macro */
60 .ASCII MACRO text:VARARG
63 .ascii MACRO text:VARARG
67 /* MASM doesn't have an ASCIZ macro */
68 .ASCIZ MACRO text:VARARG
72 .asciz MACRO text:VARARG
104 .align MACRO alignment
108 .byte MACRO args:VARARG
112 .short MACRO args:VARARG
116 .word MACRO args:VARARG
120 .long MACRO args:VARARG
124 .double MACRO args:VARARG
132 .fill MACRO count, size, value
144 .skip MACRO size, fill:=<0>
148 .space MACRO size, fill:=<0>
152 ljmp MACRO segment, offset
158 ljmp16 MACRO segment, offset
164 data32 MACRO opcode:VARARG
169 UNIMPLEMENTED MACRO name
172 absolute MACRO address
173 __absolute__address__ = address
176 resb MACRO name, size
177 name = __absolute__address__
178 __absolute__address__ = __absolute__address__ + size
182 /* We need this to distinguish repeat from macros */
189 #else /***********************************************************************/
191 /* Force intel syntax */
192 .intel_syntax noprefix
196 /* Hex numbers need to be in 0x1AB format */
199 /* Macro values need to be marked */
202 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
203 #define MACRO(...) .macro __VA_ARGS__
206 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
210 /* x86 gas expects a label with _ prefix */
215 .equ cfa_current_offset, -8
219 /* ... and .ENDP, replacing ENDP */
224 #define ENDFUNC .ENDP
226 /* MASM compatible PUBLIC */
232 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
235 /* MASM needs an end tag for segments */
239 /* MASM compatible ALIGN */
242 /* MASM compatible REPEAT, additional ENDR */
246 .macro ljmp segment, offset
247 jmp far ptr \segment:\offset
250 .macro ljmp16 segment, offset
251 jmp far ptr \segment:\offset
254 /* MASM compatible EXTERN */
258 /* MASM needs an END tag */
268 /* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
269 and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
270 .macro FPO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
274 /* Macros for x64 stack unwind OPs */
276 .macro .allocstack size
277 .cfi_adjust_cfa_offset \size
278 .set cfa_current_offset, cfa_current_offset - \size
282 .macro .pushframe param=0
284 .cfi_adjust_cfa_offset 0x30
285 .set cfa_current_offset, cfa_current_offset - 0x30
287 .cfi_adjust_cfa_offset 0x28
288 .set cfa_current_offset, cfa_current_offset - 0x28
293 .cfi_adjust_cfa_offset 8
294 .equ cfa_current_offset, cfa_current_offset - 8
295 .cfi_offset \reg, cfa_current_offset
298 .macro .savereg reg, offset
300 .cfi_offset \reg, \offset
303 .macro .savexmm128 reg, offset
305 .cfi_offset \reg, \offset
308 .macro .setframe reg, offset
309 .cfi_def_cfa reg, \offset
310 .equ cfa_current_offset, \offset
316 .macro absolute address
317 __absolute__address__ = \address
320 .macro resb name, size
321 \name = __absolute__address__
322 __absolute__address__ = __absolute__address__ + \size
325 .macro UNIMPLEMENTED2 file, line, func
332 lea rcx, MsgUnimplemented[rip]
339 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
341 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
342 conditionals. We therefore use "if", too. .if shouldn't be used at all */
346 #define elseif .elseif
354 /* Common definitions for FPO macro
355 see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
359 #define FRAME_NONFPO 3
361 #endif /* __ASM_INC__ */