add else
[reactos.git] / reactos / include / reactos / asm.h
index 3aef7f1..ffb5652 100644 (file)
@@ -2,14 +2,23 @@
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS Kernel
  * FILE:            ntoskrnl/include/amd64/asmmacro.S
- * PURPOSE:         ASM macros for for GAS and ML64
+ * PURPOSE:         ASM macros for for GAS and MASM/ML64
  * PROGRAMMERS:     Timo Kreuzer (timo.kreuzer@reactos.org)
  */
 
 #ifdef _MSC_VER
 
+/* Allow ".name" identifiers */
+OPTION DOTNAME
+
+/* Hex numbers need to be in 01ABh format */
+#define HEX(x) 0##x##h
+
+/* Macro values need to be marked */
+#define VAL(x) x
+
 /* MASM/ML doesn't want explicit [rip] addressing */
-#define RIP(address) address
+rip = 0
 
 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
 #define MACRO(name, ...) name MACRO __VA_ARGS__
@@ -24,6 +33,18 @@ ENDM
     name ENDP
 ENDM
 
+/* MASM doesn't have an ASCII macro */
+.ASCII MACRO text
+    DB text
+ENDM
+
+/* MASM doesn't have an ASCIZ macro */
+.ASCIZ MACRO text
+    DB text, 0
+ENDM
+
+/* We need this to distinguish repeat from macros */
+#define ENDR ENDM
 
 #else /***********************************************************************/
 
@@ -31,11 +52,17 @@ ENDM
 .intel_syntax noprefix
 .code64
 
-/* GAS needs explicit [rip] addressing */
-#define RIP(address) address##[rip]
+.altmacro
+
+/* Hex numbers need to be in 0x1AB format */
+#define HEX(x) 0x##x
+
+/* Macro values need to be marked */
+#define VAL(x) \x
 
 /* Due to MASM's reverse syntax, we are forced to use a precompiler macro */
-#define MACRO(name, ...) .MACRO name, __VA_ARGS__
+#define MACRO(...) .macro __VA_ARGS__
+#define ENDM .endm
 
 /* To avoid reverse syntax we provide a new macro .PROC, replacing PROC... */
 .macro .PROC name
@@ -46,7 +73,7 @@ ENDM
 .endm
 
 /* ... and .ENDP, replacing ENDP */
-.macro .ENDP
+.macro .ENDP name
     .cfi_endproc
     .endfunc
 .endm
@@ -54,6 +81,20 @@ ENDM
 /* MASM compatible PUBLIC */
 #define PUBLIC .global
 
+/* MASM compatible ALIGN */
+#define ALIGN .align
+
+/* MASM compatible REPEAT, additional ENDR */
+#define REPEAT .rept
+#define ENDR .endr
+
+/* MASM compatible EXTERN */
+.macro EXTERN name
+.endm
+
+/* MASM needs an END tag */
+#define END
+
 /* Macros for x64 stack unwind OPs */
 
 .macro .allocstack size
@@ -61,13 +102,14 @@ ENDM
     .set cfa_current_offset, cfa_current_offset - \size
 .endm
 
-.macro .pushframe code
-    .if (\code == 0)
-        .cfi_adjust_cfa_offset 0x28
-        .set cfa_current_offset, cfa_current_offset - 0x28
-    .else
+code = 1
+.macro .pushframe param=0
+    .if (\param)
         .cfi_adjust_cfa_offset 0x30
         .set cfa_current_offset, cfa_current_offset - 0x30
+    .else
+        .cfi_adjust_cfa_offset 0x28
+        .set cfa_current_offset, cfa_current_offset - 0x28
     .endif
 .endm
 
@@ -95,9 +137,11 @@ ENDM
 .macro .endprolog
 .endm
 
-.macro UNIMPLEMENTED2 file, line, func
+// Note the file1. This is a hack, as "\file" doesn't work with __FILE__, when
+// .altmacro is specified.
+.macro UNIMPLEMENTED2 file1, line, func
+
     jmp 3f
-    .equ expr, 12
 1:  .asciz "\func"
 2:  .asciz "\file"
 3:
@@ -115,5 +159,6 @@ ENDM
    conditionals. We therefore use "if", too. .if shouldn't be used at all */
 #define if .if
 #define endif .endif
+#define else .else
 
 #endif