[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1545062607-8599-11-git-send-email-yamada.masahiro@socionext.com>
Date: Tue, 18 Dec 2018 01:03:25 +0900
From: Masahiro Yamada <yamada.masahiro@...ionext.com>
To: x86@...nel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H . Peter Anvin" <hpa@...or.com>
Cc: Richard Biener <rguenther@...e.de>,
Segher Boessenkool <segher@...nel.crashing.org>,
Peter Zijlstra <peterz@...radead.org>,
Juergen Gross <jgross@...e.com>,
Josh Poimboeuf <jpoimboe@...hat.com>,
Kees Cook <keescook@...omium.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Masahiro Yamada <yamada.masahiro@...ionext.com>,
Andrey Ryabinin <aryabinin@...tuozzo.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH v3 10/12] linux/linkage: add ASM() macro to reduce duplication between C/ASM code
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@...ionext.com>
---
include/linux/linkage.h | 8 ++++++++
1 file changed, 8 insertions(+)
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
--
2.7.4
Powered by blists - more mailing lists