{ASM]
[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 .MODEL FLAT
16 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
17
18 /* Hex numbers need to be in 01ABh format */
19 #define HEX(x) 0##x##h
20
21 /* Macro values need to be marked */
22 #define VAL(x) x
23
24 /* MASM/ML doesn't want explicit [rip] addressing */
25 rip = 0
26
27 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
28 #define MACRO(name, ...) name MACRO __VA_ARGS__
29
30 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
31 .PROC MACRO name
32 name PROC FRAME
33 _name:
34 ENDM
35
36 /* ... and .ENDP, replacing ENDP */
37 .ENDP MACRO name
38 name ENDP
39 ENDM
40
41 /* MASM doesn't have an ASCII macro */
42 .ASCII MACRO text
43 DB text
44 ENDM
45
46 /* MASM doesn't have an ASCIZ macro */
47 .ASCIZ MACRO text
48 DB text, 0
49 ENDM
50
51 .text MACRO
52 ENDM
53
54 .code64 MACRO
55 .code
56 ENDM
57
58 .code32 MACRO
59 .code
60 ENDM
61
62 .align MACRO alignment
63 ALIGN alignment
64 ENDM
65
66 .byte MACRO args:VARARG
67 db args
68 ENDM
69
70 .short MACRO args:VARARG
71 dw args
72 ENDM
73
74 .long MACRO args:VARARG
75 dd args
76 ENDM
77
78 UNIMPLEMENTED MACRO name
79 ENDM
80
81 /* We need this to distinguish repeat from macros */
82 #define ENDR ENDM
83
84 #else /***********************************************************************/
85
86 /* Force intel syntax */
87 .intel_syntax noprefix
88
89 .altmacro
90
91 /* Hex numbers need to be in 0x1AB format */
92 #define HEX(y) 0x##y
93
94 /* Macro values need to be marked */
95 #define VAL(x) \x
96
97 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
98 #define MACRO(...) .macro __VA_ARGS__
99 #define ENDM .endm
100
101 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
102 .macro .PROC name
103 .func \name
104 \name:
105 .cfi_startproc
106 .equ cfa_current_offset, -8
107 .endm
108
109 /* ... and .ENDP, replacing ENDP */
110 .macro .ENDP name
111 .cfi_endproc
112 .endfunc
113 .endm
114
115 /* MASM compatible PUBLIC */
116 .macro PUBLIC symbol
117 .global \symbol
118 .endm
119
120 /* MASM compatible ALIGN */
121 #define ALIGN .align
122
123 /* MASM compatible REPEAT, additional ENDR */
124 #define REPEAT .rept
125 #define ENDR .endr
126
127 /* MASM compatible EXTERN */
128 .macro EXTERN name
129 .endm
130
131 /* MASM needs an END tag */
132 #define END
133
134 .macro .MODEL model
135 .endm
136
137 .macro .code
138 .text
139 .endm
140
141 /* Macros for x64 stack unwind OPs */
142
143 .macro .allocstack size
144 .cfi_adjust_cfa_offset \size
145 .set cfa_current_offset, cfa_current_offset - \size
146 .endm
147
148 code = 1
149 .macro .pushframe param=0
150 .if (\param)
151 .cfi_adjust_cfa_offset 0x30
152 .set cfa_current_offset, cfa_current_offset - 0x30
153 .else
154 .cfi_adjust_cfa_offset 0x28
155 .set cfa_current_offset, cfa_current_offset - 0x28
156 .endif
157 .endm
158
159 .macro .pushreg reg
160 .cfi_adjust_cfa_offset 8
161 .equ cfa_current_offset, cfa_current_offset - 8
162 .cfi_offset \reg, cfa_current_offset
163 .endm
164
165 .macro .savereg reg, offset
166 // checkme!!!
167 .cfi_offset \reg, \offset
168 .endm
169
170 .macro .savexmm128 reg, offset
171 // checkme!!!
172 .cfi_offset \reg, \offset
173 .endm
174
175 .macro .setframe reg, offset
176 .cfi_def_cfa reg, \offset
177 .equ cfa_current_offset, \offset
178 .endm
179
180 .macro .endprolog
181 .endm
182
183 .macro UNIMPLEMENTED2 file, line, func
184
185 jmp 3f
186 1: .asciz "\func"
187 2: .asciz \file
188 3:
189 sub rsp, 0x20
190 lea rcx, MsgUnimplemented[rip]
191 lea rdx, 1b[rip]
192 lea r8, 2b[rip]
193 mov r9, \line
194 call DbgPrint
195 add rsp, 0x20
196 .endm
197 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
198
199 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
200 conditionals. We therefore use "if", too. .if shouldn't be used at all */
201 #define if .if
202 #define endif .endif
203 #define else .else
204 #define elseif .elseif
205
206 #endif