1/* 2 * Copyright 2003-2009, Axel D�rfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#include <asm_defs.h> 7 8.text 9 10/* int atomic_add(int *value, int increment) 11 * (r3) 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 20FUNCTION_END(atomic_add) 21 22/* int atomic_and(int *value, int andValue) 23 * (r3) r3 r4 24 */ 25FUNCTION(atomic_and): 26lost2: lwarx %r5, 0, %r3 27 and %r0, %r5, %r4 28 stwcx. %r0, 0, %r3 29 bne- lost2 30 mr %r3, %r5 31 blr 32FUNCTION_END(atomic_and) 33 34/* int atomic_or(int *value, int orValue) 35 * (r3) r3 r4 36 */ 37FUNCTION(atomic_or): 38lost3: lwarx %r5, 0, %r3 39 or %r0, %r5, %r4 40 stwcx. %r0, 0, %r3 41 bne- lost3 42 mr %r3, %r5 43 blr 44FUNCTION_END(atomic_or) 45 46/* int atomic_set(int *value, int setTo) 47 * (r3) r3 r4 48 */ 49FUNCTION(atomic_set): 50lost4: lwarx %r5, 0, %r3 51 stwcx. %r4, 0, %r3 52 bne- lost4 53 mr %r3, %r5 54 blr 55FUNCTION_END(atomic_set) 56 57/* int atomic_test_and_set(int *value, int setTo, int testValue) 58 * (r3) r3 r4 r5 59 */ 60FUNCTION(atomic_test_and_set): 61lost5: lwarx %r6, 0, %r3 62 cmpw %r6, %r5 63 bne out5 64 stwcx. %r4, 0, %r3 65 bne- lost5 66out5: mr %r3, %r6 67 blr 68FUNCTION_END(atomic_test_and_set) 69 70// TODO: PowerPC atomic_get_and_set 71FUNCTION(atomic_get_and_set): 72 sync 73 blr 74FUNCTION_END(atomic_get_and_set) 75 76/* int atomic_get(int *value) 77 * (r3) r3 78 */ 79FUNCTION(atomic_get): 80lost6: lwarx %r5, 0, %r3 81 stwcx. %r5, 0, %r3 82 bne- lost6 83 mr %r3, %r5 84 blr 85FUNCTION_END(atomic_get) 86