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