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 #ifndef __ARCH_x86_64_ORO_SYSTEM__ 00040 #define __ARCH_x86_64_ORO_SYSTEM__ 00041 00042 // this is required for multi-core cpus 00043 // Export ORO_LOCK_PREFIX, just like the classical bitops.h does. 00044 #ifndef CONFIG_FORCE_UP 00045 #define ORO_LOCK_PREFIX "lock ; " 00046 #else 00047 #define ORO_LOCK_PREFIX "" 00048 #endif 00049 00050 struct oro__xchg_dummy { unsigned long a[100]; }; 00051 #define oro__xg(x) ((struct oro__xchg_dummy *)(x)) 00052 00053 static inline unsigned long __oro_cmpxchg(volatile void *ptr, unsigned long old, 00054 unsigned long _new, int size) 00055 { 00056 unsigned long prev; 00057 switch (size) { 00058 case 1: 00059 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgb %b1,%2" 00060 : "=a"(prev) 00061 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00062 : "memory"); 00063 return prev; 00064 case 2: 00065 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgw %w1,%2" 00066 : "=a"(prev) 00067 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00068 : "memory"); 00069 return prev; 00070 case 4: 00071 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgl %k1,%2" 00072 : "=a"(prev) 00073 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00074 : "memory"); 00075 return prev; 00076 case 8: 00077 __asm__ __volatile__(ORO_LOCK_PREFIX "cmpxchgq %1,%2" 00078 : "=a"(prev) 00079 : "q"(_new), "m"(*oro__xg(ptr)), "0"(old) 00080 : "memory"); 00081 return prev; 00082 00083 } 00084 return old; 00085 } 00086 00087 #define oro_cmpxchg(ptr,o,n)\ 00088 ((__typeof__(*(ptr)))__oro_cmpxchg((ptr),(unsigned long)(o),\ 00089 (unsigned long)(n),sizeof(*(ptr)))) 00090 00091 #undef ORO_LOCK_PREFIX 00092 00093 #endif