1/*	$NetBSD: lock_stubs.s,v 1.2 2007/02/09 21:55:01 ad Exp $	*/
2
3/*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "opt_lockdebug.h"
33#include "opt_multiprocessor.h"
34
35#include <machine/asm.h>
36
37__KERNEL_RCSID(0, "$NetBSD: lock_stubs.s,v 1.2 2007/02/09 21:55:01 ad Exp $");
38
39#include "assym.h"
40
41#if defined(MULTIPROCESSOR)
42#define	MB		mb
43#else
44#define	MB		/* nothing */
45#endif
46
47/*
48 * int	_lock_cas(uintptr_t *ptr, uintptr_t old, uintptr_t new)
49 */
50LEAF(_lock_cas, 3)
511:
52	mov	a2, v0
53	ldq_l	t1, 0(a0)
54	cmpeq	t1, a1, t1
55	beq	t1, 2f
56	stq_c	v0, 0(a0)
57	beq	v0, 3f
58	MB
59	RET
602:
61	mov	zero, v0
62	MB
63	RET
643:
65	br	1b
66END(_lock_cas)
67
68#if !defined(LOCKDEBUG)
69
70/*
71 * void mutex_enter(kmutex_t *mtx);
72 */
73LEAF(mutex_enter, 1)
74	LDGP(pv)
75	GET_CURLWP
761:
77	ldq	t1, 0(v0)
78	ldq_l	t2, 0(a0)
79	bne	t2, 2f
80	stq_c	t1, 0(a0)
81	beq	t1, 3f
82	MB
83	RET
842:
85	lda	t12, mutex_vector_enter
86	jmp	(t12)
873:
88	br	1b
89END(mutex_enter)
90
91/*
92 * void mutex_exit(kmutex_t *mtx);
93 */
94LEAF(mutex_exit, 1)
95	LDGP(pv)
96	MB
97	GET_CURLWP
98	ldq	t1, 0(v0)
99	mov	zero, t3
1001:
101	ldq_l	t2, 0(a0)
102	cmpeq	t1, t2, t2
103	beq	t2, 2f
104	stq_c	t3, 0(a0)
105	beq	t3, 3f
106	RET
1072:
108	lda	t12, mutex_vector_exit
109	jmp	(t12)
1103:
111	br	1b
112END(mutex_exit)
113
114#endif	/* !LOCKDEBUG */
115