summaryrefslogtreecommitdiff
path: root/gcell/src/ibm/sync/ppu_source
diff options
context:
space:
mode:
Diffstat (limited to 'gcell/src/ibm/sync/ppu_source')
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic.h112
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_add.h62
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_add_return.h66
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_dec.h60
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_dec_and_test.h63
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_dec_if_positive.h76
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_dec_return.h68
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_inc.h59
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_inc_return.h66
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_read.h62
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_set.h66
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_sub.h61
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_sub_and_test.h63
-rw-r--r--gcell/src/ibm/sync/ppu_source/atomic_sub_return.h65
-rw-r--r--gcell/src/ibm/sync/ppu_source/complete.h61
-rw-r--r--gcell/src/ibm/sync/ppu_source/complete_all.h70
-rw-r--r--gcell/src/ibm/sync/ppu_source/completion.h50
-rw-r--r--gcell/src/ibm/sync/ppu_source/cond.h65
-rw-r--r--gcell/src/ibm/sync/ppu_source/cond_broadcast.h70
-rw-r--r--gcell/src/ibm/sync/ppu_source/cond_init.h66
-rw-r--r--gcell/src/ibm/sync/ppu_source/cond_signal.h74
-rw-r--r--gcell/src/ibm/sync/ppu_source/cond_wait.h96
-rw-r--r--gcell/src/ibm/sync/ppu_source/init_completion.h63
-rw-r--r--gcell/src/ibm/sync/ppu_source/libsync.h114
-rw-r--r--gcell/src/ibm/sync/ppu_source/mutex.h46
-rw-r--r--gcell/src/ibm/sync/ppu_source/mutex_init.h67
-rw-r--r--gcell/src/ibm/sync/ppu_source/mutex_lock.h78
-rw-r--r--gcell/src/ibm/sync/ppu_source/mutex_trylock.h81
-rw-r--r--gcell/src/ibm/sync/ppu_source/mutex_unlock.h64
-rw-r--r--gcell/src/ibm/sync/ppu_source/pdt_libsync.xml184
-rw-r--r--gcell/src/ibm/sync/ppu_source/pdt_libsync_config.xml61
-rw-r--r--gcell/src/ibm/sync/ppu_source/sync_utils.h73
-rw-r--r--gcell/src/ibm/sync/ppu_source/trace_libsync.h117
-rw-r--r--gcell/src/ibm/sync/ppu_source/wait_for_completion.h75
34 files changed, 2524 insertions, 0 deletions
diff --git a/gcell/src/ibm/sync/ppu_source/atomic.h b/gcell/src/ibm/sync/ppu_source/atomic.h
new file mode 100644
index 000000000..105f7bf37
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic.h
@@ -0,0 +1,112 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+/*
+ * atomic.h - PPE atomic SHM counter operations.
+ *
+ * Interfaces patterned after, and hopefully compatible
+ * with PowerPC64-Linux atomic counter operations. Uses
+ * 32b values for various counters.
+ */
+#ifndef _PPU_ATOMIC_H_
+#define _PPU_ATOMIC_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+
+typedef unsigned int atomic_t __attribute__ ((aligned (128)));
+
+
+/* atomic_ea_t is a 64bit effective address that points to
+ * an atomic_t variable
+ */
+typedef unsigned long long atomic_ea_t;
+
+/**
+ * ASSUMPTIONS:
+ * On the PPE, the size of a reservation granule is 128 bytes
+ * (a cache-line), so when a programmer puts a reservation on an
+ * address, that whole cacheline is reserved. Therefore both
+ * the PPE and SPE can participate in an atomic operation as long as
+ * lwarx and getllar operate on the same cacheline.
+ */
+
+
+/*
+ * atomically loads and replaces the value v with val.
+ * Returns the old value at v
+ */
+static __inline int _atomic_replace(atomic_ea_t v, int val)
+{
+ int old;
+ void *p;
+
+ SYNC_ULL_TO_PTR(v, p);
+
+ do {
+ old = (int)__lwarx(p);
+ } while (__stwcx(p, (unsigned int)val) == 0);
+
+ return old;
+}
+
+
+/*
+ * atomically loads the value at v, adds val, replaces the
+ * value at v with the sum. Returns the old value at v
+ */
+static __inline int _atomic_modify(atomic_ea_t v, int val)
+{
+ int oldval, newval;
+ void *p;
+
+ SYNC_ULL_TO_PTR(v, p);
+
+ do {
+ oldval = (int)__lwarx(p);
+ newval = oldval + val;
+ } while (__stwcx(p, (unsigned int)newval) == 0);
+
+ return oldval;
+}
+
+
+#endif /* _PPU_ATOMIC_H_ */
+
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_add.h b/gcell/src/ibm/sync/ppu_source/atomic_add.h
new file mode 100644
index 000000000..dd7a5b25a
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_add.h
@@ -0,0 +1,62 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_ADD_H_
+#define _PPU_ATOMIC_ADD_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_add - atomically add to a counter.
+ * @v: handle to effective address of counter.
+ * @a: value to be added.
+ *
+ * Atomically add a value to a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_add(int a, atomic_ea_t v)
+{
+ _atomic_modify (v, a);
+}
+
+
+
+#endif /* _PPU_ATOMIC_ADD_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_add_return.h b/gcell/src/ibm/sync/ppu_source/atomic_add_return.h
new file mode 100644
index 000000000..0fe127565
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_add_return.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_ADD_RETURN_H_
+#define _PPU_ATOMIC_ADD_RETURN_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_add_return - atomically add to a counter and return previous value.
+ * @v: handle to effective address of counter.
+ * @a: value to be added.
+ *
+ * Atomically add a value to a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ *
+ * This routine implements the "fetch and add" primitive
+ * that is described in "Book I PowerPC User Instruction
+ * Set Architecture"
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_add_return(int a, atomic_ea_t v)
+{
+ return _atomic_modify (v, a);
+}
+
+
+#endif /* _PPU_ATOMIC_ADD_RETURN_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_dec.h b/gcell/src/ibm/sync/ppu_source/atomic_dec.h
new file mode 100644
index 000000000..4f82f04e0
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_dec.h
@@ -0,0 +1,60 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_DEC_H_
+#define _PPU_ATOMIC_DEC_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_dec - atomically decrement a counter.
+ * @v: handle to effective address of location to be modified.
+ *
+ * Atomically decrement a counter in system memory. The only
+ * restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_dec(atomic_ea_t v)
+{
+ _atomic_modify (v, -1);
+}
+
+
+#endif /* _PPU_ATOMIC_DEC_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_dec_and_test.h b/gcell/src/ibm/sync/ppu_source/atomic_dec_and_test.h
new file mode 100644
index 000000000..5093d4059
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_dec_and_test.h
@@ -0,0 +1,63 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_DEC_AND_TEST_H_
+#define _PPU_ATOMIC_DEC_AND_TEST_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_dec_and_test - atomically decrement and test if previous==0.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically decrement a counter in system memory and test
+ * if previous==0. The only restriction is that @v must be
+ * word aligned.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_dec_and_test(atomic_ea_t v)
+{
+ return (_atomic_modify(v, -1) == 0) ? 1 : 0;
+}
+
+
+#endif /* _PPU_ATOMIC_DEC_AND_TEST_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_dec_if_positive.h b/gcell/src/ibm/sync/ppu_source/atomic_dec_if_positive.h
new file mode 100644
index 000000000..c4d113bfd
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_dec_if_positive.h
@@ -0,0 +1,76 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_DEC_IF_POSITIVE_H_
+#define _PPU_ATOMIC_DEC_IF_POSITIVE_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "atomic.h"
+
+/*
+ * atomic_dec_if_positive - atomically decrement if counter is positive.
+ *
+ * v: handle to effective address of counter.
+ *
+ * Atomically decrement a counter if its value is positive.
+ * The only restriction is that v must be word aligned.
+ *
+ *
+ * Returns the old value of the counter, minus 1.
+ */
+static __inline int _atomic_dec_if_positive(atomic_ea_t v)
+{
+ int ret;
+ int tmp;
+ void *p;
+
+ SYNC_ULL_TO_PTR(v, p);
+
+ do {
+ tmp = (int)__lwarx(p);
+ ret = tmp - 1;
+ tmp = (tmp > 0) ? ret : tmp;
+ } while (__stwcx(p, (unsigned)tmp) == 0);
+
+ return ret;
+}
+
+#endif /* _PPU_ATOMIC_DEC_IF_POSITIVE_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_dec_return.h b/gcell/src/ibm/sync/ppu_source/atomic_dec_return.h
new file mode 100644
index 000000000..cd87893fa
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_dec_return.h
@@ -0,0 +1,68 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_DEC_RETURN_H_
+#define _PPU_ATOMIC_DEC_RETURN_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_dec_return - atomically decrement a counter and return previous value.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically decrement a counter in system memory and return its
+ * previous value. The only restriction is that @v must be word
+ * aligned.
+ *
+ * This routine implements the "fetch and decrement"
+ * primitive that is described in "Book I PowerPC User
+ * Instruction Set Architecture".
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_dec_return(atomic_ea_t v)
+{
+ return _atomic_modify (v, -1);
+}
+
+
+
+#endif /* _PPU_ATOMIC_DEC_RETURN_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_inc.h b/gcell/src/ibm/sync/ppu_source/atomic_inc.h
new file mode 100644
index 000000000..714aecbc0
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_inc.h
@@ -0,0 +1,59 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_INC_H_
+#define _PPU_ATOMIC_INC_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_inc - atomically increment a counter in system memory.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically increment a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_inc(atomic_ea_t v)
+{
+ _atomic_modify (v, 1);
+}
+
+#endif /* _PPU_ATOMIC_INC_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_inc_return.h b/gcell/src/ibm/sync/ppu_source/atomic_inc_return.h
new file mode 100644
index 000000000..95178f50d
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_inc_return.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_INC_RETURN_H_
+#define _PPU_ATOMIC_INC_RETURN_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+
+/**
+ * atomic_inc_return - atomically increment a counter and return previous.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically increment a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ *
+ * This routine implements the "fetch and increment"
+ * primitive that is described in "Book I PowerPC User
+ * Instruction Set Architecture"
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_inc_return(atomic_ea_t v)
+{
+ return _atomic_modify (v, 1);
+}
+
+#endif /* _PPU_ATOMIC_INC_RETURN_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_read.h b/gcell/src/ibm/sync/ppu_source/atomic_read.h
new file mode 100644
index 000000000..258fd516c
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_read.h
@@ -0,0 +1,62 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_READ_H_
+#define _PPU_ATOMIC_READ_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/*
+ * On PowerPC architecture, if v is a word_aligned address, then
+ * a load of that address is guaranteed to be atomic. An atomic
+ * read operation is simply a load.
+ */
+static __inline int _atomic_read(atomic_ea_t v)
+{
+ volatile int *p;
+
+ SYNC_ULL_TO_PTR(v, p);
+
+ return (*p);
+}
+
+
+#endif /* _PPU_ATOMIC_READ_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_set.h b/gcell/src/ibm/sync/ppu_source/atomic_set.h
new file mode 100644
index 000000000..e624af40d
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_set.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_SET_H_
+#define _PPU_ATOMIC_SET_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_set - atomically set a counter in system memory.
+ * @v: this is a 64bit address that points to an atomic_t
+ *
+ * Atomically set a counter to a given value. The only
+ * restriction is that @v must be word aligned.
+ *
+ * This routine implements the "fetch and store"
+ * primitive that is described in "Book I PowerPC User
+ * Instruction Set Architecture"
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline void _atomic_set(atomic_ea_t v, int val)
+{
+ _atomic_replace (v, val);
+}
+
+
+#endif /* _PPU_ATOMIC_SET_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_sub.h b/gcell/src/ibm/sync/ppu_source/atomic_sub.h
new file mode 100644
index 000000000..b8d35975a
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_sub.h
@@ -0,0 +1,61 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_SUB_H_
+#define _PPU_ATOMIC_SUB_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_sub - atomically subtract from a counter.
+ * @v: handle to effective address of counter.
+ * @a: value to be subtracted.
+ *
+ * Atomically subtract a value from a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_sub(int a, atomic_ea_t v)
+{
+ _atomic_modify (v, -a);
+}
+
+
+#endif /* _PPU_ATOMIC_SUB_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_sub_and_test.h b/gcell/src/ibm/sync/ppu_source/atomic_sub_and_test.h
new file mode 100644
index 000000000..37ba58896
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_sub_and_test.h
@@ -0,0 +1,63 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_SUB_AND_TEST_H_
+#define _PPU_ATOMIC_SUB_AND_TEST_H_
+
+#include "sync_utils.h"
+#include "atomic.h"
+
+/**
+ * atomic_sub_and_test - atomically subtract and test if previous==0.
+ * @v: handle to effective address of counter.
+ * @a: value to be subtracted.
+ *
+ * Atomically subtract a value from a counter in system memory
+ * and test if previous==0. The only restriction is that @v
+ * must be word aligned.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_sub_and_test(int a, atomic_ea_t v)
+{
+ return (_atomic_modify(v, -a) == 0) ? 1 : 0;
+}
+
+#endif /* _PPU_ATOMIC_SUB_AND_TEST_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/atomic_sub_return.h b/gcell/src/ibm/sync/ppu_source/atomic_sub_return.h
new file mode 100644
index 000000000..084bfa6b1
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/atomic_sub_return.h
@@ -0,0 +1,65 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_ATOMIC_SUB_RETURN_H_
+#define _PPU_ATOMIC_SUB_RETURN_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+
+/**
+ * atomic_sub_return - atomically subtract from a counter & return previous.
+ * @v: handle to effective address of counter.
+ * @a: value to be subtracted.
+ *
+ * Atomically subtract a value from a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ *
+ * Returns the previous value from system memory.
+ */
+
+
+static __inline int _atomic_sub_return(int a, atomic_ea_t v)
+{
+ return _atomic_modify (v, -a);
+}
+
+#endif /* _PPU_ATOMIC_SUB_RETURN_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/complete.h b/gcell/src/ibm/sync/ppu_source/complete.h
new file mode 100644
index 000000000..8633463f7
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/complete.h
@@ -0,0 +1,61 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COMPLETE_H_
+#define _PPU_COMPLETE_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "completion.h"
+
+
+static __inline void _complete (completion_ea_t comp)
+{
+ unsigned int old;
+ void *p;
+
+ SYNC_ULL_TO_PTR(comp, p);
+
+ do {
+ old = __lwarx(p);
+ } while (__stwcx(p, (unsigned int)1) == 0);
+}
+
+#endif /* _PPU_COMPLETE_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/complete_all.h b/gcell/src/ibm/sync/ppu_source/complete_all.h
new file mode 100644
index 000000000..c12eb7f03
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/complete_all.h
@@ -0,0 +1,70 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COMPLETE_ALL_H_
+#define _PPU_COMPLETE_ALL_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "completion.h"
+
+/**
+ * complete_all - indicate that a completion is true.
+ * @completion: handle to effective address of completion variable.
+ *
+ * Indicate that all are completed is true by storing
+ * MAX_THREADS_WAITING to the completionition variable.
+ */
+
+static __inline void _complete_all(completion_ea_t comp)
+{
+ unsigned int old;
+ unsigned int val = MAX_THREADS_WAITING;
+
+ void *p;
+
+ SYNC_ULL_TO_PTR(comp, p);
+
+ do {
+ old = __lwarx(p);
+ } while (__stwcx(p, val) == 0);
+}
+
+#endif /* _PPU_COMPLETE_ALL_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/completion.h b/gcell/src/ibm/sync/ppu_source/completion.h
new file mode 100644
index 000000000..b74bdaae7
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/completion.h
@@ -0,0 +1,50 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+
+#ifndef _PPU_COMPLETION_H_
+#define _PPU_COMPLETION_H_
+
+
+#define MAX_THREADS_WAITING 32000
+
+typedef unsigned long long completion_ea_t;
+
+#endif /* _PPU_COMPLETION_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/cond.h b/gcell/src/ibm/sync/ppu_source/cond.h
new file mode 100644
index 000000000..9a38f71a4
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/cond.h
@@ -0,0 +1,65 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COND_VAR_H_
+#define _PPU_COND_VAR_H_
+
+#include <mutex.h>
+#include <sync_utils.h>
+
+
+typedef struct
+{
+ short num_threads_signal; /* the number of threads that are going to be waken up.
+ There are 3 values possible for this parameter, 0, 1,
+ or num_threads_waiting*/
+ short num_threads_waiting; /* the number of threads that are waiting to be awaken */
+} condition_variable_t __attribute__ ((aligned (16)));
+
+typedef unsigned long long cond_ea_t; /* a system memory 64 bit address that points to
+ * a valid condition_variable_t */
+
+typedef union {
+ unsigned long long ull;
+ unsigned int ui[2];
+} val64;
+
+
+#endif /* _PPU_COND_VAR_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/cond_broadcast.h b/gcell/src/ibm/sync/ppu_source/cond_broadcast.h
new file mode 100644
index 000000000..b93bf7b37
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/cond_broadcast.h
@@ -0,0 +1,70 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COND_BROADCAST_H_
+#define _PPU_COND_BROADCAST_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "cond.h"
+
+/**
+ * cond_broadcast - indicate that a condition is true.
+ * @cond: handle to effective address of condition variable.
+ */
+static __inline void _cond_broadcast (cond_ea_t cond)
+{
+ unsigned int val;
+ void *p;
+
+ SYNC_ULL_TO_PTR(cond, p);
+
+ do {
+ val = __lwarx(p);
+
+ /* Copy the waiting count (low halfword) to
+ * the signaled count (high halfword)
+ */
+ val = (val & 0xFFFF) | ((val+1) << 16);
+
+ } while (__stwcx(p, val) == 0);
+}
+
+#endif /* _PPU_COND_BROADCAST_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/cond_init.h b/gcell/src/ibm/sync/ppu_source/cond_init.h
new file mode 100644
index 000000000..0dfbd6349
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/cond_init.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COND_INIT_H_
+#define _PPU_COND_INIT_H_
+
+#include "sync_utils.h"
+#include "cond.h"
+
+/**
+ * cond_init - initialize condition variable.
+ * @cond: handle to effective address of condition variable.
+ *
+ * Only one thread initializes a condition variable. Usually, the
+ * PPE thread initializes a condidtion variable
+ *
+ * Description: Initialize a cond variable to false.
+ */
+static __inline void _cond_init (cond_ea_t cond)
+{
+ volatile unsigned int *p;
+
+ SYNC_ULL_TO_PTR(cond, p);
+
+ *p = 0;
+}
+
+
+#endif /* _PPU_COND_INIT_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/cond_signal.h b/gcell/src/ibm/sync/ppu_source/cond_signal.h
new file mode 100644
index 000000000..dd4874827
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/cond_signal.h
@@ -0,0 +1,74 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COND_SIGNAL_H_
+#define _PPU_COND_SIGNAL_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "cond.h"
+
+/*
+ * _cond_signal: signaling any of the waiting threads to wake up.
+ */
+static __inline void _cond_signal (cond_ea_t cond)
+{
+ unsigned int val, waiting, signaled;
+ void *p;
+
+ SYNC_ULL_TO_PTR(cond, p);
+
+ do {
+ val = __lwarx(p);
+
+ waiting = val & 0xFFFF;
+ signaled = val >> 16;
+
+ /* If no other party is waiting. Don't send a signal.
+ * Otherwise, increment the signaled halfword.
+ */
+ if (waiting == signaled) break;
+ val = ((val+1) << 16) | waiting;
+
+ } while (__stwcx(p, val) == 0);
+}
+
+
+#endif /* _PPU_COND_SIGNAL_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/cond_wait.h b/gcell/src/ibm/sync/ppu_source/cond_wait.h
new file mode 100644
index 000000000..ed5fbecb1
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/cond_wait.h
@@ -0,0 +1,96 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_COND_WAIT_H_
+#define _PPU_COND_WAIT_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "mutex_lock.h"
+#include "mutex_unlock.h"
+#include "cond.h"
+
+static __inline void _cond_wait (cond_ea_t cond, mutex_ea_t mutex)
+{
+ int delta, cur_delta;
+ unsigned int val, cond_val, signaled_cnt;
+ void *p;
+
+
+ SYNC_ULL_TO_PTR(cond, p);
+
+ /* Atomically signal we have entered the condition wait by incrementing
+ * the waiting count.
+ */
+ do {
+ val = __lwarx(p);
+ val = (val & ~0xFFFF) | ((val+1) & 0xFFFF);
+ } while (__stwcx(p, val) == 0);
+
+
+ /* Release the lock
+ */
+ _mutex_unlock (mutex);
+
+ /* Determine the signal count needed for this
+ * participant to be signaled.
+ */
+
+ signaled_cnt = val >> 16;
+ delta = (int)(val & 0xFFFF) - (int)signaled_cnt;
+ if (delta < 0) delta = -delta;
+
+ /* Wait until the signaled count reaches the count
+ * previously determined.
+ */
+ do {
+ cond_val = __lwarx(p);
+
+ cur_delta = (int)(cond_val >> 16) - signaled_cnt;
+ if (cur_delta < 0) cur_delta = -cur_delta;
+
+ } while (cur_delta < delta);
+
+ /* Relock the mutex
+ */
+ _mutex_lock (mutex);
+}
+
+#endif /* _PPU_COND_WAIT_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/init_completion.h b/gcell/src/ibm/sync/ppu_source/init_completion.h
new file mode 100644
index 000000000..8e7081111
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/init_completion.h
@@ -0,0 +1,63 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_INIT_COMPLETION_H_
+#define _PPU_INIT_COMPLETION_H_
+
+#include "sync_utils.h"
+#include "completion.h"
+
+/**
+ * completion_init - initialize completion variable.
+ * @completion: handle to effective address of completion variable.
+ *
+ * Description: Initialize a completion variable to 0.
+ */
+static __inline void _init_completion(completion_ea_t comp)
+{
+ volatile unsigned int *p;
+
+ SYNC_ULL_TO_PTR(comp, p);
+
+ *p = 0;
+}
+
+
+#endif /* _PPU_INIT_COMPLETION_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/libsync.h b/gcell/src/ibm/sync/ppu_source/libsync.h
new file mode 100644
index 000000000..bd2e04347
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/libsync.h
@@ -0,0 +1,114 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_LIBSYNC_H_
+#define _PPU_LIBSYNC_H_
+
+#include "sync_utils.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned long long atomic_ea_t;
+
+extern void atomic_set(atomic_ea_t v, int val);
+extern void atomic_add(int a, atomic_ea_t v);
+extern void atomic_sub(int a, atomic_ea_t v);
+extern void atomic_inc(atomic_ea_t v);
+extern void atomic_dec(atomic_ea_t v);
+
+extern int atomic_read(atomic_ea_t v);
+extern int atomic_add_return(int a, atomic_ea_t v);
+extern int atomic_sub_return(int a, atomic_ea_t v);
+extern int atomic_inc_return(atomic_ea_t v);
+extern int atomic_dec_return(atomic_ea_t v);
+extern int atomic_sub_and_test(int a, atomic_ea_t v);
+extern int atomic_dec_and_test(atomic_ea_t v);
+extern int atomic_dec_if_positive(atomic_ea_t v);
+
+typedef unsigned long long mutex_ea_t;
+void mutex_init(mutex_ea_t lock);
+
+void mutex_lock(mutex_ea_t lock);
+int mutex_trylock(mutex_ea_t ea);
+void mutex_unlock(mutex_ea_t lock);
+
+typedef struct
+{
+ int num_threads_signal; /* the number of threads that are going to be waken up.
+ There are 3 values possible for this parameter, 0, 1,
+ or num_threads_waiting*/
+ int num_threads_waiting; /* the number of threads that are waiting to be awaken */
+} condition_variable_t __attribute__ ((aligned (16)));
+
+typedef unsigned long long cond_ea_t; /* a system memory 64 bit address that points to
+ * a valid condition_variable_t */
+
+typedef union {
+ unsigned long long ull;
+ unsigned int ui[2];
+} val64;
+
+
+void cond_init (cond_ea_t cond);
+void cond_signal (cond_ea_t cond);
+void cond_broadcast (cond_ea_t cond);
+void cond_wait (cond_ea_t cond, mutex_ea_t mutex);
+
+
+#define MAX_THREADS_WAITING 32000
+
+typedef unsigned long long completion_ea_t;
+
+extern void init_completion(completion_ea_t comp);
+extern void wait_for_completion(completion_ea_t comp);
+/*
+extern void wait_for_completion_irq(completion_ea_t comp);
+extern void wait_for_completion_irqsave(completion_ea_t comp);
+*/
+extern void complete_all(completion_ea_t comp);
+extern void complete (completion_ea_t comp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _PPU_LIBSYNC_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/mutex.h b/gcell/src/ibm/sync/ppu_source/mutex.h
new file mode 100644
index 000000000..364bb2249
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/mutex.h
@@ -0,0 +1,46 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_MUTEX_H_
+#define _PPU_MUTEX_H_ 1
+
+typedef unsigned long long mutex_ea_t;
+
+#endif /* _PPU_MUTEX_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/mutex_init.h b/gcell/src/ibm/sync/ppu_source/mutex_init.h
new file mode 100644
index 000000000..105dc2c57
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/mutex_init.h
@@ -0,0 +1,67 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_MUTEX_INIT_H_
+#define _PPU_MUTEX_INIT_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include "trace_libsync.h"
+
+/***************************************************************************/
+/**
+ * mutex_init - initialize the mutex by setting the value
+ * to 0.
+ * @lock: handle to effective address of lock variable.
+ *
+ * Description: Initialize a mutex.
+ */
+static __inline void _mutex_init(mutex_ea_t lock)
+{
+ volatile unsigned int *p;
+
+ SYNC_ULL_TO_PTR(lock, p);
+
+ *p = 0;
+
+ TRACE_MUTEX_INIT(lock);
+}
+
+#endif /* _PPU_MUTEX_INIT_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/mutex_lock.h b/gcell/src/ibm/sync/ppu_source/mutex_lock.h
new file mode 100644
index 000000000..75240a141
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/mutex_lock.h
@@ -0,0 +1,78 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_MUTEX_LOCK_H_
+#define _PPU_MUTEX_LOCK_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "mutex.h"
+#include "trace_libsync.h"
+
+/* function: _mutex_lock
+ *
+ * Aquire a lock at a location in system memory by waiting for the
+ * value to become zero, then atomically storing 1.
+ */
+static __inline void _mutex_lock (mutex_ea_t lock)
+{
+ unsigned int done = 0;
+ void *p;
+#ifdef LIBSYNC_TRACE
+ unsigned int miss = 0;
+#endif /* LIBSYNC_TRACE */
+
+ TRACE_MUTEX_LOCK_ENTRY(interval);
+
+ SYNC_ULL_TO_PTR(lock, p);
+
+ do {
+ if (__lwarx(p) == 0) done = __stwcx(p, (unsigned int) 1);
+#ifdef LIBSYNC_TRACE
+ /* if we missed the lock, note it.. */
+ if (done == 0) miss = 1;
+#endif
+ } while (done == 0);
+ __isync();
+
+ TRACE_MUTEX_LOCK_EXIT(interval, lock, miss);
+}
+
+#endif /* _PPU_MUTEX_LOCK_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/mutex_trylock.h b/gcell/src/ibm/sync/ppu_source/mutex_trylock.h
new file mode 100644
index 000000000..445196c74
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/mutex_trylock.h
@@ -0,0 +1,81 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_MUTEX_TRYLOCK_H_
+#define _PPU_MUTEX_TRYLOCK_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "mutex.h"
+#include "trace_libsync.h"
+
+/**
+ * mutex_trylock - acquire a lock, or return immediately.
+ * @lock: handle to effective address of lock variable.
+ *
+ * Description: Acquire a lock, or return immediately
+ * without polling for availability.
+ *
+ * Context: The application should not call this interface
+ * from a tight loop!! Use spin_lock() instead.
+ *
+ * Attempt to immediately aquire a lock at a location in system memory,
+ * and return 1 if the lock was aquired or 0 otherwise.
+ */
+static __inline int _mutex_trylock (mutex_ea_t lock)
+{
+ int val;
+ int ret = 0;
+ void *p;
+
+ SYNC_ULL_TO_PTR(lock, p);
+
+ do {
+ val = (int)__lwarx(p);
+ if (val) break;
+ } while ((ret = __stwcx(p, (unsigned int)1)) == 0);
+ __isync();
+
+ TRACE_MUTEX_TRYLOCK(lock,ret);
+
+ return (ret);
+}
+
+#endif /* _PPU_MUTEX_TRYLOCK_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/mutex_unlock.h b/gcell/src/ibm/sync/ppu_source/mutex_unlock.h
new file mode 100644
index 000000000..e5255be02
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/mutex_unlock.h
@@ -0,0 +1,64 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_MUTEX_UNLOCK_H_
+#define _PPU_MUTEX_UNLOCK_H_
+
+#include "mutex.h"
+#include "atomic.h"
+#include "trace_libsync.h"
+
+/* function: _mutex_unlock
+ *
+ * Release a lock held at address 'lock' in system memory.
+ * For the PU, this routine is the same _unlock, and is
+ * provided here as a simple convenience for programmers
+ * (to match the interfaces that are supported on the SPU).
+ * All I need to do is a store since store is an atomic operation by itself
+ */
+static __inline void _mutex_unlock (mutex_ea_t lock)
+{
+ _atomic_replace ((atomic_ea_t)lock, 0);
+
+ TRACE_MUTEX_UNLOCK(lock);
+}
+
+
+#endif /* _PPU_MUTEX_UNLOCK_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/pdt_libsync.xml b/gcell/src/ibm/sync/ppu_source/pdt_libsync.xml
new file mode 100644
index 000000000..d9ea2ce9f
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/pdt_libsync.xml
@@ -0,0 +1,184 @@
+<pdtGroup name="LIBSYNC" id="0x03" version="3.0">
+ <!-- PPE events -->
+ <subGroup name="PPE_MUTEX" id="0xFE03">
+ <recordType name="PPE_MUTEX_INIT" description="PPE: mutex lock init" id="0x0003" type="event">
+ <include href="/usr/share/pdt/config/pdt_ppe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="empty3" description="empty slot 3" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ <recordType name="PPE_MUTEX_LOCK" description="PPE: acquire a mutex lock" id="0x0103" type="interval">
+ <include href="/usr/share/pdt/config/pdt_ppe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="miss" description="Missed" type="int" toString="0x%x" visible="true"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ <recordType name="PPE_MUTEX_TRYLOCK" description="PPE: try to acquire a lock" id="0x0203" type="event">
+ <include href="/usr/share/pdt/config/pdt_ppe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="ret" description="Try lock return code" type="int" toString="0x%x" visible="true"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ <recordType name="PPE_MUTEX_UNLOCK" description="PPE: unlock a mutex lock" id="0x0303" type="event">
+ <include href="/usr/share/pdt/config/pdt_ppe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="empty3" description="empty slot 3" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ </subGroup>
+ <!-- SPE events -->
+ <subGroup name="SPE_MUTEX" id="0xFD03">
+ <recordType name="SPE_MUTEX_INIT" description="SPE: mutex lock init" id="0x0403" type="event">
+ <include href="/usr/share/pdt/config/pdt_spe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="empty3" description="empty slot 3" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ <recordType name="SPE_MUTEX_LOCK" description="SPE: acquire a mutex lock" id="0x0503" type="interval">
+ <include href="/usr/share/pdt/config/pdt_spe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="miss" description="Missed" type="int" toString="0x%x" visible="true"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ <recordType name="SPE_MUTEX_TRYLOCK" description="SPE: try to acquire a mutex lock" id="0x0603" type="event">
+ <include href="/usr/share/pdt/config/pdt_spe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="ret_val" description="Try lock return code" type="int" toString="0x%x" visible="true"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ <recordType name="SPE_MUTEX_UNLOCK" description="SPE: unlock a mutex lock" id="0x0703" type="event">
+ <include href="/usr/share/pdt/config/pdt_spe_event_header.xml"/>
+ <physicalField name="lock" description="Lock address" type="long" toString="0x%x" visible="true"/>
+ <physicalField name="empty3" description="empty slot 3" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty4" description="empty slot 4" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty5" description="empty slot 5" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty6" description="empty slot 6" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty7" description="empty slot 7" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty8" description="empty slot 8" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty9" description="empty slot 9" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty10" description="empty slot 10" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty11" description="empty slot 11" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty12" description="empty slot 12" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty13" description="empty slot 13" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty14" description="empty slot 14" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty15" description="empty slot 15" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty16" description="empty slot 16" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty17" description="empty slot 17" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty18" description="empty slot 18" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty19" description="empty slot 19" type="int" toString="0x%x" visible="false"/>
+ <physicalField name="empty20" description="empty slot 20" type="int" toString="0x%x" visible="false"/>
+ </recordType>
+ </subGroup>
+</pdtGroup>
diff --git a/gcell/src/ibm/sync/ppu_source/pdt_libsync_config.xml b/gcell/src/ibm/sync/ppu_source/pdt_libsync_config.xml
new file mode 100644
index 000000000..a0b848d84
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/pdt_libsync_config.xml
@@ -0,0 +1,61 @@
+<pdt_configuration application_name="libsync" output_dir="." version="3.0">
+ <groups>
+ <group name="GENERAL" description="General event types" id="0x00">
+ <view yStart="0.0" yEnd="0.2" color="0x0000FF"/>
+ <include href="/usr/share/pdt/config/pdt_general.xml"/>
+ </group>
+ <group name="LIBSPE2" description="CBE libspe 2.0 event types" id="0x01">
+ <view yStart="0.2" yEnd="0.4" color="0x00FFFF"/>
+ <include href="/usr/share/pdt/config/pdt_libspe2.xml"/>
+ </group>
+ <group name="MFCIO" description="SPE MFCIO event types" id="0x02">
+ <view yStart="0.4" yEnd="0.6" color="0x00FF80"/>
+ <include href="/usr/share/pdt/config/pdt_mfcio.xml"/>
+ </group>
+ <group name="LIBSYNC" description="General event types" id="0x03">
+ <view yStart="0.6" yEnd="0.8" color="0xFFFF00"/>
+ <include href="/usr/share/pdt/config/pdt_libsync.xml"/>
+ </group>
+ </groups>
+<configuration name="CBE">
+<host name="none"/>
+<groupsControl>
+ <group name="GENERAL" active="true">
+ <profile active="false"/>
+ <!-- The GENERAL group of events are always active-->
+ </group>
+ <group name="LIBSPE2" active="true">
+ </group>
+ <group name="LIBSYNC" active="true">
+ <sub_group name="PPE_MUTEX" active="true">
+ <event name="PPE_MUTEX_INIT" active="true"/>
+ <event name="PPE_MUTEX_LOCK" active="true"/>
+ <event name="PPE_MUTEX_TRYLOCK" active="true"/>
+ <event name="PPE_MUTEX_UNLOCK" active="true"/>
+ </sub_group>
+ </group>
+</groupsControl>
+</configuration>
+<!-- -->
+<!-- SPEs configuration - this section is read with the CBE configuration -->
+<!-- -->
+<configuration name="SPE">
+<host name="CBE"/>
+<groupsControl>
+ <group name="GENERAL" active="true">
+ <profile active="false"/>
+ <!-- The GENERAL group of events are always active-->
+ </group>
+ <group name="MFCIO" active="true">
+ </group>
+ <group name="LIBSYNC" active="true">
+ <sub_group name="SPE_MUTEX" active="true">
+ <event name="SPE_MUTEX_INIT" active="true"/>
+ <event name="SPE_MUTEX_LOCK" active="true"/>
+ <event name="SPE_MUTEX_TRYLOCK" active="true"/>
+ <event name="SPE_MUTEX_UNLOCK" active="true"/>
+ </sub_group>
+ </group>
+</groupsControl>
+</configuration>
+</pdt_configuration>
diff --git a/gcell/src/ibm/sync/ppu_source/sync_utils.h b/gcell/src/ibm/sync/ppu_source/sync_utils.h
new file mode 100644
index 000000000..c7120a3cc
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/sync_utils.h
@@ -0,0 +1,73 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _PPU_SYNC_UTILS_H_
+#define _PPU_SYNC_UTILS_H_ 1
+
+/* SYNC_ULL_TO_PTR - convert a 64-bit unsigned long long to a void
+ * pointer.
+ */
+#ifdef __powerpc64__
+
+#define SYNC_ULL_TO_PTR(_ull, _ptr) { \
+ union { \
+ void *ptr; \
+ unsigned long long ull; \
+ } _x; \
+ \
+ _x.ull = _ull; \
+ _ptr = _x.ptr; \
+}
+
+#else
+
+#define SYNC_ULL_TO_PTR(_ull, _ptr) { \
+ union { \
+ void *ptr[2]; \
+ unsigned long long ull; \
+ } _x; \
+ \
+ _x.ull = _ull; \
+ _ptr = _x.ptr[1]; \
+}
+
+#endif
+
+#endif /* _PPU_SYNC_UTILS_H_ */
diff --git a/gcell/src/ibm/sync/ppu_source/trace_libsync.h b/gcell/src/ibm/sync/ppu_source/trace_libsync.h
new file mode 100644
index 000000000..6d6f036e5
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/trace_libsync.h
@@ -0,0 +1,117 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2007 */
+/* International Business Machines Corporation */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef __LIBSYNC_PPU_TRACEHOOKS_H__
+#define __LIBSYNC_PPU_TRACEHOOKS_H__
+
+#ifdef LIBSYNC_TRACE
+
+#include <trace_events.h>
+
+/*
+ * last parameter in the trace_even and trace_interval_entry call is
+ * the stack level to report the PC in the trace record. so 0 means
+ * the PC of the current frame, 1 means the PC of the caller, etc.
+ * there's a dilemma here - these macros are included in the inline
+ * _mutex calls which get called from the (created during build)
+ * mutex functions in the mutex .c files. in that case, the level
+ * should be 1 - we don't want the PC of where in the mutex function
+ * the trace call is happening, we want the PC of whomever is calling
+ * the mutex function.
+ *
+ * but.. an app can call the inline functions - it can #include the
+ * appropriate libsync mutex .h files, and call the inlined _mutex
+ * function in their code. in that case, the appropriate level for the
+ * trace calls would be 0 - the user would want to know where in their
+ * code the call to the _mutex function is.
+ *
+ * so, we'll assume _LEVEL of 0 which is what the inline funtions need.
+ * when we build the files for libsync, we'll do a -D_LEVEL=1
+ */
+#ifndef _LEVEL
+#define _LEVEL 0
+#endif
+
+
+#define TRACE_EVENT_MUTEX_INIT 0x0003
+
+#define TRACE_MUTEX_INIT(lock) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(uint64_t)lock; \
+ trace_event(TRACE_EVENT_MUTEX_INIT, 1, &payload, "Event=%d, lock=0x%x",_LEVEL); \
+}
+
+#define TRACE_EVENT_MUTEX_LOCK 0x0103
+
+#define TRACE_MUTEX_LOCK_ENTRY(_INTERVAL) \
+trace_interval_p _INTERVAL = trace_interval_entry(TRACE_EVENT_MUTEX_LOCK, _LEVEL)
+
+#define TRACE_MUTEX_LOCK_EXIT(_INTERVAL,lock,miss) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(uint64_t)lock; \
+ payload.word[2]=(uint32_t)miss; \
+ trace_interval_exit(_INTERVAL, 2, &payload, "Event=%d, lock=0x%x, miss=0x%x"); \
+}
+
+#define TRACE_EVENT_MUTEX_TRYLOCK 0x0203
+
+#define TRACE_MUTEX_TRYLOCK(lock,ret) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(uint64_t)lock; \
+ payload.word[2]=(uint32_t)ret; \
+ trace_event(TRACE_EVENT_MUTEX_TRYLOCK, 2, &payload, "Event=%d, lock=0x%x, ret=0x%x", _LEVEL); \
+}
+
+#define TRACE_EVENT_MUTEX_UNLOCK 0x0303
+
+#define TRACE_MUTEX_UNLOCK(lock) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(uint64_t)lock; \
+ trace_event(TRACE_EVENT_MUTEX_UNLOCK, 1, &payload, "Event=%d, lock=0x%x", _LEVEL); \
+}
+
+#else /* LIBSYNC_TRACE */
+
+#define TRACE_MUTEX_INIT(lock)
+#define TRACE_MUTEX_LOCK_ENTRY(_INTERVAL)
+#define TRACE_MUTEX_LOCK_EXIT(_INTERVAL,lock,miss)
+#define TRACE_MUTEX_TRYLOCK(lock,ret_val)
+#define TRACE_MUTEX_UNLOCK(lock)
+
+#endif /* LIBSYNC_TRACE */
+
+#endif /* __LIBSYNC_PPU_TRACEHOOKS_H__ */
diff --git a/gcell/src/ibm/sync/ppu_source/wait_for_completion.h b/gcell/src/ibm/sync/ppu_source/wait_for_completion.h
new file mode 100644
index 000000000..f2b04275a
--- /dev/null
+++ b/gcell/src/ibm/sync/ppu_source/wait_for_completion.h
@@ -0,0 +1,75 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+
+#ifndef _PPU_WAIT_FOR_COMPLETION_H_
+#define _PPU_WAIT_FOR_COMPLETION_H_
+
+#include <ppu_intrinsics.h>
+#include "sync_utils.h"
+#include "completion.h"
+
+
+/**
+ * completion_wait - wait until a completion is broadcast.
+ * @comp: handle to effective address of completion variable.
+ *
+ * Description: Wait until another processor or device signals
+ * that a completionition is 'true'. The only restriction here is
+ * that @comp must be a word aligned address.
+ *
+ * Beware: This function hot polls waiting for completion.
+ */
+static __inline void _wait_for_completion(completion_ea_t comp)
+{
+ int val;
+ void *p;
+
+ SYNC_ULL_TO_PTR(comp, p);
+
+ do {
+ val = (int)__lwarx(p);
+ if (val != 1) val = (int)__stwcx(p, (unsigned int)0);
+ } while (val == 0);
+ __isync();
+}
+
+
+#endif /* _PPU_WAIT_FOR_COMPLETION_H_ */