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