1169695Skan/* Copyright (C) 2005 Free Software Foundation, Inc. 2169695Skan Contributed by Jakub Jelinek <jakub@redhat.com>. 3169695Skan 4169695Skan This file is part of the GNU OpenMP Library (libgomp). 5169695Skan 6169695Skan Libgomp is free software; you can redistribute it and/or modify it 7169695Skan under the terms of the GNU Lesser General Public License as published by 8169695Skan the Free Software Foundation; either version 2.1 of the License, or 9169695Skan (at your option) any later version. 10169695Skan 11169695Skan Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY 12169695Skan WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13169695Skan FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 14169695Skan more details. 15169695Skan 16169695Skan You should have received a copy of the GNU Lesser General Public License 17169695Skan along with libgomp; see the file COPYING.LIB. If not, write to the 18169695Skan Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19169695Skan MA 02110-1301, USA. */ 20169695Skan 21169695Skan/* As a special exception, if you link this library with other files, some 22169695Skan of which are compiled with GCC, to produce an executable, this library 23169695Skan does not by itself cause the resulting executable to be covered by the 24169695Skan GNU General Public License. This exception does not however invalidate 25169695Skan any other reasons why the executable file might be covered by the GNU 26169695Skan General Public License. */ 27169695Skan 28169695Skan/* Provide target-specific access to the futex system call. */ 29169695Skan 30169695Skan#include <sys/syscall.h> 31169695Skan#define FUTEX_WAIT 0 32169695Skan#define FUTEX_WAKE 1 33169695Skan 34169695Skanstatic inline void 35169695Skansys_futex0 (int *addr, int op, int val) 36169695Skan{ 37169695Skan register long int g1 __asm__ ("g1"); 38169695Skan register long int o0 __asm__ ("o0"); 39169695Skan register long int o1 __asm__ ("o1"); 40169695Skan register long int o2 __asm__ ("o2"); 41169695Skan register long int o3 __asm__ ("o3"); 42169695Skan 43169695Skan g1 = SYS_futex; 44169695Skan o0 = (long) addr; 45169695Skan o1 = op; 46169695Skan o2 = val; 47169695Skan o3 = 0; 48169695Skan 49169695Skan#ifdef __arch64__ 50169695Skan# define SYSCALL_STRING "ta\t0x6d" 51169695Skan#else 52169695Skan# define SYSCALL_STRING "ta\t0x10" 53169695Skan#endif 54169695Skan 55169695Skan __asm volatile (SYSCALL_STRING 56169695Skan : "=r" (g1), "=r" (o0) 57169695Skan : "0" (g1), "1" (o0), "r" (o1), "r" (o2), "r" (o3) 58169695Skan : "g2", "g3", "g4", "g5", "g6", 59169695Skan "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 60169695Skan "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 61169695Skan "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 62169695Skan "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", 63169695Skan#ifdef __arch64__ 64169695Skan "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", 65169695Skan "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", 66169695Skan#endif 67169695Skan "cc", "memory"); 68169695Skan} 69169695Skan 70169695Skanstatic inline void 71169695Skanfutex_wait (int *addr, int val) 72169695Skan{ 73169695Skan sys_futex0 (addr, FUTEX_WAIT, val); 74169695Skan} 75169695Skan 76169695Skanstatic inline void 77169695Skanfutex_wake (int *addr, int count) 78169695Skan{ 79169695Skan sys_futex0 (addr, FUTEX_WAKE, count); 80169695Skan} 81