1 /* Copyright (C) 2011-2018 Free Software Foundation, Inc.
2    Contributed by Walter Lee (walt@tilera.com)
3 
4    This file is part of the GNU Offloading and Multi Processing Library
5    (libgomp).
6 
7    Libgomp is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11 
12    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15    more details.
16 
17    Under Section 7 of GPL version 3, you are granted additional
18    permissions described in the GCC Runtime Library Exception, version
19    3.1, as published by the Free Software Foundation.
20 
21    You should have received a copy of the GNU General Public License and
22    a copy of the GCC Runtime Library Exception along with this program;
23    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24    <http://www.gnu.org/licenses/>.  */
25 
26 /* Provide target-specific access to the futex system call.  */
27 
28 #include <sys/syscall.h>
29 #include <linux/futex.h>
30 
31 static inline void
sys_futex0(int * addr,int op,int val)32 sys_futex0 (int *addr, int op, int val)
33 {
34   long _sys_result;
35   long _clobber_r2, _clobber_r3, _clobber_r4, _clobber_r5, _clobber_r10;
36   int err;
37 
38   __asm__ __volatile__ (
39     "swint1"
40     : "=R00" (_sys_result), "=R01" (err), "=R02" (_clobber_r2),
41       "=R03" (_clobber_r3), "=R04" (_clobber_r4), "=R05" (_clobber_r5),
42       "=R10" (_clobber_r10)
43     : "R10" (SYS_futex), "R00" (addr), "R01" (op), "R02" (val),
44       "R03" (0)
45     :  "r6",  "r7",
46        "r8",  "r9",        "r11", "r12", "r13", "r14", "r15",
47       "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
48       "r24", "r25", "r26", "r27", "r28", "r29", "memory");
49 }
50 
51 static inline void
futex_wait(int * addr,int val)52 futex_wait (int *addr, int val)
53 {
54   sys_futex0 (addr, FUTEX_WAIT, val);
55 }
56 
57 static inline void
futex_wake(int * addr,int count)58 futex_wake (int *addr, int count)
59 {
60   sys_futex0 (addr, FUTEX_WAKE, count);
61 }
62 
63 static inline void
cpu_relax(void)64 cpu_relax (void)
65 {
66   __asm volatile ("" : : : "memory");
67 }
68 
69 static inline void
atomic_write_barrier(void)70 atomic_write_barrier (void)
71 {
72   __sync_synchronize ();
73 }
74