1 /* 2 * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com) 3 * 4 * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. 5 */ 6 7 #ifndef _PT_MACHINE_H 8 #define _PT_MACHINE_H 1 9 #include <features.h> 10 11 #ifndef PT_EI 12 # define PT_EI __extern_always_inline 13 #endif 14 15 extern long int testandset (int *spinlock); 16 extern int __compare_and_swap (long int *p, long int oldval, long int newval); 17 18 PT_EI long int testandset(int * spinlock)19testandset (int *spinlock) 20 { 21 unsigned int old = 1; 22 23 /* Atomically exchange @spinlock with 1 */ 24 __asm__ __volatile__( 25 "ex %0, [%1]" 26 : "+r" (old) 27 : "r" (spinlock) 28 : "memory"); 29 30 return old; 31 32 } 33 34 /* Get some notion of the current stack. Need not be exactly the top 35 of the stack, just something somewhere in the current frame. 36 I don't trust register variables, so let's do this the safe way. */ 37 #define CURRENT_STACK_FRAME \ 38 __extension__ ({ char *__sp; __asm__ ("mov %0,sp" : "=r" (__sp)); __sp; }) 39 40 #else 41 #error PT_MACHINE already defined 42 #endif /* pt-machine.h */ 43