]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/mach_fat.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / kern / mach_fat.c
index a9418aa8f981bf6e8b63351c6bf0e2a341deea57..677ae0008abd65bcfcd08e9aad5ce6b11de60935 100644 (file)
 #include <kern/cpu_number.h>
 #include <mach-o/fat.h>
 #include <kern/mach_loader.h>
-#include <architecture/byte_order.h>
-
-/* XXX should be in common header */
-extern int grade_binary(cpu_type_t exectype, cpu_subtype_t execsubtype);
-
-#define CPU_TYPE_NATIVE                (cpu_type())
-#define CPU_TYPE_CLASSIC       CPU_TYPE_POWERPC
+#include <libkern/OSByteOrder.h>
+#include <machine/exec.h>
 
 /**********************************************************************
  * Routine:    fatfile_getarch2()
@@ -106,7 +101,7 @@ fatfile_getarch2(
         *      Map portion that must be accessible directly into
         *      kernel's map.
         */
-       nfat_arch = NXSwapBigLongToHost(header->nfat_arch);
+       nfat_arch = OSSwapBigToHostInt32(header->nfat_arch);
 
        end_of_archs = (off_t)nfat_arch * sizeof(struct fat_arch) + 
                sizeof(struct fat_header);
@@ -124,6 +119,7 @@ fatfile_getarch2(
        if (end_of_archs > PAGE_SIZE ||
                end_of_archs < (sizeof(struct fat_header)+sizeof(struct fat_arch)))
                return(LOAD_BADMACHO);
+
        /*
         *      Round size of fat_arch structures up to page boundry.
         */
@@ -143,15 +139,15 @@ fatfile_getarch2(
                /*
                 *      Check to see if right cpu type.
                 */
-               if(((cpu_type_t)NXSwapBigIntToHost(arch->cputype) & ~mask_bits) != req_cpu_type)
+               if(((cpu_type_t)OSSwapBigToHostInt32(arch->cputype) & ~mask_bits) != req_cpu_type)
                        continue;
 
                /*
                 *      Get the grade of the cpu subtype.
                 */
                grade = grade_binary(
-                           NXSwapBigIntToHost(arch->cputype),
-                           NXSwapBigIntToHost(arch->cpusubtype));
+                           OSSwapBigToHostInt32(arch->cputype),
+                           OSSwapBigToHostInt32(arch->cpusubtype));
 
                /*
                 *      Remember it if it's the best we've seen.
@@ -169,15 +165,15 @@ fatfile_getarch2(
                lret = LOAD_BADARCH;
        } else {
                archret->cputype        =
-                           NXSwapBigIntToHost(best_arch->cputype);
+                           OSSwapBigToHostInt32(best_arch->cputype);
                archret->cpusubtype     =
-                           NXSwapBigIntToHost(best_arch->cpusubtype);
+                           OSSwapBigToHostInt32(best_arch->cpusubtype);
                archret->offset         =
-                           NXSwapBigLongToHost(best_arch->offset);
+                           OSSwapBigToHostInt32(best_arch->offset);
                archret->size           =
-                           NXSwapBigLongToHost(best_arch->size);
+                           OSSwapBigToHostInt32(best_arch->size);
                archret->align          =
-                           NXSwapBigLongToHost(best_arch->align);
+                           OSSwapBigToHostInt32(best_arch->align);
 
                lret = LOAD_SUCCESS;
        }
@@ -188,8 +184,6 @@ fatfile_getarch2(
        return(lret);
 }
 
-extern char classichandler[];
-
 load_return_t
 fatfile_getarch_affinity(
                struct vnode            *vp,
@@ -198,15 +192,15 @@ fatfile_getarch_affinity(
                int                             affinity)
 {
                load_return_t lret;
-               int handler = (classichandler[0] != 0);
+               int handler = (exec_archhandler_ppc.path[0] != 0);
                cpu_type_t primary_type, fallback_type;
 
                if (handler && affinity) {
-                               primary_type = CPU_TYPE_CLASSIC;
-                               fallback_type = CPU_TYPE_NATIVE;
+                               primary_type = CPU_TYPE_POWERPC;
+                               fallback_type = cpu_type();
                } else {
-                               primary_type = CPU_TYPE_NATIVE;
-                               fallback_type = CPU_TYPE_CLASSIC;
+                               primary_type = cpu_type();
+                               fallback_type = CPU_TYPE_POWERPC;
                }
                /*
                 * Ignore the architectural bits when determining if an image
@@ -240,7 +234,7 @@ fatfile_getarch(
        vm_offset_t     data_ptr,
        struct fat_arch         *archret)
 {
-       return fatfile_getarch2(vp, data_ptr, CPU_TYPE_NATIVE, 0, archret);
+       return fatfile_getarch2(vp, data_ptr, cpu_type(), 0, archret);
 }
 
 /**********************************************************************
@@ -265,6 +259,6 @@ fatfile_getarch_with_bits(
        vm_offset_t     data_ptr,
        struct fat_arch         *archret)
 {
-       return fatfile_getarch2(vp, data_ptr, archbits | CPU_TYPE_NATIVE, 0, archret);
+       return fatfile_getarch2(vp, data_ptr, archbits | cpu_type(), 0, archret);
 }