Update macros a bit more
[reactos.git] / reactos / include / reactos / asm.h
1 /*
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)
7 */
8
9 #ifdef _MSC_VER
10
11 /* Allow ".name" identifiers */
12 OPTION DOTNAME
13
14 /* Hex numbers need to be in 01ABh format */
15 #define HEX(x) 0##x##h
16
17 /* MASM/ML doesn't want explicit [rip] addressing */
18 #define RIP(address) address
19
20 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
21 #define MACRO(name, ...) name MACRO __VA_ARGS__
22
23 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
24 .PROC MACRO namex
25 namex PROC FRAME
26 ENDM
27
28 /* ... and .ENDP, replacing ENDP */
29 .ENDP MACRO name
30 name ENDP
31 ENDM
32
33 /* MASM doesn't have an ASCIIZ macro */
34 .ASCIIZ MACRO text
35 DB text, 0
36 ENDM
37
38 /* We need this to distinguish repeat from macros */
39 #define ENDR ENDM
40
41 #else /***********************************************************************/
42
43 /* Force intel syntax */
44 .intel_syntax noprefix
45 .code64
46
47 /* Hex numbers need to be in 0x1AB format */
48 #define HEX(x) 0x##x
49
50 /* GAS needs explicit [rip] addressing */
51 #define RIP(address) address##[rip]
52
53 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
54 #define MACRO(name, ...) .MACRO name, __VA_ARGS__
55
56 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
57 .macro .PROC name
58 .func \name
59 \name:
60 .cfi_startproc
61 .equ cfa_current_offset, -8
62 .endm
63
64 /* ... and .ENDP, replacing ENDP */
65 .macro .ENDP name
66 .cfi_endproc
67 .endfunc
68 .endm
69
70 /* MASM compatible PUBLIC */
71 #define PUBLIC .global
72
73 /* MASM compatible ALIGN */
74 #define ALIGN .align
75
76 /* MASM compatible REPEAT, additional ENDR */
77 #define REPEAT .rept
78 #define ENDR .endr
79
80
81 /* Macros for x64 stack unwind OPs */
82
83 .macro .allocstack size
84 .cfi_adjust_cfa_offset \size
85 .set cfa_current_offset, cfa_current_offset - \size
86 .endm
87
88 .macro .pushframe code
89 .if (\code == 0)
90 .cfi_adjust_cfa_offset 0x28
91 .set cfa_current_offset, cfa_current_offset - 0x28
92 .else
93 .cfi_adjust_cfa_offset 0x30
94 .set cfa_current_offset, cfa_current_offset - 0x30
95 .endif
96 .endm
97
98 .macro .pushreg reg
99 .cfi_adjust_cfa_offset 8
100 .equ cfa_current_offset, cfa_current_offset - 8
101 .cfi_offset \reg, cfa_current_offset
102 .endm
103
104 .macro .savereg reg, offset
105 // checkme!!!
106 .cfi_offset \reg, \offset
107 .endm
108
109 .macro .savexmm128 reg, offset
110 // checkme!!!
111 .cfi_offset \reg, \offset
112 .endm
113
114 .macro .setframe reg, offset
115 .cfi_def_cfa reg, \offset
116 .equ cfa_current_offset, \offset
117 .endm
118
119 .macro .endprolog
120 .endm
121
122 .macro UNIMPLEMENTED2 file, line, func
123 jmp 3f
124 .equ expr, 12
125 1: .asciz "\func"
126 2: .asciz "\file"
127 3:
128 sub rsp, 0x20
129 lea rcx, _MsgUnimplemented[rip]
130 lea rdx, 1b[rip]
131 lea r8, 2b[rip]
132 mov r9, \line
133 call _DbgPrint
134 add rsp, 0x20
135 .endm
136 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
137
138 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
139 conditionals. We therefore use "if", too. .if shouldn't be used at all */
140 #define if .if
141 #define endif .endif
142
143 #endif