summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/arch
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2007-02-19 21:03:50 +0000
committermiod <miod@openbsd.org>2007-02-19 21:03:50 +0000
commitc0edb5b21589021bc3f272addcabe2e2641c3dbe (patch)
tree57538981903e0c00c4347b0ad920b3c5087d556e /lib/libpthread/arch
parentPut warning about shared IPL interrupts under MPVERBOSE and don't talk about (diff)
downloadwireguard-openbsd-c0edb5b21589021bc3f272addcabe2e2641c3dbe.tar.xz
wireguard-openbsd-c0edb5b21589021bc3f272addcabe2e2641c3dbe.zip
pthread bits for sh; help deraadt@, ok kettenis@
Diffstat (limited to 'lib/libpthread/arch')
-rw-r--r--lib/libpthread/arch/sh/_atomic_lock.c4
-rw-r--r--lib/libpthread/arch/sh/uthread_machdep.c57
-rw-r--r--lib/libpthread/arch/sh/uthread_machdep.h3
-rw-r--r--lib/libpthread/arch/sh/uthread_machdep_asm.S55
4 files changed, 116 insertions, 3 deletions
diff --git a/lib/libpthread/arch/sh/_atomic_lock.c b/lib/libpthread/arch/sh/_atomic_lock.c
index 63391067c94..96d46475bca 100644
--- a/lib/libpthread/arch/sh/_atomic_lock.c
+++ b/lib/libpthread/arch/sh/_atomic_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: _atomic_lock.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */
+/* $OpenBSD: _atomic_lock.c,v 1.2 2007/02/19 21:03:50 miod Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@ _atomic_lock(volatile _spinlock_lock_t *lock)
" rotcl %1 \n"
: "=m" (*lock), "=r" (old));
- return (old != _SPINLOCK_UNLOCKED);
+ return (old == 0);
}
int
diff --git a/lib/libpthread/arch/sh/uthread_machdep.c b/lib/libpthread/arch/sh/uthread_machdep.c
new file mode 100644
index 00000000000..675b4ce89c4
--- /dev/null
+++ b/lib/libpthread/arch/sh/uthread_machdep.c
@@ -0,0 +1,57 @@
+/* $OpenBSD: uthread_machdep.c,v 1.1 2007/02/19 21:03:50 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 <pthread.h>
+#include "pthread_private.h"
+
+#define STACK_ALIGNMENT 8
+
+struct regframe {
+ register_t pr;
+ register_t r14;
+ register_t r13;
+ register_t r12;
+ register_t r11;
+ register_t r10;
+ register_t r9;
+ register_t r8;
+};
+
+void
+_thread_machdep_init(struct _machdep_state* statep, void *base, int len,
+ void (*entry)(void))
+{
+ struct regframe *regs;
+
+ regs = (struct regframe *)
+ (((u_int32_t)base + len - sizeof *regs) & ~(STACK_ALIGNMENT - 1));
+ regs->pr = (register_t)entry;
+
+ statep->sp = (u_int)regs;
+}
+
+void
+_thread_machdep_save_float_state(struct _machdep_state* statep)
+{
+}
+
+void
+_thread_machdep_restore_float_state(struct _machdep_state* statep)
+{
+}
diff --git a/lib/libpthread/arch/sh/uthread_machdep.h b/lib/libpthread/arch/sh/uthread_machdep.h
index 6a534cc173c..3277ec156c1 100644
--- a/lib/libpthread/arch/sh/uthread_machdep.h
+++ b/lib/libpthread/arch/sh/uthread_machdep.h
@@ -1,4 +1,5 @@
-/* $OpenBSD: uthread_machdep.h,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */
+/* $OpenBSD: uthread_machdep.h,v 1.2 2007/02/19 21:03:50 miod Exp $ */
struct _machdep_state {
+ u_int sp;
};
diff --git a/lib/libpthread/arch/sh/uthread_machdep_asm.S b/lib/libpthread/arch/sh/uthread_machdep_asm.S
new file mode 100644
index 00000000000..702d5c04434
--- /dev/null
+++ b/lib/libpthread/arch/sh/uthread_machdep_asm.S
@@ -0,0 +1,55 @@
+/* $OpenBSD: uthread_machdep_asm.S,v 1.1 2007/02/19 21:03:50 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 <machine/asm.h>
+
+/*
+ * void _thread_machdep_switch(new, oldsave);
+ */
+ENTRY(_thread_machdep_switch)
+ /*
+ * On entry: r4 = new, r5 = oldsave
+ */
+
+ /* save caller-saved context on stack */
+ mov.l r8, @-r15
+ mov.l r9, @-r15
+ mov.l r10, @-r15
+ mov.l r11, @-r15
+ mov.l r12, @-r15
+ mov.l r13, @-r15
+ mov.l r14, @-r15
+ sts.l pr, @-r15
+
+ /* save old stack */
+ mov.l r15, @r5
+
+ /* switch stacks */
+ mov.l @r4, r15
+
+ /* restore new context */
+ lds.l @r15+, pr
+ mov.l @r15+, r14
+ mov.l @r15+, r13
+ mov.l @r15+, r12
+ mov.l @r15+, r11
+ mov.l @r15+, r10
+ mov.l @r15+, r9
+ rts
+ mov.l @r15+, r8