]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | /* Copyright (C) 2005-2024 Free Software Foundation, Inc. |
318e8c3f IG |
2 | Contributed by Ilie Garbacea <ilie@mips.com>, Chao-ying Fu <fu@mips.com>. |
3 | ||
f1f3453e TS |
4 | This file is part of the GNU Offloading and Multi Processing Library |
5 | (libgomp). | |
318e8c3f IG |
6 | |
7 | Libgomp is free software; you can redistribute it and/or modify it | |
748086b7 JJ |
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. | |
318e8c3f IG |
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 | |
748086b7 | 14 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
318e8c3f IG |
15 | more details. |
16 | ||
748086b7 JJ |
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/>. */ | |
318e8c3f IG |
25 | |
26 | /* Provide target-specific access to the futex system call. */ | |
27 | ||
28 | #include <sys/syscall.h> | |
c8451a46 SE |
29 | |
30 | #if !defined (SYS_futex) | |
31 | #define SYS_futex __NR_futex | |
32 | #endif | |
33 | ||
318e8c3f IG |
34 | #define FUTEX_WAIT 0 |
35 | #define FUTEX_WAKE 1 | |
36 | ||
c24dbebb CLT |
37 | #ifdef __mips16 |
38 | static void __attribute__((noinline,nomips16)) | |
39 | #else | |
318e8c3f | 40 | static inline void |
c24dbebb | 41 | #endif |
318e8c3f IG |
42 | sys_futex0 (int *addr, int op, int val) |
43 | { | |
c24dbebb | 44 | register unsigned long __v0 asm("$2"); |
318e8c3f IG |
45 | register unsigned long __a0 asm("$4") = (unsigned long) addr; |
46 | register unsigned long __a1 asm("$5") = (unsigned long) op; | |
47 | register unsigned long __a2 asm("$6") = (unsigned long) val; | |
48 | register unsigned long __a3 asm("$7") = 0; | |
49 | ||
c24dbebb CLT |
50 | __asm volatile ("li $2, %6\n\t" |
51 | "syscall" | |
318e8c3f IG |
52 | /* returns $a3 (errno), $v0 (return value) */ |
53 | : "=r" (__v0), "=r" (__a3) | |
c24dbebb CLT |
54 | /* arguments in a0-a3, and syscall number */ |
55 | : "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a3), | |
56 | "IK" (SYS_futex) | |
318e8c3f IG |
57 | /* clobbers at, v1, t0-t9, memory */ |
58 | : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", "$14", | |
59 | "$15", "$24", "$25", "memory"); | |
60 | } | |
61 | ||
62 | static inline void | |
63 | futex_wait (int *addr, int val) | |
64 | { | |
65 | sys_futex0 (addr, FUTEX_WAIT, val); | |
66 | } | |
67 | ||
68 | static inline void | |
69 | futex_wake (int *addr, int count) | |
70 | { | |
71 | sys_futex0 (addr, FUTEX_WAKE, count); | |
72 | } | |
73 | ||
74 | static inline void | |
75 | cpu_relax (void) | |
76 | { | |
77 | __asm volatile ("" : : : "memory"); | |
78 | } |