# G5_detector.cpp

    00001 /* $Id: G5_detector.cpp 8033 2007-01-10 18:12:09Z KUDr $ */
    00002
    00003 #include <mach/mach.h>
    00004 #include <mach/mach_host.h>
    00005 #include <mach/host_info.h>
    00006 #include <mach/machine.h>
    00007 #include <stdio.h>
    00008
    00009
    00010 #ifndef CPU_SUBTYPE_POWERPC_970
    00011 #define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
    00012 #endif
    00013
    00014 // this function is a lightly modified version of some code from Apple's developer homepage to detect G5 CPUs at runtime
    00015 main()
    00016 {
    00017   host_basic_info_data_t hostInfo;
    00018   mach_msg_type_number_t infoCount;
    00019   boolean_t is_G5;
    00020
    00021   infoCount = HOST_BASIC_INFO_COUNT;
    00022   host_info(mach_host_self(), HOST_BASIC_INFO,
    00023         (host_info_t)&hostInfo, &infoCount);
    00024
    00025    is_G5 = ((hostInfo.cpu_type == CPU_TYPE_POWERPC) &&
    00026       (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970));
    00027    if (is_G5)
    00028      printf("1");
    00029 }