kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
/* Copyright 2009, 2010 The University of Texas at Austin.           */
kusano 2b45e8
/* All rights reserved.                                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* Redistribution and use in source and binary forms, with or        */
kusano 2b45e8
/* without modification, are permitted provided that the following   */
kusano 2b45e8
/* conditions are met:                                               */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   1. Redistributions of source code must retain the above         */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer.                                                  */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   2. Redistributions in binary form must reproduce the above      */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer in the documentation and/or other materials       */
kusano 2b45e8
/*      provided with the distribution.                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
kusano 2b45e8
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
kusano 2b45e8
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
kusano 2b45e8
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
kusano 2b45e8
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
kusano 2b45e8
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
kusano 2b45e8
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
kusano 2b45e8
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
kusano 2b45e8
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
kusano 2b45e8
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
kusano 2b45e8
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
kusano 2b45e8
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
kusano 2b45e8
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
kusano 2b45e8
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* The views and conclusions contained in the software and           */
kusano 2b45e8
/* documentation are those of the authors and should not be          */
kusano 2b45e8
/* interpreted as representing official policies, either expressed   */
kusano 2b45e8
/* or implied, of The University of Texas at Austin.                 */
kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
kusano 2b45e8
#include  <sys utsname.h=""></sys>
kusano 2b45e8
#ifdef _AIX
kusano 2b45e8
#include <sys vminfo.h=""></sys>
kusano 2b45e8
#endif
kusano 2b45e8
#ifdef __APPLE__
kusano 2b45e8
#include <mach mach.h=""></mach>
kusano 2b45e8
#include <mach mach_host.h=""></mach>
kusano 2b45e8
#include <mach host_info.h=""></mach>
kusano 2b45e8
#include <mach machine.h=""></mach>
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define CPUTYPE_UNKNOWN    0
kusano 2b45e8
#define CPUTYPE_POWER3     1
kusano 2b45e8
#define CPUTYPE_POWER4     2
kusano 2b45e8
#define CPUTYPE_PPC970     3
kusano 2b45e8
#define CPUTYPE_POWER5     4
kusano 2b45e8
#define CPUTYPE_POWER6     5
kusano 2b45e8
#define CPUTYPE_CELL       6
kusano 2b45e8
#define CPUTYPE_PPCG4	   7
kusano 2b45e8
kusano 2b45e8
char *cpuname[] = {
kusano 2b45e8
  "UNKNOWN",
kusano 2b45e8
  "POWER3",
kusano 2b45e8
  "POWER4",
kusano 2b45e8
  "PPC970",
kusano 2b45e8
  "POWER5",
kusano 2b45e8
  "POWER6",
kusano 2b45e8
  "CELL",
kusano 2b45e8
  "PPCG4",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
char *lowercpuname[] = {
kusano 2b45e8
  "unknown",
kusano 2b45e8
  "power3",
kusano 2b45e8
  "power4",
kusano 2b45e8
  "ppc970",
kusano 2b45e8
  "power5",
kusano 2b45e8
  "power6",
kusano 2b45e8
  "cell",
kusano 2b45e8
  "ppcg4",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
char *corename[] = {
kusano 2b45e8
  "UNKNOWN",
kusano 2b45e8
  "POWER3",
kusano 2b45e8
  "POWER4",
kusano 2b45e8
  "POWER4",
kusano 2b45e8
  "POWER4",
kusano 2b45e8
  "POWER6",
kusano 2b45e8
  "CELL",
kusano 2b45e8
  "PPCG4",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
int detect(void){
kusano 2b45e8
kusano 2b45e8
#ifdef linux
kusano 2b45e8
  FILE *infile;
kusano 2b45e8
  char buffer[512], *p;
kusano 2b45e8
kusano 2b45e8
  p = (char *)NULL;
kusano 2b45e8
  infile = fopen("/proc/cpuinfo", "r");
kusano 2b45e8
  while (fgets(buffer, sizeof(buffer), infile)){
kusano 2b45e8
    if (!strncmp("cpu", buffer, 3)){
kusano 2b45e8
	p = strchr(buffer, ':') + 2;
kusano 2b45e8
#if 0
kusano 2b45e8
	fprintf(stderr, "%s\n", p);
kusano 2b45e8
#endif
kusano 2b45e8
	break;
kusano 2b45e8
      }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  fclose(infile);
kusano 2b45e8
kusano 2b45e8
  if (!strncasecmp(p, "POWER3", 6)) return CPUTYPE_POWER3;
kusano 2b45e8
  if (!strncasecmp(p, "POWER4", 6)) return CPUTYPE_POWER4;
kusano 2b45e8
  if (!strncasecmp(p, "PPC970", 6)) return CPUTYPE_PPC970;
kusano 2b45e8
  if (!strncasecmp(p, "POWER5", 6)) return CPUTYPE_POWER5;
kusano 2b45e8
  if (!strncasecmp(p, "POWER6", 6)) return CPUTYPE_POWER6;
kusano 2b45e8
  if (!strncasecmp(p, "Cell",   4)) return CPUTYPE_CELL;
kusano 2b45e8
  if (!strncasecmp(p, "7447",   4)) return CPUTYPE_PPCG4;
kusano 2b45e8
kusano 2b45e8
  return CPUTYPE_UNKNOWN;
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef _AIX
kusano 2b45e8
  return CPUTYPE_POWER5;
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef __APPLE__
kusano 2b45e8
  host_basic_info_data_t   hostInfo;
kusano 2b45e8
  mach_msg_type_number_t  infoCount;
kusano 2b45e8
kusano 2b45e8
  infoCount = HOST_BASIC_INFO_COUNT;
kusano 2b45e8
  host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
kusano 2b45e8
kusano 2b45e8
  if (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_7450) return CPUTYPE_PPCG4;
kusano 2b45e8
  if (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970)  return CPUTYPE_PPC970;
kusano 2b45e8
 
kusano 2b45e8
  return  CPUTYPE_PPC970;
kusano 2b45e8
#endif
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_architecture(void){
kusano 2b45e8
  printf("POWER");
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_subdirname(void){
kusano 2b45e8
    printf("power");
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
void get_subarchitecture(void){
kusano 2b45e8
  printf("%s", cpuname[detect()]);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_cpuconfig(void){
kusano 2b45e8
#if 0
kusano 2b45e8
#ifdef _AIX
kusano 2b45e8
  struct vminfo info;
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  printf("#define %s\n", cpuname[detect()]);
kusano 2b45e8
  printf("#define CORE_%s\n", corename[detect()]);
kusano 2b45e8
kusano 2b45e8
  printf("#define L1_DATA_SIZE 32768\n");
kusano 2b45e8
  printf("#define L1_DATA_LINESIZE 128\n");
kusano 2b45e8
  printf("#define L2_SIZE 524288\n");
kusano 2b45e8
  printf("#define L2_LINESIZE 128 \n");
kusano 2b45e8
  printf("#define DTB_DEFAULT_ENTRIES 128\n");
kusano 2b45e8
  printf("#define DTB_SIZE 4096\n");
kusano 2b45e8
  printf("#define L2_ASSOCIATIVE 8\n");
kusano 2b45e8
kusano 2b45e8
#if 0
kusano 2b45e8
#ifdef _AIX
kusano 2b45e8
  if (vmgetinfo(&info, VMINFO, 0) == 0) {
kusano 2b45e8
    if ((info.lgpg_size >> 20) >= 1024) {
kusano 2b45e8
      printf("#define ALLOC_HUGETLB\n");
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_libname(void){
kusano 2b45e8
  printf("%s", lowercpuname[detect()]);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
char *get_corename(void){
kusano 2b45e8
  return cpuname[detect()];
kusano 2b45e8
}