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 <stdio.h></stdio.h>
kusano 2b45e8
#include <string.h></string.h>
kusano 2b45e8
#include <sys sysinfo.h=""></sys>
kusano 2b45e8
#include "cpuid.h"
kusano 2b45e8
kusano 2b45e8
#ifdef __ECC
kusano 2b45e8
#include <ia64intrin.h></ia64intrin.h>
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
static inline unsigned long cpuid(unsigned long regnum){ 
kusano 2b45e8
  unsigned long value;
kusano 2b45e8
kusano 2b45e8
#ifdef __ECC
kusano 2b45e8
  value = __getIndReg(_IA64_REG_INDR_CPUID, regnum);
kusano 2b45e8
#else
kusano 2b45e8
  asm ("mov %0=cpuid[%r1]" : "=r"(value) : "rO"(regnum));
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  return value;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
int have_cpuid(void){ return 1;}
kusano 2b45e8
kusano 2b45e8
int get_vendor(void){
kusano 2b45e8
  unsigned long cpuid0, cpuid1;
kusano 2b45e8
  char vendor[18];
kusano 2b45e8
kusano 2b45e8
  cpuid0 = cpuid(0);
kusano 2b45e8
  cpuid1 = cpuid(1);
kusano 2b45e8
  
kusano 2b45e8
  *(unsigned long *)(&vendor[0]) = cpuid0;
kusano 2b45e8
  *(unsigned long *)(&vendor[8]) = cpuid1;
kusano 2b45e8
  vendor[17] = (char)0;
kusano 2b45e8
kusano 2b45e8
  if (!strcmp(vendor, "GenuineIntel")) return VENDOR_INTEL;
kusano 2b45e8
kusano 2b45e8
  return VENDOR_UNKNOWN;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
int get_cputype(int gettype){
kusano 2b45e8
  unsigned long cpuid3;
kusano 2b45e8
kusano 2b45e8
  cpuid3 = cpuid(3);
kusano 2b45e8
  
kusano 2b45e8
  switch (gettype) {
kusano 2b45e8
  case GET_ARCHREV :
kusano 2b45e8
    return BITMASK(cpuid3, 32, 0xff);
kusano 2b45e8
  case GET_FAMILY :
kusano 2b45e8
    return BITMASK(cpuid3, 24, 0xff);
kusano 2b45e8
  case GET_MODEL :
kusano 2b45e8
    return BITMASK(cpuid3, 16, 0xff);
kusano 2b45e8
  case GET_REVISION :
kusano 2b45e8
    return BITMASK(cpuid3,  8, 0xff);
kusano 2b45e8
  case GET_NUMBER :
kusano 2b45e8
    return BITMASK(cpuid3,  0, 0xff);
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return 0;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
char *get_cpunamechar(void){
kusano 2b45e8
  if (get_cputype(GET_FAMILY) == 0x07) return "ITANIUM";
kusano 2b45e8
  if (get_cputype(GET_FAMILY) == 0x1f) return "ITANIUM2";
kusano 2b45e8
  if (get_cputype(GET_FAMILY) == 0x20) return "ITANIUM2";
kusano 2b45e8
kusano 2b45e8
  return "UNKNOWN";
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
char *get_libname(void){
kusano 2b45e8
  if (get_cputype(GET_FAMILY) == 0x07) { printf("itanium"); return NULL;}
kusano 2b45e8
  if (get_cputype(GET_FAMILY) == 0x1f) { printf("itanium2"); return NULL;}
kusano 2b45e8
  if (get_cputype(GET_FAMILY) == 0x20) { printf("itanium2"); return NULL;}
kusano 2b45e8
kusano 2b45e8
  printf("UNKNOWN");
kusano 2b45e8
kusano 2b45e8
  return NULL;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_architecture(void){
kusano 2b45e8
  printf("IA64");
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_subarchitecture(void){
kusano 2b45e8
    printf("%s", get_cpunamechar());
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_subdirname(void){
kusano 2b45e8
    printf("ia64");
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_cpuconfig(void){
kusano 2b45e8
  printf("#define %s\n", get_cpunamechar());
kusano 2b45e8
  printf("#define L1_DATA_SIZE 262144\n");
kusano 2b45e8
  printf("#define L1_DATA_LINESIZE 128\n");
kusano 2b45e8
  printf("#define L2_SIZE 1572864\n");
kusano 2b45e8
  printf("#define L2_LINESIZE 128\n");
kusano 2b45e8
  printf("#define DTB_SIZE 16384\n");
kusano 2b45e8
  printf("#define DTB_DEFAULT_ENTRIES 128\n");
kusano 2b45e8
}
kusano 2b45e8