/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
#ident "$Header: libmutexs.s,v 2.1.1.4 92/10/15 14:01:02 marker Exp $"

#include <regdef.h>
#if defined (SYSTYPE_BSD43)
#include <asm.h>
#else
#include <sys/asm.h>
#endif

#ifdef KPIC
	.option pic2
#endif

#ifdef MIPS2
LEAF(mips2_test_and_set)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	move	t0,a1
	sc	t0,(a0)
	beqz	t0,mips2_test_and_set
	nop
	j	ra
	nop
	.end	mips2_test_and_set

LEAF(mips2_test_then_and)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	and	t0,v0,a1
	sc	t0,(a0)
	beqz	t0,mips2_test_then_and
	nop
	j	ra
	nop
	.end	mips2_test_then_and

LEAF(mips2_test_then_nand)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	and	t0,v0,a1
	not	t0
	sc	t0,(a0)
	beqz	t0,mips2_test_then_nand
	nop
	j	ra
	nop
	.end	mips2_test_then_and

LEAF(mips2_test_then_nor)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	nor	t0,v0,a1
	sc	t0,(a0)
	beqz	t0,mips2_test_then_nor
	nop
	j	ra
	nop
	.end	mips2_test_then_nor

LEAF(mips2_test_then_not)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	not	t0,v0
	sc	t0,(a0)
	beqz	t0,mips2_test_then_not
	nop
	j	ra
	nop
	.end	mips2_test_then_not

LEAF(mips2_test_then_xor)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	xor	t0,v0,a1
	sc	t0,(a0)
	beqz	t0,mips2_test_then_xor
	nop
	j	ra
	nop
	.end	mips2_test_then_xor

LEAF(mips2_test_then_or)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	or	t0,v0,a1
	sc	t0,(a0)
	beqz	t0,mips2_test_then_or
	nop
	j	ra
	nop
	.end	mips2_test_then_or

LEAF(mips2_test_then_add)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	add	t0,v0,a1
	sc	t0,(a0)
	beqz	t0,mips2_test_then_add
	nop
	j	ra
	nop
	.end	mips2_test_then_add

LEAF(mips2_add_then_test)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	ll	v0,(a0)
	add	v0,a1
	move	t0,v0
	sc	t0,(a0)
	beqz	t0,mips2_add_then_test
	nop
	j	ra
	nop
	.end	mips2_add_then_test

LEAF(is_mips2)
	.set	noreorder
#ifdef KPIC
	.cpload	t9
#endif
	li	v0,-2
	bgezl	v0,ret
	addi	v0,1
	addi	v0,1
ret:
	j	ra
	nop
	.end	is_mips2
#endif /* MIPS2 */

LEAF(_read_delay)
	.set noreorder
#ifdef KPIC
	.cpload	t9
#endif
	addi	a0,-1
	bgtz	a0,_read_delay
	nop
	j	ra
	nop
	.end	_read_delay

LEAF(_flush_writebuf)
	.set noreorder
#ifdef KPIC
	.cpload	t9
#endif
	la	t0,_dummy
_flush: addi	a0,-1
	bgtz	a0,_flush
	sw	a0,(t0)
	j	ra
	nop
	.data
#ifdef KPIC
_dummy:	.gpword	0
#else
_dummy:	.word	0
#endif
	.end	_flush_writebuf
