|
Packit |
6c4009 |
/* Copyright (C) 2010-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library. If not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef _ATOMIC_MACHINE_H
|
|
Packit |
6c4009 |
#define _ATOMIC_MACHINE_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
#include <m68k-vdso.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Coldfire has no atomic compare-and-exchange operation, but the
|
|
Packit |
6c4009 |
kernel provides userspace atomicity operations. Use them. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
typedef int32_t atomic32_t;
|
|
Packit |
6c4009 |
typedef uint32_t uatomic32_t;
|
|
Packit |
6c4009 |
typedef int_fast32_t atomic_fast32_t;
|
|
Packit |
6c4009 |
typedef uint_fast32_t uatomic_fast32_t;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
typedef intptr_t atomicptr_t;
|
|
Packit |
6c4009 |
typedef uintptr_t uatomicptr_t;
|
|
Packit |
6c4009 |
typedef intmax_t atomic_max_t;
|
|
Packit |
6c4009 |
typedef uintmax_t uatomic_max_t;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define __HAVE_64B_ATOMICS 0
|
|
Packit |
6c4009 |
#define USE_ATOMIC_COMPILER_BUILTINS 0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* XXX Is this actually correct? */
|
|
Packit |
6c4009 |
#define ATOMIC_EXCHANGE_USES_CAS 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The only basic operation needed is compare and exchange. */
|
|
Packit |
6c4009 |
/* For ColdFire we'll have to trap into the kernel mode anyway,
|
|
Packit |
6c4009 |
so trap from the library rather then from the kernel wrapper. */
|
|
Packit |
6c4009 |
#ifdef SHARED
|
|
Packit |
6c4009 |
# define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
/* Use temporary variables to workaround call-clobberness of \
|
|
Packit |
6c4009 |
the registers. */ \
|
|
Packit |
6c4009 |
__typeof (mem) _mem = mem; \
|
|
Packit |
6c4009 |
__typeof (oldval) _oldval = oldval; \
|
|
Packit |
6c4009 |
__typeof (newval) _newval = newval; \
|
|
Packit |
6c4009 |
register uint32_t *_a0 asm ("a0") = (uint32_t *) _mem; \
|
|
Packit |
6c4009 |
register uint32_t _d0 asm ("d0") = (uint32_t) _oldval; \
|
|
Packit |
6c4009 |
register uint32_t _d1 asm ("d1") = (uint32_t) _newval; \
|
|
Packit |
6c4009 |
void *tmp; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
asm ("movel #_GLOBAL_OFFSET_TABLE_@GOTPC, %2\n\t" \
|
|
Packit |
6c4009 |
"lea (-6, %%pc, %2), %2\n\t" \
|
|
Packit |
6c4009 |
"movel " STR_M68K_VDSO_SYMBOL (__vdso_atomic_cmpxchg_32) \
|
|
Packit |
6c4009 |
"@GOT(%2), %2\n\t" \
|
|
Packit |
6c4009 |
"movel (%2), %2\n\t" \
|
|
Packit |
6c4009 |
"jsr (%2)\n\t" \
|
|
Packit |
6c4009 |
: "+d" (_d0), "+m" (*_a0), "=&a" (tmp) \
|
|
Packit |
6c4009 |
: "a" (_a0), "d" (_d1)); \
|
|
Packit |
6c4009 |
(__typeof (oldval)) _d0; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
/* Use temporary variables to workaround call-clobberness of \
|
|
Packit |
6c4009 |
the registers. */ \
|
|
Packit |
6c4009 |
__typeof (mem) _mem = mem; \
|
|
Packit |
6c4009 |
__typeof (oldval) _oldval = oldval; \
|
|
Packit |
6c4009 |
__typeof (newval) _newval = newval; \
|
|
Packit |
6c4009 |
register uint32_t _d0 asm ("d0") = SYS_ify (atomic_cmpxchg_32); \
|
|
Packit |
6c4009 |
register uint32_t *_a0 asm ("a0") = (uint32_t *) _mem; \
|
|
Packit |
6c4009 |
register uint32_t _d2 asm ("d2") = (uint32_t) _oldval; \
|
|
Packit |
6c4009 |
register uint32_t _d1 asm ("d1") = (uint32_t) _newval; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
asm ("trap #0" \
|
|
Packit |
6c4009 |
: "+d" (_d0), "+m" (*_a0) \
|
|
Packit |
6c4009 |
: "a" (_a0), "d" (_d2), "d" (_d1)); \
|
|
Packit |
6c4009 |
(__typeof (oldval)) _d0; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef SHARED
|
|
Packit |
6c4009 |
# define atomic_full_barrier() \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
void *tmp; \
|
|
Packit |
6c4009 |
\
|
|
Packit |
6c4009 |
asm ("movel #_GLOBAL_OFFSET_TABLE_@GOTPC, %0\n\t" \
|
|
Packit |
6c4009 |
"lea (-6, %pc, %0), %0\n\t" \
|
|
Packit |
6c4009 |
"movel " STR_M68K_VDSO_SYMBOL (__vdso_atomic_barrier) \
|
|
Packit |
6c4009 |
"@GOT(%0), %0\n\t" \
|
|
Packit |
6c4009 |
"movel (%0), %0\n\t" \
|
|
Packit |
6c4009 |
"jsr (%0)\n\t" \
|
|
Packit |
6c4009 |
: "=&a" (tmp)); \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# define atomic_full_barrier() \
|
|
Packit |
6c4009 |
(INTERNAL_SYSCALL (atomic_barrier, , 0), (void) 0)
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif
|