diff options
author | rsc <devnull@localhost> | 2005-07-21 18:29:04 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-07-21 18:29:04 +0000 |
commit | fe8c925e8ad3fe1fb95b89d26dcb828c6b31f548 (patch) | |
tree | 02a152fbf48aa957f3bfb69148a90e7811320afa /src/libthread | |
parent | 6a73f8b6c12c1618fdf02c70236155b68086f8b2 (diff) | |
download | plan9port-fe8c925e8ad3fe1fb95b89d26dcb828c6b31f548.tar.gz plan9port-fe8c925e8ad3fe1fb95b89d26dcb828c6b31f548.tar.bz2 plan9port-fe8c925e8ad3fe1fb95b89d26dcb828c6b31f548.zip |
OpenBSD, thanks to Tim Wiess
Diffstat (limited to 'src/libthread')
-rw-r--r-- | src/libthread/BSD.c | 8 | ||||
-rw-r--r-- | src/libthread/OpenBSD-386-asm.s | 145 | ||||
-rw-r--r-- | src/libthread/OpenBSD.c | 18 | ||||
-rw-r--r-- | src/libthread/mkfile | 5 |
4 files changed, 123 insertions, 53 deletions
diff --git a/src/libthread/BSD.c b/src/libthread/BSD.c index 2679cd21..0bc19057 100644 --- a/src/libthread/BSD.c +++ b/src/libthread/BSD.c @@ -90,6 +90,14 @@ _spinlock(spinlock_t *lk) lock((Lock*)&lk->access_lock); } +void +_spinunlock(spinlock_t *lk) +{ + unlock((Lock*)&lk->access_lock); +} + + + /* * sleep and wakeup */ diff --git a/src/libthread/OpenBSD-386-asm.s b/src/libthread/OpenBSD-386-asm.s index f9a80255..7ffb413c 100644 --- a/src/libthread/OpenBSD-386-asm.s +++ b/src/libthread/OpenBSD-386-asm.s @@ -1,54 +1,99 @@ -.globl _tas -_tas: - movl $0xCAFEBABE, %eax - movl 4(%esp), %ecx - xchgl %eax, 0(%ecx) - ret +#include "FreeBSD-386-asm.s" -.globl setmcontext -setmcontext: - movl 4(%esp), %edx - movl 8(%edx), %fs - movl 12(%edx), %es - movl 16(%edx), %ds - movl 76(%edx), %ss - movl 20(%edx), %edi - movl 24(%edx), %esi - movl 28(%edx), %ebp - movl %esp, %ecx - movl 72(%edx), %esp - pushl 60(%edx) /* eip */ - pushl 44(%edx) /* ecx */ - pushl 48(%edx) /* eax */ - movl 36(%edx), %ebx - movl 40(%edx), %edx - movl 12(%ecx), %eax - popl %eax - popl %ecx - ret +/* + * Copyright (c) 2000 Peter Wemm <peter@FreeBSD.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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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/syscall.h> +#include <machine/asm.h> + +ENTRY(rfork_thread) + pushl %ebp + movl %esp, %ebp + pushl %esi + + /* + * Push thread info onto the new thread's stack + */ + movl 12(%ebp), %esi # get stack addr -.globl getmcontext -getmcontext: - pushl %edx - movl 8(%esp), %edx - movl %fs, 8(%edx) - movl %es, 12(%edx) - movl %ds, 16(%edx) - movl %ss, 76(%edx) - movl %edi, 20(%edx) - movl %esi, 24(%edx) - movl %ebp, 28(%edx) - movl %ebx, 36(%edx) - movl $1, 48(%edx) - popl %eax - movl %eax, 40(%edx) - movl %ecx, 44(%edx) - movl (%esp), %eax /* eip */ - movl %eax, 60(%edx) - movl %esp, %eax - addl $4, %eax /* setmcontext will re-push the eip */ - movl %eax, 72(%edx) - movl 40(%edx), %edx - xorl %eax, %eax + subl $4, %esi + movl 20(%ebp), %eax # get start argument + movl %eax, (%esi) + + subl $4, %esi + movl 16(%ebp), %eax # get start thread address + movl %eax, (%esi) + + /* + * Prepare and execute the thread creation syscall + */ + pushl 8(%ebp) + pushl $0 + movl $SYS_rfork, %eax + int $0x80 + jb 2f + + /* + * Check to see if we are in the parent or child + */ + cmpl $0, %edx + jnz 1f + addl $8, %esp + popl %esi + movl %ebp, %esp + popl %ebp ret + .p2align 2 + + /* + * If we are in the child (new thread), then + * set-up the call to the internal subroutine. If it + * returns, then call __exit. + */ +1: + movl %esi,%esp + popl %eax + call *%eax + addl $4, %esp + + /* + * Exit system call + */ + pushl %eax + pushl $0 + movl $SYS_exit, %eax + int $0x80 + /* + * Branch here if the thread creation fails: + */ +2: + addl $8, %esp + popl %esi + movl %ebp, %esp + popl %ebp + PIC_PROLOGUE + jmp PIC_PLT(_C_LABEL(__cerror))
\ No newline at end of file diff --git a/src/libthread/OpenBSD.c b/src/libthread/OpenBSD.c index 9aaa28cb..0cfa0d39 100644 --- a/src/libthread/OpenBSD.c +++ b/src/libthread/OpenBSD.c @@ -2,3 +2,21 @@ #include "BSD.c" +static spinlock_t mlock = { 0, 0, NULL, 0 }; + +void +_thread_malloc_lock(void) +{ + _spinlock(&mlock); +} + +void +_thread_malloc_unlock(void) +{ + _spinunlock(&mlock); +} + +void +_thread_malloc_init(void) +{ +} diff --git a/src/libthread/mkfile b/src/libthread/mkfile index 5a6913ea..0b620565 100644 --- a/src/libthread/mkfile +++ b/src/libthread/mkfile @@ -32,9 +32,8 @@ tspawnloop: tspawnloop.$O # with generic .s rule in mkcommon on case-insensitive # systems like Mac OS X. -OpenBSD-power-asm.$O: OpenBSD-power-asm.S - $CC $CFLAGS $stem.S - +OpenBSD-%-asm.$O: OpenBSD-%-asm.S + $CC $CFLAGS OpenBSD-$stem-asm.S test:V: tprimes tspawn primes 1 10007 >p1.txt |