Skip to contentSkip to conversation

lib/cobalt: arm: Account for register allocation clash gcc 9+

PATCH In review Jan Kiszka 2 participants 3 messages Aug 7, 2021

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 lib/cobalt: arm: Account for register allocation clash gcc 9+

From: Jan Kiszka <[email protected]>

Modern gcc can claim r7 for own purposes, denying the syscall code to assign it directly. Work around this by saving/restoring it around the syscall.

---
 lib/cobalt/arch/arm/include/asm/xenomai/syscall.h | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
lib/cobalt/arch/arm/include/asm/xenomai/syscall.h +4 -9
index 8f48eb16f2..0941e6c845 100644
@@ -89,15 +89,11 @@
 #define __sys1(x)	__sys2(x)
 
 #ifdef __ARM_EABI__
-#define __SYS_REG , "r7"
-#define __SYS_REG_DECL register unsigned long __r7 __asm__ ("r7")
-#define __SYS_REG_SET __r7 = XENO_ARM_SYSCALL
-#define __SYS_REG_INPUT ,"r" (__r7)
-#define __SYS_CALLOP "swi\t0"
+#define __SYS_REG_DECL unsigned long __r7 = XENO_ARM_SYSCALL
+#define __SYS_REG_INPUT , [__r7] "r" (__r7)
+#define __SYS_CALLOP "push {r7}; mov %%r7,%[__r7]; swi\t0; pop {r7}"
 #else
-#define __SYS_REG
 #define __SYS_REG_DECL
-#define __SYS_REG_SET
 #define __SYS_REG_INPUT
 #define __NR_OABI_SYSCALL_BASE	0x900000
 #define __SYS_CALLOP "swi\t" __sys1(__NR_OABI_SYSCALL_BASE + XENO_ARM_SYSCALL) ""
@@ -109,9 +105,8 @@
 		__SYS_REG_DECL;						\
 		LOADARGS_##nr(__xn_syscode(op), args);			\
 		__asm__ __volatile__ ("" : /* */ : /* */ :		\
-				      CLOBBER_REGS_##nr __SYS_REG);	\
+				      CLOBBER_REGS_##nr);		\
 		LOADREGS_##nr;						\
-		__SYS_REG_SET;						\
 		__asm__ __volatile__ (					\
 			__SYS_CALLOP					\
 			: "=r" (__r0)					\
Signature · 1 line
2.31.1
#1 lore raw
Quoted 35 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Modern gcc can claim r7 for own purposes, denying the syscall code to assign it directly. Work around this by saving/restoring it around the syscall.

---
 lib/cobalt/arch/arm/include/asm/xenomai/syscall.h | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
lib/cobalt/arch/arm/include/asm/xenomai/syscall.h +3 -7
index 8f48eb16f2..0941e6c845 100644
@@ -89,15 +89,11 @@
 #define __sys1(x)	__sys2(x)
 
 #ifdef __ARM_EABI__
-#define __SYS_REG , "r7"
-#define __SYS_REG_DECL register unsigned long __r7 __asm__ ("r7")
-#define __SYS_REG_SET __r7 = XENO_ARM_SYSCALL
-#define __SYS_REG_INPUT ,"r" (__r7)
-#define __SYS_CALLOP "swi\t0"
+#define __SYS_REG_DECL unsigned long __r7 = XENO_ARM_SYSCALL
+#define __SYS_REG_INPUT , [__r7] "r" (__r7)
+#define __SYS_CALLOP "push {r7}; mov %%r7,%[__r7]; swi\t0; pop {r7}"
 #else
-#define __SYS_REG
 #define __SYS_REG_DECL
-#define __SYS_REG_SET
 #define __SYS_REG_INPUT
 #define __NR_OABI_SYSCALL_BASE	0x900000
 #define __SYS_CALLOP "swi\t" __sys1(__NR_OABI_SYSCALL_BASE + XENO_ARM_SYSCALL) ""

lib/cobalt/arch/arm/include/asm/xenomai/syscall.h line 112

Quoted 10 lines
lib/cobalt/arch/arm/include/asm/xenomai/syscall.h +1 -2
@@ -109,9 +105,8 @@
 		__SYS_REG_DECL;						\
 		LOADARGS_##nr(__xn_syscode(op), args);			\
 		__asm__ __volatile__ ("" : /* */ : /* */ :		\
-				      CLOBBER_REGS_##nr __SYS_REG);	\
+				      CLOBBER_REGS_##nr);		\
 		LOADREGS_##nr;						\
-		__SYS_REG_SET;						\
 		__asm__ __volatile__ (					\
 			__SYS_CALLOP					\
 			: "=r" (__r0)					\

Mm, this does indeed look like a workaround more than a fix. Eventually, we may be better off providing out-of-line syscall wrappers directly written in asm, or as naked C routines with bells and suspenders (no_instrument and the like) including the code produced by the XENOMAI_SYSCALL macro exclusively.

Signature · 1 line
Philippe.
#2 lore raw
Quoted 43 lines · Philippe Gerum via Xenomai
Quoted 41 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Modern gcc can claim r7 for own purposes, denying the syscall code to assign it directly. Work around this by saving/restoring it around the syscall.

---
 lib/cobalt/arch/arm/include/asm/xenomai/syscall.h | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
lib/cobalt/arch/arm/include/asm/xenomai/syscall.h +4 -8
index 8f48eb16f2..0941e6c845 100644
@@ -89,15 +89,11 @@
 #define __sys1(x)	__sys2(x)
 
 #ifdef __ARM_EABI__
-#define __SYS_REG , "r7"
-#define __SYS_REG_DECL register unsigned long __r7 __asm__ ("r7")
-#define __SYS_REG_SET __r7 = XENO_ARM_SYSCALL
-#define __SYS_REG_INPUT ,"r" (__r7)
-#define __SYS_CALLOP "swi\t0"
+#define __SYS_REG_DECL unsigned long __r7 = XENO_ARM_SYSCALL
+#define __SYS_REG_INPUT , [__r7] "r" (__r7)
+#define __SYS_CALLOP "push {r7}; mov %%r7,%[__r7]; swi\t0; pop {r7}"
 #else
-#define __SYS_REG
 #define __SYS_REG_DECL
-#define __SYS_REG_SET
 #define __SYS_REG_INPUT
 #define __NR_OABI_SYSCALL_BASE	0x900000
 #define __SYS_CALLOP "swi\t" __sys1(__NR_OABI_SYSCALL_BASE + XENO_ARM_SYSCALL) ""
@@ -109,9 +105,8 @@
 		__SYS_REG_DECL;						\
 		LOADARGS_##nr(__xn_syscode(op), args);			\
 		__asm__ __volatile__ ("" : /* */ : /* */ :		\
-				      CLOBBER_REGS_##nr __SYS_REG);	\
+				      CLOBBER_REGS_##nr);		\
 		LOADREGS_##nr;						\
Quoted 8 lines

lib/cobalt/arch/arm/include/asm/xenomai/syscall.h line 112

Quoted 4 lines
lib/cobalt/arch/arm/include/asm/xenomai/syscall.h +0 -1
-		__SYS_REG_SET;						\
 		__asm__ __volatile__ (					\
 			__SYS_CALLOP					\
 			: "=r" (__r0)					\

Mm, this does indeed look like a workaround more than a fix. Eventually, we may be better off providing out-of-line syscall wrappers directly written in asm, or as naked C routines with bells and suspenders

I mean belt. Well, bells too in case that helps...

Quoted 2 lines

(no_instrument and the like) including the code produced by the XENOMAI_SYSCALL macro exclusively.

Signature · 1 line
Philippe.