Home | History | Annotate | Line # | Download | only in alpha
      1 /* Copyright (C) 2005-2024 Free Software Foundation, Inc.
      2    Contributed by Richard Henderson <rth (at) redhat.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 #ifndef SYS_futex
     29 #define SYS_futex               394
     30 #endif
     31 
     32 
     33 static inline void
     34 futex_wait (int *addr, int val)
     35 {
     36   register long sc_0 __asm__("$0");
     37   register long sc_16 __asm__("$16");
     38   register long sc_17 __asm__("$17");
     39   register long sc_18 __asm__("$18");
     40   register long sc_19 __asm__("$19");
     41 
     42   sc_0 = SYS_futex;
     43   sc_16 = (long) addr;
     44   sc_17 = gomp_futex_wait;
     45   sc_18 = val;
     46   sc_19 = 0;
     47   __asm volatile ("callsys"
     48 		  : "=r" (sc_0), "=r"(sc_19)
     49 		  : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18), "1"(sc_19)
     50 		  : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",
     51 		    "$22", "$23", "$24", "$25", "$27", "$28", "memory");
     52   if (__builtin_expect (sc_19, 0) && sc_0 == ENOSYS)
     53     {
     54       gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
     55       gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
     56       sc_0 = SYS_futex;
     57       sc_17 &= ~FUTEX_PRIVATE_FLAG;
     58       sc_19 = 0;
     59       __asm volatile ("callsys"
     60 		      : "=r" (sc_0), "=r"(sc_19)
     61 		      : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18),
     62 			"1"(sc_19)
     63 		      : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",
     64 			"$22", "$23", "$24", "$25", "$27", "$28", "memory");
     65     }
     66 }
     67 
     68 static inline void
     69 futex_wake (int *addr, int count)
     70 {
     71   register long sc_0 __asm__("$0");
     72   register long sc_16 __asm__("$16");
     73   register long sc_17 __asm__("$17");
     74   register long sc_18 __asm__("$18");
     75   register long sc_19 __asm__("$19");
     76 
     77   sc_0 = SYS_futex;
     78   sc_16 = (long) addr;
     79   sc_17 = gomp_futex_wake;
     80   sc_18 = count;
     81   __asm volatile ("callsys"
     82 		  : "=r" (sc_0), "=r"(sc_19)
     83 		  : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18)
     84 		  : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",
     85 		    "$22", "$23", "$24", "$25", "$27", "$28", "memory");
     86   if (__builtin_expect (sc_19, 0) && sc_0 == ENOSYS)
     87     {
     88       gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
     89       gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
     90       sc_0 = SYS_futex;
     91       sc_17 &= ~FUTEX_PRIVATE_FLAG;
     92       __asm volatile ("callsys"
     93 		      : "=r" (sc_0), "=r"(sc_19)
     94 		      : "0"(sc_0), "r" (sc_16), "r"(sc_17), "r"(sc_18)
     95 		      : "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8",
     96 			"$22", "$23", "$24", "$25", "$27", "$28", "memory");
     97     }
     98 }
     99 
    100 static inline void
    101 cpu_relax (void)
    102 {
    103   __asm volatile ("" : : : "memory");
    104 }
    105