]> git.saurik.com Git - apple/xnu.git/blob - libkern/ppc/OSAtomic.s
xnu-792.13.8.tar.gz
[apple/xnu.git] / libkern / ppc / OSAtomic.s
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1997-1998 Apple Computer, Inc.
32 *
33 *
34 * HISTORY
35 *
36 * sdouglas 22 Oct 97 - first checked in from DriverServices
37 * sdouglas 28 Jul 98 - start IOKit
38 */
39
40 #include <architecture/ppc/asm_help.h>
41
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;
44 ; ENTRY functionName
45 ;
46 ; Assembly directives to begin an exported function.
47 ;
48 ; Takes: functionName - name of the exported function
49 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50
51 .macro ENTRY
52 .text
53 .align 2
54 .globl $0
55 $0:
56 .endmacro
57
58 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59
60 /*
61 int OSCompareAndSwap( UInt32 oldVal, UInt32 newVal, UInt32 * addr )
62 This is now an alias to hw_compare_and_store, see xnu/libkern/Makefile.
63
64 void * OSDequeueAtomic(void ** inList, SInt32 inOffset)
65 This is also aliased, to hw_dequeue_atomic.
66
67 void OSEnqueueAtomic(void ** inList, void * inNewLink, SInt32 inOffset)
68 This is aliased to hw_queue_atomic.
69 */
70
71 /*
72 Note: We can not use the hw_atomic routines provided by osfmk/ppc as
73 the return the result of the addition not the original value.
74 */
75 /*
76 SInt32 OSDecrementAtomic(SInt32 * value)
77 */
78 ENTRY _OSDecrementAtomic
79 mr r4, r3
80 li r3, -1
81 b _OSAddAtomic
82
83 /*
84 SInt32 OSIncrementAtomic(SInt32 * value)
85 */
86
87 .align 5
88
89 ENTRY _OSIncrementAtomic
90 mr r4, r3
91 li r3, 1
92
93 /*
94 SInt32 OSAddAtomic(SInt32 amount, SInt32 * value)
95 */
96
97 ENTRY _OSAddAtomic
98
99 mr r5,r3 /* Save the increment */
100 .L_AAretry:
101 lwarx r3, 0, r4 /* Grab the area value */
102 add r6, r3, r5 /* Add the value */
103 stwcx. r6, 0, r4 /* Try to save the new value */
104 bne- .L_AAretry /* Didn't get it, try again... */
105 blr /* Return the original value */