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