]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/m68k/coldfire/atomic-machine.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / m68k / coldfire / atomic-machine.h
1 /* Copyright (C) 2010-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.
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 _ATOMIC_MACHINE_H
20 #define _ATOMIC_MACHINE_H 1
21
22 #include <stdint.h>
23 #include <sysdep.h>
24 #include <m68k-vdso.h>
25
26 /* Coldfire has no atomic compare-and-exchange operation, but the
27 kernel provides userspace atomicity operations. Use them. */
28
29 typedef int32_t atomic32_t;
30 typedef uint32_t uatomic32_t;
31 typedef int_fast32_t atomic_fast32_t;
32 typedef uint_fast32_t uatomic_fast32_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 __HAVE_64B_ATOMICS 0
40 #define USE_ATOMIC_COMPILER_BUILTINS 0
41
42 /* XXX Is this actually correct? */
43 #define ATOMIC_EXCHANGE_USES_CAS 1
44
45 /* The only basic operation needed is compare and exchange. */
46 /* For ColdFire we'll have to trap into the kernel mode anyway,
47 so trap from the library rather then from the kernel wrapper. */
48 #ifdef SHARED
49 # define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
50 ({ \
51 /* Use temporary variables to workaround call-clobberness of \
52 the registers. */ \
53 __typeof (mem) _mem = mem; \
54 __typeof (oldval) _oldval = oldval; \
55 __typeof (newval) _newval = newval; \
56 register uint32_t *_a0 asm ("a0") = (uint32_t *) _mem; \
57 register uint32_t _d0 asm ("d0") = (uint32_t) _oldval; \
58 register uint32_t _d1 asm ("d1") = (uint32_t) _newval; \
59 void *tmp; \
60 \
61 asm ("movel #_GLOBAL_OFFSET_TABLE_@GOTPC, %2\n\t" \
62 "lea (-6, %%pc, %2), %2\n\t" \
63 "movel " STR_M68K_VDSO_SYMBOL (__vdso_atomic_cmpxchg_32) \
64 "@GOT(%2), %2\n\t" \
65 "movel (%2), %2\n\t" \
66 "jsr (%2)\n\t" \
67 : "+d" (_d0), "+m" (*_a0), "=&a" (tmp) \
68 : "a" (_a0), "d" (_d1)); \
69 (__typeof (oldval)) _d0; \
70 })
71 #else
72 # define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
73 ({ \
74 /* Use temporary variables to workaround call-clobberness of \
75 the registers. */ \
76 __typeof (mem) _mem = mem; \
77 __typeof (oldval) _oldval = oldval; \
78 __typeof (newval) _newval = newval; \
79 register uint32_t _d0 asm ("d0") = SYS_ify (atomic_cmpxchg_32); \
80 register uint32_t *_a0 asm ("a0") = (uint32_t *) _mem; \
81 register uint32_t _d2 asm ("d2") = (uint32_t) _oldval; \
82 register uint32_t _d1 asm ("d1") = (uint32_t) _newval; \
83 \
84 asm ("trap #0" \
85 : "+d" (_d0), "+m" (*_a0) \
86 : "a" (_a0), "d" (_d2), "d" (_d1)); \
87 (__typeof (oldval)) _d0; \
88 })
89 #endif
90
91 #ifdef SHARED
92 # define atomic_full_barrier() \
93 ({ \
94 void *tmp; \
95 \
96 asm ("movel #_GLOBAL_OFFSET_TABLE_@GOTPC, %0\n\t" \
97 "lea (-6, %pc, %0), %0\n\t" \
98 "movel " STR_M68K_VDSO_SYMBOL (__vdso_atomic_barrier) \
99 "@GOT(%0), %0\n\t" \
100 "movel (%0), %0\n\t" \
101 "jsr (%0)\n\t" \
102 : "=&a" (tmp)); \
103 })
104 #else
105 # define atomic_full_barrier() \
106 (INTERNAL_SYSCALL (atomic_barrier, , 0), (void) 0)
107 #endif
108
109 #endif