[PATCH v2 3/6] h8300: Assembly functions

Yoshinori Sato ysato at users.sourceforge.jp
Sat May 23 17:06:24 UTC 2015


- remove symbol prefix
- new startup
- new clone syscall support

Signed-off-by: Yoshinori Sato <ysato at users.sourceforge.jp>
---
 libc/sysdeps/linux/h8300/__longjmp.S   |  4 +-
 libc/sysdeps/linux/h8300/bsd-_setjmp.S |  6 ++-
 libc/sysdeps/linux/h8300/bsd-setjmp.S  |  9 ++--
 libc/sysdeps/linux/h8300/clone.S       | 34 +++++++++----
 libc/sysdeps/linux/h8300/crt0.S        | 69 --------------------------
 libc/sysdeps/linux/h8300/crt1.S        | 91 ++++++++++++++++++++++++++++++++++
 libc/sysdeps/linux/h8300/crti.S        |  8 +--
 libc/sysdeps/linux/h8300/crtn.S        |  4 +-
 libc/sysdeps/linux/h8300/setjmp.S      |  4 +-
 libc/sysdeps/linux/h8300/vfork.S       | 44 +++++++++++++---
 10 files changed, 170 insertions(+), 103 deletions(-)
 delete mode 100644 libc/sysdeps/linux/h8300/crt0.S
 create mode 100644 libc/sysdeps/linux/h8300/crt1.S

diff --git a/libc/sysdeps/linux/h8300/__longjmp.S b/libc/sysdeps/linux/h8300/__longjmp.S
index eb433df..283aace 100644
--- a/libc/sysdeps/linux/h8300/__longjmp.S
+++ b/libc/sysdeps/linux/h8300/__longjmp.S
@@ -5,9 +5,9 @@
 #endif
 	.text
 	
-.global ___longjmp
+.global __longjmp
 
-___longjmp:
+__longjmp:
 	mov.l	er1,er1
 	bne	1f
 	sub.l	er1,er1
diff --git a/libc/sysdeps/linux/h8300/bsd-_setjmp.S b/libc/sysdeps/linux/h8300/bsd-_setjmp.S
index fbe7025..016c95f 100644
--- a/libc/sysdeps/linux/h8300/bsd-_setjmp.S
+++ b/libc/sysdeps/linux/h8300/bsd-_setjmp.S
@@ -9,9 +9,9 @@
 #endif
 	.text
 	
-.global __setjmp
+.global _setjmp
 
-__setjmp:
+_setjmp:
 	add.l	#JB_SIZE,er0
 	mov.l	@sp,er1		; return PC
 	mov.l	er1, at -er0
@@ -23,3 +23,5 @@ __setjmp:
 	sub.l	er0,er0
 	mov.l	er0,@(JB_SIZE:16,er1)
 	rts
+
+	.end
diff --git a/libc/sysdeps/linux/h8300/bsd-setjmp.S b/libc/sysdeps/linux/h8300/bsd-setjmp.S
index 74ebb8f..914a3b8 100644
--- a/libc/sysdeps/linux/h8300/bsd-setjmp.S
+++ b/libc/sysdeps/linux/h8300/bsd-setjmp.S
@@ -9,9 +9,9 @@
 #endif
 	.text
 	
-.global _setjmp
+.global setjmp
 
-_setjmp:
+setjmp:
 	add.l	#JB_SIZE,er0
 	mov.l	@sp,er1		; return PC
 	mov.l	er1, at -er0
@@ -21,8 +21,9 @@ _setjmp:
 	mov.l	er4, at -er0
 	sub.l	er0,er0
 #if !defined(__PIC__)
-	jmp	@___sigjmp_save
+	jmp	@__sigjmp_save
 #else
-	mov.l	@(___sigjmp_save at GOTOFF,er5),er1
+	mov.l	@(__sigjmp_save at GOTOFF,er5),er1
 	jmp	@er3
 #endif
+	.end
diff --git a/libc/sysdeps/linux/h8300/clone.S b/libc/sysdeps/linux/h8300/clone.S
index 554a297..7c5a530 100644
--- a/libc/sysdeps/linux/h8300/clone.S
+++ b/libc/sysdeps/linux/h8300/clone.S
@@ -1,5 +1,4 @@
-/* Adapted from glibc */
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. */
+/* Copyright 2015 Yoshinori Sato <ysato at users.sourceforge.jp> */
 
 /* clone is even more special than fork as it mucks with stacks
    and invokes a function in the right context after its all over.  */
@@ -8,7 +7,8 @@
 #include <bits/errno.h>
 #include <sys/syscall.h>
 
-/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
+/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg
+		void *parent_tidptr, void *tls, void *child_tidptr)  */
 
 #ifdef __H8300H__
 	.h8300h
@@ -18,8 +18,8 @@
 #endif
 
 .text
-.globl	_clone
-_clone:
+.globl	clone
+clone:
 	/* Sanity check arguments.  */
 	mov.l	#-EINVAL,er3
 	mov.l	er0,er0			/* no NULL function pointers */
@@ -31,13 +31,25 @@ _clone:
 	mov.l	@(4:16,sp),er3
 	mov.l	er3, at -er1
 
-	/* Do the system call */
+	/* setup argument */
 	mov.l	er0,er3			/* er3 = child entry */
-	mov.l	er1,er0
-	mov.l	er2,er1			/* er1 = flags */
-	mov.l	er0,er2			/* er2 = child sp */
-	mov.l	#__NR_clone,r0
+	sub.l	#20,sp
+	mov.l	er2, at sp			/* flags */
+	mov.l	er1,@(4,sp)		/* new sp */
+	mov.l	sp,er1
+	mov.l	@(20+8,sp),er0
+	mov.l	er0, at er1		/* parent tid */
+	adds	#4,er1
+	mov.l	@(20+16,sp),er0
+	mov.l	er0, at er1		/* child tid */
+	adds	#4,er1
+	mov.l	@(20+12,sp),er0
+	mov.l	er0, at er1		/* tls */
+	/* do the system call */
+	mov.l	sp,er1
+	mov.l	#__NR_clone,er0
 	trapa	#0
+	add.l	#20,sp
 	mov.l	er0,er0
 	bmi	__syscall_error
 	beq	thread_start
@@ -66,3 +78,5 @@ thread_start:
 	mov.l	er0,er1
 	mov.l	#__NR_exit,er0
 	trapa	#0
+
+	.end
diff --git a/libc/sysdeps/linux/h8300/crt0.S b/libc/sysdeps/linux/h8300/crt0.S
deleted file mode 100644
index be6768d..0000000
--- a/libc/sysdeps/linux/h8300/crt0.S
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Copyright (C) 1991, 1992 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 Library General Public License as
-published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, see <http://www.gnu.org/licenses/>.  */
-
-#include <features.h>
-
-	.global	_start
-	.global __exit
-	.global atexit
-	.global main
-
-#ifdef __H8300S__
-	.h8300s
-#else
-	.h8300h
-#endif
-	.text
-
-_start: /* put here so that references to _start work with elf-PIC */
-
-	mov.l	@(0,sp),er0	/* argc */
-	mov.l	@(4,sp),er1	/* argv */
-	mov.l	@(8,sp),er2	/* envp */
-#if !defined(__PIC__)
-	jsr	@___uClibc_main
-#else
-	mov.l	@(___uClibc_main at GOTOFF,er5),er3
-	jsr	@er3
-#endif
-
-	/* If that didn't kill us, ... */
-__exit:
-	mov.l	er0,er1
-	sub.l	er0,er0
-	inc.l	#1,er0		 /* __NR_exit */
-	trapa	#0
-
-/*
- *	this was needed for gcc/g++-builds,  atexit was not getting included
- *	for some stupid reason,  this gets us a compiler
- */
-empty_func:
-	rts
-	.weak atexit
-	atexit = empty_func
-
-
-/* Define a symbol for the first piece of initialized data.  */
-	.data
-	.globl __data_start
-__data_start:
-	.long 0
-	.weak data_start
-	data_start = __data_start
-
diff --git a/libc/sysdeps/linux/h8300/crt1.S b/libc/sysdeps/linux/h8300/crt1.S
new file mode 100644
index 0000000..342910e
--- /dev/null
+++ b/libc/sysdeps/linux/h8300/crt1.S
@@ -0,0 +1,91 @@
+/* Copyright (C) 1991, 1992 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, see <http://www.gnu.org/licenses/>.  */
+
+#include <features.h>
+
+	.global	_start
+	.global __exit
+	.global atexit
+	.global main
+
+#ifdef __H8300S__
+	.h8300s
+#else
+	.h8300h
+#endif
+/*	
+void __uClibc_main(int (*main)(int, char **, char **), int argc,
+                    char **argv, void (*app_init)(void), void (*app_fini)(void),
+                    void (*rtld_fini)(void),void *stack_end attribute_unused)
+*/
+	.text
+
+_start: /* put here so that references to _start work with elf-PIC */
+
+	mov.l	@sp+,er1	/* argc */
+	mov.l	@sp+,er2	/* argv */
+	add.l	#4,sp
+	
+#if !defined(__PIC__)
+	mov.l	sp, @-sp
+	sub.l	er0,er0
+	mov.l	er0, at -sp
+	mov.l	#_fini,er0
+	mov.l	er0, at -sp
+	mov.l	#_init,er0
+	mov.l	er0, at -sp
+	mov.l	#main,er0
+	jsr	@__uClibc_main
+#else
+	mov.l	sp, @-sp
+	sub.l	er0,er0
+	mov.l	er0, at -sp
+	mov.l	@(_fini at GOTOFF,er5),er0
+	mov.l	er0, at -sp
+	mov.l	@(_init at GOTOFF,er5),er0
+	mov.l	er0, at -sp
+	mov.l	@(main at GOTOFF,er5),er0
+	mov.l	@(__uClibc_main at GOTOFF,er5),er3
+	jsr	@er3
+#endif
+
+	/* If that didn't kill us, ... */
+__exit:
+	mov.l	er0,er1
+	sub.l	er0,er0
+	inc.l	#1,er0		 /* __NR_exit */
+	trapa	#0
+
+/*
+ *	this was needed for gcc/g++-builds,  atexit was not getting included
+ *	for some stupid reason,  this gets us a compiler
+ */
+empty_func:
+	rts
+	.weak atexit
+	atexit = empty_func
+
+
+/* Define a symbol for the first piece of initialized data.  */
+	.data
+	.globl _data_start
+_data_start:
+	.long 0
+	.weak data_start
+	data_start = _data_start
+
diff --git a/libc/sysdeps/linux/h8300/crti.S b/libc/sysdeps/linux/h8300/crti.S
index 270df27..cc6afe9 100644
--- a/libc/sysdeps/linux/h8300/crti.S
+++ b/libc/sysdeps/linux/h8300/crti.S
@@ -10,8 +10,8 @@
 	.section .init
 ; #NO_APP
 	.align 1
-	.global __init
-__init:
+	.global _init
+_init:
 	mov.l	er6, at -er7
 	mov.l	er7,er6
 ; #APP
@@ -20,8 +20,8 @@ __init:
 	.section .fini
 ; #NO_APP
 	.align 1
-	.global __fini
-__fini:
+	.global _fini
+_fini:
 	mov.l	er6, at -er7
 	mov.l	er7,er6
 ; #APP
diff --git a/libc/sysdeps/linux/h8300/crtn.S b/libc/sysdeps/linux/h8300/crtn.S
index 8f9fa1f..a390704 100644
--- a/libc/sysdeps/linux/h8300/crtn.S
+++ b/libc/sysdeps/linux/h8300/crtn.S
@@ -10,7 +10,7 @@
 	.section .init
 ; #NO_APP
 	.align 1
-	.global __init
+	.global _init
 ; #NO_APP
 	mov.l	@er7+,er6
 	rts
@@ -19,7 +19,7 @@
 	.section .fini
 ; #NO_APP
 	.align 1
-	.global __fini
+	.global _fini
 ; #NO_APP
 	mov.l	@er7+,er6
 	rts
diff --git a/libc/sysdeps/linux/h8300/setjmp.S b/libc/sysdeps/linux/h8300/setjmp.S
index f2795fa..0b8f052 100644
--- a/libc/sysdeps/linux/h8300/setjmp.S
+++ b/libc/sysdeps/linux/h8300/setjmp.S
@@ -7,9 +7,9 @@
 #endif
 	.text
 
-.global ___sigsetjmp
+.global __sigsetjmp
 
-___sigsetjmp:
+__sigsetjmp:
 	add.l	#JB_SIZE,er0
 	mov.l	@sp,er1		; return PC
 	mov.l	er1, at -er0
diff --git a/libc/sysdeps/linux/h8300/vfork.S b/libc/sysdeps/linux/h8300/vfork.S
index 9b65f4f..13674eb 100644
--- a/libc/sysdeps/linux/h8300/vfork.S
+++ b/libc/sysdeps/linux/h8300/vfork.S
@@ -1,10 +1,7 @@
+/* Copyright 2002, 2015 Yoshinori Sato <ysato at users.sourceforge.jp> */
 
 #include <sys/syscall.h>
 
-#ifndef __NR_vfork
-#define __NR_vfork __NR_fork /* uClinux-2.0 only has fork which is vfork */
-#endif
-
 #ifdef __H8300S__
 	.h8300s
 #else
@@ -12,14 +9,16 @@
 #endif
 	.text
 	.align 2
-	.globl	___vfork
-	.hidden	___vfork
-	.type	___vfork, at function
-___vfork:
+	.globl	__vfork
+	.hidden	__vfork
+	.type	__vfork, at function
+__vfork:
+#ifdef __NR_vfork
 	mov.l	@sp+, er1
 	sub.l	er0,er0
 	mov.b	#__NR_vfork,r0l
 	trapa	#0
+
 	mov.l	#-4096, er2
 	cmp.l 	er0,er2
 	bcs     fix_errno
@@ -35,6 +34,35 @@ fix_errno:
 	sub.l	er0,er0
 	dec.l	#1,er0
 	jmp	@er1                     /* don't return,  just jmp directly */
+#else
+	mov.l	@sp+,er2		/* er2 = return address */
+	mov.l	#vfork_args,er1
+	sub.l	er0,er0
+	mov.b	#__NR_clone,r0l
+	trapa	#0
+	mov.l	#-4096,er1
+	cmp.l	er0,er1
+	bcc	done
+	neg.l	er0
+#if !defined(__PIC__)
+	mov.l	er0, at errno
+#else
+	mov.l	@(errno at GOTOFF,er5),er1
+	mov.l	er0, at er1
+#endif
+	sub.l	er0,er0
+	dec.l	#1,er0
+done:
+	jmp	@er2
+
+vfork_args:
+	.long	0x80004100	/* CLONE_VFORK | CLONE_VM | SIGCHLD */
+	.long	0
+	.long	0
+	.long	0
+	.long	0
+#endif
 
 weak_alias(__vfork,vfork)
 libc_hidden_def(vfork)
+	.end
-- 
2.1.4



More information about the uClibc mailing list