# G5_detector.cpp

Go to the documentation of this file.

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