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