1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2005.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <abort-instr.h>
23 #include <kernel-features.h>
25 /* We need EFAULT, ENONSYS */
26 #if !defined EFAULT && !defined ENOSYS
31 #ifndef _BITS_ATOMIC_H
32 #define _BITS_ATOMIC_H 1
34 typedef int8_t atomic8_t;
35 typedef uint8_t uatomic8_t;
36 typedef int_fast8_t atomic_fast8_t;
37 typedef uint_fast8_t uatomic_fast8_t;
39 typedef int32_t atomic32_t;
40 typedef uint32_t uatomic32_t;
41 typedef int_fast32_t atomic_fast32_t;
42 typedef uint_fast32_t uatomic_fast32_t;
44 typedef intptr_t atomicptr_t;
45 typedef uintptr_t uatomicptr_t;
46 typedef intmax_t atomic_max_t;
47 typedef uintmax_t uatomic_max_t;
54 /* Use the kernel atomic light weight syscalls on hppa */
57 /* Note r31 is the link register */
58 #define LWS_CLOBBER "r1", "r26", "r25", "r24", "r23", "r22", "r21", "r20", "r28", "r31", "memory"
59 #define ASM_EAGAIN "11"
62 /* The only basic operation needed is compare and exchange. */
63 # define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
65 volatile int lws_errno = EFAULT; \
66 volatile int lws_ret = 0xdeadbeef; \
69 "copy %3, %%r26 \n\t" \
70 "copy %4, %%r25 \n\t" \
71 "copy %5, %%r24 \n\t" \
72 "ble " LWS "(%%sr2, %%r0) \n\t" \
73 "ldi " LWS_CAS ", %%r20 \n\t" \
74 "cmpib,=,n " ASM_EAGAIN ",%%r21,0b \n\t" \
76 "stw %%r28, %0 \n\t" \
77 "sub %%r0, %%r21, %%r21 \n\t" \
78 "stw %%r21, %1 \n\t" \
79 : "=m" (lws_ret), "=m" (lws_errno), "=m" (*mem) \
80 : "r" (mem), "r" (oldval), "r" (newval) \
84 if(lws_errno == EFAULT || lws_errno == ENOSYS) \
90 # define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
93 ret = atomic_compare_and_exchange_val_acq(mem, newval, oldval); \
94 /* Return 1 if it was already acquired */ \
98 # error __ASSUME_LWS_CAS is required to build glibc.
100 /* __ASSUME_LWS_CAS */