]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/loose_ends.c
xnu-344.tar.gz
[apple/xnu.git] / osfmk / i386 / loose_ends.c
index abf2750bec38d158547404513626334728235d47..e64faedb222a2f25a58726e9052e9a31991b9f75 100644 (file)
         * Should be rewritten in asm anyway.
         */
 
+
+
+/*
+ *              Copies data from a physical page to a virtual page.  This is used to
+ *              move data from the kernel to user state.
+ *
+ */
+
+kern_return_t
+copyp2v(char *from, char *to, unsigned int size) {
+
+  return(copyout(phystokv(from), to, size));
+}
+
 /*
  * bcopy_phys - like bcopy but copies from/to physical addresses.
  *              this is trivial since all phys mem is mapped into 
@@ -154,6 +168,85 @@ strlen(
        return string - 1 - ret;
 }
 
+#include <libkern/OSAtomic.h>
+
+uint32_t
+hw_atomic_add(
+       uint32_t        *dest,
+       uint32_t        delt)
+{
+       uint32_t        oldValue;
+       uint32_t        newValue;
+       
+       do {
+               oldValue = *dest;
+               newValue = (oldValue + delt);
+       } while (!OSCompareAndSwap((UInt32)oldValue,
+                                                                       (UInt32)newValue, (UInt32 *)dest));
+       
+       return newValue;
+}
+
+uint32_t
+hw_atomic_sub(
+       uint32_t        *dest,
+       uint32_t        delt)
+{
+       uint32_t        oldValue;
+       uint32_t        newValue;
+       
+       do {
+               oldValue = *dest;
+               newValue = (oldValue - delt);
+       } while (!OSCompareAndSwap((UInt32)oldValue,
+                                                                       (UInt32)newValue, (UInt32 *)dest));
+       
+       return newValue;
+}
+
+uint32_t
+hw_atomic_or(
+       uint32_t        *dest,
+       uint32_t        mask)
+{
+       uint32_t        oldValue;
+       uint32_t        newValue;
+       
+       do {
+               oldValue = *dest;
+               newValue = (oldValue | mask);
+       } while (!OSCompareAndSwap((UInt32)oldValue,
+                                                                       (UInt32)newValue, (UInt32 *)dest));
+       
+       return newValue;
+}
+
+uint32_t
+hw_atomic_and(
+       uint32_t        *dest,
+       uint32_t        mask)
+{
+       uint32_t        oldValue;
+       uint32_t        newValue;
+       
+       do {
+               oldValue = *dest;
+               newValue = (oldValue & mask);
+       } while (!OSCompareAndSwap((UInt32)oldValue,
+                                                                       (UInt32)newValue, (UInt32 *)dest));
+       
+       return newValue;
+}
+
+uint32_t
+hw_compare_and_store(
+       uint32_t        oldval,
+       uint32_t        newval,
+       uint32_t        *dest)
+{
+       return OSCompareAndSwap((UInt32)oldval, (UInt32)newval, (UInt32 *)dest);
+}
+
 #if    MACH_ASSERT
 
 /*