aboutsummaryrefslogtreecommitdiff
path: root/src/libthread
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2012-07-14 10:16:54 -0400
committerRuss Cox <rsc@swtch.com>2012-07-14 10:16:54 -0400
commit20f5692b7fe1190e6c518ed82764ded41dd92986 (patch)
treeab8d3b81a01e087180489b6c8627911440786976 /src/libthread
parentc934984537a7673f980d731e10baec18d0c97c05 (diff)
downloadplan9port-20f5692b7fe1190e6c518ed82764ded41dd92986.tar.gz
plan9port-20f5692b7fe1190e6c518ed82764ded41dd92986.tar.bz2
plan9port-20f5692b7fe1190e6c518ed82764ded41dd92986.zip
openbsd updates (thanks Pascal Stumpf)
R=rsc http://codereview.appspot.com/6401049
Diffstat (limited to 'src/libthread')
-rw-r--r--src/libthread/OpenBSD-386-asm.s99
-rw-r--r--src/libthread/OpenBSD-power-asm.S37
-rw-r--r--src/libthread/OpenBSD-x86_64-asm.S44
-rw-r--r--src/libthread/OpenBSD-x86_64.c32
-rw-r--r--src/libthread/mkfile2
-rw-r--r--src/libthread/sysofiles.sh2
-rw-r--r--src/libthread/threadimpl.h2
7 files changed, 80 insertions, 138 deletions
diff --git a/src/libthread/OpenBSD-386-asm.s b/src/libthread/OpenBSD-386-asm.s
index 1a59436f..dad1b536 100644
--- a/src/libthread/OpenBSD-386-asm.s
+++ b/src/libthread/OpenBSD-386-asm.s
@@ -1,100 +1 @@
#include "FreeBSD-386-asm.s"
-
-/*
- * 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
-
- 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))
-
diff --git a/src/libthread/OpenBSD-power-asm.S b/src/libthread/OpenBSD-power-asm.S
index 25ceb45c..03b46e7b 100644
--- a/src/libthread/OpenBSD-power-asm.S
+++ b/src/libthread/OpenBSD-power-asm.S
@@ -1,6 +1,3 @@
-#include <sys/syscall.h>
-#include <machine/asm.h>
-
ENTRY(_tas)
li %r0, 0
mr %r4, %r3
@@ -89,37 +86,3 @@ ENTRY(_setmcontext)
lwz %r3, 6*4(%r3)
blr
-
-ENTRY(rfork_thread)
- /* sanity check */
- cmpwi %r4, 0
- beq 1f
- cmpwi %r5, 0
- beq 1f
-
- mr %r7,%r4
-
- /* call rfork */
- li %r0, SYS_rfork
- sc
- cmpwi %r0, 0
- bne 2f
-
- /* check if we are parent or child */
- cmpwi %r3, 0
- bnelr
-
- /* child */
- mtlr %r5 /* fp */
- mr %r3, %r6 /* arg */
- mr %r1, %r7 /* new sp */
- blrl
-
- /* child returned, call _exit */
- li %r0, SYS_exit
- sc
-1:
- li %r3, -1
-2:
- b PIC_PLT(_C_LABEL(__cerror))
-
diff --git a/src/libthread/OpenBSD-x86_64-asm.S b/src/libthread/OpenBSD-x86_64-asm.S
new file mode 100644
index 00000000..e982cdef
--- /dev/null
+++ b/src/libthread/OpenBSD-x86_64-asm.S
@@ -0,0 +1,44 @@
+.text
+.align 8
+
+.globl libthread_getmcontext
+libthread_getmcontext:
+ movq $1, 0*8(%rdi) // rax
+ movq %rbx, 1*8(%rdi)
+ movq %rcx, 2*8(%rdi)
+ movq %rdx, 3*8(%rdi)
+ movq %rsi, 4*8(%rdi)
+ movq %rdi, 5*8(%rdi)
+ movq %rbp, 6*8(%rdi)
+ movq %rsp, 7*8(%rdi)
+ movq %r8, 8*8(%rdi)
+ movq %r9, 9*8(%rdi)
+ movq %r10, 10*8(%rdi)
+ movq %r11, 11*8(%rdi)
+ movq %r12, 12*8(%rdi)
+ movq %r13, 13*8(%rdi)
+ movq %r14, 14*8(%rdi)
+ movq %r15, 15*8(%rdi)
+ movq $0, %rax
+ ret
+
+.globl libthread_setmcontext
+libthread_setmcontext:
+ movq 0*8(%rdi), %rax
+ movq 1*8(%rdi), %rbx
+ movq 2*8(%rdi), %rcx
+ movq 3*8(%rdi), %rdx
+ movq 4*8(%rdi), %rsi
+ // %rdi later
+ movq 6*8(%rdi), %rbp
+ movq 7*8(%rdi), %rsp
+ movq 8*8(%rdi), %r8
+ movq 9*8(%rdi), %r9
+ movq 10*8(%rdi), %r10
+ movq 11*8(%rdi), %r11
+ movq 12*8(%rdi), %r12
+ movq 13*8(%rdi), %r13
+ movq 14*8(%rdi), %r14
+ movq 15*8(%rdi), %r15
+ movq 5*8(%rdi), %rdi
+ ret
diff --git a/src/libthread/OpenBSD-x86_64.c b/src/libthread/OpenBSD-x86_64.c
new file mode 100644
index 00000000..0593e481
--- /dev/null
+++ b/src/libthread/OpenBSD-x86_64.c
@@ -0,0 +1,32 @@
+#include "threadimpl.h"
+
+void
+makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
+{
+ uintptr *sp;
+ va_list arg;
+
+//fprint(2, "makecontext %d\n", argc);
+ if(argc != 2)
+ sysfatal("libthread: makecontext misused");
+ va_start(arg, argc);
+ uc->mc.di = va_arg(arg, uint);
+ uc->mc.si = va_arg(arg, uint);
+//fprint(2, "%ux %ux\n", uc->mc.di, uc->mc.si);
+ va_end(arg);
+
+ sp = (uintptr*)((char*)uc->uc_stack.ss_sp+uc->uc_stack.ss_size);
+ *--sp = 0; // fn's return address
+ *--sp = (uintptr)fn; // return address of setcontext
+ uc->mc.sp = (uintptr)sp;
+}
+
+int
+swapcontext(ucontext_t *oucp, ucontext_t *ucp)
+{
+ if(getcontext(oucp) == 0)
+ setcontext(ucp);
+ return 0;
+}
+
+
diff --git a/src/libthread/mkfile b/src/libthread/mkfile
index 9c06f331..f621ac60 100644
--- a/src/libthread/mkfile
+++ b/src/libthread/mkfile
@@ -16,7 +16,7 @@ OFILES=\
<$PLAN9/src/mksyslib
HFILES=thread.h threadimpl.h
-OpenBSD.$O FreeBSD.$O: BSD.c
+FreeBSD.$O: BSD.c
NetBSD.$O: Linux.c
tprimes: test/tprimes.$O
diff --git a/src/libthread/sysofiles.sh b/src/libthread/sysofiles.sh
index d4f852a4..9eeea606 100644
--- a/src/libthread/sysofiles.sh
+++ b/src/libthread/sysofiles.sh
@@ -18,7 +18,7 @@ case "$tag" in
echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME-${OBJTYPE}.o pthread.o
;;
*-OpenBSD-*)
- echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o $SYSNAME.o
+ echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o pthread.o
;;
*)
echo pthread.o
diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h
index 4397bac7..9518f785 100644
--- a/src/libthread/threadimpl.h
+++ b/src/libthread/threadimpl.h
@@ -56,6 +56,8 @@ extern void makecontext(ucontext_t*, void(*)(), int, ...);
# define ucontext_t libthread_ucontext_t
# if defined __i386__
# include "386-ucontext.h"
+# elif defined __amd64__
+# include "x86_64-ucontext.h"
# else
# include "power-ucontext.h"
# endif