|
Packit Service |
82fcde |
/* Low-level functions for atomic operations. Nios II version.
|
|
Packit Service |
82fcde |
Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library. If not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifndef _NIOS2_ATOMIC_MACHINE_H
|
|
Packit Service |
82fcde |
#define _NIOS2_ATOMIC_MACHINE_H 1
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <stdint.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef int32_t atomic32_t;
|
|
Packit Service |
82fcde |
typedef uint32_t uatomic32_t;
|
|
Packit Service |
82fcde |
typedef int_fast32_t atomic_fast32_t;
|
|
Packit Service |
82fcde |
typedef uint_fast32_t uatomic_fast32_t;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef intptr_t atomicptr_t;
|
|
Packit Service |
82fcde |
typedef uintptr_t uatomicptr_t;
|
|
Packit Service |
82fcde |
typedef intmax_t atomic_max_t;
|
|
Packit Service |
82fcde |
typedef uintmax_t uatomic_max_t;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __HAVE_64B_ATOMICS 0
|
|
Packit Service |
82fcde |
#define USE_ATOMIC_COMPILER_BUILTINS 0
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* XXX Is this actually correct? */
|
|
Packit Service |
82fcde |
#define ATOMIC_EXCHANGE_USES_CAS 1
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), 0)
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), 0)
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
register int r2 asm ("r2"); \
|
|
Packit Service |
82fcde |
register int* r4 asm ("r4") = (int*)(mem); \
|
|
Packit Service |
82fcde |
register int r5 asm ("r5"); \
|
|
Packit Service |
82fcde |
register int r6 asm ("r6") = (int)(newval); \
|
|
Packit Service |
82fcde |
int retval, orig_oldval = (int)(oldval); \
|
|
Packit Service |
82fcde |
long kernel_cmpxchg = 0x1004; \
|
|
Packit Service |
82fcde |
while (1) \
|
|
Packit Service |
82fcde |
{ \
|
|
Packit Service |
82fcde |
r5 = *r4; \
|
|
Packit Service |
82fcde |
if (r5 != orig_oldval) \
|
|
Packit Service |
82fcde |
{ \
|
|
Packit Service |
82fcde |
retval = r5; \
|
|
Packit Service |
82fcde |
break; \
|
|
Packit Service |
82fcde |
} \
|
|
Packit Service |
82fcde |
asm volatile ("callr %1\n" \
|
|
Packit Service |
82fcde |
: "=r" (r2) \
|
|
Packit Service |
82fcde |
: "r" (kernel_cmpxchg), "r" (r4), "r" (r5), "r" (r6) \
|
|
Packit Service |
82fcde |
: "ra", "memory"); \
|
|
Packit Service |
82fcde |
if (!r2) { retval = orig_oldval; break; } \
|
|
Packit Service |
82fcde |
} \
|
|
Packit Service |
82fcde |
(__typeof (*(mem))) retval; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
register int r2 asm ("r2"); \
|
|
Packit Service |
82fcde |
register int *r4 asm ("r4") = (int*)(mem); \
|
|
Packit Service |
82fcde |
register int r5 asm ("r5") = (int)(oldval); \
|
|
Packit Service |
82fcde |
register int r6 asm ("r6") = (int)(newval); \
|
|
Packit Service |
82fcde |
long kernel_cmpxchg = 0x1004; \
|
|
Packit Service |
82fcde |
asm volatile ("callr %1\n" \
|
|
Packit Service |
82fcde |
: "=r" (r2) \
|
|
Packit Service |
82fcde |
: "r" (kernel_cmpxchg), "r" (r4), "r" (r5), "r" (r6) \
|
|
Packit Service |
82fcde |
: "ra", "memory"); \
|
|
Packit Service |
82fcde |
r2; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_full_barrier() ({ asm volatile ("sync"); })
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#endif /* _NIOS2_ATOMIC_MACHINE_H */
|