]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2003-2015 Free Software Foundation, Inc. |
6752404e CD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2005. | |
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/>. */ | |
6752404e | 18 | |
783398d8 CD |
19 | #include <stdint.h> /* Required for type definitions e.g. uint8_t. */ |
20 | #include <abort-instr.h> /* Required for ABORT_INSTRUCTIUON. */ | |
21 | #include <kernel-features.h> /* Required for __ASSUME_LWS_CAS. */ | |
6752404e | 22 | |
3ad1f14c CD |
23 | /* We need EFAULT, ENONSYS */ |
24 | #if !defined EFAULT && !defined ENOSYS | |
6752404e CD |
25 | #define EFAULT 14 |
26 | #define ENOSYS 251 | |
6752404e CD |
27 | #endif |
28 | ||
29 | #ifndef _BITS_ATOMIC_H | |
30 | #define _BITS_ATOMIC_H 1 | |
31 | ||
32 | typedef int8_t atomic8_t; | |
33 | typedef uint8_t uatomic8_t; | |
34 | typedef int_fast8_t atomic_fast8_t; | |
35 | typedef uint_fast8_t uatomic_fast8_t; | |
36 | ||
37 | typedef int32_t atomic32_t; | |
38 | typedef uint32_t uatomic32_t; | |
39 | typedef int_fast32_t atomic_fast32_t; | |
40 | typedef uint_fast32_t uatomic_fast32_t; | |
41 | ||
42 | typedef intptr_t atomicptr_t; | |
43 | typedef uintptr_t uatomicptr_t; | |
44 | typedef intmax_t atomic_max_t; | |
45 | typedef uintmax_t uatomic_max_t; | |
46 | ||
1ea339b6 TR |
47 | #define __HAVE_64B_ATOMICS 0 |
48 | #define USE_ATOMIC_COMPILER_BUILTINS 0 | |
49 | ||
6752404e CD |
50 | /* prev = *addr; |
51 | if (prev == old) | |
52 | *addr = new; | |
53 | return prev; */ | |
54 | ||
5556231d | 55 | /* Use the kernel atomic light weight syscalls on hppa. */ |
2906e90e CD |
56 | #define _LWS "0xb0" |
57 | #define _LWS_CAS "0" | |
58 | /* Note r31 is the link register. */ | |
59 | #define _LWS_CLOBBER "r1", "r26", "r25", "r24", "r23", "r22", "r21", "r20", "r28", "r31", "memory" | |
60 | /* String constant for -EAGAIN. */ | |
5556231d | 61 | #define _ASM_EAGAIN "-11" |
2906e90e CD |
62 | /* String constant for -EDEADLOCK. */ |
63 | #define _ASM_EDEADLOCK "-45" | |
6752404e CD |
64 | |
65 | #if __ASSUME_LWS_CAS | |
66 | /* The only basic operation needed is compare and exchange. */ | |
5abebba4 | 67 | # define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \ |
6752404e | 68 | ({ \ |
2906e90e CD |
69 | volatile int lws_errno; \ |
70 | volatile int lws_ret; \ | |
6752404e CD |
71 | asm volatile( \ |
72 | "0: \n\t" \ | |
2906e90e CD |
73 | "copy %2, %%r26 \n\t" \ |
74 | "copy %3, %%r25 \n\t" \ | |
75 | "copy %4, %%r24 \n\t" \ | |
76 | "ble " _LWS "(%%sr2, %%r0) \n\t" \ | |
77 | "ldi " _LWS_CAS ", %%r20 \n\t" \ | |
78 | "ldi " _ASM_EAGAIN ", %%r24 \n\t" \ | |
79 | "cmpb,=,n %%r24, %%r21, 0b \n\t" \ | |
80 | "nop \n\t" \ | |
81 | "ldi " _ASM_EDEADLOCK ", %%r25 \n\t" \ | |
82 | "cmpb,=,n %%r25, %%r21, 0b \n\t" \ | |
6752404e CD |
83 | "nop \n\t" \ |
84 | "stw %%r28, %0 \n\t" \ | |
6752404e | 85 | "stw %%r21, %1 \n\t" \ |
5abebba4 | 86 | : "=m" (lws_ret), "=m" (lws_errno) \ |
6752404e | 87 | : "r" (mem), "r" (oldval), "r" (newval) \ |
2906e90e | 88 | : _LWS_CLOBBER \ |
6752404e | 89 | ); \ |
5abebba4 | 90 | \ |
0e8a8f6d | 91 | if(lws_errno == -EFAULT || lws_errno == -ENOSYS) \ |
5abebba4 CD |
92 | ABORT_INSTRUCTION; \ |
93 | \ | |
6752404e CD |
94 | lws_ret; \ |
95 | }) | |
96 | ||
5abebba4 | 97 | # define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \ |
6752404e CD |
98 | ({ \ |
99 | int ret; \ | |
100 | ret = atomic_compare_and_exchange_val_acq(mem, newval, oldval); \ | |
2906e90e | 101 | /* Return 1 if it was already acquired. */ \ |
8fe357d5 | 102 | (ret != (int)oldval); \ |
6752404e CD |
103 | }) |
104 | #else | |
3ad1f14c | 105 | # error __ASSUME_LWS_CAS is required to build glibc. |
5556231d | 106 | #endif |
3ad1f14c | 107 | /* __ASSUME_LWS_CAS */ |
6752404e | 108 | |
6752404e | 109 | #endif |
3ad1f14c | 110 | /* _BITS_ATOMIC_H */ |