[git commit] h8300: Assembly functions
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Tue May 26 20:15:26 UTC 2015
commit: http://git.uclibc.org/uClibc/commit/?id=5e3820a8c616be4eaa1bdd1a55a713cb3a564537
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master
- remove symbol prefix
- new startup
- new clone syscall support
Signed-off-by: Yoshinori Sato <ysato at users.sourceforge.jp>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
libc/sysdeps/linux/h8300/__longjmp.S | 6 +-
libc/sysdeps/linux/h8300/bsd-_setjmp.S | 10 +++--
libc/sysdeps/linux/h8300/bsd-setjmp.S | 13 +++---
libc/sysdeps/linux/h8300/clone.S | 36 ++++++++++++-----
libc/sysdeps/linux/h8300/{crt0.S => crt1.S} | 38 +++++++++++++++----
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 | 54 ++++++++++++++++++++------
9 files changed, 120 insertions(+), 53 deletions(-)
diff --git a/libc/sysdeps/linux/h8300/__longjmp.S b/libc/sysdeps/linux/h8300/__longjmp.S
index eb433df..bcb0985 100644
--- a/libc/sysdeps/linux/h8300/__longjmp.S
+++ b/libc/sysdeps/linux/h8300/__longjmp.S
@@ -4,10 +4,10 @@
.h8300h
#endif
.text
-
-.global ___longjmp
-___longjmp:
+.global __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..766d9cc 100644
--- a/libc/sysdeps/linux/h8300/bsd-_setjmp.S
+++ b/libc/sysdeps/linux/h8300/bsd-_setjmp.S
@@ -1,4 +1,4 @@
-/* BSD `_setjmp' entry point to `sigsetjmp (..., 0)'. H8/300 version. */
+/* BSD `_setjmp' entry point to `sigsetjmp (..., 0)'. H8/300 version. */
#include <jmpbuf-offsets.h>
@@ -8,10 +8,10 @@
.h8300h
#endif
.text
-
-.global __setjmp
-__setjmp:
+.global _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..77c810f 100644
--- a/libc/sysdeps/linux/h8300/bsd-setjmp.S
+++ b/libc/sysdeps/linux/h8300/bsd-setjmp.S
@@ -1,4 +1,4 @@
-/* BSD `_setjmp' entry point to `sigsetjmp (..., 1)'. H8/300 version. */
+/* BSD `_setjmp' entry point to `sigsetjmp (..., 1)'. H8/300 version. */
#include <jmpbuf-offsets.h>
@@ -8,10 +8,10 @@
.h8300h
#endif
.text
-
-.global _setjmp
-_setjmp:
+.global 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..a00eba4 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
@@ -62,7 +74,9 @@ __syscall_error:
thread_start:
mov.l @sp+,er0 /* restore args */
- jsr @er3
+ jsr @er3
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/crt1.S
similarity index 66%
rename from libc/sysdeps/linux/h8300/crt0.S
rename to libc/sysdeps/linux/h8300/crt1.S
index be6768d..847872a 100644
--- a/libc/sysdeps/linux/h8300/crt0.S
+++ b/libc/sysdeps/linux/h8300/crt1.S
@@ -28,17 +28,39 @@ not, see <http://www.gnu.org/licenses/>. */
#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 @(0,sp),er0 /* argc */
- mov.l @(4,sp),er1 /* argv */
- mov.l @(8,sp),er2 /* envp */
+ mov.l @sp+,er1 /* argc */
+ mov.l @sp+,er2 /* argv */
+ add.l #4,sp
+
#if !defined(__PIC__)
- jsr @___uClibc_main
+ 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 @(___uClibc_main at GOTOFF,er5),er3
+ 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
@@ -61,9 +83,9 @@ empty_func:
/* Define a symbol for the first piece of initialized data. */
.data
- .globl __data_start
-__data_start:
+ .globl _data_start
+_data_start:
.long 0
.weak data_start
- data_start = __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..1c70dd2 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,29 +9,60 @@
#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
- jmp @er1 /* don't return, just jmp directly */
+ jmp @er1 /* don't return, just jmp directly */
fix_errno:
neg.l er0
-#if !defined(__PIC__)
+# if !defined(__PIC__)
mov.l er0, at _errno
-#else
+# else
mov.l @(_errno at GOTOFF,er5),er2
mov.l er0, at er2
-#endif
+# endif
sub.l er0,er0
dec.l #1,er0
- jmp @er1 /* don't return, just jmp directly */
+ 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
More information about the uClibc-cvs
mailing list