]> 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 305bc37ea0ad5503d44019dc868005d5a2dd4134..e64faedb222a2f25a58726e9052e9a31991b9f75 100644 (file)
@@ -54,6 +54,7 @@
 #include <string.h>
 #include <mach/boolean.h>
 #include <mach/i386/vm_types.h>
+#include <mach/i386/vm_param.h>
 #include <kern/kern_types.h>
 #include <kern/misc_protos.h>
 #include <i386/misc_protos.h>
        /*
         * 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 
+ *              kernel virtual space
+ */
+
+void
+bcopy_phys(const char *from, char *to, vm_size_t bytes)
+{
+  bcopy((char *)phystokv(from), (char *)phystokv(to), bytes);
+}
+
+
 /* 
  * ovbcopy - like bcopy, but recognizes overlapping ranges and handles 
  *           them correctly.
@@ -111,6 +140,113 @@ int bcmp(
        return len;
 }
 
+int
+memcmp(s1, s2, n)
+       register char *s1, *s2;
+       register n;
+{
+       while (--n >= 0)
+               if (*s1++ != *s2++)
+                       return (*--s1 - *--s2);
+       return (0);
+}
+
+/*
+ * Abstract:
+ * strlen returns the number of characters in "string" preceeding
+ * the terminating null character.
+ */
+
+size_t
+strlen(
+       register const char *string)
+{
+       register const char *ret = string;
+
+       while (*string++ != '\0')
+               continue;
+       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
 
 /*