|
From: Richard C. <Ric...@su...> - 2004-05-04 14:25:52
|
Hi Marcelo,
This patch was created by Sean McGoogan <sea...@su...>:
[sh64] Bug fix: add clearer (more explicit) liveness dependency
constraints to _syscalln() assembler inline functions, to stop more
aggressive compiler optimisers passing the arguments pertaining to the
TRAPA in arbitrary registers. This is an essential bug fix for sh64, to
remove some dangerous congenital assumptions in the register
assignments.
Please apply.
Cheers
Richard
--- sh64--to-marcelo--040430--patch-1/include/asm-sh64/unistd.h 2004-04-30 12:53:29.000000000 +0100
+++ sh64--to-marcelo--040430--patch-2/include/asm-sh64/unistd.h 2004-04-30 16:05:35.000000000 +0100
@@ -287,20 +287,31 @@
type name(void) \
{ \
register unsigned long __sc0 __asm__ ("r9") = ((0x10 << 16) | __NR_##name); \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "()" \
: "=r" (__sc0) \
: "r" (__sc0) ); \
__syscall_return(type,__sc0); \
}
+ /*
+ * The apparent spurious "dummy" assembler comment is *needed*,
+ * as without it, the compiler treats the arg<n> variables
+ * as no longer live just before the asm. The compiler can
+ * then optimize the storage into any registers it wishes.
+ * The additional dummy statement forces the compiler to put
+ * the arguments into the correct registers before the TRAPA.
+ */
#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
register unsigned long __sc0 __asm__ ("r9") = ((0x11 << 16) | __NR_##name); \
register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "(%2)" \
: "=r" (__sc0) \
: "r" (__sc0), "r" (__sc2)); \
+__asm__ __volatile__ ("!dummy %0 %1" \
+ : \
+ : "r" (__sc0), "r" (__sc2)); \
__syscall_return(type,__sc0); \
}
@@ -310,9 +321,12 @@
register unsigned long __sc0 __asm__ ("r9") = ((0x12 << 16) | __NR_##name); \
register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "(%2,%3)" \
: "=r" (__sc0) \
: "r" (__sc0), "r" (__sc2), "r" (__sc3) ); \
+__asm__ __volatile__ ("!dummy %0 %1 %2" \
+ : \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3) ); \
__syscall_return(type,__sc0); \
}
@@ -323,9 +337,12 @@
register unsigned long __sc2 __asm__ ("r2") = (unsigned long) arg1; \
register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "(%2,%3,%4)" \
: "=r" (__sc0) \
: "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4) ); \
+__asm__ __volatile__ ("!dummy %0 %1 %2 %3" \
+ : \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4) ); \
__syscall_return(type,__sc0); \
}
@@ -337,9 +354,12 @@
register unsigned long __sc3 __asm__ ("r3") = (unsigned long) arg2; \
register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
register unsigned long __sc5 __asm__ ("r5") = (unsigned long) arg4; \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "(%2,%3,%4,%5)" \
: "=r" (__sc0) \
: "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5) );\
+__asm__ __volatile__ ("!dummy %0 %1 %2 %3 %4" \
+ : \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5) );\
__syscall_return(type,__sc0); \
}
@@ -352,9 +372,13 @@
register unsigned long __sc4 __asm__ ("r4") = (unsigned long) arg3; \
register unsigned long __sc5 __asm__ ("r5") = (unsigned long) arg4; \
register unsigned long __sc6 __asm__ ("r6") = (unsigned long) arg5; \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "(%2,%3,%4,%5,%6)" \
: "=r" (__sc0) \
- : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
+ "r" (__sc6)); \
+__asm__ __volatile__ ("!dummy %0 %1 %2 %3 %4 %5" \
+ : \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
"r" (__sc6)); \
__syscall_return(type,__sc0); \
}
@@ -369,9 +393,13 @@
register unsigned long __sc5 __asm__ ("r5") = (unsigned long) arg4; \
register unsigned long __sc6 __asm__ ("r6") = (unsigned long) arg5; \
register unsigned long __sc7 __asm__ ("r7") = (unsigned long) arg6; \
-__asm__ __volatile__ ("trapa %1" \
+__asm__ __volatile__ ("trapa %1 !\t\t\t" #name "(%2,%3,%4,%5,%6,%7)" \
: "=r" (__sc0) \
- : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
+ "r" (__sc6), "r" (__sc7)); \
+__asm__ __volatile__ ("!dummy %0 %1 %2 %3 %4 %5 %6" \
+ : \
+ : "r" (__sc0), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5), \
"r" (__sc6), "r" (__sc7)); \
__syscall_return(type,__sc0); \
}
--
Richard \\\ SH-4/SH-5 Core & Debug Architect
Curnow \\\ SuperH (UK) Ltd, Bristol
|