1/* 2 * Copyright 2013, winocm. <winocm@icloud.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * Redistributions in binary form must reproduce the above copyright notice, this 12 * list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * If you are going to use this software in any form that does not involve 16 * releasing the source to this project or improving it, let me know beforehand. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29/* 30 * OSAtomic operations. 31 */ 32 33#include <arm/arch.h> 34 35.code 32 36.arm 37.syntax unified 38 39#if __ARM_ARCH == 6 40#define NO_EXCLUSIVES 1 41#endif 42 43#if defined(BOARD_CONFIG_OMAP3530) || defined(BOARD_CONFIG_OMAP335X) 44//#define NO_EXCLUSIVES 1 45#endif 46 47.align 4 48.globl _OSCompareAndSwap64 49_OSCompareAndSwap64: 50 ldr r12, [sp] 51 stmfd sp!,{r4,r5,lr} 52_loop: 53 /* ldrexd r4, [r12] */ 54#ifdef NO_EXCLUSIVES 55 ldrd r4, [r12] 56#else 57 .long 0xe1bc4f9f 58#endif 59 teq r0, r4 60 teqeq r1, r5 61 movne r0, #0 62 bne ret 63 /* strexd r4, r2, [r12] */ 64#ifdef NO_EXCLUSIVES 65 strd r2, [r12] 66 mov r4, #0 67#else 68 .long 0xe1ac4f92 69#endif 70 cmp r4, #0 71 bne _loop 72 mov r0, #1 73ret: 74 ldmfd sp!,{r4,r5,pc} 75 76.align 4 77.globl _OSAddAtomic64 78_OSAddAtomic64: 79 stmfd sp!, {r4-r9,lr} 80loop: 81#ifdef NO_EXCLUSIVES 82 ldrd r4, [r2] 83#else 84 ldrexd r4, r5, [r2] 85#endif 86 adds r8, r4, r0 87 adc r9, r5, r1 88#ifdef NO_EXCLUSIVES 89 strd r8, r9, [r2] 90 mov r3, #0 91#else 92 strexd r3, r8, r9, [r2] 93#endif 94 cmp r3, #0 95 bne loop 96 mov r0, r4 97 mov r1, r5 98 ldmfd sp!, {r4-r9,pc} 99 100#ifndef _ARM_ARCH_6 101.code 16 102.thumb_func _OSCompareAndSwapPtr 103#endif 104.align 4 105.globl _OSCompareAndSwapPtr 106_OSCompareAndSwapPtr: 107 stmfd sp!,{r7,lr} 108 blx _hw_compare_and_store 109 ldmfd sp!,{r7,lr} 110 bx lr 111 112#ifndef _ARM_ARCH_6 113.align 4 114.thumb_func _OSAddAtomicLong 115#endif 116.globl _OSAddAtomicLong 117_OSAddAtomicLong: 118 stmfd sp!,{r7,lr} 119 blx _OSAddAtomic 120 ldmfd sp!,{r7,lr} 121 bx lr 122