x86/asm: macro improvements in <asm/asm.h>
H. Peter Anvin
reviewercover x86/asm: macro improvements in <asm/asm.h>
From: "H. Peter Anvin (Intel)" <[email protected]>
This patchset adds the following improvements to <asm/asm.h>:
1. Makes the __ASM_FORM() macros accept arguments with commas. This allows the __ASM_FORM() macros to be used directly in header files for macros that can be used from either C or assembly, even for instructions that have multiple operands.
2. Add an _ASM_BYTES() macro for the delicate job of hand-crafting instructions out of bytes.
3. Replace the _ASM_MK_NOPS() macro in <asm/nops.h> with _ASM_BYTES().
The change to the tools/ directory is mainly because <asm/nops.h> now depends on <asm/asm.h>.
---
arch/x86/include/asm/asm.h | 23 ++--- arch/x86/include/asm/nops.h | 24 ++--- tools/arch/x86/include/asm/asm.h | 189 ++++++++++++++++++++++++++++++++++++++ tools/arch/x86/include/asm/nops.h | 24 ++--- 4 files changed, 221 insertions(+), 39 deletions(-)
H. Peter Anvin
reviewerPATCH 1/3 x86/asm: have the __ASM_FORM macros handle commas in arguments
From: "H. Peter Anvin (Intel)" <[email protected]>
The __ASM_FORM macros are really useful, but in order to be able to use them to define instructions via .byte directives breaks because of the necessary commas. Change the macros to handle commas correctly.
--- arch/x86/include/asm/asm.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
arch/x86/include/asm/asm.h +10 -11
@@ -3,25 +3,24 @@#define _ASM_X86_ASM_H#ifdef __ASSEMBLY__ -# define __ASM_FORM (x) x -# define __ASM_FORM_RAW (x) x -# define __ASM_FORM_COMMA (x) x, +# define __ASM_FORM (x, ...) x,## __VA_ARGS__ +# define __ASM_FORM_RAW (x, ...) x,## __VA_ARGS__ +# define __ASM_FORM_COMMA (x, ...) x,## __VA_ARGS__,#else #include <linux/stringify.h> - -# define __ASM_FORM (x) " " __stringify(x) " " -# define __ASM_FORM_RAW (x) __stringify(x) -# define __ASM_FORM_COMMA (x) " " __stringify(x) "," +# define __ASM_FORM (x, ...) " " __stringify(x,##__VA_ARGS__) " " +# define __ASM_FORM_RAW (x, ...) __stringify(x,##__VA_ARGS__) +# define __ASM_FORM_COMMA (x, ...) " " __stringify(x,##__VA_ARGS__) ","#endif #ifndef __x86_64__/* 32 bit */ -# define __ASM_SEL (a,b) __ASM_FORM(a) -# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(a) +# define __ASM_SEL (a,b) __ASM_FORM(a) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(a)#else /* 64 bit */ -# define __ASM_SEL (a,b) __ASM_FORM(b) -# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b) +# define __ASM_SEL (a,b) __ASM_FORM(b) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b)#endif #define __ASM_SIZE (inst, ...) __ASM_SEL(inst##l##__VA_ARGS__, \
Signature · 1 line
2.31.1
[tip: x86/asm] x86/asm: Have the __ASM_FORM macros handle commas in arguments
The following commit has been merged into the x86/asm branch of tip:
The following commit has been merged into the x86/asm branch of tip:
Commit-ID: be5bb8021c9731f5593de6419ae35d3f16a3e497 Gitweb: https://git.kernel.org/tip/be5bb8021c9731f5593de6419ae35d3f16a3e497 Author: H. Peter Anvin (Intel) <[email protected]> AuthorDate: Mon, 10 May 2021 02:09:38 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 10 May 2021 12:33:28 +02:00
x86/asm: Have the __ASM_FORM macros handle commas in arguments
The __ASM_FORM macros are really useful, but in order to be able to use them to define instructions via .byte directives breaks because of the necessary commas. Change the macros to handle commas correctly.
[ mingo: Removed stray whitespaces & aligned the definitions vertically. ]
--- arch/x86/include/asm/asm.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
arch/x86/include/asm/asm.h +10 -11
@@ -3,25 +3,24 @@#define _ASM_X86_ASM_H#ifdef __ASSEMBLY__ -# define __ASM_FORM (x) x -# define __ASM_FORM_RAW (x) x -# define __ASM_FORM_COMMA (x) x, +# define __ASM_FORM (x, ...) x,## __VA_ARGS__ +# define __ASM_FORM_RAW (x, ...) x,## __VA_ARGS__ +# define __ASM_FORM_COMMA (x, ...) x,## __VA_ARGS__,#else #include <linux/stringify.h> - -# define __ASM_FORM (x) " " __stringify(x) " " -# define __ASM_FORM_RAW (x) __stringify(x) -# define __ASM_FORM_COMMA (x) " " __stringify(x) "," +# define __ASM_FORM (x, ...) " " __stringify(x,##__VA_ARGS__) " " +# define __ASM_FORM_RAW (x, ...) __stringify(x,##__VA_ARGS__) +# define __ASM_FORM_COMMA (x, ...) " " __stringify(x,##__VA_ARGS__) ","#endif #ifndef __x86_64__/* 32 bit */ -# define __ASM_SEL (a,b) __ASM_FORM(a) -# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(a) +# define __ASM_SEL (a,b) __ASM_FORM(a) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(a)#else /* 64 bit */ -# define __ASM_SEL (a,b) __ASM_FORM(b) -# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b) +# define __ASM_SEL (a,b) __ASM_FORM(b) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b)#endif #define __ASM_SIZE (inst, ...) __ASM_SEL(inst##l##__VA_ARGS__, \
H. Peter Anvin
reviewerPATCH 2/3 x86/asm: add _ASM_BYTES() macro for a .byte ... opcode sequence
In reply to H. Peter AnvinFrom: "H. Peter Anvin (Intel)" <[email protected]>
Make it easy to create a sequence of bytes that can be used in either assembly proper on in a C asm() statement.
--- arch/x86/include/asm/asm.h | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/include/asm/asm.h +2 -0
@@ -13,6 +13,8 @@# define __ASM_FORM_COMMA (x, ...) " " __stringify(x,##__VA_ARGS__) ","#endif +#define _ASM_BYTES (x, ...) __ASM_FORM(.byte x,##__VA_ARGS__ ;) +#ifndef __x86_64__/* 32 bit */ # define __ASM_SEL (a,b) __ASM_FORM(a)
Signature · 1 line
2.31.1
[tip: x86/asm] x86/asm: Add _ASM_BYTES() macro for a .byte ... opcode sequence
The following commit has been merged into the x86/asm branch of tip:
The following commit has been merged into the x86/asm branch of tip:
Commit-ID: d88be187a6e6f3a97dfa7ddc500bb9ca191b3772 Gitweb: https://git.kernel.org/tip/d88be187a6e6f3a97dfa7ddc500bb9ca191b3772 Author: H. Peter Anvin (Intel) <[email protected]> AuthorDate: Mon, 10 May 2021 02:09:39 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 10 May 2021 12:33:28 +02:00
x86/asm: Add _ASM_BYTES() macro for a .byte ... opcode sequence
Make it easy to create a sequence of bytes that can be used in either assembly proper on in a C asm() statement.
--- arch/x86/include/asm/asm.h | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/include/asm/asm.h +2 -0
@@ -13,6 +13,8 @@# define __ASM_FORM_COMMA (x, ...) " " __stringify(x,##__VA_ARGS__) ","#endif +#define _ASM_BYTES (x, ...) __ASM_FORM(.byte x,##__VA_ARGS__ ;) +#ifndef __x86_64__/* 32 bit */ # define __ASM_SEL (a,b) __ASM_FORM(a)
H. Peter Anvin
reviewerPATCH 3/3 x86/asm: use _ASM_BYTES() in <asm/nops.h>
In reply to H. Peter AnvinFrom: "H. Peter Anvin (Intel)" <[email protected]>
Use the new generalized _ASM_BYTES() macro from <asm/asm.h> instead of the "home grown" _ASM_MK_NOP() in <asm/nops.h>.
Add <asm/asm.h> and update <asm/nops.h> in the tools directory...
--- arch/x86/include/asm/nops.h | 24 ++-- tools/arch/x86/include/asm/asm.h | 189 ++++++++++++++++++++++++++++++ tools/arch/x86/include/asm/nops.h | 24 ++-- 3 files changed, 209 insertions(+), 28 deletions(-) create mode 100644 tools/arch/x86/include/asm/asm.h
arch/x86/include/asm/nops.h +10 -14
@@ -2,6 +2,8 @@#ifndef _ASM_X86_NOPS_H#define _ASM_X86_NOPS_H +#include <asm/asm.h> +/* * Define nops for use with alternative() and for tracing. */
@@ -57,20 +59,14 @@#endif /* CONFIG_64BIT */ -#ifdef __ASSEMBLY__ -#define _ASM_MK_NOP (x) .byte x -#else -#define _ASM_MK_NOP (x) ".byte " __stringify(x) "\n" -#endif - -#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1) -#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2) -#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3) -#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4) -#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5) -#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6) -#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7) -#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8) +#define ASM_NOP1 _ASM_BYTES(BYTES_NOP1) +#define ASM_NOP2 _ASM_BYTES(BYTES_NOP2) +#define ASM_NOP3 _ASM_BYTES(BYTES_NOP3) +#define ASM_NOP4 _ASM_BYTES(BYTES_NOP4) +#define ASM_NOP5 _ASM_BYTES(BYTES_NOP5) +#define ASM_NOP6 _ASM_BYTES(BYTES_NOP6) +#define ASM_NOP7 _ASM_BYTES(BYTES_NOP7) +#define ASM_NOP8 _ASM_BYTES(BYTES_NOP8)#define ASM_NOP_MAX 8
tools/arch/x86/include/asm/asm.h new file +189 -0
189 lines not on this page · raw message
tools/arch/x86/include/asm/nops.h +10 -14
@@ -2,6 +2,8 @@#ifndef _ASM_X86_NOPS_H#define _ASM_X86_NOPS_H +#include <asm/asm.h> +/* * Define nops for use with alternative() and for tracing. */
@@ -57,20 +59,14 @@#endif /* CONFIG_64BIT */ -#ifdef __ASSEMBLY__ -#define _ASM_MK_NOP (x) .byte x -#else -#define _ASM_MK_NOP (x) ".byte " __stringify(x) "\n" -#endif - -#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1) -#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2) -#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3) -#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4) -#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5) -#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6) -#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7) -#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8) +#define ASM_NOP1 _ASM_BYTES(BYTES_NOP1) +#define ASM_NOP2 _ASM_BYTES(BYTES_NOP2) +#define ASM_NOP3 _ASM_BYTES(BYTES_NOP3) +#define ASM_NOP4 _ASM_BYTES(BYTES_NOP4) +#define ASM_NOP5 _ASM_BYTES(BYTES_NOP5) +#define ASM_NOP6 _ASM_BYTES(BYTES_NOP6) +#define ASM_NOP7 _ASM_BYTES(BYTES_NOP7) +#define ASM_NOP8 _ASM_BYTES(BYTES_NOP8)#define ASM_NOP_MAX 8
Signature · 1 line
2.31.1
[tip: x86/asm] x86/asm: Use _ASM_BYTES() in <asm/nops.h>
The following commit has been merged into the x86/asm branch of tip:
The following commit has been merged into the x86/asm branch of tip:
Commit-ID: eef23e72b78b36924aea8be5ec7c54e628c442ef Gitweb: https://git.kernel.org/tip/eef23e72b78b36924aea8be5ec7c54e628c442ef Author: H. Peter Anvin (Intel) <[email protected]> AuthorDate: Mon, 10 May 2021 02:09:40 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 10 May 2021 12:33:28 +02:00
x86/asm: Use _ASM_BYTES() in <asm/nops.h>
Use the new generalized _ASM_BYTES() macro from <asm/asm.h> instead of the "home grown" _ASM_MK_NOP() in <asm/nops.h>.
Add <asm/asm.h> and update <asm/nops.h> in the tools directory...
--- arch/x86/include/asm/nops.h | 24 +--- tools/arch/x86/include/asm/asm.h | 189 +++++++++++++++++++++++++++++- tools/arch/x86/include/asm/nops.h | 24 +--- 3 files changed, 209 insertions(+), 28 deletions(-) create mode 100644 tools/arch/x86/include/asm/asm.h
arch/x86/include/asm/nops.h +10 -14
@@ -2,6 +2,8 @@#ifndef _ASM_X86_NOPS_H#define _ASM_X86_NOPS_H +#include <asm/asm.h> +/* * Define nops for use with alternative() and for tracing. */
@@ -57,20 +59,14 @@#endif /* CONFIG_64BIT */ -#ifdef __ASSEMBLY__ -#define _ASM_MK_NOP (x) .byte x -#else -#define _ASM_MK_NOP (x) ".byte " __stringify(x) "\n" -#endif - -#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1) -#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2) -#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3) -#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4) -#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5) -#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6) -#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7) -#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8) +#define ASM_NOP1 _ASM_BYTES(BYTES_NOP1) +#define ASM_NOP2 _ASM_BYTES(BYTES_NOP2) +#define ASM_NOP3 _ASM_BYTES(BYTES_NOP3) +#define ASM_NOP4 _ASM_BYTES(BYTES_NOP4) +#define ASM_NOP5 _ASM_BYTES(BYTES_NOP5) +#define ASM_NOP6 _ASM_BYTES(BYTES_NOP6) +#define ASM_NOP7 _ASM_BYTES(BYTES_NOP7) +#define ASM_NOP8 _ASM_BYTES(BYTES_NOP8)#define ASM_NOP_MAX 8
tools/arch/x86/include/asm/asm.h new file +189 -0
189 lines not on this page · raw message
tools/arch/x86/include/asm/nops.h +10 -14
@@ -2,6 +2,8 @@#ifndef _ASM_X86_NOPS_H#define _ASM_X86_NOPS_H +#include <asm/asm.h> +/* * Define nops for use with alternative() and for tracing. */
@@ -57,20 +59,14 @@#endif /* CONFIG_64BIT */ -#ifdef __ASSEMBLY__ -#define _ASM_MK_NOP (x) .byte x -#else -#define _ASM_MK_NOP (x) ".byte " __stringify(x) "\n" -#endif - -#define ASM_NOP1 _ASM_MK_NOP(BYTES_NOP1) -#define ASM_NOP2 _ASM_MK_NOP(BYTES_NOP2) -#define ASM_NOP3 _ASM_MK_NOP(BYTES_NOP3) -#define ASM_NOP4 _ASM_MK_NOP(BYTES_NOP4) -#define ASM_NOP5 _ASM_MK_NOP(BYTES_NOP5) -#define ASM_NOP6 _ASM_MK_NOP(BYTES_NOP6) -#define ASM_NOP7 _ASM_MK_NOP(BYTES_NOP7) -#define ASM_NOP8 _ASM_MK_NOP(BYTES_NOP8) +#define ASM_NOP1 _ASM_BYTES(BYTES_NOP1) +#define ASM_NOP2 _ASM_BYTES(BYTES_NOP2) +#define ASM_NOP3 _ASM_BYTES(BYTES_NOP3) +#define ASM_NOP4 _ASM_BYTES(BYTES_NOP4) +#define ASM_NOP5 _ASM_BYTES(BYTES_NOP5) +#define ASM_NOP6 _ASM_BYTES(BYTES_NOP6) +#define ASM_NOP7 _ASM_BYTES(BYTES_NOP7) +#define ASM_NOP8 _ASM_BYTES(BYTES_NOP8)#define ASM_NOP_MAX 8