#include "opt_multiprocessor.h"
#include "opt_lockdebug.h"
#define __MUTEX_PRIVATE
#include <machine/asm.h>
#include <machine/mutex.h>
#include <machine/reg.h>
#include <machine/cpu.h>
#include "assym.h"
#ifndef LOCKDEBUG
.global mutex_enter_crit_start
.global mutex_enter_crit_end
.import mutex_vector_enter, code
.import mutex_vector_exit, code
.import mutex_wakeup, code
LEAF_ENTRY(mutex_exit)
ldi MUTEX_ADAPTIVE_UNOWNED, %t1
ldw MTX_OWNER(%arg0),%t2
depi 0, 27, 1, %t2
comb,= %t1, %t2, .Lexit_slowpath
nop
ldi __SIMPLELOCK_RAW_UNLOCKED, %t2
ldo (MTX_LOCK + HPPA_LDCW_ALIGN - 1)(%arg0), %t3
depi 0, 31, 4, %t3
stw %t1, MTX_OWNER(%arg0)
stw %t2, 0(%t3)
sync
ldb MTX_WAITERS(%arg0), %t4
comib,= 0, %t4, .Lexit_done
nop
ldil L%mutex_wakeup, %t1
ldo R%mutex_wakeup(%t1), %t1
.call
bv,n %r0(%t1)
.Lexit_slowpath:
ldil L%mutex_vector_exit, %t1
ldo R%mutex_vector_exit(%t1), %t1
.call
bv,n %r0(%t1)
.Lexit_done:
bv,n %r0(%rp)
EXIT(mutex_exit)
LEAF_ENTRY(mutex_enter)
ldi MUTEX_ADAPTIVE_UNOWNED, %t1
ldw MTX_OWNER(%arg0), %t2
comb,=,n %t1, %t2, .Lmutexunowned
.Lenter_slowpath:
ldil L%mutex_vector_enter, %t1
ldo R%mutex_vector_enter(%t1), %t1
.call
bv,n %r0(%t1)
nop
.Lmutexunowned:
ldo (MTX_LOCK + HPPA_LDCW_ALIGN - 1)(%arg0), %t1
depi 0, 31, 4, %t1
ldcw 0(%t1), %ret0
mutex_enter_crit_start:
comib,= 0, %ret0, .Lenter_slowpath
GET_CURLWP(%t2)
bv %r0(%rp)
stw %t2, MTX_OWNER(%arg0)
mutex_enter_crit_end:
EXIT(mutex_enter)
#endif
#ifndef MULTIPROCESSOR
.global _lock_cas_ras_start
.global _lock_cas_ras_end
LEAF_ENTRY(_lock_cas)
_lock_cas_ras_start:
ldw 0(%arg0),%t1
comb,<> %arg1, %t1, 1f
copy %t1,%ret0
stw %arg2,0(%arg0)
_lock_cas_ras_end:
copy %arg1,%ret0
1:
bv,n %r0(%rp)
EXIT(_lock_cas)
STRONG_ALIAS(_atomic_cas_ulong,_lock_cas)
STRONG_ALIAS(atomic_cas_ulong,_lock_cas)
STRONG_ALIAS(_atomic_cas_32,_lock_cas)
STRONG_ALIAS(atomic_cas_32,_lock_cas)
STRONG_ALIAS(_atomic_cas_uint,_lock_cas)
STRONG_ALIAS(atomic_cas_uint,_lock_cas)
STRONG_ALIAS(_atomic_cas_ptr,_lock_cas)
STRONG_ALIAS(atomic_cas_ptr,_lock_cas)
STRONG_ALIAS(_atomic_cas_ulong_ni,_lock_cas)
STRONG_ALIAS(atomic_cas_ulong_ni,_lock_cas)
STRONG_ALIAS(_atomic_cas_32_ni,_lock_cas)
STRONG_ALIAS(atomic_cas_32_ni,_lock_cas)
STRONG_ALIAS(_atomic_cas_uint_ni,_lock_cas)
STRONG_ALIAS(atomic_cas_uint_ni,_lock_cas)
STRONG_ALIAS(_atomic_cas_ptr_ni,_lock_cas)
STRONG_ALIAS(atomic_cas_ptr_ni,_lock_cas)
#else
#define IL \
.word __SIMPLELOCK_RAW_UNLOCKED ! \
.word __SIMPLELOCK_RAW_UNLOCKED ! \
.word __SIMPLELOCK_RAW_UNLOCKED ! \
.word __SIMPLELOCK_RAW_UNLOCKED ! \
#define I8 \
IL IL IL IL IL IL IL IL
#define I64 \
I8 I8 I8 I8 I8 I8 I8 I8
.section .data
.align 4096
.export _lock_hash, data
_lock_hash:
I64 I64
I64 I64
I64 I64
I64 I64
I64 I64
I64 I64
I64 I64
I64 I64
LEAF_ENTRY(_lock_cas)
ALTENTRY(_lock_cas_mp)
mfctl %eiem, %t1
mtctl %r0, %eiem
extru %arg0, 21+8-1, 8, %ret0
ldil L%_lock_hash, %r1
zdep %ret0, 27, 28, %ret0
ldo R%_lock_hash(%r1), %r1
addl %ret0, %r1, %ret0
ldo 15(%ret0), %ret0
copy %ret0, %t3
depi 0, 31, 4, %t3
ldcw 0(%t3), %ret0
comib,<>,n 0, %ret0, _lock_cas_mp_interlocked
_lock_cas_mp_spin:
ldw 0(%t3), %ret0
comib,= 0, %ret0, _lock_cas_mp_spin
nop
ldcw 0(%t3), %ret0
comib,= 0, %ret0, _lock_cas_mp_spin
nop
_lock_cas_mp_interlocked:
ldw 0(%arg0), %ret0
comclr,<> %arg1, %ret0, %r0
stw %arg2, 0(%arg0)
sync
ldi __SIMPLELOCK_RAW_UNLOCKED, %t4
stw %t4, 0(%t3)
bv %r0(%r2)
mtctl %t1, %eiem
EXIT(_lock_cas)
STRONG_ALIAS(_atomic_cas_ulong,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_ulong,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_32,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_32,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_uint,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_uint,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_ptr,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_ptr,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_ulong_ni,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_ulong_ni,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_32_ni,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_32_ni,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_uint_ni,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_uint_ni,_lock_cas_mp)
STRONG_ALIAS(_atomic_cas_ptr_ni,_lock_cas_mp)
STRONG_ALIAS(atomic_cas_ptr_ni,_lock_cas_mp)
#endif