From patchwork Mon May 18 07:32:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshinori Sato X-Patchwork-Id: 473290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id 965D81401B5 for ; Mon, 18 May 2015 17:53:14 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 4035432C94; Mon, 18 May 2015 07:53:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a1LG4t44bHrZ; Mon, 18 May 2015 07:52:54 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id EFE2C32BA9; Mon, 18 May 2015 07:52:50 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id E63E21C22AD for ; Mon, 18 May 2015 07:52:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id E157D94FB9 for ; Mon, 18 May 2015 07:52:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ww6yiqRNIaS9 for ; Mon, 18 May 2015 07:52:46 +0000 (UTC) X-Greylist: delayed 00:20:30 by SQLgrey-1.7.6 Received: from mail2.asahi-net.or.jp (mail2.asahi-net.or.jp [202.224.39.198]) by hemlock.osuosl.org (Postfix) with ESMTP id 2F0AB94E7A for ; Mon, 18 May 2015 07:52:45 +0000 (UTC) Received: from sa76r4 (y081184.ppp.asahi-net.or.jp [118.243.81.184]) by mail2.asahi-net.or.jp (Postfix) with ESMTP id CEF6D731C; Mon, 18 May 2015 16:32:18 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by sa76r4 (Postfix) with ESMTP id 961BEE005; Mon, 18 May 2015 16:32:18 +0900 (JST) X-Virus-Scanned: Debian amavisd-new at sa76r4.localdomain Received: from sa76r4 ([127.0.0.1]) by localhost (sa76r4.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NwZ4w37HIj2f; Mon, 18 May 2015 16:32:18 +0900 (JST) Received: by sa76r4 (Postfix, from userid 1000) id 78C7BA05; Mon, 18 May 2015 16:32:18 +0900 (JST) From: Yoshinori Sato To: uclibc@uclibc.org Subject: [PATCH 3/6] h8300: Assembly functions Date: Mon, 18 May 2015 16:32:04 +0900 Message-Id: <1431934327-1278-4-git-send-email-ysato@users.sourceforge.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1431934327-1278-1-git-send-email-ysato@users.sourceforge.jp> References: <1431934327-1278-1-git-send-email-ysato@users.sourceforge.jp> X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" - remove symbol prefix - new startup - new clone syscall support Signed-off-by: Yoshinori Sato --- 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,@-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,@-er0 @@ -21,8 +21,9 @@ _setjmp: mov.l er4,@-er0 sub.l er0,er0 #if !defined(__PIC__) - jmp @___sigjmp_save + jmp @__sigjmp_save #else - mov.l @(___sigjmp_save@GOTOFF,er5),er1 + mov.l @(__sigjmp_save@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 */ /* 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 #include -/* 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,@-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,@sp /* flags */ + mov.l er1,@(4,sp) /* new sp */ + mov.l sp,er1 + mov.l @(20+8,sp),er0 + mov.l er0,@er1 /* parent tid */ + adds #4,er1 + mov.l @(20+16,sp),er0 + mov.l er0,@er1 /* child tid */ + adds #4,er1 + mov.l @(20+12,sp),er0 + mov.l er0,@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 . */ - -#include - - .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@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 . */ + +#include + + .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,@-sp + mov.l #_fini,er0 + mov.l er0,@-sp + mov.l #_init,er0 + mov.l er0,@-sp + mov.l #main,er0 + jsr @__uClibc_main +#else + mov.l sp, @-sp + sub.l er0,er0 + mov.l er0,@-sp + mov.l @(_fini@GOTOFF,er5),er0 + mov.l er0,@-sp + mov.l @(_init@GOTOFF,er5),er0 + mov.l er0,@-sp + mov.l @(main@GOTOFF,er5),er0 + mov.l @(__uClibc_main@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,@-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,@-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,@-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 */ #include -#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,@function -___vfork: + .globl __vfork + .hidden __vfork + .type __vfork,@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,@errno +#else + mov.l @(errno@GOTOFF,er5),er1 + mov.l er0,@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