[AUDIO-BRINGUP]
[reactos.git] / include / reactos / 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 .org MACRO value
111 ORG value
112 ENDM
113
114 .fill MACRO repeat, size, value
115 // FIXME
116 ENDM
117
118 ljmp MACRO segment, offset
119 // FIXME
120 ENDM
121
122 UNIMPLEMENTED MACRO name
123 ENDM
124
125 /* We need this to distinguish repeat from macros */
126 #define ENDR ENDM
127
128 #else /***********************************************************************/
129
130 /* Force intel syntax */
131 .intel_syntax noprefix
132
133 .altmacro
134
135 /* Hex numbers need to be in 0x1AB format */
136 #define HEX(y) 0x##y
137
138 /* Macro values need to be marked */
139 #define VAL(x) \x
140
141 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
142 #define MACRO(...) .macro __VA_ARGS__
143 #define ENDM .endm
144
145 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
146 .macro .PROC name
147 .func \name
148 \name:
149 .cfi_startproc
150 .equ cfa_current_offset, -8
151 .endm
152
153 /* ... and .ENDP, replacing ENDP */
154 .macro .ENDP name
155 .cfi_endproc
156 .endfunc
157 .endm
158
159 /* MASM compatible PUBLIC */
160 .macro PUBLIC symbol
161 .global \symbol
162 .endm
163
164 /* Dummy ASSUME */
165 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
166 .endm
167
168 /* MASM needs an end tag for segments */
169 .macro .endcode16
170 .endm
171
172 /* MASM compatible ALIGN */
173 #define ALIGN .align
174
175 /* MASM compatible REPEAT, additional ENDR */
176 #define REPEAT .rept
177 #define ENDR .endr
178
179 .macro ljmp segment, offset
180 jmp far ptr \segment:\offset
181 .endm
182
183 /* MASM compatible EXTERN */
184 .macro EXTERN name
185 .endm
186
187 /* MASM needs an END tag */
188 #define END
189
190 .macro .MODEL model
191 .endm
192
193 .macro .code
194 .text
195 .endm
196
197 /* Macros for x64 stack unwind OPs */
198
199 .macro .allocstack size
200 .cfi_adjust_cfa_offset \size
201 .set cfa_current_offset, cfa_current_offset - \size
202 .endm
203
204 code = 1
205 .macro .pushframe param=0
206 .if (\param)
207 .cfi_adjust_cfa_offset 0x30
208 .set cfa_current_offset, cfa_current_offset - 0x30
209 .else
210 .cfi_adjust_cfa_offset 0x28
211 .set cfa_current_offset, cfa_current_offset - 0x28
212 .endif
213 .endm
214
215 .macro .pushreg reg
216 .cfi_adjust_cfa_offset 8
217 .equ cfa_current_offset, cfa_current_offset - 8
218 .cfi_offset \reg, cfa_current_offset
219 .endm
220
221 .macro .savereg reg, offset
222 // checkme!!!
223 .cfi_offset \reg, \offset
224 .endm
225
226 .macro .savexmm128 reg, offset
227 // checkme!!!
228 .cfi_offset \reg, \offset
229 .endm
230
231 .macro .setframe reg, offset
232 .cfi_def_cfa reg, \offset
233 .equ cfa_current_offset, \offset
234 .endm
235
236 .macro .endprolog
237 .endm
238
239 .macro UNIMPLEMENTED2 file, line, func
240
241 jmp 3f
242 1: .asciz "\func"
243 2: .asciz \file
244 3:
245 sub rsp, 0x20
246 lea rcx, MsgUnimplemented[rip]
247 lea rdx, 1b[rip]
248 lea r8, 2b[rip]
249 mov r9, \line
250 call DbgPrint
251 add rsp, 0x20
252 .endm
253 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
254
255 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
256 conditionals. We therefore use "if", too. .if shouldn't be used at all */
257 #define if .if
258 #define endif .endif
259 #define else .else
260 #define elseif .elseif
261
262 #endif