]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/cddl/contrib/opensolaris/common/atomic/powerpc64/opensolaris_atomic.S
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / cddl / contrib / opensolaris / common / atomic / powerpc64 / opensolaris_atomic.S
1 /*-
2  * Copyright (C) 2010 Nathan Whitehorn
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27
28 #include <machine/asm.h>
29
30 ENTRY(atomic_add_64_nv)
31    1:   ldarx   %r5,0,%r3
32         add     %r5,%r4,%r5
33         stdcx.  %r5,0,%r3
34         bne-    1b
35
36         mr      %r3,%r5
37         blr
38
39 ENTRY(atomic_cas_32)
40    1:   lwarx   %r6,0,%r3
41         cmplw   %r6,%r4
42         bne     2f
43         stwcx.  %r5,0,%r3
44         bne-    1b
45         b       3f
46
47    2:   stwcx.  %r6,0,%r3       /* clear reservation */
48
49    3:   mr      %r3,%r6
50         blr
51
52 ENTRY(atomic_cas_64)
53    1:   ldarx   %r6,0,%r3
54         cmpld   %r6,%r4
55         bne     2f
56         stdcx.  %r5,0,%r3
57         bne-    1b
58         b       3f
59
60    2:   stdcx.  %r6,0,%r3       /* clear reservation */
61
62    3:   mr      %r3,%r6
63         blr
64
65 ENTRY(atomic_or_8_nv)
66         li      %r6,3
67         andc.   %r6,%r3,%r6             /* r6 = r3 & ~4 */ 
68         addi    %r7,%r6,3
69         sub     %r7,%r7,%r3             /* offset in r7 */
70         sldi    %r7,%r7,3               /* bits to shift in r7 */
71
72         rlwinm  %r4,%r4,0,24,31         /* mask and rotate the argument */
73         slw     %r4,%r4,%r7
74
75    1:   lwarx   %r5,0,%r6
76         or      %r5,%r4,%r5
77         stwcx.  %r5,0,%r6
78         bne-    1b
79
80         srw     %r3,%r5,%r7
81         rlwinm  %r3,%r3,0,24,31         /* mask return value */
82         
83         blr
84
85 ENTRY(membar_producer)
86         eieio
87         blr
88