Blob Blame History Raw
From: "H. Peter Anvin (Intel)" <hpa@zytor.com>
Date: Fri, 10 Sep 2021 12:59:09 -0700
Subject: x86/asm: Add _ASM_RIP() macro for x86-64 (%rip) suffix
Git-commit: f87bc8dc7a7c438c70f97b4e51c76a183313272e
Patch-mainline: v5.16-rc1
References: git-fixes

Add a macro _ASM_RIP() to add a (%rip) suffix on 64 bits only. This is
useful for immediate memory references where one doesn't want gcc
to possibly use a register indirection as it may in the case of an "m"
constraint.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210910195910.2542662-3-hpa@zytor.com

Acked-by: Nikolay Borisov <nik.borisov@suse.com>
---
 arch/x86/include/asm/asm.h |    5 +++++
 1 file changed, 5 insertions(+)

--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -5,10 +5,12 @@
 # define __ASM_FORM(x)	x
 # define __ASM_FORM_RAW(x)     x
 # define __ASM_FORM_COMMA(x) x,
+# define __ASM_REGPFX	     %
 #else
 # define __ASM_FORM(x)	" " #x " "
 # define __ASM_FORM_RAW(x)     #x
 # define __ASM_FORM_COMMA(x) " " #x ","
+# define __ASM_REGPFX			%%
 #endif

 #ifndef __x86_64__
@@ -45,6 +47,9 @@
 #define _ASM_SI		__ASM_REG(si)
 #define _ASM_DI		__ASM_REG(di)

+/* Adds a (%rip) suffix on 64 bits only; for immediate memory references */
+#define _ASM_RIP(x)	__ASM_SEL_RAW(x, x (__ASM_REGPFX rip))
+
 #ifndef __x86_64__
 /* 32 bit */