Sync with trunk head
[reactos.git] / 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 .586
15 .MODEL FLAT
16
17 /* Hex numbers need to be in 01ABh format */
18 #define HEX(x) 0##x##h
19
20 /* Macro values need to be marked */
21 #define VAL(x) x
22
23 /* MASM/ML doesn't want explicit [rip] addressing */
24 rip = 0
25
26 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
27 #define MACRO(name, ...) name MACRO __VA_ARGS__
28
29 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
30 .PROC MACRO name
31 name PROC FRAME
32 _name:
33 ENDM
34
35 /* ... and .ENDP, replacing ENDP */
36 .ENDP MACRO name
37 name ENDP
38 ENDM
39
40 /* MASM doesn't have an ASCII macro */
41 .ASCII MACRO text
42 DB text
43 ENDM
44
45 /* MASM doesn't have an ASCIZ macro */
46 .ASCIZ MACRO text
47 DB text, 0
48 ENDM
49
50 .text MACRO
51 ENDM
52
53 .code64 MACRO
54 .code
55 ENDM
56
57 .code32 MACRO
58 .code
59 ENDM
60
61 UNIMPLEMENTED MACRO name
62 ENDM
63
64 /* We need this to distinguish repeat from macros */
65 #define ENDR ENDM
66
67 #else /***********************************************************************/
68
69 /* Force intel syntax */
70 .intel_syntax noprefix
71 .code64
72
73 .altmacro
74
75 /* Hex numbers need to be in 0x1AB format */
76 #define HEX(x) 0x##x
77
78 /* Macro values need to be marked */
79 #define VAL(x) \x
80
81 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
82 #define MACRO(...) .macro __VA_ARGS__
83 #define ENDM .endm
84
85 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
86 .macro .PROC name
87 .func \name
88 \name:
89 .cfi_startproc
90 .equ cfa_current_offset, -8
91 .endm
92
93 /* ... and .ENDP, replacing ENDP */
94 .macro .ENDP name
95 .cfi_endproc
96 .endfunc
97 .endm
98
99 /* MASM compatible PUBLIC */
100 .macro PUBLIC symbol
101 .global \symbol
102 .endm
103
104 /* MASM compatible ALIGN */
105 #define ALIGN .align
106
107 /* MASM compatible REPEAT, additional ENDR */
108 #define REPEAT .rept
109 #define ENDR .endr
110
111 /* MASM compatible EXTERN */
112 .macro EXTERN name
113 .endm
114
115 /* MASM needs an END tag */
116 #define END
117
118 .macro .MODEL model
119 .endm
120
121 .macro .code
122 .text
123 .endm
124
125 /* Macros for x64 stack unwind OPs */
126
127 .macro .allocstack size
128 .cfi_adjust_cfa_offset \size
129 .set cfa_current_offset, cfa_current_offset - \size
130 .endm
131
132 code = 1
133 .macro .pushframe param=0
134 .if (\param)
135 .cfi_adjust_cfa_offset 0x30
136 .set cfa_current_offset, cfa_current_offset - 0x30
137 .else
138 .cfi_adjust_cfa_offset 0x28
139 .set cfa_current_offset, cfa_current_offset - 0x28
140 .endif
141 .endm
142
143 .macro .pushreg reg
144 .cfi_adjust_cfa_offset 8
145 .equ cfa_current_offset, cfa_current_offset - 8
146 .cfi_offset \reg, cfa_current_offset
147 .endm
148
149 .macro .savereg reg, offset
150 // checkme!!!
151 .cfi_offset \reg, \offset
152 .endm
153
154 .macro .savexmm128 reg, offset
155 // checkme!!!
156 .cfi_offset \reg, \offset
157 .endm
158
159 .macro .setframe reg, offset
160 .cfi_def_cfa reg, \offset
161 .equ cfa_current_offset, \offset
162 .endm
163
164 .macro .endprolog
165 .endm
166
167 .macro UNIMPLEMENTED2 file, line, func
168
169 jmp 3f
170 1: .asciz "\func"
171 2: .asciz \file
172 3:
173 sub rsp, 0x20
174 lea rcx, MsgUnimplemented[rip]
175 lea rdx, 1b[rip]
176 lea r8, 2b[rip]
177 mov r9, \line
178 call DbgPrint
179 add rsp, 0x20
180 .endm
181 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
182
183 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
184 conditionals. We therefore use "if", too. .if shouldn't be used at all */
185 #define if .if
186 #define endif .endif
187 #define else .else
188 #define elseif .elseif
189
190 #endif