diff mbox series

[v3,10/12] linux/linkage: add ASM() macro to reduce duplication between C/ASM code

Message ID 1545062607-8599-11-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
Series x86, kbuild: revert macrofying inline assembly code | expand

Commit Message

Masahiro Yamada Dec. 17, 2018, 4:03 p.m. UTC
We often duplicate similar assembly code to use it from .c and .S files.
The difference is mostly the presence of double quotes.

So, here is a new macro ASM().
(We have similar approach for __ASM_FORM(), etc.)

The usage is like this:

    #define MY_CODE              \
    ASM(    .section ".text"    )\
    ASM(    movl $1, %eax       )

In C context, the preprocessor expands it into:

  ".section \".text\"" "\n\t" "movl $1, %eax" "\n\t"

This is perfect for the use from the inline asm(...) in .c files.

In assembly context, the preprocessor expands it into:

  .section ".text" ; movl $1, %eax ;

This is fine for the use in .S files.

I used double-expansion like __stringify() so that we can use
macros in ASM(...).

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 include/linux/linkage.h | 8 ++++++++
 1 file changed, 8 insertions(+)

-- 
2.7.4
diff mbox series

Patch

diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 7c47b1a..80faeae 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -12,6 +12,14 @@ 
 #define ASM_NL		 ;
 #endif
 
+#ifdef __ASSEMBLY__
+#define _ASM(x...)	x ASM_NL
+#else
+#define _ASM(x...)	#x __stringify(\n\t)
+#endif
+/* Doing two levels allows macros to be used in ASM(...) */
+#define ASM(x...)	_ASM(x)
+
 #ifdef __cplusplus
 #define CPP_ASMLINKAGE extern "C"
 #else