add else
[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 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 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
64 #define MACRO(...) .macro __VA_ARGS__
65 #define ENDM .endm
66
67 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
68 .macro .PROC name
69 .func \name
70 \name:
71 .cfi_startproc
72 .equ cfa_current_offset, -8
73 .endm
74
75 /* ... and .ENDP, replacing ENDP */
76 .macro .ENDP name
77 .cfi_endproc
78 .endfunc
79 .endm
80
81 /* MASM compatible PUBLIC */
82 #define PUBLIC .global
83
84 /* MASM compatible ALIGN */
85 #define ALIGN .align
86
87 /* MASM compatible REPEAT, additional ENDR */
88 #define REPEAT .rept
89 #define ENDR .endr
90
91 /* MASM compatible EXTERN */
92 .macro EXTERN name
93 .endm
94
95 /* MASM needs an END tag */
96 #define END
97
98 /* Macros for x64 stack unwind OPs */
99
100 .macro .allocstack size
101 .cfi_adjust_cfa_offset \size
102 .set cfa_current_offset, cfa_current_offset - \size
103 .endm
104
105 code = 1
106 .macro .pushframe param=0
107 .if (\param)
108 .cfi_adjust_cfa_offset 0x30
109 .set cfa_current_offset, cfa_current_offset - 0x30
110 .else
111 .cfi_adjust_cfa_offset 0x28
112 .set cfa_current_offset, cfa_current_offset - 0x28
113 .endif
114 .endm
115
116 .macro .pushreg reg
117 .cfi_adjust_cfa_offset 8
118 .equ cfa_current_offset, cfa_current_offset - 8
119 .cfi_offset \reg, cfa_current_offset
120 .endm
121
122 .macro .savereg reg, offset
123 // checkme!!!
124 .cfi_offset \reg, \offset
125 .endm
126
127 .macro .savexmm128 reg, offset
128 // checkme!!!
129 .cfi_offset \reg, \offset
130 .endm
131
132 .macro .setframe reg, offset
133 .cfi_def_cfa reg, \offset
134 .equ cfa_current_offset, \offset
135 .endm
136
137 .macro .endprolog
138 .endm
139
140 // Note the file1. This is a hack, as "\file" doesn't work with __FILE__, when
141 // .altmacro is specified.
142 .macro UNIMPLEMENTED2 file1, line, func
143
144 jmp 3f
145 1: .asciz "\func"
146 2: .asciz "\file"
147 3:
148 sub rsp, 0x20
149 lea rcx, _MsgUnimplemented[rip]
150 lea rdx, 1b[rip]
151 lea r8, 2b[rip]
152 mov r9, \line
153 call _DbgPrint
154 add rsp, 0x20
155 .endm
156 #define UNIMPLEMENTED UNIMPLEMENTED2 __FILE__, __LINE__,
157
158 /* MASM/ML uses ".if" for runtime conditionals, and "if" for compile time
159 conditionals. We therefore use "if", too. .if shouldn't be used at all */
160 #define if .if
161 #define endif .endif
162 #define else .else
163
164 #endif