[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#578076: sh4: syscalls do not work



Package: klibc
Version: 1.5.17-4
Severity: important
Tags: patch
User: debian-sh4@superh.org
Usertags: sh4

Using the patch from bug #574834 klibc now builds, but does not work. It
assumes that the kernel returns the result of the syscalls in register
r3, while it behaves like a normal call, with the results in register 
r0.

Also the pipe syscall needs a special handling as on some other 
architectures, the structure passed in argument is not filled, instead 
the two fd are returned in r0 and r1.

The patch below fixes the problem. It has been tested by creating an
initrd with initramfs and booting the system with it.

--- a/usr/klibc/SYSCALLS.def
+++ b/usr/klibc/SYSCALLS.def
@@ -115,7 +115,7 @@
 int mkdir(const char *, mode_t);
 <?> int mkdirat(int, const char *, const char *, mode_t);
 int rmdir(const char *);
-<!alpha,ia64,mips,mips64,sparc,sparc64> int pipe(int *);
+<!alpha,ia64,mips,mips64,sh,sparc,sparc64> int pipe(int *);
 mode_t umask(mode_t);
 int chroot(const char *);
 int symlink(const char *, const char *);
only in patch2:
unchanged:
--- a/usr/klibc/arch/sh/syscall.S
+++ b/usr/klibc/arch/sh/syscall.S
@@ -5,7 +5,7 @@
  * r4..r7 contain arguments 0-3 per the standard calling convention,
  * and arguments 4-5 are passed in r0 and r1.
  *
- * The return value is in r3 rather than standard r0.
+ * The return value is in r0.
  */
 
 	.section ".text.syscall","ax"
@@ -16,17 +16,17 @@
 	mov.l	@(0,sp),r0
 	mov.l	@(4,sp),r1
 	trapa	#0x15
-	mov.l	1f,r0
-	cmp/hs	r0,r3
+	mov.l	1f,r1
+	cmp/hs	r0,r1
 	bt/s	3f
-	  neg	r3,r4
-	mov.l	2f,r5
-	mov.l	r4,@r5
+	  neg	r0,r1
+	mov.l	2f,r2
+	mov.l	r1,@r2
 	rts
 	  mov	#-1,r0
 3:
 	rts
-	  mov	r3,r0
+	  nop
 
 	.align 2
 1:	.long	-4096		/* Errno limit */
only in patch2:
unchanged:
--- a/usr/klibc/arch/sh/Kbuild
+++ b/usr/klibc/arch/sh/Kbuild
@@ -2,7 +2,7 @@
 # klibc files for sh
 #
 
-klib-y := setjmp.o syscall.o
+klib-y := pipe.o setjmp.o syscall.o
 
 always  := crt0.o
 targets := crt0.o
only in patch2:
unchanged:
--- a/usr/klibc/arch/sh/pipe.S
+++ b/usr/klibc/arch/sh/pipe.S
@@ -0,0 +1,35 @@
+/*
+ * arch/sh/pipe.S
+ *
+ * The pipe system call is special on sh: it returns
+ * the two file descriptors in r0 and r1.
+ */
+
+#include <asm/unistd.h>
+
+	.section ".text.syscall","ax"
+	.align	2
+	.globl	pipe
+	.type	pipe,@function
+pipe:
+	mov	#__NR_pipe, r3
+	trapa	#0x10
+	mov.l	1f,r2
+	cmp/hs	r0,r2
+	bt/s	3f
+	  neg	r0,r2
+	mov.l	2f,r3
+	mov.l	r2,@r3
+	rts
+	  mov	#-1,r0
+3:
+	mov.l   r0, @r4
+	mov.l   r1, @(4, r4)
+	rts
+	  mov	#0,r0
+
+	.align 2
+1:	.long	-4096		/* Errno limit */
+2:	.long	errno
+
+	.size	pipe,.-pipe


-- System Information:
Debian Release: squeeze/sid
Architecture: sh4

Kernel: Linux 2.6.31.12
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash



Reply to: