1*0a6a1f1dSLionel Sambuc /*	$NetBSD: atomic_op_asm.h,v 1.6 2014/03/07 07:17:54 matt Exp $	*/
2b6cbf720SGianluca Guida 
3b6cbf720SGianluca Guida /*-
4b6cbf720SGianluca Guida  * Copyright (c) 2007 The NetBSD Foundation, Inc.
5b6cbf720SGianluca Guida  * All rights reserved.
6b6cbf720SGianluca Guida  *
7b6cbf720SGianluca Guida  * This code is derived from software contributed to The NetBSD Foundation
8b6cbf720SGianluca Guida  * by Jason R. Thorpe.
9b6cbf720SGianluca Guida  *
10b6cbf720SGianluca Guida  * Redistribution and use in source and binary forms, with or without
11b6cbf720SGianluca Guida  * modification, are permitted provided that the following conditions
12b6cbf720SGianluca Guida  * are met:
13b6cbf720SGianluca Guida  * 1. Redistributions of source code must retain the above copyright
14b6cbf720SGianluca Guida  *    notice, this list of conditions and the following disclaimer.
15b6cbf720SGianluca Guida  * 2. Redistributions in binary form must reproduce the above copyright
16b6cbf720SGianluca Guida  *    notice, this list of conditions and the following disclaimer in the
17b6cbf720SGianluca Guida  *    documentation and/or other materials provided with the distribution.
18b6cbf720SGianluca Guida  *
19b6cbf720SGianluca Guida  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20b6cbf720SGianluca Guida  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21b6cbf720SGianluca Guida  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22b6cbf720SGianluca Guida  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23b6cbf720SGianluca Guida  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b6cbf720SGianluca Guida  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b6cbf720SGianluca Guida  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b6cbf720SGianluca Guida  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b6cbf720SGianluca Guida  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b6cbf720SGianluca Guida  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29b6cbf720SGianluca Guida  * POSSIBILITY OF SUCH DAMAGE.
30b6cbf720SGianluca Guida  */
31b6cbf720SGianluca Guida 
32b6cbf720SGianluca Guida #ifndef _ATOMIC_OP_ASM_H_
33b6cbf720SGianluca Guida #define	_ATOMIC_OP_ASM_H_
34b6cbf720SGianluca Guida 
35b6cbf720SGianluca Guida #include <machine/asm.h>
36b6cbf720SGianluca Guida 
37b6cbf720SGianluca Guida #if defined(_KERNEL)
38b6cbf720SGianluca Guida 
39b6cbf720SGianluca Guida #define	ATOMIC_OP_ALIAS(a,s)	STRONG_ALIAS(a,s)
40b6cbf720SGianluca Guida 
41b6cbf720SGianluca Guida #else /* _KERNEL */
42b6cbf720SGianluca Guida 
43b6cbf720SGianluca Guida #define	ATOMIC_OP_ALIAS(a,s)	WEAK_ALIAS(a,s)
44b6cbf720SGianluca Guida 
45b6cbf720SGianluca Guida #endif /* _KERNEL */
46b6cbf720SGianluca Guida 
47*0a6a1f1dSLionel Sambuc #define	ATOMIC_OP_32_ARG(op,insn,arg) \
48*0a6a1f1dSLionel Sambuc ENTRY(_atomic_##op##_32)	; \
49*0a6a1f1dSLionel Sambuc 	mr	%r10,%r3	; \
50*0a6a1f1dSLionel Sambuc 1:	lwarx	%r3,0,%r10	; \
51*0a6a1f1dSLionel Sambuc 	insn	%r5,%r3,arg	; \
52*0a6a1f1dSLionel Sambuc 	stwcx.	%r5,0,%r10	; \
53*0a6a1f1dSLionel Sambuc 	beqlr+			; \
54*0a6a1f1dSLionel Sambuc 	b	1b		; \
55*0a6a1f1dSLionel Sambuc END(_atomic_##op##_32)		; \
56*0a6a1f1dSLionel Sambuc ATOMIC_OP_ALIAS(atomic_##op##_32,_atomic_##op##_32)
57*0a6a1f1dSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc #define	ATOMIC_OP_64_ARG(op,insn,arg) \
59*0a6a1f1dSLionel Sambuc ENTRY(_atomic_##op##_64)	; \
60*0a6a1f1dSLionel Sambuc 	mr	%r10,%r3	; \
61*0a6a1f1dSLionel Sambuc 1:	ldarx	%r3,0,%r10	; \
62*0a6a1f1dSLionel Sambuc 	insn	%r5,%r3,arg	; \
63*0a6a1f1dSLionel Sambuc 	stdcx.	%r5,0,%r10	; \
64*0a6a1f1dSLionel Sambuc 	beqlr+			; \
65*0a6a1f1dSLionel Sambuc 	b	1b		; \
66*0a6a1f1dSLionel Sambuc END(_atomic_##op##_64)		; \
67*0a6a1f1dSLionel Sambuc ATOMIC_OP_ALIAS(atomic_##op##_64,_atomic_##op##_64)
68*0a6a1f1dSLionel Sambuc 
69*0a6a1f1dSLionel Sambuc #define	ATOMIC_OP_32_ARG_NV(op,insn,arg) \
70*0a6a1f1dSLionel Sambuc ENTRY(_atomic_##op##_32_nv)	; \
71*0a6a1f1dSLionel Sambuc 	mr	%r10,%r3	; \
72*0a6a1f1dSLionel Sambuc 1:	lwarx	%r3,0,%r10	; \
73*0a6a1f1dSLionel Sambuc 	insn	%r3,%r3,arg	; \
74*0a6a1f1dSLionel Sambuc 	stwcx.	%r3,0,%r10	; \
75*0a6a1f1dSLionel Sambuc 	beqlr+			; \
76*0a6a1f1dSLionel Sambuc 	b	1b		; \
77*0a6a1f1dSLionel Sambuc END(_atomic_##op##_32_nv)	; \
78*0a6a1f1dSLionel Sambuc ATOMIC_OP_ALIAS(atomic_##op##_32_nv,_atomic_##op##_32_nv)
79*0a6a1f1dSLionel Sambuc 
80*0a6a1f1dSLionel Sambuc #define	ATOMIC_OP_64_ARG_NV(op,insn,arg) \
81*0a6a1f1dSLionel Sambuc ENTRY(_atomic_##op##_64_nv)	; \
82*0a6a1f1dSLionel Sambuc 	mr	%r10,%r3	; \
83*0a6a1f1dSLionel Sambuc 1:	ldarx	%r3,0,%r10	; \
84*0a6a1f1dSLionel Sambuc 	insn	%r3,%r3,arg	; \
85*0a6a1f1dSLionel Sambuc 	stdcx.	%r3,0,%r10	; \
86*0a6a1f1dSLionel Sambuc 	beqlr+			; \
87*0a6a1f1dSLionel Sambuc 	b	1b		; \
88*0a6a1f1dSLionel Sambuc END(_atomic_##op##_64_nv)	; \
89*0a6a1f1dSLionel Sambuc ATOMIC_OP_ALIAS(atomic_##op##_64_nv,_atomic_##op##_64_nv)
90*0a6a1f1dSLionel Sambuc 
91*0a6a1f1dSLionel Sambuc #define ATOMIC_OP_32(op)	ATOMIC_OP_32_ARG(op,op,%r4)
92*0a6a1f1dSLionel Sambuc #define ATOMIC_OP_32_NV(op)	ATOMIC_OP_32_ARG_NV(op,op,%r4)
93*0a6a1f1dSLionel Sambuc 
94*0a6a1f1dSLionel Sambuc #define ATOMIC_OP_64(op)	ATOMIC_OP_64_ARG(op,op,%r4)
95*0a6a1f1dSLionel Sambuc #define ATOMIC_OP_64_NV(op)	ATOMIC_OP_64_ARG_NV(op,op,%r4)
96*0a6a1f1dSLionel Sambuc 
97b6cbf720SGianluca Guida #endif /* _ATOMIC_OP_ASM_H_ */
98