1/* 2** Copyright 2003, Axel D�rfler, axeld@pinc-software.de. All rights reserved. 3** Distributed under the terms of the OpenBeOS License. 4*/ 5 6#define FUNCTION(x) .global x; .type x,@function; x 7 8.text 9 10/* int atomic_add(int *value, int increment) 11 * r3 r4 12 */ 13FUNCTION(atomic_add): 14lost1: lwarx %r5, 0, %r3 // reserve memory address located in "r3" 15 add %r0, %r5, %r4 // (contents are stored in "r5") 16 stwcx. %r0, 0, %r3 17 bne- lost1 // try again if reservation was lost 18 mr %r3, %r5 // return old value (was in "r5") 19 blr 20 21/* int atomic_and(int *value, int andValue) 22 * r3 r4 23 */ 24FUNCTION(atomic_and): 25lost2: lwarx %r5, 0, %r3 26 and %r0, %r5, %r4 27 stwcx. %r0, 0, %r3 28 bne- lost2 29 mr %r3, %r5 30 blr 31 32/* int atomic_or(int *value, int orValue) 33 * r3 r4 34 */ 35FUNCTION(atomic_or): 36lost3: lwarx %r5, 0, %r3 37 or %r0, %r5, %r4 38 stwcx. %r0, 0, %r3 39 bne- lost3 40 mr %r3, %r5 41 blr 42 43/* int atomic_set(int *value, int setTo) 44 * r3 r4 45 */ 46FUNCTION(atomic_set): 47lost4: lwarx %r5, 0, %r3 48 stwcx. %r4, 0, %r3 49 bne- lost4 50 mr %r3, %r5 51 blr 52 53/* int atomic_test_and_set(int *value, int setTo, int testValue) 54 * r3 r4 r5 55 */ 56FUNCTION(atomic_test_and_set): 57lost5: lwarx %r6, 0, %r3 58 cmpw %r6, %r5 59 bne out5 60 stwcx. %r4, 0, %r3 61out5: mr %r3, %r6 62 blr 63 64/* int atomic_get(int *value) 65 * r3 66 */ 67FUNCTION(atomic_get): 68lost6: lwarx %r5, 0, %r3 69 stwcx. %r5, 0, %r3 70 bne- lost6 71 mr %r3, %r5 72 blr 73