]>
Commit | Line | Data |
---|---|---|
5624e564 | 1 | /* Copyright (C) 2005-2015 Free Software Foundation, Inc. |
953ff289 DN |
2 | Contributed by Richard Henderson <rth@redhat.com>. |
3 | ||
f1f3453e TS |
4 | This file is part of the GNU Offloading and Multi Processing Library |
5 | (libgomp). | |
953ff289 DN |
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. | |
953ff289 DN |
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 |
953ff289 DN |
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/>. */ | |
953ff289 DN |
25 | |
26 | /* Provide target-specific access to the futex system call. */ | |
27 | ||
c01ecafc | 28 | #ifdef __x86_64__ |
953ff289 DN |
29 | # ifndef SYS_futex |
30 | # define SYS_futex 202 | |
31 | # endif | |
32 | ||
33 | static inline void | |
34 | futex_wait (int *addr, int val) | |
35 | { | |
a68ab351 | 36 | register long r10 __asm__("%r10"); |
953ff289 DN |
37 | long res; |
38 | ||
a68ab351 | 39 | r10 = 0; |
953ff289 DN |
40 | __asm volatile ("syscall" |
41 | : "=a" (res) | |
a68ab351 JJ |
42 | : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait), |
43 | "d" (val), "r" (r10) | |
953ff289 | 44 | : "r11", "rcx", "memory"); |
a68ab351 JJ |
45 | if (__builtin_expect (res == -ENOSYS, 0)) |
46 | { | |
47 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
48 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
49 | r10 = 0; | |
50 | __asm volatile ("syscall" | |
51 | : "=a" (res) | |
52 | : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait), | |
53 | "d" (val), "r" (r10) | |
54 | : "r11", "rcx", "memory"); | |
55 | } | |
953ff289 DN |
56 | } |
57 | ||
58 | static inline void | |
59 | futex_wake (int *addr, int count) | |
60 | { | |
61 | long res; | |
62 | ||
63 | __asm volatile ("syscall" | |
64 | : "=a" (res) | |
a68ab351 JJ |
65 | : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake), |
66 | "d" (count) | |
953ff289 | 67 | : "r11", "rcx", "memory"); |
a68ab351 JJ |
68 | if (__builtin_expect (res == -ENOSYS, 0)) |
69 | { | |
70 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
71 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
72 | __asm volatile ("syscall" | |
73 | : "=a" (res) | |
74 | : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake), | |
75 | "d" (count) | |
76 | : "r11", "rcx", "memory"); | |
77 | } | |
953ff289 DN |
78 | } |
79 | #else | |
80 | # ifndef SYS_futex | |
81 | # define SYS_futex 240 | |
82 | # endif | |
83 | ||
a68ab351 | 84 | static inline long |
8ed501f1 | 85 | sys_futex0 (int *addr, int op, int val) |
953ff289 DN |
86 | { |
87 | long res; | |
88 | ||
89 | __asm volatile ("int $0x80" | |
90 | : "=a" (res) | |
91 | : "0"(SYS_futex), "b" (addr), "c"(op), | |
92 | "d"(val), "S"(0) | |
93 | : "memory"); | |
a68ab351 | 94 | return res; |
953ff289 DN |
95 | } |
96 | ||
953ff289 DN |
97 | static inline void |
98 | futex_wait (int *addr, int val) | |
99 | { | |
a68ab351 JJ |
100 | long res = sys_futex0 (addr, gomp_futex_wait, val); |
101 | if (__builtin_expect (res == -ENOSYS, 0)) | |
102 | { | |
103 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
104 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
105 | sys_futex0 (addr, gomp_futex_wait, val); | |
106 | } | |
953ff289 DN |
107 | } |
108 | ||
109 | static inline void | |
110 | futex_wake (int *addr, int count) | |
111 | { | |
a68ab351 JJ |
112 | long res = sys_futex0 (addr, gomp_futex_wake, count); |
113 | if (__builtin_expect (res == -ENOSYS, 0)) | |
114 | { | |
115 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
116 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
117 | sys_futex0 (addr, gomp_futex_wake, count); | |
118 | } | |
953ff289 DN |
119 | } |
120 | ||
c01ecafc | 121 | #endif /* __x86_64__ */ |
a68ab351 JJ |
122 | |
123 | static inline void | |
124 | cpu_relax (void) | |
125 | { | |
68a12ef3 | 126 | __builtin_ia32_pause (); |
a68ab351 | 127 | } |