diff options
author | Shin-ichiro KAWASAKI <shinichiro.kawasaki.mg@hitachi.com> | 2009-09-28 16:11:39 +0900 |
---|---|---|
committer | Tony Sim <sim.chinyeow@renesas.com> | 2009-09-28 16:11:39 +0900 |
commit | 10093276e98d26428875480c502a278dffe550c7 (patch) | |
tree | 82b93376f21744cb1696a27c084d633d162a6ab1 /libc/arch-sh/bionic | |
parent | 4e30c09e57a0351daff70f6657794569445be21c (diff) | |
download | bionic-10093276e98d26428875480c502a278dffe550c7.zip bionic-10093276e98d26428875480c502a278dffe550c7.tar.gz bionic-10093276e98d26428875480c502a278dffe550c7.tar.bz2 |
added and modified bionic code to support SuperH architecture
modified: libc/Android.mk
new files: libc/arch-sh/bionic/*
new files: libc/arch-sh/include/*
Diffstat (limited to 'libc/arch-sh/bionic')
-rw-r--r-- | libc/arch-sh/bionic/__get_pc.S | 37 | ||||
-rw-r--r-- | libc/arch-sh/bionic/__get_sp.S | 36 | ||||
-rw-r--r-- | libc/arch-sh/bionic/__get_tls.c | 37 | ||||
-rw-r--r-- | libc/arch-sh/bionic/__set_tls.c | 37 | ||||
-rw-r--r-- | libc/arch-sh/bionic/_exit_with_stack_teardown.S | 52 | ||||
-rw-r--r-- | libc/arch-sh/bionic/_setjmp.S | 125 | ||||
-rw-r--r-- | libc/arch-sh/bionic/atomic_cmpxchg.S | 50 | ||||
-rw-r--r-- | libc/arch-sh/bionic/atomics_sh.c | 100 | ||||
-rw-r--r-- | libc/arch-sh/bionic/bzero.S | 29 | ||||
-rw-r--r-- | libc/arch-sh/bionic/clone.S | 74 | ||||
-rw-r--r-- | libc/arch-sh/bionic/crtbegin_dynamic.S | 95 | ||||
-rw-r--r-- | libc/arch-sh/bionic/crtbegin_static.S | 96 | ||||
-rw-r--r-- | libc/arch-sh/bionic/crtend.S | 39 | ||||
-rw-r--r-- | libc/arch-sh/bionic/ffs.S | 103 | ||||
-rw-r--r-- | libc/arch-sh/bionic/memcpy.S | 268 | ||||
-rw-r--r-- | libc/arch-sh/bionic/memmove.S | 5 | ||||
-rw-r--r-- | libc/arch-sh/bionic/memset.S | 295 | ||||
-rw-r--r-- | libc/arch-sh/bionic/pipe.S | 63 | ||||
-rw-r--r-- | libc/arch-sh/bionic/setjmp.S | 167 | ||||
-rw-r--r-- | libc/arch-sh/bionic/sigsetjmp.S | 166 | ||||
-rw-r--r-- | libc/arch-sh/bionic/syscall.S | 69 | ||||
-rw-r--r-- | libc/arch-sh/bionic/unwind.c | 30 |
22 files changed, 1973 insertions, 0 deletions
diff --git a/libc/arch-sh/bionic/__get_pc.S b/libc/arch-sh/bionic/__get_pc.S new file mode 100644 index 0000000..155b387 --- /dev/null +++ b/libc/arch-sh/bionic/__get_pc.S @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +.text +.type __get_pc, @function +.globl __get_pc +.align 4 + +__get_pc: + mova 1f, r0 + rts +1: nop + diff --git a/libc/arch-sh/bionic/__get_sp.S b/libc/arch-sh/bionic/__get_sp.S new file mode 100644 index 0000000..0e34a01 --- /dev/null +++ b/libc/arch-sh/bionic/__get_sp.S @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +.text +.type __get_sp, @function +.globl __get_sp +.align 4 + +__get_sp: + rts + mov r15, r0 + diff --git a/libc/arch-sh/bionic/__get_tls.c b/libc/arch-sh/bionic/__get_tls.c new file mode 100644 index 0000000..8a5e4ff --- /dev/null +++ b/libc/arch-sh/bionic/__get_tls.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* see the implementation of __set_tls and pthread.c to understand this + * code. Basically, the content of fs:[0] always is a pointer to the base + * address of the tls region + */ +void *__get_tls(void) +{ + void *tls; + asm volatile("stc gbr, %0" : "=r"(tls)); + return tls; +} diff --git a/libc/arch-sh/bionic/__set_tls.c b/libc/arch-sh/bionic/__set_tls.c new file mode 100644 index 0000000..7f863de --- /dev/null +++ b/libc/arch-sh/bionic/__set_tls.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include <pthread.h> + +/* + * Simply set tls address into GBR. + */ +int __set_tls(void *ptr) +{ + asm volatile("ldc %0, gbr" : /* no output */ : "r" (ptr)); + return 0; +} diff --git a/libc/arch-sh/bionic/_exit_with_stack_teardown.S b/libc/arch-sh/bionic/_exit_with_stack_teardown.S new file mode 100644 index 0000000..6356eb6 --- /dev/null +++ b/libc/arch-sh/bionic/_exit_with_stack_teardown.S @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include <asm/unistd.h> + +.text +.type _exit_with_stack_teardown, @function +.globl _exit_with_stack_teardown +.align 4 + +# void _exit_with_stack_teardown(void * stackBase, int stackSize, int retCode) + +_exit_with_stack_teardown: + mov r6, r8 /* save retCode : breaks r8 value */ + mov.l 0f, r3 /* system call number */ + trapa #(2 + 0x10) /* invoke system call with num of args */ + + mov r8, r4 /* restore retCode */ + mov.l 1f, r3 /* system call number */ + trapa #(1 + 0x10) /* invoke system call with num of args */ + + /* exit() should never return, cause a crash if it does */ + mov #0, r0 + mov.l @r0, r0 + + .align 2 +0: .long __NR_munmap +1: .long __NR_exit diff --git a/libc/arch-sh/bionic/_setjmp.S b/libc/arch-sh/bionic/_setjmp.S new file mode 100644 index 0000000..a04fcb6 --- /dev/null +++ b/libc/arch-sh/bionic/_setjmp.S @@ -0,0 +1,125 @@ +/* $OpenBSD: _setjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $ */ +/* $NetBSD: _setjmp.S,v 1.7 2006/01/05 02:04:41 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)_setjmp.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from the last call to + * _setjmp(a) + * by restoring registers from the stack. + * The previous signal state is NOT restored. + */ + +ENTRY(_setjmp) + xor r0, r0 +#if defined(__SH4__) && !defined(__SH4_NOFPU__) + add #(_JBLEN * 4), r4 + sts fpscr, r1 + mov.l r1, @-r4 + lds r0, fpscr + sts.l fpul, @-r4 + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 + frchg + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 + lds r1, fpscr +#else + add #((_JBLEN - 10) * 4), r4 +#endif + sts.l mach, @-r4 + sts.l macl, @-r4 + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + sts.l pr, @-r4 + mov.l r0, @-r4 /* dummy signal mask */ + rts + mov.l r0, @-r4 /* no saved signal mask */ + SET_ENTRY_SIZE(_setjmp) + +ENTRY(_longjmp) + add #8, r4 + lds.l @r4+, pr + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + lds.l @r4+, macl + lds.l @r4+, mach +#if defined(__SH4__) && !defined(__SH4_NOFPU__) + xor r0, r0 + lds r0, fpscr + frchg + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 + frchg + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 + lds.l @r4+, fpul + lds.l @r4+, fpscr +#endif + + mov r5, r0 + tst r0, r0 + bf .L0 + add #1, r0 +.L0: + rts + nop + SET_ENTRY_SIZE(_longjmp) diff --git a/libc/arch-sh/bionic/atomic_cmpxchg.S b/libc/arch-sh/bionic/atomic_cmpxchg.S new file mode 100644 index 0000000..4ccd6cf --- /dev/null +++ b/libc/arch-sh/bionic/atomic_cmpxchg.S @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +.text +.type __atomic_cmpxchg, @function +.globl __atomic_cmpxchg +.align 4 + +__atomic_cmpxchg: + mova 1f, r0 + nop + mov r15, r1 + mov #-8, r15 /* critical region start */ +0: mov.l @r6, r2 + cmp/eq r2, r4 + bt not_yet_modified + mov #1, r0 + bra done + nop +not_yet_modified: + mov #0, r0 + mov.l r5, @r6 +done: +1: mov r1, r15 /* critical region end */ + rts + nop diff --git a/libc/arch-sh/bionic/atomics_sh.c b/libc/arch-sh/bionic/atomics_sh.c new file mode 100644 index 0000000..16966f7 --- /dev/null +++ b/libc/arch-sh/bionic/atomics_sh.c @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <pthread.h> +#include <linux/futex.h> + +#define SWAP_LOCK_COUNT 32U +static pthread_mutex_t _swap_locks[SWAP_LOCK_COUNT]; + +#define SWAP_LOCK(addr) \ + &_swap_locks[((unsigned)(void *)(addr) >> 3U) % SWAP_LOCK_COUNT] + +#if 0 +/* + * Only this function is moved to atomic_cmpxchg.S, and + * implemented with gUSA framework. + */ +int __atomic_cmpxchg(int old, int _new, volatile int *ptr) +{ + int result; + pthread_mutex_t *lock = SWAP_LOCK(ptr); + + pthread_mutex_lock(lock); + + if (*ptr == old) { + *ptr = _new; + result = 0; + } else { + result = 1; + } + pthread_mutex_unlock(lock); + return result; +} +#else +extern int __atomic_cmpxchg(int old, int _new, volatile int *ptr); +#endif + +int __atomic_swap(int _new, volatile int *ptr) +{ + int oldValue; + do { + oldValue = *ptr; + } while (__atomic_cmpxchg(oldValue, _new, ptr)); + return oldValue; +} + +int __atomic_dec(volatile int *ptr) +{ + int oldValue; + do { + oldValue = *ptr; + } while (__atomic_cmpxchg(oldValue, oldValue-1, ptr)); + return oldValue; +} + +int __atomic_inc(volatile int *ptr) +{ + int32_t oldValue; + do { + oldValue = *ptr; + } while (__atomic_cmpxchg(oldValue, oldValue+1, ptr)); + return oldValue; +} + +extern int futex(volatile void *, int, int, void *, void *, int); + +int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout) +{ + return futex(ftx, FUTEX_WAIT, val, (void *)timeout, NULL, 0); +} + +int __futex_wake(volatile void *ftx, int count) +{ + return futex(ftx, FUTEX_WAKE, count, NULL, NULL, 0); +} diff --git a/libc/arch-sh/bionic/bzero.S b/libc/arch-sh/bionic/bzero.S new file mode 100644 index 0000000..ca8bed4 --- /dev/null +++ b/libc/arch-sh/bionic/bzero.S @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#define BZERO +#include "memset.S" diff --git a/libc/arch-sh/bionic/clone.S b/libc/arch-sh/bionic/clone.S new file mode 100644 index 0000000..0bbaecb --- /dev/null +++ b/libc/arch-sh/bionic/clone.S @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include <sys/linux-syscalls.h> + +.text +.type __pthread_clone, @function +.globl __pthread_clone +.align 4 + +__pthread_clone: + /* insert the args onto the new stack */ + mov r5, r0 + mov.l r4, @-r0 /* func */ + mov.l r7, @-r0 /* arg */ + + /* do the system call */ + mov r6, r4 /* Set clone_flags. new sp is ready in r5. */ + mov.l 0f, r3 + trapa #(4 + 0x10) + + /* check error */ + cmp/pz r0 + bf __error + + /* check if parent or child */ + cmp/pl r0 + bt __return + + /* prepare args for __thread_entry */ + mov #8, r1 + sub r1, r15 /* -8 */ + mov.l @r15+, r5 /* +4 */ /* arg */ + mov.l @r15+, r4 /* +4 */ /* func */ + mov r15, r6 /* tls */ + + /* jump to __thread_entry */ + mov.l 1f, r0 + jmp @r0 + nop + +__error: + mov #-1, r0 +__return: + rts + nop + + .align 2 +0: .long __NR_clone +1: .long __thread_entry diff --git a/libc/arch-sh/bionic/crtbegin_dynamic.S b/libc/arch-sh/bionic/crtbegin_dynamic.S new file mode 100644 index 0000000..dc485dd --- /dev/null +++ b/libc/arch-sh/bionic/crtbegin_dynamic.S @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +.text +.align 4 +.type _start,#function +.globl _start + +# this is the small startup code that is first run when +# any executable that is statically-linked with Bionic +# runs. +# +# it's purpose is to call __libc_init with appropriate +# arguments, which are: +# +# - the address of the raw data block setup by the Linux +# kernel ELF loader +# +# - address of an "onexit" function, not used on any +# platform supported by Bionic +# +# - address of the "main" function of the program. We +# can't hard-code it in the adr pseudo instruction +# so we use a tiny trampoline that will get relocated +# by the dynamic linker before this code runs +# +# - address of the constructor list +# +_start: + mov r15, r4 + mov #0, r5 + mov.l 0f, r6 + mova 2f, r0 + mov r0, r7 + mov.l 1f, r0 + jmp @r0 + nop + + .balign 4 +0: .long main +1: .long __libc_init +2: .long __PREINIT_ARRAY__ + .long __INIT_ARRAY__ + .long __FINI_ARRAY__ + .long __CTOR_LIST__ + +# the .ctors section contains a list of pointers to "constructor" +# functions that need to be called in order during C library initialization, +# just before the program is being run. This is a C++ requirement +# +# the last entry shall be 0, and is defined in crtend.S +# + .section .preinit_array, "aw" + .globl __PREINIT_ARRAY__ +__PREINIT_ARRAY__: + .long -1 + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + + .section .ctors, "aw" + .globl __CTOR_LIST__ +__CTOR_LIST__: + .long -1 diff --git a/libc/arch-sh/bionic/crtbegin_static.S b/libc/arch-sh/bionic/crtbegin_static.S new file mode 100644 index 0000000..97db1e4 --- /dev/null +++ b/libc/arch-sh/bionic/crtbegin_static.S @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +.text +.align 4 +.type _start,#function +.globl _start + +# this is the small startup code that is first run when +# any executable that is statically-linked with Bionic +# runs. +# +# it's purpose is to call __libc_init with appropriate +# arguments, which are: +# +# - the address of the raw data block setup by the Linux +# kernel ELF loader +# +# - address of an "onexit" function, not used on any +# platform supported by Bionic +# +# - address of the "main" function of the program. We +# can't hard-code it in the adr pseudo instruction +# so we use a tiny trampoline that will get relocated +# by the dynamic linker before this code runs +# +# - address of the constructor list +# +_start: + mov r15, r4 + mov #0, r5 + mov.l 0f, r6 + mova 2f, r0 + mov r0, r7 + mov.l 1f, r0 + jmp @r0 + nop + + .balign 4 +0: .long main +1: .long __libc_init +2: .long __PREINIT_ARRAY__ + .long __INIT_ARRAY__ + .long __FINI_ARRAY__ + .long __CTOR_LIST__ + +# the .ctors section contains a list of pointers to "constructor" +# functions that need to be called in order during C library initialization, +# just before the program is being run. This is a C++ requirement +# +# the last entry shall be 0, and is defined in crtend.S +# + .section .preinit_array, "aw" + .globl __PREINIT_ARRAY__ +__PREINIT_ARRAY__: + .long -1 + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + + .section .ctors, "aw" + .globl __CTOR_LIST__ +__CTOR_LIST__: + .long -1 + diff --git a/libc/arch-sh/bionic/crtend.S b/libc/arch-sh/bionic/crtend.S new file mode 100644 index 0000000..4ced3aa --- /dev/null +++ b/libc/arch-sh/bionic/crtend.S @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + .section .preinit_array, "aw" + .long 0 + + .section .init_array, "aw" + .long 0 + + .section .fini_array, "aw" + .long 0 + + .section .ctors, "aw" + .long 0 diff --git a/libc/arch-sh/bionic/ffs.S b/libc/arch-sh/bionic/ffs.S new file mode 100644 index 0000000..733694b --- /dev/null +++ b/libc/arch-sh/bionic/ffs.S @@ -0,0 +1,103 @@ +/* $NetBSD: ffs.S,v 1.1 2005/12/20 19:28:50 christos Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by ITOH Yasufumi. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <machine/asm.h> + +#if defined(LIBC_SCCS) && !defined(lint) + RCSID("$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:50 christos Exp $") +#endif + +/* + * ffs - find first bit set + * + * This code makes use of ``test 8bit'' and ``shift 8bit'' instructions. + * The remaining 8bit is tested in every 2bit. + */ + +ENTRY(ffs) + mov r4,r0 ! using r0 specific instructions + tst #0xff,r0 + bf/s L8bit + mov #0+1,r1 ! ret = 1..8 + + tst r0,r0 ! ffs(0) is 0 + bt Lzero ! testing here to accelerate ret=1..8 cases + + shlr8 r0 + tst #0xff,r0 + bf/s L8bit + mov #8+1,r1 ! ret = 9..16 + + shlr8 r0 + tst #0xff,r0 + bf/s L8bit + mov #16+1,r1 ! ret = 17..24 + + shlr8 r0 + mov #24+1,r1 ! ret = 25..32 + +L8bit: + tst #0x0f,r0 + bt 4f + + tst #0x03,r0 + bt 2f + tst #0x01,r0 ! not bit 0 -> T + mov #0,r0 + rts + addc r1,r0 ! 0 + r1 + T -> r0 + +2: tst #0x04,r0 + mov #2,r0 + rts + addc r1,r0 + +4: tst #0x30,r0 + bt 6f + tst #0x10,r0 + mov #4,r0 + rts + addc r1,r0 + +6: tst #0x40,r0 + mov #6,r0 + rts + addc r1,r0 + +Lzero: rts + nop diff --git a/libc/arch-sh/bionic/memcpy.S b/libc/arch-sh/bionic/memcpy.S new file mode 100644 index 0000000..9d1b897 --- /dev/null +++ b/libc/arch-sh/bionic/memcpy.S @@ -0,0 +1,268 @@ +/* $OpenBSD: memcpy.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: memcpy.S,v 1.2 2006/04/22 23:53:47 uwe Exp $ */ + +/* + * Copyright (c) 2000 SHIMIZU Ryo <ryo@misakimix.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <machine/asm.h> + +#if !defined(MEMCOPY) && !defined(MEMMOVE) && !defined(BCOPY) +#define MEMCOPY +#endif + +#if defined(MEMCOPY) || defined(MEMMOVE) +#define REG_DST0 r3 +#define REG_SRC r5 +#define REG_DST r4 +#else +#define REG_SRC r4 +#define REG_DST r5 +#endif + +#define REG_LEN r6 + +#if defined(MEMCOPY) +ENTRY(memcpy) +#elif defined(MEMMOVE) +ENTRY(memmove) +#elif defined(BCOPY) +ENTRY(bcopy) +#endif +#ifdef REG_DST0 + mov REG_DST,REG_DST0 +#endif + cmp/eq REG_DST,REG_SRC /* if ( src == dst ) return; */ + bt/s bcopy_return + cmp/hi REG_DST,REG_SRC + bf/s bcopy_overlap + + mov REG_SRC,r0 + xor REG_DST,r0 + and #3,r0 + mov r0,r1 + tst r0,r0 /* (src ^ dst) & 3 */ + bf/s word_align + +longword_align: + tst REG_LEN,REG_LEN /* if ( len==0 ) return; */ + bt/s bcopy_return + + + mov REG_SRC,r0 + tst #1,r0 /* if ( src & 1 ) */ + bt 1f + mov.b @REG_SRC+,r0 /* *dst++ = *src++; */ + add #-1,REG_LEN + mov.b r0,@REG_DST + add #1,REG_DST +1: + + + mov #1,r0 + cmp/hi r0,REG_LEN /* if ( (len > 1) && */ + bf/s 1f + mov REG_SRC,r0 + tst #2,r0 /* (src & 2) { */ + bt 1f + mov.w @REG_SRC+,r0 /* *((unsigned short*)dst)++ = *((unsigned short*)src)++; */ + add #-2,REG_LEN /* len -= 2; */ + mov.w r0,@REG_DST + add #2,REG_DST /* } */ +1: + + + mov #3,r1 + cmp/hi r1,REG_LEN /* while ( len > 3 ) { */ + bf/s no_align_delay + tst REG_LEN,REG_LEN +2: + mov.l @REG_SRC+,r0 /* *((unsigned long*)dst)++ = *((unsigned long*)src)++; */ + add #-4,REG_LEN /* len -= 4; */ + mov.l r0,@REG_DST + cmp/hi r1,REG_LEN + bt/s 2b + add #4,REG_DST /* } */ + + bra no_align_delay + tst REG_LEN,REG_LEN + + +word_align: + mov r1,r0 + tst #1,r0 + bf/s no_align_delay + tst REG_LEN,REG_LEN /* if ( len == 0 ) return; */ + bt bcopy_return + + + mov REG_SRC,r0 /* if ( src & 1 ) */ + tst #1,r0 + bt 1f + mov.b @REG_SRC+,r0 /* *dst++ = *src++; */ + add #-1,REG_LEN + mov.b r0,@REG_DST + add #1,REG_DST +1: + + + mov #1,r1 + cmp/hi r1,REG_LEN /* while ( len > 1 ) { */ + bf/s no_align_delay + tst REG_LEN,REG_LEN +2: + mov.w @REG_SRC+,r0 /* *((unsigned short*)dst)++ = *((unsigned short*)src)++; */ + add #-2,REG_LEN /* len -= 2; */ + mov.w r0,@REG_DST + cmp/hi r1,REG_LEN + bt/s 2b + add #2,REG_DST /* } */ + + +no_align: + tst REG_LEN,REG_LEN /* while ( len!= ) { */ +no_align_delay: + bt bcopy_return +1: + mov.b @REG_SRC+,r0 /* *dst++ = *src++; */ + add #-1,REG_LEN /* len--; */ + mov.b r0,@REG_DST + tst REG_LEN,REG_LEN + bf/s 1b + add #1,REG_DST /* } */ +bcopy_return: + rts +#ifdef REG_DST0 + mov REG_DST0,r0 +#else + nop +#endif + + +bcopy_overlap: + add REG_LEN,REG_SRC + add REG_LEN,REG_DST + + mov REG_SRC,r0 + xor REG_DST,r0 + and #3,r0 + mov r0,r1 + tst r0,r0 /* (src ^ dst) & 3 */ + bf/s ov_word_align + +ov_longword_align: + tst REG_LEN,REG_LEN /* if ( len==0 ) return; */ + bt/s bcopy_return + + + mov REG_SRC,r0 + tst #1,r0 /* if ( src & 1 ) */ + bt 1f + add #-1,REG_SRC /* *--dst = *--src; */ + mov.b @REG_SRC,r0 + mov.b r0,@-REG_DST + add #-1,REG_LEN +1: + + + mov #1,r0 + cmp/hi r0,REG_LEN /* if ( (len > 1) && */ + bf/s 1f + mov REG_SRC,r0 + tst #2,r0 /* (src & 2) { */ + bt 1f + add #-2,REG_SRC /* *--((unsigned short*)dst) = *--((unsigned short*)src); */ + mov.w @REG_SRC,r0 + add #-2,REG_LEN /* len -= 2; */ + mov.w r0,@-REG_DST /* } */ +1: + + + mov #3,r1 + cmp/hi r1,REG_LEN /* while ( len > 3 ) { */ + bf/s ov_no_align_delay + tst REG_LEN,REG_LEN +2: + add #-4,REG_SRC + mov.l @REG_SRC,r0 /* *((unsigned long*)dst)++ = *((unsigned long*)src)++; */ + add #-4,REG_LEN /* len -= 4; */ + cmp/hi r1,REG_LEN + bt/s 2b + mov.l r0,@-REG_DST /* } */ + + bra ov_no_align_delay + tst REG_LEN,REG_LEN + + +ov_word_align: + mov r1,r0 + tst #1,r0 + bf/s ov_no_align_delay + tst REG_LEN,REG_LEN /* if ( len == 0 ) return; */ + bt bcopy_return + + + mov REG_SRC,r0 /* if ( src & 1 ) */ + tst #1,r0 + bt 1f + add #-1,REG_SRC + mov.b @REG_SRC,r0 /* *--dst = *--src; */ + add #-1,REG_LEN + mov.b r0,@-REG_DST +1: + + + mov #1,r1 + cmp/hi r1,REG_LEN /* while ( len > 1 ) { */ + bf/s ov_no_align_delay + tst REG_LEN,REG_LEN +2: + add #-2,REG_SRC + mov.w @REG_SRC,r0 /* *--((unsigned short*)dst) = *--((unsigned short*)src); */ + add #-2,REG_LEN /* len -= 2; */ + cmp/hi r1,REG_LEN + bt/s 2b + mov.w r0,@-REG_DST /* } */ + + +ov_no_align: + tst REG_LEN,REG_LEN /* while ( len!= ) { */ +ov_no_align_delay: + bt 9f +1: + add #-1,REG_SRC + mov.b @REG_SRC,r0 /* *--dst = *--src; */ + add #-1,REG_LEN /* len--; */ + tst REG_LEN,REG_LEN + bf/s 1b + mov.b r0,@-REG_DST /* } */ +9: + rts +#ifdef REG_DST0 + mov REG_DST0,r0 +#else + nop +#endif diff --git a/libc/arch-sh/bionic/memmove.S b/libc/arch-sh/bionic/memmove.S new file mode 100644 index 0000000..023fc10 --- /dev/null +++ b/libc/arch-sh/bionic/memmove.S @@ -0,0 +1,5 @@ +/* $OpenBSD: memmove.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: memmove.S,v 1.2 2006/04/22 23:53:47 uwe Exp $ */ + +#define MEMMOVE +#include "memcpy.S" diff --git a/libc/arch-sh/bionic/memset.S b/libc/arch-sh/bionic/memset.S new file mode 100644 index 0000000..73b0d06 --- /dev/null +++ b/libc/arch-sh/bionic/memset.S @@ -0,0 +1,295 @@ +/* $OpenBSD: memset.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: memset.S,v 1.1 2005/12/20 19:28:50 christos Exp $ */ + +/*- + * Copyright (c) 2002 SHIMIZU Ryo. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <machine/asm.h> + +#define REG_PTR r0 +#define REG_TMP1 r1 + +#ifdef BZERO +# define REG_C r2 +# define REG_DST r4 +# define REG_LEN r5 +#else +# define REG_DST0 r3 +# define REG_DST r4 +# define REG_C r5 +# define REG_LEN r6 +#endif + +#ifdef BZERO +ENTRY(bzero) +#else +ENTRY(memset) + mov REG_DST,REG_DST0 /* for return value */ +#endif + /* small amount to fill ? */ + mov #28,REG_TMP1 + cmp/hs REG_TMP1,REG_LEN /* if (len >= 28) goto large; */ + bt/s large + mov #12,REG_TMP1 /* if (len >= 12) goto small; */ + cmp/hs REG_TMP1,REG_LEN + bt/s small +#ifdef BZERO + mov #0,REG_C +#endif + /* very little fill (0 ~ 11 bytes) */ + tst REG_LEN,REG_LEN + add REG_DST,REG_LEN + bt/s done + add #1,REG_DST + + /* unroll 4 loops */ + cmp/eq REG_DST,REG_LEN +1: mov.b REG_C,@-REG_LEN + bt/s done + cmp/eq REG_DST,REG_LEN + mov.b REG_C,@-REG_LEN + bt/s done + cmp/eq REG_DST,REG_LEN + mov.b REG_C,@-REG_LEN + bt/s done + cmp/eq REG_DST,REG_LEN + mov.b REG_C,@-REG_LEN + bf/s 1b + cmp/eq REG_DST,REG_LEN +done: +#ifdef BZERO + rts + nop +#else + rts + mov REG_DST0,r0 +#endif + + +small: + mov REG_DST,r0 + tst #1,r0 + bt/s small_aligned + mov REG_DST,REG_TMP1 + shll REG_LEN + mova 1f,r0 /* 1f must be 4bytes aligned! */ + add #16,REG_TMP1 /* REG_TMP1 = dst+16; */ + sub REG_LEN,r0 + jmp @r0 + mov REG_C,r0 + + .align 2 + mov.b r0,@(15,REG_TMP1) + mov.b r0,@(14,REG_TMP1) + mov.b r0,@(13,REG_TMP1) + mov.b r0,@(12,REG_TMP1) + mov.b r0,@(11,REG_TMP1) + mov.b r0,@(10,REG_TMP1) + mov.b r0,@(9,REG_TMP1) + mov.b r0,@(8,REG_TMP1) + mov.b r0,@(7,REG_TMP1) + mov.b r0,@(6,REG_TMP1) + mov.b r0,@(5,REG_TMP1) + mov.b r0,@(4,REG_TMP1) + mov.b r0,@(3,REG_TMP1) + mov.b r0,@(2,REG_TMP1) + mov.b r0,@(1,REG_TMP1) + mov.b r0,@REG_TMP1 + mov.b r0,@(15,REG_DST) + mov.b r0,@(14,REG_DST) + mov.b r0,@(13,REG_DST) + mov.b r0,@(12,REG_DST) + mov.b r0,@(11,REG_DST) + mov.b r0,@(10,REG_DST) + mov.b r0,@(9,REG_DST) + mov.b r0,@(8,REG_DST) + mov.b r0,@(7,REG_DST) + mov.b r0,@(6,REG_DST) + mov.b r0,@(5,REG_DST) + mov.b r0,@(4,REG_DST) + mov.b r0,@(3,REG_DST) + mov.b r0,@(2,REG_DST) + mov.b r0,@(1,REG_DST) +#ifdef BZERO + rts +1: mov.b r0,@REG_DST +#else + mov.b r0,@REG_DST +1: rts + mov REG_DST0,r0 +#endif + + +/* 2 bytes aligned small fill */ +small_aligned: +#ifndef BZERO + extu.b REG_C,REG_TMP1 /* REG_C = ??????xx, REG_TMP1 = ????00xx */ + shll8 REG_C /* REG_C = ????xx00, REG_TMP1 = ????00xx */ + or REG_TMP1,REG_C /* REG_C = ????xxxx */ +#endif + + mov REG_LEN,r0 + tst #1,r0 /* len is aligned? */ + bt/s 1f + add #-1,r0 + mov.b REG_C,@(r0,REG_DST) /* fill last a byte */ + mov r0,REG_LEN +1: + + mova 1f,r0 /* 1f must be 4bytes aligned! */ + sub REG_LEN,r0 + jmp @r0 + mov REG_C,r0 + + .align 2 + mov.w r0,@(30,REG_DST) + mov.w r0,@(28,REG_DST) + mov.w r0,@(26,REG_DST) + mov.w r0,@(24,REG_DST) + mov.w r0,@(22,REG_DST) + mov.w r0,@(20,REG_DST) + mov.w r0,@(18,REG_DST) + mov.w r0,@(16,REG_DST) + mov.w r0,@(14,REG_DST) + mov.w r0,@(12,REG_DST) + mov.w r0,@(10,REG_DST) + mov.w r0,@(8,REG_DST) + mov.w r0,@(6,REG_DST) + mov.w r0,@(4,REG_DST) + mov.w r0,@(2,REG_DST) +#ifdef BZERO + rts +1: mov.w r0,@REG_DST +#else + mov.w r0,@REG_DST +1: rts + mov REG_DST0,r0 +#endif + + + + .align 2 +large: +#ifdef BZERO + mov #0,REG_C +#else + extu.b REG_C,REG_TMP1 /* REG_C = ??????xx, REG_TMP1 = ????00xx */ + shll8 REG_C /* REG_C = ????xx00, REG_TMP1 = ????00xx */ + or REG_C,REG_TMP1 /* REG_C = ????xx00, REG_TMP1 = ????xxxx */ + swap.w REG_TMP1,REG_C /* REG_C = xxxx????, REG_TMP1 = ????xxxx */ + xtrct REG_TMP1,REG_C /* REG_C = xxxxxxxx */ +#endif + + mov #3,REG_TMP1 + tst REG_TMP1,REG_DST + mov REG_DST,REG_PTR + bf/s unaligned_dst + add REG_LEN,REG_PTR /* REG_PTR = dst + len; */ + tst REG_TMP1,REG_LEN + bf/s unaligned_len + +aligned: + /* fill 32*n bytes */ + mov #32,REG_TMP1 + cmp/hi REG_LEN,REG_TMP1 + bt 9f + .align 2 +1: sub REG_TMP1,REG_PTR + mov.l REG_C,@REG_PTR + sub REG_TMP1,REG_LEN + mov.l REG_C,@(4,REG_PTR) + cmp/hi REG_LEN,REG_TMP1 + mov.l REG_C,@(8,REG_PTR) + mov.l REG_C,@(12,REG_PTR) + mov.l REG_C,@(16,REG_PTR) + mov.l REG_C,@(20,REG_PTR) + mov.l REG_C,@(24,REG_PTR) + bf/s 1b + mov.l REG_C,@(28,REG_PTR) +9: + + /* fill left 4*n bytes */ + cmp/eq REG_DST,REG_PTR + bt 9f + add #4,REG_DST + cmp/eq REG_DST,REG_PTR +1: mov.l REG_C,@-REG_PTR + bt/s 9f + cmp/eq REG_DST,REG_PTR + mov.l REG_C,@-REG_PTR + bt/s 9f + cmp/eq REG_DST,REG_PTR + mov.l REG_C,@-REG_PTR + bt/s 9f + cmp/eq REG_DST,REG_PTR + mov.l REG_C,@-REG_PTR + bf/s 1b + cmp/eq REG_DST,REG_PTR +9: +#ifdef BZERO + rts + nop +#else + rts + mov REG_DST0,r0 +#endif + + +unaligned_dst: + mov #1,REG_TMP1 + tst REG_TMP1,REG_DST /* if (dst & 1) { */ + add #1,REG_TMP1 + bt/s 2f + tst REG_TMP1,REG_DST + mov.b REG_C,@REG_DST /* *dst++ = c; */ + add #1,REG_DST + tst REG_TMP1,REG_DST +2: /* } */ + /* if (dst & 2) { */ + bt 4f + mov.w REG_C,@REG_DST /* *(u_int16_t*)dst++ = c; */ + add #2,REG_DST +4: /* } */ + + + tst #3,REG_PTR /* if (ptr & 3) { */ + bt/s 4f /* */ +unaligned_len: + tst #1,REG_PTR /* if (ptr & 1) { */ + bt/s 2f + tst #2,REG_PTR + mov.b REG_C,@-REG_PTR /* --ptr = c; */ +2: /* } */ + /* if (ptr & 2) { */ + bt 4f + mov.w REG_C,@-REG_PTR /* *--(u_int16_t*)ptr = c; */ +4: /* } */ + /* } */ + + mov REG_PTR,REG_LEN + bra aligned + sub REG_DST,REG_LEN + diff --git a/libc/arch-sh/bionic/pipe.S b/libc/arch-sh/bionic/pipe.S new file mode 100644 index 0000000..936da2d --- /dev/null +++ b/libc/arch-sh/bionic/pipe.S @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include <sys/linux-syscalls.h> + +.text +.type pipe, @function +.globl pipe +.align 4 + +pipe: + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(0 + 0x10) + + + /* check return value */ + cmp/pz r0 + bt setfds + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + bra end + nop +setfds: + mov.l r0, @r4 + add #4, r4 + mov.l r1, @r4 +end: + rts + nop + + .align 2 +0: .long __NR_pipe +1: .long __set_syscall_errno diff --git a/libc/arch-sh/bionic/setjmp.S b/libc/arch-sh/bionic/setjmp.S new file mode 100644 index 0000000..67f3397 --- /dev/null +++ b/libc/arch-sh/bionic/setjmp.S @@ -0,0 +1,167 @@ +/* $OpenBSD: setjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $ */ +/* $NetBSD: setjmp.S,v 1.10 2006/01/05 19:21:37 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)setjmp.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- setjmp, longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + */ + +ENTRY(setjmp) + PIC_PROLOGUE(.L_got_1) + sts.l pr, @-sp + mov.l r4, @-sp + + mov.l .L_sigprocmask_1, r0 + mov r4, r6 + mov #1, r4 /* how = SIG_BLOCK */ + mov #0, r5 /* new = NULL */ +1: CALL r0 + add #4, r6 /* old = &sigmask */ + + mov.l @sp+, r4 + lds.l @sp+, pr + PIC_EPILOGUE + + /* identical to _setjmp except that the first word is non-zero */ +#if defined(__SH4__) && !defined(__SH4_NOFPU__) + add #(_JBLEN * 4), r4 + sts fpscr, r1 + xor r0, r0 + mov.l r1, @-r4 + lds r0, fpscr + sts.l fpul, @-r4 + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 + frchg + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 + lds r1, fpscr +#else + add #((_JBLEN - 10) * 4), r4 +#endif + sts.l mach, @-r4 + sts.l macl, @-r4 + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + sts.l pr, @-r4 + add #-4, r4 /* skip signal mask */ + mov #1, r0 + mov.l r0, @-r4 /* has signal mask */ + rts + xor r0, r0 + + .align 2 +.L_got_1: PIC_GOT_DATUM +.L_sigprocmask_1: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(setjmp) + +ENTRY(longjmp) + /* we won't return here, so we don't need to save pr and r12 */ + PIC_PROLOGUE_NOSAVE(.L_got_2) + mov.l r5, @-sp + mov.l r4, @-sp + + mov.l .L_sigprocmask_2, r0 + mov r4, r5 + mov #3, r4 /* how = SIG_SETMASK */ + add #4, r5 /* new = &sigmask */ +1: CALL r0 + mov #0, r6 /* old = NULL */ + + mov.l @sp+, r4 + mov.l @sp+, r5 + + /* identical to _longjmp */ + add #8, r4 + lds.l @r4+, pr + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + lds.l @r4+, macl + lds.l @r4+, mach +#if defined(__SH4__) && !defined(__SH4_NOFPU__) + xor r0, r0 + lds r0, fpscr + frchg + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 + frchg + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 + lds.l @r4+, fpul + lds.l @r4+, fpscr +#endif + + mov r5, r0 + tst r0, r0 /* make sure return value is non-zero */ + bf .L0 + add #1, r0 +.L0: + rts + nop + + .align 2 +.L_got_2: PIC_GOT_DATUM +.L_sigprocmask_2: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(longjmp) diff --git a/libc/arch-sh/bionic/sigsetjmp.S b/libc/arch-sh/bionic/sigsetjmp.S new file mode 100644 index 0000000..f88913a --- /dev/null +++ b/libc/arch-sh/bionic/sigsetjmp.S @@ -0,0 +1,166 @@ +/* $OpenBSD: sigsetjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $ */ +/* $NetBSD: sigsetjmp.S,v 1.9 2006/01/05 19:21:37 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)setjmp.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> +#include <machine/setjmp.h> + +ENTRY(sigsetjmp) + tst r5, r5 /* if (savemask == 0) */ + bt 2f + + /* identical to setjmp */ + PIC_PROLOGUE(.L_got_1) + sts.l pr, @-sp + mov.l r4, @-sp + mov.l r5, @-sp + + mov.l .L_sigprocmask_1, r0 + mov r4, r6 + mov #1, r4 /* how = SIG_BLOCK */ + mov #0, r5 /* new = NULL */ +1: CALL r0 + add #4, r6 /* old = &sigmask */ + + mov.l @sp+, r5 + mov.l @sp+, r4 + lds.l @sp+, pr + PIC_EPILOGUE + +2: /* identical to _setjmp except that first word is in r5 */ +#if defined(__SH4__) && !defined(__SH4_NOFPU__) + add #(_JBLEN * 4), r4 + sts fpscr, r1 + xor r0, r0 + mov.l r1, @-r4 + lds r0, fpscr + sts.l fpul, @-r4 + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 + frchg + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 + lds r1, fpscr +#else + add #((_JBLEN - 10) * 4), r4 +#endif + sts.l mach, @-r4 + sts.l macl, @-r4 + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + sts.l pr, @-r4 + add #-4, r4 /* skip signal mask */ + mov.l r5, @-r4 /* has signal mask? */ + rts + xor r0, r0 + + .align 2 +.L_got_1: PIC_GOT_DATUM +.L_sigprocmask_1: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(sigsetjmp) + +ENTRY(siglongjmp) + mov.l @r4+, r0 + tst r0, r0 + bt 2f /* if no mask */ + + /* identical to longjmp */ + /* we won't return here, so we don't need to save pr and r12 */ + PIC_PROLOGUE_NOSAVE(.L_got_2) + mov.l r5, @-sp + mov.l r4, @-sp + + mov.l .L_sigprocmask_2, r0 + mov r4, r5 /* new = &sigmask */ + mov #3, r4 /* how = SIG_SETMASK */ +1: CALL r0 + mov #0, r6 /* old = NULL */ + + mov.l @sp+, r4 + mov.l @sp+, r5 + +2: /* identical to _longjmp */ + add #4, r4 + lds.l @r4+, pr + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + lds.l @r4+, macl + lds.l @r4+, mach +#if defined(__SH4__) && !defined(__SH4_NOFPU__) + xor r0, r0 + lds r0, fpscr + frchg + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 + frchg + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 + lds.l @r4+, fpul + lds.l @r4+, fpscr +#endif + + mov r5, r0 + tst r0, r0 /* make sure return value is non-zero */ + bf .L0 + add #1, r0 +.L0: + rts + nop + + .align 2 +.L_got_2: PIC_GOT_DATUM +.L_sigprocmask_2: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(siglongjmp) diff --git a/libc/arch-sh/bionic/syscall.S b/libc/arch-sh/bionic/syscall.S new file mode 100644 index 0000000..7e9f307 --- /dev/null +++ b/libc/arch-sh/bionic/syscall.S @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include <sys/linux-syscalls.h> + +.text +.type syscall, @function +.globl syscall +.align 4 + +/* + * Current implementation assumes that the all syscall + * has maximum 7 arguments. + */ +syscall: + /* get args */ + mov r4, r3 /* system call number */ + mov r5, r4 + mov r6, r5 + mov r7, r6 + mov.l @r15, r7 + mov.l @(4, r15), r0 + mov.l @(8, r15), r1 + mov.l @(12, r15), r2 + + /* invoke trap */ + trapa #(7 + 0x10) /* assuming 7 arguments */ + + /* check return value */ + cmp/pz r0 + bt end + + /* keep error number */ + mov.l r0, @-r15 + mov.l 0f, r1 + jsr @r1 + mov r0, r4 + mov.l @r15+, r0 + +end: + rts + nop + + .align 2 +0: .long __set_errno diff --git a/libc/arch-sh/bionic/unwind.c b/libc/arch-sh/bionic/unwind.c new file mode 100644 index 0000000..33ec58c --- /dev/null +++ b/libc/arch-sh/bionic/unwind.c @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +typedef long unsigned int *_Unwind_Ptr; + |