* Sync to recent trunk (r52563).
[reactos.git] / include / asm / asm.inc
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 _USE_ML
10
11 /* Allow ".name" identifiers */
12 OPTION DOTNAME
13
14 #ifdef _M_IX86
15 .686P
16 .XMM
17 .MODEL FLAT
18 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
19 #endif
20
21 /* Hex numbers need to be in 01ABh format */
22 #define HEX(x) 0##x##h
23
24 /* Macro values need to be marked */
25 #define VAL(x) x
26
27 /* MASM/ML doesn't want explicit [rip] addressing */
28 rip = 0
29
30 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
31 #define MACRO(name, ...) name MACRO __VA_ARGS__
32
33 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
34 .PROC MACRO name
35 name PROC FRAME
36 _name:
37 ENDM
38 #define FUNC .PROC
39
40 /* ... and .ENDP, replacing ENDP */
41 .ENDP MACRO name
42 name ENDP
43 ENDM
44 #define ENDFUNC .ENDP
45
46 /* MASM doesn't have an ASCII macro */
47 .ASCII MACRO text:VARARG
48 DB text
49 ENDM
50 .ascii MACRO text:VARARG
51 DB text
52 ENDM
53
54 /* MASM doesn't have an ASCIZ macro */
55 .ASCIZ MACRO text:VARARG
56 DB text
57 DB 0
58 ENDM
59 .asciz MACRO text:VARARG
60 DB text
61 DB 0
62 ENDM
63
64 .code64 MACRO
65 .code
66 ENDM
67
68 .code32 MACRO
69 .code
70 .586P
71 ENDM
72
73 .code16 MACRO
74 ASSUME nothing
75 .text SEGMENT use16
76 .586P
77 ENDM
78
79 .endcode16 MACRO
80 .text ENDS
81 ENDM
82
83 .bss MACRO
84 .DATA?
85 ASSUME nothing
86 ENDM
87
88 //.text MACRO
89 //ENDM
90
91 .align MACRO alignment
92 ALIGN alignment
93 ENDM
94
95 .byte MACRO args:VARARG
96 db args
97 ENDM
98
99 .short MACRO args:VARARG
100 dw args
101 ENDM
102
103 .word MACRO args:VARARG
104 dw args
105 ENDM
106
107 .long MACRO args:VARARG
108 dd args
109 ENDM
110
111 .double MACRO args:VARARG
112 dq args
113 ENDM
114
115 .org MACRO value
116 ORG value
117 ENDM
118
119 .fill MACRO count, size, value
120 REPEAT count
121 if (size EQ 1)
122 DB value
123 elseif (size EQ 2)
124 DW value
125 elseif (size EQ 4)
126 DD value
127 endif
128 ENDM
129 ENDM
130
131 .space MACRO count
132 DB 0 DUP (count)
133 ENDM
134
135 ljmp MACRO segment, offset
136 DB 0EAh
137 DD offset
138 DW segment
139 ENDM
140
141 ljmp16 MACRO segment, offset
142 DB 0EAh
143 DW offset
144 DW segment
145 ENDM
146
147 UNIMPLEMENTED MACRO name
148 ENDM
149
150 absolute MACRO address
151 __absolute__address__ = address
152 ENDM
153
154 resb MACRO name, size
155 name = __absolute__address__
156 __absolute__address__ = __absolute__address__ + size
157 ENDM
158
159
160 /* We need this to distinguish repeat from macros */
161 #define ENDR ENDM
162
163 #define CR 13
164 #define LF 10
165 #define NUL 0
166
167 #else /***********************************************************************/
168
169 /* Force intel syntax */
170 .intel_syntax noprefix
171
172 .altmacro
173
174 /* Hex numbers need to be in 0x1AB format */
175 #define HEX(y) 0x##y
176
177 /* Macro values need to be marked */
178 #define VAL(x) \x
179
180 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
181 #define MACRO(...) .macro __VA_ARGS__
182 #define ENDM .endm
183
184 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
185 .macro .PROC name
186 .func \name
187 \name:
188 .cfi_startproc
189 .equ cfa_current_offset, -8
190 .endm
191
192 /* ... and .ENDP, replacing ENDP */
193 .macro .ENDP name
194 .cfi_endproc
195 .endfunc
196 .endm
197
198 /* MASM compatible PUBLIC */
199 .macro PUBLIC symbol
200 .global \symbol
201 .endm
202
203 /* Dummy ASSUME */
204 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
205 .endm
206
207 /* MASM needs an end tag for segments */
208 .macro .endcode16
209 .endm
210
211 /* MASM compatible ALIGN */
212 #define ALIGN .align
213
214 /* MASM compatible REPEAT, additional ENDR */
215 #define REPEAT .rept
216 #define ENDR .endr
217
218 .macro ljmp segment, offset
219 jmp far ptr \segment:\offset
220 .endm
221
222 .macro ljmp16 segment, offset
223 jmp far ptr \segment:\offset
224 .endm
225
226 /* MASM compatible EXTERN */
227 .macro EXTERN name
228 .endm
229
230 /* MASM needs an END tag */
231 #define END
232
233 .macro .MODEL model
234 .endm
235
236 .macro .code
237 .text
238 .endm
239
240 /* Macros for x64 stack unwind OPs */
241
242 .macro .allocstack size
243 .cfi_adjust_cfa_offset \size
244 .set cfa_current_offset, cfa_current_offset - \size
245 .endm
246
247 code = 1
248 .macro .pushframe param=0
249 .if (\param)
250 .cfi_adjust_cfa_offset 0x30
251 .set cfa_current_offset, cfa_current_offset - 0x30
252 .else
253 .cfi_adjust_cfa_offset 0x28
254 .set cfa_current_offset, cfa_current_offset - 0x28
255 .endif
256 .endm
257
258 .macro .pushreg reg
259 .cfi_adjust_cfa_offset 8
260 .equ cfa_current_offset, cfa_current_offset - 8
261 .cfi_offset \reg, cfa_current_offset
262 .endm
263
264 .macro .savereg reg, offset
265 // checkme!!!
266 .cfi_offset \reg, \offset
267 .endm
268
269 .macro .savexmm128 reg, offset
270 // checkme!!!
271 .cfi_offset \reg, \offset
272 .endm
273
274 .macro .setframe reg, offset
275 .cfi_def_cfa reg, \offset
276 .equ cfa_current_offset, \offset
277 .endm
278
279 .macro .endprolog
280 .endm
281
282 .macro absolute address
283 __absolute__address__ = \address
284 ENDM
285
286 .macro resb name, size
287 \name = __absolute__address__
288 __absolute__address__ = __absolute__address__ + \size
289 ENDM
290
291 .macro UNIMPLEMENTED2 file, line, func
292
293 jmp 3f
294 1: .asciz "\func"
295 2: .asciz \file
296 3:
297 sub rsp, 0x20
298 lea rcx, MsgUnimplemented[rip]
299 lea rdx, 1b[rip]
300 lea r8, 2b[rip]
301 mov r9, \line
302 call DbgPrint
303 add rsp, 0x20
304 .endm
305 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
306
307 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
308 conditionals. We therefore use "if", too. .if shouldn't be used at all */
309 #define if .if
310 #define endif .endif
311 #define else .else
312 #define elseif .elseif
313
314 #define CR "\r"
315 #define LF "\n"
316 #define NUL "\0"
317
318 #endif