00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jan 10 15:59:15 CET 2005 oro_system.h 00003 00004 oro_system.h - description 00005 ------------------- 00006 begin : Mon January 10 2005 00007 copyright : (C) 2005 Peter Soetens 00008 email : peter.soetens@mech.kuleuven.ac.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 #include "../../rtt-config.h" 00039 00040 // do not rely on system headers : 00041 // i386 : 00042 #ifndef __ASM_ORO_SYSTEM_H 00043 #define __ASM_ORO_SYSTEM_H 00044 00045 // this is required for multi-core cpus 00046 // Export ORO_LOCK_PREFIX, just like the classical bitops.h does. 00047 #ifndef CONFIG_FORCE_UP 00048 #define ORO_LOCK_PREFIX "lock ; " 00049 #else 00050 #define ORO_LOCK_PREFIX "" 00051 #endif 00052 00053 struct oro__xchg_dummy { unsigned long a[100]; }; 00054 #define oro__xg(x) ((struct oro__xchg_dummy *)(x)) 00055 00056 static inline unsigned long __oro_cmpxchg(volatile void *ptr, unsigned long old, 00057 unsigned long _new, int size) 00058 { 00059 unsigned long prev; 00060 switch (size) { 00061 case 1: 00062 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgb %b1,%2" 00063 : "=a"(prev) 00064 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00065 : "memory"); 00066 return prev; 00067 case 2: 00068 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgw %w1,%2" 00069 : "=a"(prev) 00070 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00071 : "memory"); 00072 return prev; 00073 case 4: 00074 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgl %1,%2" 00075 : "=a"(prev) 00076 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00077 : "memory"); 00078 return prev; 00079 } 00080 return old; 00081 } 00082 00083 #define oro_cmpxchg(ptr,o,n)\ 00084 ((__typeof__(*(ptr)))__oro_cmpxchg((ptr),(unsigned long)(o),\ 00085 (unsigned long)(n),sizeof(*(ptr)))) 00086 00087 #endif // __ASM_ORO_SYSTEM_H