]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/nios2/atomic-machine.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / nios2 / atomic-machine.h
1 /* Low-level functions for atomic operations. Nios II version.
2 Copyright (C) 2012-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _NIOS2_ATOMIC_MACHINE_H
20 #define _NIOS2_ATOMIC_MACHINE_H 1
21
22 #include <stdint.h>
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 intptr_t atomicptr_t;
30 typedef uintptr_t uatomicptr_t;
31 typedef intmax_t atomic_max_t;
32 typedef uintmax_t uatomic_max_t;
33
34 #define __HAVE_64B_ATOMICS 0
35 #define USE_ATOMIC_COMPILER_BUILTINS 0
36
37 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
38 (abort (), (__typeof (*mem)) 0)
39 #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
40 (abort (), (__typeof (*mem)) 0)
41 #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
42 (abort (), (__typeof (*mem)) 0)
43
44 #define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
45 (abort (), 0)
46 #define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \
47 (abort (), 0)
48 #define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
49 (abort (), 0)
50
51 #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
52 ({ \
53 register int r2 asm ("r2"); \
54 register int* r4 asm ("r4") = (int*)(mem); \
55 register int r5 asm ("r5"); \
56 register int r6 asm ("r6") = (int)(newval); \
57 int retval, orig_oldval = (int)(oldval); \
58 long kernel_cmpxchg = 0x1004; \
59 while (1) \
60 { \
61 r5 = *r4; \
62 if (r5 != orig_oldval) \
63 { \
64 retval = r5; \
65 break; \
66 } \
67 asm volatile ("callr %1\n" \
68 : "=r" (r2) \
69 : "r" (kernel_cmpxchg), "r" (r4), "r" (r5), "r" (r6) \
70 : "ra", "memory"); \
71 if (!r2) { retval = orig_oldval; break; } \
72 } \
73 (__typeof (*(mem))) retval; \
74 })
75
76 #define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
77 ({ \
78 register int r2 asm ("r2"); \
79 register int *r4 asm ("r4") = (int*)(mem); \
80 register int r5 asm ("r5") = (int)(oldval); \
81 register int r6 asm ("r6") = (int)(newval); \
82 long kernel_cmpxchg = 0x1004; \
83 asm volatile ("callr %1\n" \
84 : "=r" (r2) \
85 : "r" (kernel_cmpxchg), "r" (r4), "r" (r5), "r" (r6) \
86 : "ra", "memory"); \
87 r2; \
88 })
89
90 #define atomic_full_barrier() ({ asm volatile ("sync"); })
91
92 #endif /* _NIOS2_ATOMIC_MACHINE_H */