Commit Diff


commit - c934984537a7673f980d731e10baec18d0c97c05
commit + 20f5692b7fe1190e6c518ed82764ded41dd92986
blob - 7ed634e7a9d4b5a20fd1c4551f0ae1601c00e781
blob + 69d14e3d06f2095f05b8c5acf96c76ddfb16547e
--- include/u.h
+++ include/u.h
@@ -116,6 +116,8 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)
 #	undef _NEEDULONG
 #elif defined(__OpenBSD__)
 #	include <sys/types.h>
+#	include <pthread.h>
+#	define PLAN9PORT_USING_PTHREADS 1
 #	undef _NEEDUSHORT
 #	undef _NEEDUINT
 #	undef _NEEDULONG
blob - 1a59436fa45e281f029c9ebd49b2c0cbec2acaff
blob + dad1b5368419b4001ff1594e72fa4ebc8849a0ed
--- src/libthread/OpenBSD-386-asm.s
+++ 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))
-
blob - 25ceb45c1054deaa4322e35a662213e748d0100d
blob + 03b46e7beb9cb2154d93f34c39855e13569676be
--- src/libthread/OpenBSD-power-asm.S
+++ 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))
-
blob - /dev/null
blob + e982cdef87d47e930ba560b48bbce22d59fc94d2 (mode 644)
--- /dev/null
+++ 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
blob - /dev/null
blob + 0593e481dd6399d10b6a8e11df4d17bcc2295b94 (mode 644)
--- /dev/null
+++ 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;
+}
+
+
blob - 9c06f331255a80a702d5f8b95baec5178d2066a9
blob + f621ac6074e0608a825ee2fc71fc4c2d36efc0fa
--- src/libthread/mkfile
+++ 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
blob - d4f852a4cf7756dd8063e7e8d6109d8ab143968c
blob + 9eeea606bb53c1ddae3cef5c1ecf7ba0059c7c16
--- src/libthread/sysofiles.sh
+++ 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
blob - 4397bac72762ca71c996334b739e50023e10b732
blob + 9518f785e5abb9b8c09e6b50c1d1ae4f9a0d5b38
--- src/libthread/threadimpl.h
+++ 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