oro_system.h

00001 /***************************************************************************
00002   tag: FMTC  Tue Mar 11 21:49:19 CET 2008  oro_system.h
00003 
00004                         oro_system.h -  description
00005                            -------------------
00006     begin                : Tue March 11 2008
00007     copyright            : (C) 2008 FMTC
00008     email                : peter.soetens@fmtc.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 
00039 #include "oro_atomic.h"
00040 
00041 #ifdef _cplusplus
00042 extern "C"
00043 {
00044 #endif // _cplusplus
00045 
00046 #define __HAVE_ARCH_CMPXCHG 1
00047 
00048 static __inline__ unsigned long
00049 __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long newp)
00050 {
00051     unsigned int prev;
00052 
00053     __asm__ __volatile__ (
00054     LWSYNC_ON_SMP
00055 "1: lwarx   %0,0,%2     # __cmpxchg_u32\n\
00056     cmpw    0,%0,%3\n\
00057     bne-    2f\n"
00058     PPC405_ERR77(0,%2)
00059 "   stwcx.  %4,0,%2\n\
00060     bne-    1b"
00061     ISYNC_ON_SMP
00062     "\n\
00063 2:"
00064     : "=&r" (prev), "=m" (*p)
00065     : "r" (p), "r" (old), "r" (newp), "m" (*p)
00066     : "cc", "memory");
00067 
00068     return prev;
00069 }
00070 
00071   // KG did explicit cast to remove following error
00072   /*
00073   /kgad/orocos-port-branch/ports/ecos/arch/powerpc/boa5200/orecos-library/install/include/os/oro_powerpc/oro_system.h:
00074   In function `long unsigned int __oro_cmpxchg(volatile void*, long
00075   unsigned int, long unsigned int, unsigned int)':
00076   /kgad/orocos-port-branch/ports/ecos/arch/powerpc/boa5200/orecos-library/install/include/os/oro_powerpc/oro_system.h:52:
00077   error: invalid conversion from `volatile void*' to `volatile
00078   unsigned int*'
00079   /kgad/orocos-port-branch/ports/ecos/arch/powerpc/boa5200/orecos-library/install/include/os/oro_powerpc/oro_system.h:52:
00080   error:   initializing argument 1 of `long unsigned int
00081   __cmpxchg_u32(volatile unsigned int*, long unsigned int, long
00082   unsigned int)' */
00083 
00084 static __inline__ unsigned long
00085 __oro_cmpxchg(volatile void *ptr, unsigned long old, unsigned long newp, unsigned int size)
00086 {
00087     switch (size) {
00088     case 4:
00089         return __cmpxchg_u32((volatile unsigned int *) ptr, old, newp);
00090     }
00091     return old;
00092 }
00093 
00094 #define oro_cmpxchg(ptr,o,n)                         \
00095   ({                                     \
00096      __typeof__(*(ptr)) _o_ = (o);                   \
00097      __typeof__(*(ptr)) _n_ = (n);                   \
00098      (__typeof__(*(ptr))) __oro_cmpxchg((ptr), (unsigned long)_o_,       \
00099                     (unsigned long)_n_, sizeof(*(ptr))); \
00100   })
00101 
00102 #ifdef _cplusplus
00103 } // end extern "C"
00104 #endif // _cplusplus
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3