diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2005-12-23 19:52:05 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2005-12-23 19:52:05 +0000 |
commit | 2b17641b5733b57e596e0e098eba33b18c7762e4 (patch) | |
tree | 75f718232d58079a16d5c8c82c4f04f4981892b0 /lib/librthread/arch | |
parent | 6fa0cfa9a3789672215e42898c9fa4a19f2f2f20 (diff) |
vax support bits for librthread (need the child_return() fix just commited).
Diffstat (limited to 'lib/librthread/arch')
-rw-r--r-- | lib/librthread/arch/vax/_atomic_lock.c | 42 | ||||
-rw-r--r-- | lib/librthread/arch/vax/rfork_thread.S | 69 |
2 files changed, 111 insertions, 0 deletions
diff --git a/lib/librthread/arch/vax/_atomic_lock.c b/lib/librthread/arch/vax/_atomic_lock.c new file mode 100644 index 00000000000..8f0a0fd510b --- /dev/null +++ b/lib/librthread/arch/vax/_atomic_lock.c @@ -0,0 +1,42 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 2005/12/23 19:52:04 miod Exp $ */ + +/* + * Atomic lock for vax + * Written by Miodrag Vallat <miod@openbsd.org> - placed in the public domain. + */ + +#include "spinlock.h" + +int +_atomic_lock(volatile _spinlock_lock_t *lock) +{ + _spinlock_lock_t old; + + /* + * The Branch on Bit Set and Set Interlocked instruction + * sets a given bit in a register or a memory location, as an + * atomic, interlocked operation. + * If the bit was set, execution continues at the branch + * location. + * + * For more details, please refer to the Vax Architecture + * Reference Manual, chapter 3 (Instructions), section + * ``Control instructions''. + */ + __asm__ ( + "movl $1, %1\n" /* _SPINLOCK_LOCKED */ + "bbssi $0, %0, 1f\n" + "movl $0, %1\n" /* _SPINLOCK_UNLOCKED */ + "1: \n" + : "=m" (*lock), "=r" (old) : "0" (*lock) + ); + + return (old != _SPINLOCK_UNLOCKED); +} + +int +_atomic_is_locked(volatile _spinlock_lock_t *lock) +{ + + return (*lock != _SPINLOCK_UNLOCKED); +} diff --git a/lib/librthread/arch/vax/rfork_thread.S b/lib/librthread/arch/vax/rfork_thread.S new file mode 100644 index 00000000000..c6fdc602079 --- /dev/null +++ b/lib/librthread/arch/vax/rfork_thread.S @@ -0,0 +1,69 @@ +/* $OpenBSD: rfork_thread.S,v 1.1 2005/12/23 19:52:04 miod Exp $ */ + +/* + * Copyright (c) 2005, Miodrag Vallat + * + * 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. + * + * 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 "../../../libc/arch/vax/SYS.h" + +/* + * int rfork_thread(int flags, void *stack, void (*func)(void *), void *arg); + */ +ENTRY(rfork_thread, R2|R3|R4) + /* + * Save thread creation arguments into registers. + */ + movl 8(ap), r2 /* stack */ + movl 12(ap), r3 /* func */ + movl 16(ap), r4 /* arg */ + + __DO_SYSCALL(rfork) + jcs 9f + + cmpl r0, $0 + beql 1f + + /* + * In parent process: just return. + */ + ret + +1: + /* + * In child process: switch stack, invoke function, then exit. + * Note that since we can not pass a register to calls, we need + * to waste 4 bytes of stack in every thread. + */ + movl r2, sp /* stack */ + pushl r3 /* func */ + pushl r4 /* arg */ + calls $1, *4(sp) /* func */ + + __DO_SYSCALL(threxit) + +9: + /* + * system call failed. + */ + jmp __cerror |