[git commit master] mips specific bits needed for nptl

Austin Foxley austinf at cetoncorp.com
Fri Apr 23 14:31:55 UTC 2010


commit: http://git.uclibc.org/uClibc/commit/?id=6abc8f6c7c847291a9b20cb5b84e9a2dfe3b578a
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

 * vfork impl with support for SAVE_PID, RESTORE_PID
 * sysdep.h assembly macros

Signed-off-by: Austin Foxley <austinf at cetoncorp.com>
---
 libc/sysdeps/linux/mips/Makefile.arch   |    8 ++-
 libc/sysdeps/linux/mips/clone.S         |    2 +
 libc/sysdeps/linux/mips/sys/asm.h       |   16 +++++
 libc/sysdeps/linux/mips/sys/regdef.h    |    2 +
 libc/sysdeps/linux/mips/syscall_error.S |   82 ++++++++++++++++++++++++++
 libc/sysdeps/linux/mips/sysdep.h        |   54 +++++++++++++++++
 libc/sysdeps/linux/mips/vfork.S         |   97 +++++++++++++++++++++++++++++++
 7 files changed, 259 insertions(+), 2 deletions(-)
 create mode 100644 libc/sysdeps/linux/mips/syscall_error.S
 create mode 100644 libc/sysdeps/linux/mips/sysdep.h
 create mode 100644 libc/sysdeps/linux/mips/vfork.S

diff --git a/libc/sysdeps/linux/mips/Makefile.arch b/libc/sysdeps/linux/mips/Makefile.arch
index 2570a69..73e6499 100644
--- a/libc/sysdeps/linux/mips/Makefile.arch
+++ b/libc/sysdeps/linux/mips/Makefile.arch
@@ -7,11 +7,15 @@
 
 CSRC := \
 	__longjmp.c  brk.c setjmp_aux.c mmap.c __syscall_error.c \
-	cacheflush.c pread_write.c sysmips.c _test_and_set.c sigaction.c \
+	cacheflush.c pread_write.c sysmips.c _test_and_set.c \
 	readahead.c
 
 ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),y)
-        CSRC += posix_fadvise.c posix_fadvise64.c
+CSRC += posix_fadvise.c posix_fadvise64.c
+endif
+
+ifneq ($(UCLIBC_HAS_THREADS_NATIVE),y)
+CSRC += sigaction.c
 endif
 
 SSRC := bsd-_setjmp.S bsd-setjmp.S setjmp.S clone.S syscall.S pipe.S
diff --git a/libc/sysdeps/linux/mips/clone.S b/libc/sysdeps/linux/mips/clone.S
index 15fa295..52b81cb 100644
--- a/libc/sysdeps/linux/mips/clone.S
+++ b/libc/sysdeps/linux/mips/clone.S
@@ -132,3 +132,5 @@ L(__thread_start):
         jal             _exit
 #endif
 	.end  __thread_start
+weak_alias(clone, __clone)
+
diff --git a/libc/sysdeps/linux/mips/sys/asm.h b/libc/sysdeps/linux/mips/sys/asm.h
index 79d1439..d424ed3 100644
--- a/libc/sysdeps/linux/mips/sys/asm.h
+++ b/libc/sysdeps/linux/mips/sys/asm.h
@@ -472,4 +472,20 @@ symbol		=	value
 # define MTC0	dmtc0
 #endif
 
+/* The MIPS archtectures do not have a uniform memory model.  Particular
+   platforms may provide additional guarantees - for instance, the R4000
+   LL and SC instructions implicitly perform a SYNC, and the 4K promises
+   strong ordering.
+
+   However, in the absence of those guarantees, we must assume weak ordering
+   and SYNC explicitly where necessary.
+
+   Some obsolete MIPS processors may not support the SYNC instruction.  This
+   applies to "true" MIPS I processors; most of the processors which compile
+   using MIPS I implement parts of MIPS II.  */
+
+#ifndef MIPS_SYNC
+# define MIPS_SYNC      sync
+#endif
+
 #endif /* sys/asm.h */
diff --git a/libc/sysdeps/linux/mips/sys/regdef.h b/libc/sysdeps/linux/mips/sys/regdef.h
index 9d2c4c1..2d94130 100644
--- a/libc/sysdeps/linux/mips/sys/regdef.h
+++ b/libc/sysdeps/linux/mips/sys/regdef.h
@@ -20,6 +20,8 @@
 #ifndef _SYS_REGDEF_H
 #define _SYS_REGDEF_H
 
+#include <sgidefs.h>
+
 /*
  * Symbolic register names for 32 bit ABI
  */
diff --git a/libc/sysdeps/linux/mips/syscall_error.S b/libc/sysdeps/linux/mips/syscall_error.S
new file mode 100644
index 0000000..c96b6ed
--- /dev/null
+++ b/libc/sysdeps/linux/mips/syscall_error.S
@@ -0,0 +1,82 @@
+/* Copyright (C) 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2002, 2003 
+   Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Brendan Kehoe (brendan at zen.org).
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sys/asm.h>
+#include <sysdep.h>
+#include <bits/errno.h>
+
+#ifdef __UCLIBC_HAS_THREADS__
+
+LOCALSZ= 3
+FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
+RAOFF= FRAMESZ-(1*SZREG)
+GPOFF= FRAMESZ-(2*SZREG)
+V0OFF= FRAMESZ-(3*SZREG)
+	
+ENTRY(__syscall_error)
+#ifdef __PIC__
+	.set noat
+	SETUP_GPX (AT)
+	.set at
+#endif
+	PTR_SUBU sp, FRAMESZ
+	.set noat
+	SETUP_GPX64(GPOFF,AT)
+	.set at
+#ifdef __PIC__
+	SAVE_GP(GPOFF)
+#endif
+	REG_S	v0, V0OFF(sp)
+	REG_S	ra, RAOFF(sp)
+
+	/* Find our per-thread errno address  */
+	jal	__errno_location
+
+	/* Store the error value.  */
+	REG_L	t0, V0OFF(sp)
+	sw	t0, 0(v0)
+
+	/* And just kick back a -1.  */
+	REG_L	ra, RAOFF(sp)
+	RESTORE_GP64
+	PTR_ADDU sp, FRAMESZ
+	li	v0, -1
+	j	ra
+	END(__syscall_error)
+
+#else /* __UCLIBC_HAS_THREADS__ */
+
+
+ENTRY(__syscall_error)
+#ifdef __PIC__
+	SETUP_GPX (AT)
+#endif
+	SETUP_GPX64 (t9, AT)
+	
+	/* Store it in errno... */
+	sw v0, errno
+
+	/* And just kick back a -1.  */
+	li v0, -1
+
+	RESTORE_GP64
+	j ra
+	END(__syscall_error)
+#endif  /* __UCLIBC_HAS_THREADS__ */
diff --git a/libc/sysdeps/linux/mips/sysdep.h b/libc/sysdeps/linux/mips/sysdep.h
new file mode 100644
index 0000000..38d4ce9
--- /dev/null
+++ b/libc/sysdeps/linux/mips/sysdep.h
@@ -0,0 +1,54 @@
+/* Adapted from glibc's sysdeps/unix/mips/sysdep.h */
+
+/* Copyright (C) 1992, 1995, 1997, 1999, 2000, 2002, 2003
+   Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Brendan Kehoe (brendan at zen.org).
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <features.h>
+
+#if __UCLIBC_HAS_THREADS_NATIVE__
+#include_next <sysdep.h>
+
+#else
+
+#ifdef __ASSEMBLER__
+
+#include <sgidefs.h>
+#include <sys/regdef.h>
+
+#define ENTRY(name) \
+  .globl name;                                                                \
+  .align 2;                                                                   \
+  .ent name,0;                                                                \
+  name##:
+
+#undef END
+#define END(function)                                   \
+                .end    function;                       \
+                .size   function,.-function
+
+#if _MIPS_SIM == _ABIO32
+# define L(label) $L ## label
+#else
+# define L(label) .L ## label
+#endif
+
+#endif
+
+#endif /* __UCLIBC_HAS_THREADS_NATIVE__ */
diff --git a/libc/sysdeps/linux/mips/vfork.S b/libc/sysdeps/linux/mips/vfork.S
new file mode 100644
index 0000000..8400df0
--- /dev/null
+++ b/libc/sysdeps/linux/mips/vfork.S
@@ -0,0 +1,97 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* vfork() is just a special case of clone().  */
+
+#include <sys/asm.h>
+#include <sysdep.h>
+
+#ifndef SAVE_PID
+#define SAVE_PID
+#endif
+
+#ifndef RESTORE_PID
+#define RESTORE_PID
+#endif
+
+
+/* int vfork() */
+
+	.text
+LOCALSZ= 1
+FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
+GPOFF= FRAMESZ-(1*SZREG)
+NESTED(__vfork,FRAMESZ,sp)
+#ifdef __PIC__
+	SETUP_GP
+#endif
+	PTR_SUBU sp, FRAMESZ
+	SETUP_GP64 (a5, __vfork)
+#ifdef __PIC__
+	SAVE_GP (GPOFF)
+#endif
+#ifdef PROF
+# if (_MIPS_SIM != _ABIO32)
+	PTR_S		a5, GPOFF(sp)
+# endif
+	.set		noat
+	move		$1, ra
+# if (_MIPS_SIM == _ABIO32)
+	subu		sp,sp,8
+# endif
+	jal		_mcount
+	.set		at
+# if (_MIPS_SIM != _ABIO32)
+	PTR_L		a5, GPOFF(sp)
+# endif
+#endif
+
+	PTR_ADDU	sp, FRAMESZ
+
+	SAVE_PID
+
+	li		a0, 0x4112	/* CLONE_VM | CLONE_VFORK | SIGCHLD */
+	move		a1, sp
+
+	/* Do the system call */
+	li		v0,__NR_clone
+	syscall
+
+	RESTORE_PID
+
+	bnez		a3,L(error)
+
+	/* Successful return from the parent or child.  */
+	RESTORE_GP64
+	j		ra
+	nop
+
+	/* Something bad happened -- no child created.  */
+L(error):
+#ifdef __PIC__
+	PTR_LA		t9, __syscall_error
+	RESTORE_GP64
+	jr		t9
+#else
+	RESTORE_GP64
+	j		__syscall_error
+#endif
+	END(__vfork)
+
+.weak vfork;
+	vfork = __vfork
-- 
1.6.3.3



More information about the uClibc-cvs mailing list