Home | History | Annotate | Line # | Download | only in sparc
      1  1.1.1.12  mrg /* Copyright (C) 2005-2024 Free Software Foundation, Inc.
      2       1.1  mrg    Contributed by Jakub Jelinek <jakub (at) redhat.com>.
      3       1.1  mrg 
      4   1.1.1.3  mrg    This file is part of the GNU Offloading and Multi Processing Library
      5   1.1.1.3  mrg    (libgomp).
      6       1.1  mrg 
      7       1.1  mrg    Libgomp is free software; you can redistribute it and/or modify it
      8       1.1  mrg    under the terms of the GNU General Public License as published by
      9       1.1  mrg    the Free Software Foundation; either version 3, or (at your option)
     10       1.1  mrg    any later version.
     11       1.1  mrg 
     12       1.1  mrg    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
     13       1.1  mrg    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     14       1.1  mrg    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     15       1.1  mrg    more details.
     16       1.1  mrg 
     17       1.1  mrg    Under Section 7 of GPL version 3, you are granted additional
     18       1.1  mrg    permissions described in the GCC Runtime Library Exception, version
     19       1.1  mrg    3.1, as published by the Free Software Foundation.
     20       1.1  mrg 
     21       1.1  mrg    You should have received a copy of the GNU General Public License and
     22       1.1  mrg    a copy of the GCC Runtime Library Exception along with this program;
     23       1.1  mrg    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     24       1.1  mrg    <http://www.gnu.org/licenses/>.  */
     25       1.1  mrg 
     26       1.1  mrg /* Provide target-specific access to the futex system call.  */
     27       1.1  mrg 
     28       1.1  mrg #include <sys/syscall.h>
     29       1.1  mrg 
     30       1.1  mrg static inline long
     31       1.1  mrg sys_futex0 (int *addr, int op, int val)
     32       1.1  mrg {
     33       1.1  mrg   register long int g1  __asm__ ("g1");
     34       1.1  mrg   register long int o0  __asm__ ("o0");
     35       1.1  mrg   register long int o1  __asm__ ("o1");
     36       1.1  mrg   register long int o2  __asm__ ("o2");
     37       1.1  mrg   register long int o3  __asm__ ("o3");
     38       1.1  mrg 
     39       1.1  mrg   g1 = SYS_futex;
     40       1.1  mrg   o0 = (long) addr;
     41       1.1  mrg   o1 = op;
     42       1.1  mrg   o2 = val;
     43       1.1  mrg   o3 = 0;
     44       1.1  mrg 
     45       1.1  mrg #ifdef __arch64__
     46       1.1  mrg # define SYSCALL_STRING "ta\t0x6d; bcs,a,pt %%xcc, 1f; sub %%g0, %%o0, %%o0; 1:"
     47       1.1  mrg #else
     48       1.1  mrg # define SYSCALL_STRING "ta\t0x10; bcs,a 1f; sub %%g0, %%o0, %%o0; 1:"
     49       1.1  mrg #endif
     50       1.1  mrg 
     51       1.1  mrg   __asm volatile (SYSCALL_STRING
     52       1.1  mrg 		  : "=r" (g1), "=r" (o0)
     53       1.1  mrg 		  : "0" (g1), "1" (o0), "r" (o1), "r" (o2), "r" (o3)
     54       1.1  mrg 		  : "g2", "g3", "g4", "g5", "g6",
     55       1.1  mrg 		    "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
     56       1.1  mrg 		    "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
     57       1.1  mrg 		    "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
     58       1.1  mrg 		    "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
     59       1.1  mrg #ifdef __arch64__
     60       1.1  mrg 		    "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
     61       1.1  mrg 		    "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
     62       1.1  mrg #endif
     63       1.1  mrg 		    "cc", "memory");
     64       1.1  mrg   return o0;
     65       1.1  mrg }
     66       1.1  mrg 
     67       1.1  mrg static inline void
     68       1.1  mrg futex_wait (int *addr, int val)
     69       1.1  mrg {
     70       1.1  mrg   long err = sys_futex0 (addr, gomp_futex_wait, val);
     71       1.1  mrg   if (__builtin_expect (err == ENOSYS, 0))
     72       1.1  mrg     {
     73       1.1  mrg       gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
     74       1.1  mrg       gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
     75       1.1  mrg       sys_futex0 (addr, gomp_futex_wait, val);
     76       1.1  mrg     }
     77       1.1  mrg }
     78       1.1  mrg 
     79       1.1  mrg static inline void
     80       1.1  mrg futex_wake (int *addr, int count)
     81       1.1  mrg {
     82       1.1  mrg   long err = sys_futex0 (addr, gomp_futex_wake, count);
     83       1.1  mrg   if (__builtin_expect (err == ENOSYS, 0))
     84       1.1  mrg     {
     85       1.1  mrg       gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
     86       1.1  mrg       gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
     87       1.1  mrg       sys_futex0 (addr, gomp_futex_wake, count);
     88       1.1  mrg     }
     89       1.1  mrg }
     90       1.1  mrg 
     91       1.1  mrg static inline void
     92       1.1  mrg cpu_relax (void)
     93       1.1  mrg {
     94   1.1.1.2  mrg   __asm volatile ("rd %%ccr, %%g0" : : : "memory");
     95       1.1  mrg }
     96