]> git.ipfire.org Git - thirdparty/glibc.git/blame - 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
CommitLineData
f7a9f785 1/* Copyright (C) 2010-2016 Free Software Foundation, Inc.
40111cb9
MK
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
ab84e3ff
PE
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
40111cb9 18
de071d19
JM
19#ifndef _ATOMIC_MACHINE_H
20#define _ATOMIC_MACHINE_H 1
40111cb9
MK
21
22#include <stdint.h>
23#include <sysdep.h>
0f4341fb 24#include <m68k-vdso.h>
40111cb9
MK
25
26/* Coldfire has no atomic compare-and-exchange operation, but the
27 kernel provides userspace atomicity operations. Use them. */
28
29typedef int32_t atomic32_t;
30typedef uint32_t uatomic32_t;
31typedef int_fast32_t atomic_fast32_t;
32typedef uint_fast32_t uatomic_fast32_t;
33
34typedef intptr_t atomicptr_t;
35typedef uintptr_t uatomicptr_t;
36typedef intmax_t atomic_max_t;
37typedef uintmax_t uatomic_max_t;
38
1ea339b6
TR
39#define __HAVE_64B_ATOMICS 0
40#define USE_ATOMIC_COMPILER_BUILTINS 0
41
40111cb9
MK
42/* The only basic operation needed is compare and exchange. */
43/* For ColdFire we'll have to trap into the kernel mode anyway,
44 so trap from the library rather then from the kernel wrapper. */
45#ifdef SHARED
46# define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
47 ({ \
3b7d2b39
AS
48 /* Use temporary variables to workaround call-clobberness of \
49 the registers. */ \
40111cb9
MK
50 __typeof (mem) _mem = mem; \
51 __typeof (oldval) _oldval = oldval; \
52 __typeof (newval) _newval = newval; \
45819cbc
AS
53 register uint32_t *_a0 asm ("a0") = (uint32_t *) _mem; \
54 register uint32_t _d0 asm ("d0") = (uint32_t) _oldval; \
55 register uint32_t _d1 asm ("d1") = (uint32_t) _newval; \
40111cb9
MK
56 void *tmp; \
57 \
58 asm ("movel #_GLOBAL_OFFSET_TABLE_@GOTPC, %2\n\t" \
59 "lea (-6, %%pc, %2), %2\n\t" \
60 "movel " STR_M68K_VDSO_SYMBOL (__vdso_atomic_cmpxchg_32) \
61 "@GOT(%2), %2\n\t" \
62 "movel (%2), %2\n\t" \
63 "jsr (%2)\n\t" \
64 : "+d" (_d0), "+m" (*_a0), "=&a" (tmp) \
65 : "a" (_a0), "d" (_d1)); \
45819cbc 66 (__typeof (oldval)) _d0; \
40111cb9
MK
67 })
68#else
69# define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
70 ({ \
3b7d2b39
AS
71 /* Use temporary variables to workaround call-clobberness of \
72 the registers. */ \
40111cb9
MK
73 __typeof (mem) _mem = mem; \
74 __typeof (oldval) _oldval = oldval; \
75 __typeof (newval) _newval = newval; \
45819cbc
AS
76 register uint32_t _d0 asm ("d0") = SYS_ify (atomic_cmpxchg_32); \
77 register uint32_t *_a0 asm ("a0") = (uint32_t *) _mem; \
78 register uint32_t _d2 asm ("d2") = (uint32_t) _oldval; \
79 register uint32_t _d1 asm ("d1") = (uint32_t) _newval; \
40111cb9
MK
80 \
81 asm ("trap #0" \
82 : "+d" (_d0), "+m" (*_a0) \
83 : "a" (_a0), "d" (_d2), "d" (_d1)); \
45819cbc 84 (__typeof (oldval)) _d0; \
40111cb9
MK
85 })
86#endif
87
88#ifdef SHARED
89# define atomic_full_barrier() \
90 ({ \
91 void *tmp; \
92 \
93 asm ("movel #_GLOBAL_OFFSET_TABLE_@GOTPC, %0\n\t" \
94 "lea (-6, %pc, %0), %0\n\t" \
95 "movel " STR_M68K_VDSO_SYMBOL (__vdso_atomic_barrier) \
96 "@GOT(%0), %0\n\t" \
97 "movel (%0), %0\n\t" \
98 "jsr (%0)\n\t" \
99 : "=&a" (tmp)); \
100 })
101#else
102# define atomic_full_barrier() \
103 (INTERNAL_SYSCALL (atomic_barrier, , 0), (void) 0)
104#endif
105
106#endif