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