diff options
Diffstat (limited to 'lib/libpthread/arch')
-rw-r--r-- | lib/libpthread/arch/arm/_atomic_lock.c | 18 | ||||
-rw-r--r-- | lib/libpthread/arch/arm/uthread_machdep.c | 88 | ||||
-rw-r--r-- | lib/libpthread/arch/arm/uthread_machdep.h | 7 | ||||
-rw-r--r-- | lib/libpthread/arch/arm/uthread_machdep_asm.S | 137 |
4 files changed, 250 insertions, 0 deletions
diff --git a/lib/libpthread/arch/arm/_atomic_lock.c b/lib/libpthread/arch/arm/_atomic_lock.c new file mode 100644 index 00000000000..81797dcaa7f --- /dev/null +++ b/lib/libpthread/arch/arm/_atomic_lock.c @@ -0,0 +1,18 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 2004/02/09 13:14:34 drahn Exp $ */ +/* + * Atomic lock for powerpc + */ + +#include "spinlock.h" + +int +_atomic_lock(volatile _spinlock_lock_t *lock) +{ + _spinlock_lock_t old; + + __asm__("swp %0, %2, [%1]" + : "=r" (old), "=r" (lock) + : "r" (_SPINLOCK_LOCKED), "1" (lock) ); + + return (old != _SPINLOCK_UNLOCKED); +} diff --git a/lib/libpthread/arch/arm/uthread_machdep.c b/lib/libpthread/arch/arm/uthread_machdep.c new file mode 100644 index 00000000000..12996411b75 --- /dev/null +++ b/lib/libpthread/arch/arm/uthread_machdep.c @@ -0,0 +1,88 @@ +/* $OpenBSD: uthread_machdep.c,v 1.1 2004/02/09 13:14:34 drahn Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain */ + +#include <pthread.h> +#include "pthread_private.h" + +#if 0 +#define ALIGNBYTES 0xf + +/* Register save frame as it appears on the stack */ +struct frame { + int r1; + int reserved; + int gp[32-14]; + int lr, cr, ctr, xer; + double fp[32]; + double fs; + /* The rest are only valid in the initial frame */ + int next_r1; + int next_lr; +}; + +/* + * Given a stack and an entry function, initialise a state + * structure that can be later switched to. + */ +void +_thread_machdep_init(statep, base, len, entry) + struct _machdep_state* statep; + void *base; + int len; + void (*entry)(void); +{ + struct frame *f; + + /* Locate the initial frame, aligned at the top of the stack */ + f = (struct frame *)(((int)base + len - sizeof *f) & ~ALIGNBYTES); + + f->r1 = (int)&f->next_r1; + f->reserved = 0; + f->lr = (int)entry; + f->next_r1 = 0; /* for gdb */ + f->next_lr = 0; /* for gdb */ + + /* Initialise the new thread with all the state from this thread. */ + +#define copyreg(x) __asm__ volatile ("stw " #x ", %0" : "=m"(f->gp[x-14])) + copyreg(14); copyreg(15); copyreg(16); copyreg(17); copyreg(18); + copyreg(19); copyreg(20); copyreg(21); copyreg(22); copyreg(23); + copyreg(24); copyreg(25); copyreg(26); copyreg(27); copyreg(28); + copyreg(29); copyreg(30); copyreg(31); + +#define copysreg(nm) __asm__ volatile ("mf" #nm " %0" : "=r"(f->nm)) + copysreg(cr); copysreg(ctr); copysreg(xer); + +#define copyfreg(x) __asm__ volatile ("stfd " #x ", %0" : "=m"(f->fp[x])) + copyfreg(0); copyfreg(1); copyfreg(2); copyfreg(3); + copyfreg(4); copyfreg(5); copyfreg(6); copyfreg(7); + copyfreg(8); copyfreg(9); copyfreg(10); copyfreg(11); + copyfreg(12); copyfreg(13); copyfreg(14); copyfreg(15); + copyfreg(16); copyfreg(17); copyfreg(18); copyfreg(19); + copyfreg(20); copyfreg(21); copyfreg(22); copyfreg(23); + copyfreg(24); copyfreg(25); copyfreg(26); copyfreg(27); + copyfreg(28); copyfreg(29); copyfreg(30); copyfreg(31); + + __asm__ volatile ("mffs 0; stfd 0, %0" : "=m"(f->fs)); + + statep->frame = (int)f; +} +#endif + + +/* + * No-op float saves. + * (Floating point registers were saved in _thread_machdep_switch()) + */ + +void +_thread_machdep_save_float_state(statep) + struct _machdep_state* statep; +{ +} + +void +_thread_machdep_restore_float_state(statep) + struct _machdep_state* statep; +{ +} diff --git a/lib/libpthread/arch/arm/uthread_machdep.h b/lib/libpthread/arch/arm/uthread_machdep.h new file mode 100644 index 00000000000..4829c6e9bea --- /dev/null +++ b/lib/libpthread/arch/arm/uthread_machdep.h @@ -0,0 +1,7 @@ +/* $OpenBSD: uthread_machdep.h,v 1.1 2004/02/09 13:14:34 drahn Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ + +struct _machdep_state { + int frame; +}; + diff --git a/lib/libpthread/arch/arm/uthread_machdep_asm.S b/lib/libpthread/arch/arm/uthread_machdep_asm.S new file mode 100644 index 00000000000..7781d633fe5 --- /dev/null +++ b/lib/libpthread/arch/arm/uthread_machdep_asm.S @@ -0,0 +1,137 @@ +/* $OpenBSD: uthread_machdep_asm.S,v 1.1 2004/02/09 13:14:34 drahn Exp $ */ +/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ + +#if 0 +#include <machine/asm.h> + +/* These need to be kept in sync with uthread_machdep.c */ +#define REGOFF(n) (2*4 + (n-14)*4) +#define FPOFF(n) (REGOFF(36) + (n)*8) +#define FRAMESIZE FPOFF(33) + +#define SA(x) (((x)+0xf)&~0xf) + +ENTRY(_thread_machdep_switch) + stwu 1, -SA(FRAMESIZE)(1) + + /* Save context into frame */ + stw 14, REGOFF(14)(1) + stw 15, REGOFF(15)(1) + stw 16, REGOFF(16)(1) + stw 17, REGOFF(17)(1) + stw 18, REGOFF(18)(1) + stw 19, REGOFF(19)(1) + stw 20, REGOFF(20)(1) + stw 21, REGOFF(21)(1) + stw 22, REGOFF(22)(1) + stw 23, REGOFF(23)(1) + stw 24, REGOFF(24)(1) + stw 25, REGOFF(25)(1) + stw 26, REGOFF(26)(1) + stw 27, REGOFF(27)(1) + stw 28, REGOFF(28)(1) + stw 29, REGOFF(29)(1) + stw 30, REGOFF(30)(1) + stw 31, REGOFF(31)(1) + mflr 0; stw 0, REGOFF(32)(1) + mfcr 0; stw 0, REGOFF(33)(1) + mfctr 0; stw 0, REGOFF(34)(1) + mfxer 0; stw 0, REGOFF(35)(1) + stfd 0, FPOFF(0)(1) + stfd 1, FPOFF(1)(1) + stfd 2, FPOFF(2)(1) + stfd 3, FPOFF(3)(1) + stfd 4, FPOFF(4)(1) + stfd 5, FPOFF(5)(1) + stfd 6, FPOFF(6)(1) + stfd 7, FPOFF(7)(1) + stfd 8, FPOFF(8)(1) + stfd 9, FPOFF(9)(1) + stfd 10, FPOFF(10)(1) + stfd 11, FPOFF(11)(1) + stfd 12, FPOFF(12)(1) + stfd 13, FPOFF(13)(1) + stfd 14, FPOFF(14)(1) + stfd 15, FPOFF(15)(1) + stfd 16, FPOFF(16)(1) + stfd 17, FPOFF(17)(1) + stfd 18, FPOFF(18)(1) + stfd 19, FPOFF(19)(1) + stfd 20, FPOFF(20)(1) + stfd 21, FPOFF(21)(1) + stfd 22, FPOFF(22)(1) + stfd 23, FPOFF(23)(1) + stfd 24, FPOFF(24)(1) + stfd 25, FPOFF(25)(1) + stfd 26, FPOFF(26)(1) + stfd 27, FPOFF(27)(1) + stfd 28, FPOFF(28)(1) + stfd 29, FPOFF(29)(1) + stfd 30, FPOFF(30)(1) + stfd 31, FPOFF(31)(1) + mffs 0; stfd 0, FPOFF(32)(1) + + /* Switch stacks */ + stw 1, 0(4) + lwz 1, 0(3) + + /* Restore context from the frame */ + lfd 0, FPOFF(32)(1); mtfsf 0xff, 0 + lfd 31, FPOFF(31)(1) + lfd 30, FPOFF(30)(1) + lfd 29, FPOFF(29)(1) + lfd 28, FPOFF(28)(1) + lfd 27, FPOFF(27)(1) + lfd 26, FPOFF(26)(1) + lfd 25, FPOFF(25)(1) + lfd 24, FPOFF(24)(1) + lfd 23, FPOFF(23)(1) + lfd 22, FPOFF(22)(1) + lfd 21, FPOFF(21)(1) + lfd 20, FPOFF(20)(1) + lfd 19, FPOFF(19)(1) + lfd 18, FPOFF(18)(1) + lfd 17, FPOFF(17)(1) + lfd 16, FPOFF(16)(1) + lfd 15, FPOFF(15)(1) + lfd 14, FPOFF(14)(1) + lfd 13, FPOFF(13)(1) + lfd 12, FPOFF(12)(1) + lfd 11, FPOFF(11)(1) + lfd 10, FPOFF(10)(1) + lfd 9, FPOFF(9)(1) + lfd 8, FPOFF(8)(1) + lfd 7, FPOFF(7)(1) + lfd 6, FPOFF(6)(1) + lfd 5, FPOFF(5)(1) + lfd 4, FPOFF(4)(1) + lfd 3, FPOFF(3)(1) + lfd 2, FPOFF(2)(1) + lfd 1, FPOFF(1)(1) + lfd 0, FPOFF(0)(1) + + lwz 0, REGOFF(35)(1); mtxer 0 + lwz 0, REGOFF(34)(1); mtctr 0 + lwz 0, REGOFF(33)(1); mtcr 0 + lwz 0, REGOFF(32)(1); mtlr 0 + lwz 31, REGOFF(31)(1) + lwz 30, REGOFF(30)(1) + lwz 29, REGOFF(29)(1) + lwz 28, REGOFF(28)(1) + lwz 27, REGOFF(27)(1) + lwz 26, REGOFF(26)(1) + lwz 25, REGOFF(25)(1) + lwz 24, REGOFF(24)(1) + lwz 23, REGOFF(23)(1) + lwz 22, REGOFF(22)(1) + lwz 21, REGOFF(21)(1) + lwz 20, REGOFF(20)(1) + lwz 19, REGOFF(19)(1) + lwz 18, REGOFF(18)(1) + lwz 17, REGOFF(17)(1) + lwz 16, REGOFF(16)(1) + lwz 15, REGOFF(15)(1) + lwz 14, REGOFF(14)(1) + la 1, SA(FRAMESIZE)(1) + blr +#endif |