[RTL]
[reactos.git] / reactos / 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 _USE_ML
10
11 /* Allow ".name" identifiers */
12 OPTION DOTNAME
13
14 .586
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 .text MACRO
53 ENDM
54
55 .code64 MACRO
56 .code
57 ENDM
58
59 .code32 MACRO
60 .code
61 ENDM
62
63 .align MACRO alignment
64 ALIGN alignment
65 ENDM
66
67 .byte MACRO args:VARARG
68 db args
69 ENDM
70
71 .short MACRO args:VARARG
72 dw args
73 ENDM
74
75 .long MACRO args:VARARG
76 dd args
77 ENDM
78
79 .double MACRO args:VARARG
80 dq args
81 ENDM
82
83 UNIMPLEMENTED MACRO name
84 ENDM
85
86 /* We need this to distinguish repeat from macros */
87 #define ENDR ENDM
88
89 #else /***********************************************************************/
90
91 /* Force intel syntax */
92 .intel_syntax noprefix
93
94 .altmacro
95
96 /* Hex numbers need to be in 0x1AB format */
97 #define HEX(y) 0x##y
98
99 /* Macro values need to be marked */
100 #define VAL(x) \x
101
102 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
103 #define MACRO(...) .macro __VA_ARGS__
104 #define ENDM .endm
105
106 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
107 .macro .PROC name
108 .func \name
109 \name:
110 .cfi_startproc
111 .equ cfa_current_offset, -8
112 .endm
113
114 /* ... and .ENDP, replacing ENDP */
115 .macro .ENDP name
116 .cfi_endproc
117 .endfunc
118 .endm
119
120 /* MASM compatible PUBLIC */
121 .macro PUBLIC symbol
122 .global \symbol
123 .endm
124
125 /* Dummy ASSUME */
126 .macro ASSUME p1 p2 p3 p4 p5 p6 p7 p8
127 .endm
128
129 /* MASM compatible ALIGN */
130 #define ALIGN .align
131
132 /* MASM compatible REPEAT, additional ENDR */
133 #define REPEAT .rept
134 #define ENDR .endr
135
136 /* MASM compatible EXTERN */
137 .macro EXTERN name
138 .endm
139
140 /* MASM needs an END tag */
141 #define END
142
143 .macro .MODEL model
144 .endm
145
146 .macro .code
147 .text
148 .endm
149
150 /* Macros for x64 stack unwind OPs */
151
152 .macro .allocstack size
153 .cfi_adjust_cfa_offset \size
154 .set cfa_current_offset, cfa_current_offset - \size
155 .endm
156
157 code = 1
158 .macro .pushframe param=0
159 .if (\param)
160 .cfi_adjust_cfa_offset 0x30
161 .set cfa_current_offset, cfa_current_offset - 0x30
162 .else
163 .cfi_adjust_cfa_offset 0x28
164 .set cfa_current_offset, cfa_current_offset - 0x28
165 .endif
166 .endm
167
168 .macro .pushreg reg
169 .cfi_adjust_cfa_offset 8
170 .equ cfa_current_offset, cfa_current_offset - 8
171 .cfi_offset \reg, cfa_current_offset
172 .endm
173
174 .macro .savereg reg, offset
175 // checkme!!!
176 .cfi_offset \reg, \offset
177 .endm
178
179 .macro .savexmm128 reg, offset
180 // checkme!!!
181 .cfi_offset \reg, \offset
182 .endm
183
184 .macro .setframe reg, offset
185 .cfi_def_cfa reg, \offset
186 .equ cfa_current_offset, \offset
187 .endm
188
189 .macro .endprolog
190 .endm
191
192 .macro UNIMPLEMENTED2 file, line, func
193
194 jmp 3f
195 1: .asciz "\func"
196 2: .asciz \file
197 3:
198 sub rsp, 0x20
199 lea rcx, MsgUnimplemented[rip]
200 lea rdx, 1b[rip]
201 lea r8, 2b[rip]
202 mov r9, \line
203 call DbgPrint
204 add rsp, 0x20
205 .endm
206 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
207
208 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
209 conditionals. We therefore use "if", too. .if shouldn't be used at all */
210 #define if .if
211 #define endif .endif
212 #define else .else
213 #define elseif .elseif
214
215 #endif