deduplicate mips64/n32 syscall clobbered register lists

this patch is not purely non-functional changes, since before, $8 and
$9 were wrongly in the clobberlist for syscalls with fewer than 5 or 6
arguments. of course it's impossible for syscalls to have different
clobbers depending on their number of arguments. the clobberlist for
the recently-added 5- and 6-argument forms was correct, and for the 0-
to 4-argument forms was erroneously copied from the mips o32 ABI where
the additional arguments had to be passed on the stack.

in making this change, I reviewed the kernel sources, and $8 and $9
are always saved for 64-bit kernels since they're part of the syscall
argument list for n32 and n64 ABIs.
This commit is contained in:
Rich Felker 2019-07-16 20:31:38 -04:00
parent 03919b26ed
commit db2a148d9d
2 changed files with 22 additions and 28 deletions

View File

@ -46,6 +46,10 @@ static void __stat_fix(struct kernel_stat *kst, struct stat *st)
st->st_blocks = kst->st_blocks; st->st_blocks = kst->st_blocks;
} }
#define SYSCALL_CLOBBERLIST \
"$1", "$3", "$10", "$11", "$12", "$13", \
"$14", "$15", "$24", "$25", "hi", "lo", "memory"
static inline long __syscall0(long n) static inline long __syscall0(long n)
{ {
register long r7 __asm__("$7"); register long r7 __asm__("$7");
@ -53,8 +57,7 @@ static inline long __syscall0(long n)
__asm__ __volatile__ ( __asm__ __volatile__ (
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7) : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
return r7 ? -r2 : r2; return r7 ? -r2 : r2;
} }
@ -67,8 +70,7 @@ static inline long __syscall1(long n, long a)
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4) "r"(r4)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
return r7 ? -r2 : r2; return r7 ? -r2 : r2;
} }
@ -88,8 +90,7 @@ static inline long __syscall2(long n, long a, long b)
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5) "r"(r4), "r"(r5)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
ret = r2; ret = r2;
@ -117,8 +118,7 @@ static inline long __syscall3(long n, long a, long b, long c)
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6) "r"(r4), "r"(r5), "r"(r6)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
ret = r2; ret = r2;
@ -148,8 +148,7 @@ static inline long __syscall4(long n, long a, long b, long c, long d)
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6) "r"(r4), "r"(r5), "r"(r6)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
ret = r2; ret = r2;
@ -182,8 +181,7 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e)
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6), "r"(r8) "r"(r4), "r"(r5), "r"(r6), "r"(r8)
: "$1", "$3", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
ret = r2; ret = r2;
@ -217,8 +215,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
"daddu $2,$0,%2 ; syscall" "daddu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6), "r"(r8), "r"(r9) "r"(r4), "r"(r5), "r"(r6), "r"(r8), "r"(r9)
: "$1", "$3", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
ret = r2; ret = r2;

View File

@ -15,6 +15,10 @@ static inline void __stat_fix(long p)
} }
#endif #endif
#define SYSCALL_CLOBBERLIST \
"$1", "$3", "$10", "$11", "$12", "$13", \
"$14", "$15", "$24", "$25", "hi", "lo", "memory"
static inline long __syscall0(long n) static inline long __syscall0(long n)
{ {
register long r7 __asm__("$7"); register long r7 __asm__("$7");
@ -22,8 +26,7 @@ static inline long __syscall0(long n)
__asm__ __volatile__ ( __asm__ __volatile__ (
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7) : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
return r7 ? -r2 : r2; return r7 ? -r2 : r2;
} }
@ -36,8 +39,7 @@ static inline long __syscall1(long n, long a)
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4) "r"(r4)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
return r7 ? -r2 : r2; return r7 ? -r2 : r2;
} }
@ -51,8 +53,7 @@ static inline long __syscall2(long n, long a, long b)
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5) "r"(r4), "r"(r5)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
long ret = r2; long ret = r2;
if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b); if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
@ -70,8 +71,7 @@ static inline long __syscall3(long n, long a, long b, long c)
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6) "r"(r4), "r"(r5), "r"(r6)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
long ret = r2; long ret = r2;
if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b); if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
@ -89,8 +89,7 @@ static inline long __syscall4(long n, long a, long b, long c, long d)
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6) "r"(r4), "r"(r5), "r"(r6)
: "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (r7) return -r2; if (r7) return -r2;
long ret = r2; long ret = r2;
if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b); if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
@ -110,8 +109,7 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e)
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6), "r"(r8) "r"(r4), "r"(r5), "r"(r6), "r"(r8)
: "$1", "$3", "$9", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b); if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
if (n == SYS_newfstatat) __stat_fix(c); if (n == SYS_newfstatat) __stat_fix(c);
return r2; return r2;
@ -130,8 +128,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
"addu $2,$0,%2 ; syscall" "addu $2,$0,%2 ; syscall"
: "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7), : "=&r"(r2), "=r"(r7) : "ir"(n), "0"(r2), "1"(r7),
"r"(r4), "r"(r5), "r"(r6), "r"(r8), "r"(r9) "r"(r4), "r"(r5), "r"(r6), "r"(r8), "r"(r9)
: "$1", "$3", "$10", "$11", "$12", "$13", : SYSCALL_CLOBBERLIST);
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b); if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
if (n == SYS_newfstatat) __stat_fix(c); if (n == SYS_newfstatat) __stat_fix(c);
return r2; return r2;