1169695Skan/* Copyright (C) 2005 Free Software Foundation, Inc. 2169695Skan Contributed by Richard Henderson <rth@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#define FUTEX_WAIT 0 31169695Skan#define FUTEX_WAKE 1 32169695Skan 33169695Skan#ifdef __LP64__ 34169695Skan# ifndef SYS_futex 35169695Skan# define SYS_futex 202 36169695Skan# endif 37169695Skan 38169695Skanstatic inline void 39169695Skanfutex_wait (int *addr, int val) 40169695Skan{ 41169695Skan register long r10 __asm__("%r10") = 0; 42169695Skan long res; 43169695Skan 44169695Skan __asm volatile ("syscall" 45169695Skan : "=a" (res) 46169695Skan : "0"(SYS_futex), "D" (addr), "S"(FUTEX_WAIT), 47169695Skan "d"(val), "r"(r10) 48169695Skan : "r11", "rcx", "memory"); 49169695Skan} 50169695Skan 51169695Skanstatic inline void 52169695Skanfutex_wake (int *addr, int count) 53169695Skan{ 54169695Skan long res; 55169695Skan 56169695Skan __asm volatile ("syscall" 57169695Skan : "=a" (res) 58169695Skan : "0"(SYS_futex), "D" (addr), "S"(FUTEX_WAKE), "d"(count) 59169695Skan : "r11", "rcx", "memory"); 60169695Skan} 61169695Skan#else 62169695Skan# ifndef SYS_futex 63169695Skan# define SYS_futex 240 64169695Skan# endif 65169695Skan 66169695Skan# ifdef __PIC__ 67169695Skan 68169695Skanstatic inline void 69169695Skansys_futex0 (int *addr, int op, int val) 70169695Skan{ 71169695Skan long res; 72169695Skan 73169695Skan __asm volatile ("xchgl\t%%ebx, %2\n\t" 74169695Skan "int\t$0x80\n\t" 75169695Skan "xchgl\t%%ebx, %2" 76169695Skan : "=a" (res) 77169695Skan : "0"(SYS_futex), "r" (addr), "c"(op), 78169695Skan "d"(val), "S"(0) 79169695Skan : "memory"); 80169695Skan} 81169695Skan 82169695Skan# else 83169695Skan 84169695Skanstatic inline void 85169695Skansys_futex0 (int *addr, int op, int val) 86169695Skan{ 87169695Skan long res; 88169695Skan 89169695Skan __asm volatile ("int $0x80" 90169695Skan : "=a" (res) 91169695Skan : "0"(SYS_futex), "b" (addr), "c"(op), 92169695Skan "d"(val), "S"(0) 93169695Skan : "memory"); 94169695Skan} 95169695Skan 96169695Skan# endif /* __PIC__ */ 97169695Skan 98169695Skanstatic inline void 99169695Skanfutex_wait (int *addr, int val) 100169695Skan{ 101169695Skan sys_futex0 (addr, FUTEX_WAIT, val); 102169695Skan} 103169695Skan 104169695Skanstatic inline void 105169695Skanfutex_wake (int *addr, int count) 106169695Skan{ 107169695Skan sys_futex0 (addr, FUTEX_WAKE, count); 108169695Skan} 109169695Skan 110169695Skan#endif /* __LP64__ */ 111