1/* $OpenBSD: _atomic_lock.S,v 1.1 2017/08/15 06:13:24 guenther Exp $ */ 2/* David Leonard, <d@csee.uq.edu.au>. Public domain. */ 3 4#include <machine/asm.h> 5 6LEAF(_atomic_lock,1) 7 LDGP(pv) 8 9 /* NOTE: using ldl_l/stl_c instead of 10 ldq_l and stq_c as machine/spinlock.h 11 defines _atomic_lock_t as int */ 120: ldl_l v0, 0(a0) /* read existing lock value */ 13 mov 1, t0 /* locked value to store */ 14 stl_c t0, 0(a0) /* attempt to store, status in t0 */ 15 beq t0, 1f /* branch forward to optimise prediction */ 16 mb /* sync with other processors */ 17 RET /* return with v0==0 if lock obtained */ 181: br 0b /* loop to try again */ 19END(_atomic_lock) 20