diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2007-03-24 18:21:35 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2007-03-24 18:21:35 +0000 |
commit | d615ac397c48549fba1f9f82937c266784fd4d1b (patch) | |
tree | 6a60aa3f53626b4c211e2f822046e3f608c0ecf5 /lib/librthread | |
parent | b85e9ba20c14a428d67fc578018fd8a539c89f7b (diff) |
rfork sh bits.
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/arch/sh/_atomic_lock.c | 60 | ||||
-rw-r--r-- | lib/librthread/arch/sh/rfork_thread.S | 61 |
2 files changed, 121 insertions, 0 deletions
diff --git a/lib/librthread/arch/sh/_atomic_lock.c b/lib/librthread/arch/sh/_atomic_lock.c new file mode 100644 index 00000000000..ae589c1fcf3 --- /dev/null +++ b/lib/librthread/arch/sh/_atomic_lock.c @@ -0,0 +1,60 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 2007/03/24 18:21:34 miod Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Gregory McGarry. + * + * 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 "spinlock.h" + +int +_atomic_lock(volatile _spinlock_lock_t *lock) +{ + _spinlock_lock_t old; + + __asm volatile( + " tas.b %0 \n" + " mov #0, %1 \n" + " rotcl %1 \n" + : "=m" (*lock), "=r" (old)); + + return (old == 0); +} + +int +_atomic_is_locked(volatile _spinlock_lock_t *lock) +{ + + return (*lock != _SPINLOCK_UNLOCKED); +} diff --git a/lib/librthread/arch/sh/rfork_thread.S b/lib/librthread/arch/sh/rfork_thread.S new file mode 100644 index 00000000000..80fdf2c3cad --- /dev/null +++ b/lib/librthread/arch/sh/rfork_thread.S @@ -0,0 +1,61 @@ +/* $OpenBSD: rfork_thread.S,v 1.1 2007/03/24 18:21:34 miod Exp $ */ + +/* + * Copyright (c) 2007 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "../../../libc/arch/sh/SYS.h" + +/* + * int rfork_thread(int flags, void *stack, void (*func)(void *), void *arg); + * r4 r5 r6 r7 + */ +ENTRY(rfork_thread) + mov.l .LSYS_rfork, r0 + .word 0xc380 /* trapa #0x80 */ + bf 9f + + tst r0, r0 + bt 1f + + /* + * In parent process: just return. + */ + rts + nop + +1: + /* + * In child process: switch stack, invoke function, then exit. + */ + mov r5, sp + jsr @r6 + mov r7, r4 + + mov.l .LSYS_threxit, r0 + .word 0xc380 /* trapa #0x80 */ + +9: + /* + * System call failure. + */ + JUMP_CERROR + + .align 2 +.LSYS_rfork: .long SYS_rfork +.LSYS_threxit: .long SYS_threxit + + SET_ENTRY_SIZE(rfork_thread) |