1 /* 2 * Copyright (C) 2017 Hangzhou C-SKY Microsystems co.,ltd. 3 * 4 * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB 5 * in this tarball. 6 */ 7 8 #ifndef __CSKY_ATOMIC_H_ 9 #define __CSKY_ATOMIC_H_ 10 11 #include <stdint.h> 12 #include <sysdep.h> 13 14 typedef int8_t atomic8_t; 15 typedef uint8_t uatomic8_t; 16 typedef int_fast8_t atomic_fast8_t; 17 typedef uint_fast8_t uatomic_fast8_t; 18 19 typedef int16_t atomic16_t; 20 typedef uint16_t uatomic16_t; 21 typedef int_fast16_t atomic_fast16_t; 22 typedef uint_fast16_t uatomic_fast16_t; 23 24 typedef int32_t atomic32_t; 25 typedef uint32_t uatomic32_t; 26 typedef int_fast32_t atomic_fast32_t; 27 typedef uint_fast32_t uatomic_fast32_t; 28 29 typedef int64_t atomic64_t; 30 typedef uint64_t uatomic64_t; 31 typedef int_fast64_t atomic_fast64_t; 32 typedef uint_fast64_t uatomic_fast64_t; 33 34 typedef intptr_t atomicptr_t; 35 typedef uintptr_t uatomicptr_t; 36 typedef intmax_t atomic_max_t; 37 typedef uintmax_t uatomic_max_t; 38 39 # define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval) \ 40 (abort (), 0) 41 42 # define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval) \ 43 (abort (), 0) 44 45 # define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval) \ 46 ({ __typeof(mem) _mem = (mem); \ 47 __typeof(oldval) _oldval = oldval; \ 48 __typeof(newval) _newval = newval; \ 49 register __typeof(oldval) _a0 __asm__ ("a0") = _oldval; \ 50 register __typeof(newval) _a1 __asm__ ("a1") = _newval; \ 51 register __typeof(mem) _a2 __asm__ ("a2") = _mem; \ 52 __asm__ __volatile__ ("trap 2;" \ 53 : "+r" (_a0) : "r" (_a1) , "r" (_a2) \ 54 : "a3", "memory"); \ 55 _a0; }) 56 57 # define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval) \ 58 (abort (), 0) 59 60 #define __arch_compare_and_exchange_val_8_int(mem, newval, oldval) \ 61 (abort (), 0) 62 63 #define __arch_compare_and_exchange_val_16_int(mem, newval, oldval) \ 64 (abort (), 0) 65 66 #define __arch_compare_and_exchange_val_32_int(mem, newval, oldval) \ 67 ({ __typeof (mem) _mem = (mem); \ 68 __typeof (*mem) __gret = *_mem; \ 69 unsigned int _tmp = 0; \ 70 __typeof (oldval) _oldval = oldval; \ 71 __typeof (newval) _newval = newval; \ 72 register __typeof (oldval) _a0 __asm__ ("a0") = _oldval; \ 73 register __typeof (newval) _a1 __asm__ ("a1") = _newval; \ 74 register __typeof (mem) _a2 __asm__ ("a2") = _mem; \ 75 __asm__ __volatile__ ("1:\n\t" \ 76 "ldw %1, (%4, 0x0)\n\t" \ 77 "cmpne %1, %0\n\t" \ 78 "bt 2f\n\t" \ 79 "mov %2, %0\n\t" \ 80 "trap 2\n\t" \ 81 "cmpnei %0, 0\n\t" \ 82 "mov %0, %2\n\t" \ 83 "bt 1b\n\t" \ 84 "2: \n\t" \ 85 :"+r" (_a0), "+r"(__gret), "+r" (_tmp) :"r" (_a1) , "r" (_a2) \ 86 : "a3", "memory"); \ 87 __gret; }) 88 89 # define __arch_compare_and_exchange_val_64_int(mem, newval, oldval) \ 90 (abort (), 0) 91 92 # define atomic_compare_and_exchange_bool_acq(mem, new, old) \ 93 __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \ 94 mem, new, old) 95 96 # define atomic_compare_and_exchange_val_acq(mem, new, old) \ 97 __atomic_val_bysize (__arch_compare_and_exchange_val, int, \ 98 mem, new, old) 99 100 #endif 101