[352] | 1 | #if __ARM_ARCH_4__ || __ARM_ARCH_4T__ || __ARM_ARCH == 4
|
---|
| 2 | #define BLX "mov lr,pc\n\tbx"
|
---|
| 3 | #else
|
---|
| 4 | #define BLX "blx"
|
---|
| 5 | #endif
|
---|
| 6 |
|
---|
| 7 | extern uintptr_t __attribute__((__visibility__("hidden")))
|
---|
| 8 | __a_cas_ptr, __a_barrier_ptr;
|
---|
| 9 |
|
---|
| 10 | #if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
|
---|
| 11 | || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
|
---|
| 12 |
|
---|
| 13 | #define a_ll a_ll
|
---|
| 14 | static inline int a_ll(volatile int *p)
|
---|
| 15 | {
|
---|
| 16 | int v;
|
---|
| 17 | __asm__ __volatile__ ("ldrex %0, %1" : "=r"(v) : "Q"(*p));
|
---|
| 18 | return v;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | #define a_sc a_sc
|
---|
| 22 | static inline int a_sc(volatile int *p, int v)
|
---|
| 23 | {
|
---|
| 24 | int r;
|
---|
| 25 | __asm__ __volatile__ ("strex %0,%2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory");
|
---|
| 26 | return !r;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | #if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
|
---|
| 30 |
|
---|
| 31 | #define a_barrier a_barrier
|
---|
| 32 | static inline void a_barrier()
|
---|
| 33 | {
|
---|
| 34 | __asm__ __volatile__ ("dmb ish" : : : "memory");
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | #define a_pre_llsc a_barrier
|
---|
| 40 | #define a_post_llsc a_barrier
|
---|
| 41 |
|
---|
| 42 | #else
|
---|
| 43 |
|
---|
| 44 | #define a_cas a_cas
|
---|
| 45 | static inline int a_cas(volatile int *p, int t, int s)
|
---|
| 46 | {
|
---|
| 47 | for (;;) {
|
---|
| 48 | register int r0 __asm__("r0") = t;
|
---|
| 49 | register int r1 __asm__("r1") = s;
|
---|
| 50 | register volatile int *r2 __asm__("r2") = p;
|
---|
| 51 | register uintptr_t r3 __asm__("r3") = __a_cas_ptr;
|
---|
| 52 | int old;
|
---|
| 53 | __asm__ __volatile__ (
|
---|
| 54 | BLX " r3"
|
---|
| 55 | : "+r"(r0), "+r"(r3) : "r"(r1), "r"(r2)
|
---|
| 56 | : "memory", "lr", "ip", "cc" );
|
---|
| 57 | if (!r0) return t;
|
---|
| 58 | if ((old=*p)!=t) return old;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | #endif
|
---|
| 63 |
|
---|
| 64 | #ifndef a_barrier
|
---|
| 65 | #define a_barrier a_barrier
|
---|
| 66 | static inline void a_barrier()
|
---|
| 67 | {
|
---|
| 68 | register uintptr_t ip __asm__("ip") = __a_barrier_ptr;
|
---|
| 69 | __asm__ __volatile__( BLX " ip" : "+r"(ip) : : "memory", "cc", "lr" );
|
---|
| 70 | }
|
---|
| 71 | #endif
|
---|
| 72 |
|
---|
| 73 | #define a_crash a_crash
|
---|
| 74 | static inline void a_crash()
|
---|
| 75 | {
|
---|
| 76 | __asm__ __volatile__(
|
---|
| 77 | #ifndef __thumb__
|
---|
| 78 | ".word 0xe7f000f0"
|
---|
| 79 | #else
|
---|
| 80 | ".short 0xdeff"
|
---|
| 81 | #endif
|
---|
| 82 | : : : "memory");
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | #if __ARM_ARCH >= 5
|
---|
| 86 |
|
---|
| 87 | #define a_clz_32 a_clz_32
|
---|
| 88 | static inline int a_clz_32(uint32_t x)
|
---|
| 89 | {
|
---|
| 90 | __asm__ ("clz %0, %1" : "=r"(x) : "r"(x));
|
---|
| 91 | return x;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | #endif
|
---|