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 "cpuid.h"
kusano 2b45e8
kusano 2b45e8
#ifndef CPUIDEMU
kusano 2b45e8
kusano 2b45e8
#if defined(__APPLE__) && defined(__i386__)
kusano 2b45e8
void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx);
kusano 2b45e8
#else
kusano 2b45e8
static inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx){
kusano 2b45e8
  __asm__ __volatile__
kusano 2b45e8
    ("cpuid": "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op) : "cc");
kusano 2b45e8
kusano 2b45e8
}
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#else
kusano 2b45e8
kusano 2b45e8
typedef struct {
kusano 2b45e8
  unsigned int id, a, b, c, d;
kusano 2b45e8
} idlist_t;
kusano 2b45e8
kusano 2b45e8
typedef struct {
kusano 2b45e8
  char *vendor;
kusano 2b45e8
  char *name;
kusano 2b45e8
  int start, stop;
kusano 2b45e8
} vendor_t;
kusano 2b45e8
kusano 2b45e8
extern idlist_t idlist[];
kusano 2b45e8
extern vendor_t vendor[];
kusano 2b45e8
kusano 2b45e8
static int cv = VENDOR;
kusano 2b45e8
kusano 2b45e8
void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx){
kusano 2b45e8
kusano 2b45e8
  static int current = 0;
kusano 2b45e8
kusano 2b45e8
  int start = vendor[cv].start;
kusano 2b45e8
  int stop  = vendor[cv].stop;
kusano 2b45e8
  int count = stop - start;
kusano 2b45e8
kusano 2b45e8
  if ((current < start) || (current > stop)) current = start;
kusano 2b45e8
kusano 2b45e8
  while ((count > 0) && (idlist[current].id != op)) {
kusano 2b45e8
    
kusano 2b45e8
    current ++;
kusano 2b45e8
    if (current > stop) current = start;
kusano 2b45e8
    count --;
kusano 2b45e8
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  *eax = idlist[current].a;
kusano 2b45e8
  *ebx = idlist[current].b;
kusano 2b45e8
  *ecx = idlist[current].c;
kusano 2b45e8
  *edx = idlist[current].d;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
static inline int have_cpuid(void){
kusano 2b45e8
  int eax, ebx, ecx, edx;
kusano 2b45e8
kusano 2b45e8
  cpuid(0, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
  return eax;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static inline int have_excpuid(void){
kusano 2b45e8
  int eax, ebx, ecx, edx;
kusano 2b45e8
kusano 2b45e8
  cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
  return eax & 0xffff;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
int get_vendor(void){
kusano 2b45e8
  int eax, ebx, ecx, edx;
kusano 2b45e8
  char vendor[13];
kusano 2b45e8
kusano 2b45e8
  cpuid(0, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
  
kusano 2b45e8
  *(int *)(&vendor[0]) = ebx;
kusano 2b45e8
  *(int *)(&vendor[4]) = edx;
kusano 2b45e8
  *(int *)(&vendor[8]) = ecx;
kusano 2b45e8
  vendor[12] = (char)0;
kusano 2b45e8
kusano 2b45e8
  if (!strcmp(vendor, "GenuineIntel")) return VENDOR_INTEL;
kusano 2b45e8
  if (!strcmp(vendor, " UMC UMC UMC")) return VENDOR_UMC;
kusano 2b45e8
  if (!strcmp(vendor, "AuthenticAMD")) return VENDOR_AMD;
kusano 2b45e8
  if (!strcmp(vendor, "CyrixInstead")) return VENDOR_CYRIX;
kusano 2b45e8
  if (!strcmp(vendor, "NexGenDriven")) return VENDOR_NEXGEN;
kusano 2b45e8
  if (!strcmp(vendor, "CentaurHauls")) return VENDOR_CENTAUR;
kusano 2b45e8
  if (!strcmp(vendor, "RiseRiseRise")) return VENDOR_RISE;
kusano 2b45e8
  if (!strcmp(vendor, " SiS SiS SiS")) return VENDOR_SIS;
kusano 2b45e8
  if (!strcmp(vendor, "GenuineTMx86")) return VENDOR_TRANSMETA;
kusano 2b45e8
  if (!strcmp(vendor, "Geode by NSC")) return VENDOR_NSC;
kusano 2b45e8
kusano 2b45e8
  if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
kusano 2b45e8
kusano 2b45e8
  return VENDOR_UNKNOWN;
kusano 2b45e8
}
kusano 2b45e8
  
kusano 2b45e8
int get_cputype(int gettype){
kusano 2b45e8
  int eax, ebx, ecx, edx;
kusano 2b45e8
  int extend_family, family;
kusano 2b45e8
  int extend_model, model;
kusano 2b45e8
  int type, stepping;
kusano 2b45e8
  int feature = 0;
kusano 2b45e8
kusano 2b45e8
  cpuid(1, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
  
kusano 2b45e8
  switch (gettype) {
kusano 2b45e8
  case GET_EXFAMILY :
kusano 2b45e8
    return BITMASK(eax, 20, 0xff);
kusano 2b45e8
  case GET_EXMODEL :
kusano 2b45e8
    return BITMASK(eax, 16, 0x0f);
kusano 2b45e8
  case GET_TYPE :
kusano 2b45e8
    return BITMASK(eax, 12, 0x03);
kusano 2b45e8
  case GET_FAMILY :
kusano 2b45e8
    return BITMASK(eax,  8, 0x0f);
kusano 2b45e8
  case GET_MODEL :
kusano 2b45e8
    return BITMASK(eax,  4, 0x0f);
kusano 2b45e8
  case GET_APICID :
kusano 2b45e8
    return BITMASK(ebx, 24, 0x0f);
kusano 2b45e8
  case GET_LCOUNT :
kusano 2b45e8
    return BITMASK(ebx, 16, 0x0f);
kusano 2b45e8
  case GET_CHUNKS :
kusano 2b45e8
    return BITMASK(ebx,  8, 0x0f);
kusano 2b45e8
  case GET_STEPPING :
kusano 2b45e8
    return BITMASK(eax,  0, 0x0f);
kusano 2b45e8
  case GET_BLANDID :
kusano 2b45e8
    return BITMASK(ebx,  0, 0xff);
kusano 2b45e8
  case GET_NUMSHARE :
kusano 2b45e8
    if (have_cpuid() < 4) return 0;
kusano 2b45e8
    cpuid(4, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
    return BITMASK(eax, 14, 0xfff);
kusano 2b45e8
  case GET_NUMCORES :
kusano 2b45e8
    if (have_cpuid() < 4) return 0;
kusano 2b45e8
    cpuid(4, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
    return BITMASK(eax, 26, 0x3f);
kusano 2b45e8
kusano 2b45e8
  case GET_FEATURE :
kusano 2b45e8
    if ((edx & (1 <<  3)) != 0) feature |= HAVE_PSE;
kusano 2b45e8
    if ((edx & (1 << 15)) != 0) feature |= HAVE_CMOV;
kusano 2b45e8
    if ((edx & (1 << 19)) != 0) feature |= HAVE_CFLUSH;
kusano 2b45e8
    if ((edx & (1 << 23)) != 0) feature |= HAVE_MMX;
kusano 2b45e8
    if ((edx & (1 << 25)) != 0) feature |= HAVE_SSE;
kusano 2b45e8
    if ((edx & (1 << 26)) != 0) feature |= HAVE_SSE2;
kusano 2b45e8
    if ((edx & (1 << 27)) != 0) {
kusano 2b45e8
      if (BITMASK(ebx, 16, 0x0f) > 0) feature |= HAVE_HIT;
kusano 2b45e8
    }
kusano 2b45e8
    if ((ecx & (1 <<  0)) != 0) feature |= HAVE_SSE3;
kusano 2b45e8
    if ((ecx & (1 <<  9)) != 0) feature |= HAVE_SSSE3;
kusano 2b45e8
    if ((ecx & (1 << 19)) != 0) feature |= HAVE_SSE4_1;
kusano 2b45e8
    if ((ecx & (1 << 20)) != 0) feature |= HAVE_SSE4_2;
kusano 2b45e8
kusano 2b45e8
    if (have_excpuid() >= 0x01) {
kusano 2b45e8
      cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
      if ((ecx & (1 <<  6)) != 0) feature |= HAVE_SSE4A;
kusano 2b45e8
      if ((ecx & (1 <<  7)) != 0) feature |= HAVE_MISALIGNSSE;
kusano 2b45e8
      if ((edx & (1 << 30)) != 0) feature |= HAVE_3DNOWEX;
kusano 2b45e8
      if ((edx & (1 << 31)) != 0) feature |= HAVE_3DNOW;
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    if (have_excpuid() >= 0x1a) {
kusano 2b45e8
      cpuid(0x8000001a, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
      if ((eax & (1 <<  0)) != 0) feature |= HAVE_128BITFPU;
kusano 2b45e8
      if ((eax & (1 <<  1)) != 0) feature |= HAVE_FASTMOVU;
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
  }
kusano 2b45e8
  return feature;
kusano 2b45e8
}
kusano 2b45e8
  
kusano 2b45e8
int get_cacheinfo(int type, cache_info_t *cacheinfo){
kusano 2b45e8
  int eax, ebx, ecx, edx, cpuid_level;
kusano 2b45e8
  int info[15];
kusano 2b45e8
  int i;
kusano 2b45e8
  cache_info_t LC1, LD1, L2, L3, 
kusano 2b45e8
    ITB, DTB, LITB, LDTB,
kusano 2b45e8
    L2ITB, L2DTB, L2LITB, L2LDTB;
kusano 2b45e8
kusano 2b45e8
  LC1.size    = 0; LC1.associative = 0; LC1.linesize = 0; LC1.shared = 0;
kusano 2b45e8
  LD1.size    = 0; LD1.associative    = 0; LD1.linesize    = 0; LD1.shared    = 0;
kusano 2b45e8
  L2.size     = 0; L2.associative     = 0; L2.linesize     = 0; L2.shared     = 0;
kusano 2b45e8
  L3.size     = 0; L3.associative     = 0; L3.linesize     = 0; L3.shared     = 0;
kusano 2b45e8
  ITB.size    = 0; ITB.associative    = 0; ITB.linesize    = 0; ITB.shared    = 0;
kusano 2b45e8
  DTB.size    = 0; DTB.associative    = 0; DTB.linesize    = 0; DTB.shared    = 0;
kusano 2b45e8
  LITB.size   = 0; LITB.associative   = 0; LITB.linesize   = 0; LITB.shared   = 0;
kusano 2b45e8
  LDTB.size   = 0; LDTB.associative   = 0; LDTB.linesize   = 0; LDTB.shared   = 0;
kusano 2b45e8
  L2ITB.size  = 0; L2ITB.associative  = 0; L2ITB.linesize  = 0; L2ITB.shared  = 0;
kusano 2b45e8
  L2DTB.size  = 0; L2DTB.associative  = 0; L2DTB.linesize  = 0; L2DTB.shared  = 0;
kusano 2b45e8
  L2LITB.size = 0; L2LITB.associative = 0; L2LITB.linesize = 0; L2LITB.shared = 0;
kusano 2b45e8
  L2LDTB.size = 0; L2LDTB.associative = 0; L2LDTB.linesize = 0; L2LDTB.shared = 0;
kusano 2b45e8
kusano 2b45e8
  cpuid(0, &cpuid_level, &ebx, &ecx, &edx);
kusano 2b45e8
kusano 2b45e8
  if (cpuid_level > 1) {
kusano 2b45e8
kusano 2b45e8
    cpuid(2, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
kusano 2b45e8
    info[ 0] = BITMASK(eax,  8, 0xff);
kusano 2b45e8
    info[ 1] = BITMASK(eax, 16, 0xff);
kusano 2b45e8
    info[ 2] = BITMASK(eax, 24, 0xff);
kusano 2b45e8
    
kusano 2b45e8
    info[ 3] = BITMASK(ebx,  0, 0xff);
kusano 2b45e8
    info[ 4] = BITMASK(ebx,  8, 0xff);
kusano 2b45e8
    info[ 5] = BITMASK(ebx, 16, 0xff);
kusano 2b45e8
    info[ 6] = BITMASK(ebx, 24, 0xff);
kusano 2b45e8
    
kusano 2b45e8
    info[ 7] = BITMASK(ecx,  0, 0xff);
kusano 2b45e8
    info[ 8] = BITMASK(ecx,  8, 0xff);
kusano 2b45e8
    info[ 9] = BITMASK(ecx, 16, 0xff);
kusano 2b45e8
    info[10] = BITMASK(ecx, 24, 0xff);
kusano 2b45e8
    
kusano 2b45e8
    info[11] = BITMASK(edx,  0, 0xff);
kusano 2b45e8
    info[12] = BITMASK(edx,  8, 0xff);
kusano 2b45e8
    info[13] = BITMASK(edx, 16, 0xff);
kusano 2b45e8
    info[14] = BITMASK(edx, 24, 0xff);
kusano 2b45e8
    
kusano 2b45e8
    for (i = 0; i < 15; i++){
kusano 2b45e8
kusano 2b45e8
      switch (info[i]){
kusano 2b45e8
kusano 2b45e8
	/* This table is from http://www.sandpile.org/ia32/cpuid.htm */
kusano 2b45e8
kusano 2b45e8
      case 0x01 :
kusano 2b45e8
	ITB.size        =     4;
kusano 2b45e8
	ITB.associative =     4;
kusano 2b45e8
	ITB.linesize     =   32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x02 :
kusano 2b45e8
	LITB.size        = 4096;
kusano 2b45e8
	LITB.associative =    0;
kusano 2b45e8
	LITB.linesize    =    2;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x03 :
kusano 2b45e8
	DTB.size        =     4;
kusano 2b45e8
	DTB.associative =     4;
kusano 2b45e8
	DTB.linesize     =   64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x04 :
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative =    4;
kusano 2b45e8
	LDTB.linesize    =    8;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x05 :
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative =    4;
kusano 2b45e8
	LDTB.linesize    =   32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x06 :
kusano 2b45e8
	LC1.size        = 8;
kusano 2b45e8
	LC1.associative = 4;
kusano 2b45e8
	LC1.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x08 :
kusano 2b45e8
	LC1.size        = 16;
kusano 2b45e8
	LC1.associative = 4;
kusano 2b45e8
	LC1.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x09 :
kusano 2b45e8
	LC1.size        = 32;
kusano 2b45e8
	LC1.associative = 4;
kusano 2b45e8
	LC1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x0a :
kusano 2b45e8
	LD1.size        = 8;
kusano 2b45e8
	LD1.associative = 2;
kusano 2b45e8
	LD1.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x0c :
kusano 2b45e8
	LD1.size        = 16;
kusano 2b45e8
	LD1.associative = 4;
kusano 2b45e8
	LD1.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x0d :
kusano 2b45e8
	LD1.size        = 16;
kusano 2b45e8
	LD1.associative = 4;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x0e :
kusano 2b45e8
	LD1.size        = 24;
kusano 2b45e8
	LD1.associative = 6;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x10 :
kusano 2b45e8
	LD1.size        = 16;
kusano 2b45e8
	LD1.associative = 4;
kusano 2b45e8
	LD1.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x15 :
kusano 2b45e8
	LC1.size        = 16;
kusano 2b45e8
	LC1.associative = 4;
kusano 2b45e8
	LC1.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x1a :
kusano 2b45e8
	L2.size         = 96;
kusano 2b45e8
	L2.associative  = 6;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x21 :
kusano 2b45e8
	L2.size         = 256;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x22 :
kusano 2b45e8
	L3.size         = 512;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x23 :
kusano 2b45e8
	L3.size         = 1024;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x25 :
kusano 2b45e8
	L3.size         = 2048;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x29 :
kusano 2b45e8
	L3.size         = 4096;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x2c :
kusano 2b45e8
	LD1.size        = 32;
kusano 2b45e8
	LD1.associative = 8;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x30 :
kusano 2b45e8
	LC1.size        = 32;
kusano 2b45e8
	LC1.associative = 8;
kusano 2b45e8
	LC1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x39 :
kusano 2b45e8
	L2.size         = 128;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x3a :
kusano 2b45e8
	L2.size         = 192;
kusano 2b45e8
	L2.associative  = 6;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x3b :
kusano 2b45e8
	L2.size         = 128;
kusano 2b45e8
	L2.associative  = 2;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x3c :
kusano 2b45e8
	L2.size         = 256;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x3d :
kusano 2b45e8
	L2.size         = 384;
kusano 2b45e8
	L2.associative  = 6;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x3e :
kusano 2b45e8
	L2.size         = 512;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x41 :
kusano 2b45e8
	L2.size         = 128;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x42 :
kusano 2b45e8
	L2.size         = 256;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x43 :
kusano 2b45e8
	L2.size         = 512;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x44 :
kusano 2b45e8
	L2.size         = 1024;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x45 :
kusano 2b45e8
	L2.size         = 2048;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x46 :
kusano 2b45e8
	L3.size         = 4096;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x47 :
kusano 2b45e8
	L3.size         = 8192;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x48 :
kusano 2b45e8
	L2.size         = 3184;
kusano 2b45e8
	L2.associative  = 12;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x49 :
kusano 2b45e8
	if ((get_cputype(GET_FAMILY) == 0x0f) && (get_cputype(GET_MODEL) == 0x06)) {
kusano 2b45e8
	  L3.size         = 4096;
kusano 2b45e8
	  L3.associative  = 16;
kusano 2b45e8
	  L3.linesize     = 64;
kusano 2b45e8
	} else {
kusano 2b45e8
	  L2.size         = 4096;
kusano 2b45e8
	  L2.associative  = 16;
kusano 2b45e8
	  L2.linesize     = 64;
kusano 2b45e8
	}
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x4a :
kusano 2b45e8
	L3.size         = 6144;
kusano 2b45e8
	L3.associative  = 12;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x4b :
kusano 2b45e8
	L3.size         = 8192;
kusano 2b45e8
	L3.associative  = 16;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x4c :
kusano 2b45e8
	L3.size         = 12280;
kusano 2b45e8
	L3.associative  = 12;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x4d :
kusano 2b45e8
	L3.size         = 16384;
kusano 2b45e8
	L3.associative  = 16;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x4e :
kusano 2b45e8
	L2.size         = 6144;
kusano 2b45e8
	L2.associative  = 24;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x4f :
kusano 2b45e8
	ITB.size         = 4;
kusano 2b45e8
	ITB.associative  = 0;
kusano 2b45e8
	ITB.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x50 :
kusano 2b45e8
	ITB.size         = 4;
kusano 2b45e8
	ITB.associative  = 0;
kusano 2b45e8
	ITB.linesize     = 64;
kusano 2b45e8
	LITB.size        = 4096;
kusano 2b45e8
	LITB.associative = 0;
kusano 2b45e8
	LITB.linesize    = 64;
kusano 2b45e8
	LITB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x51 :
kusano 2b45e8
	ITB.size        = 4;
kusano 2b45e8
	ITB.associative = 0;
kusano 2b45e8
	ITB.linesize     = 128;
kusano 2b45e8
	LITB.size        = 4096;
kusano 2b45e8
	LITB.associative = 0;
kusano 2b45e8
	LITB.linesize    = 128;
kusano 2b45e8
	LITB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x52 :
kusano 2b45e8
	ITB.size         = 4;
kusano 2b45e8
	ITB.associative  = 0;
kusano 2b45e8
	ITB.linesize     = 256;
kusano 2b45e8
	LITB.size        = 4096;
kusano 2b45e8
	LITB.associative = 0;
kusano 2b45e8
	LITB.linesize    = 256;
kusano 2b45e8
	LITB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x55 :
kusano 2b45e8
	LITB.size        = 4096;
kusano 2b45e8
	LITB.associative = 0;
kusano 2b45e8
	LITB.linesize    = 7;
kusano 2b45e8
	LITB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x56 :
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative = 4;
kusano 2b45e8
	LDTB.linesize    = 16;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x57 :
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative = 4;
kusano 2b45e8
	LDTB.linesize    = 16;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x5b :
kusano 2b45e8
	DTB.size         = 4;
kusano 2b45e8
	DTB.associative  = 0;
kusano 2b45e8
	DTB.linesize     = 64;
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative = 0;
kusano 2b45e8
	LDTB.linesize    = 64;
kusano 2b45e8
	LDTB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x5c :
kusano 2b45e8
	DTB.size         = 4;
kusano 2b45e8
	DTB.associative  = 0;
kusano 2b45e8
	DTB.linesize     = 128;
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative = 0;
kusano 2b45e8
	LDTB.linesize    = 128;
kusano 2b45e8
	LDTB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x5d :
kusano 2b45e8
	DTB.size         = 4;
kusano 2b45e8
	DTB.associative  = 0;
kusano 2b45e8
	DTB.linesize     = 256;
kusano 2b45e8
	LDTB.size        = 4096;
kusano 2b45e8
	LDTB.associative = 0;
kusano 2b45e8
	LDTB.linesize    = 256;
kusano 2b45e8
	LDTB.shared      = 1;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x60 :
kusano 2b45e8
	LD1.size        = 16;
kusano 2b45e8
	LD1.associative = 8;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x66 :
kusano 2b45e8
	LD1.size        = 8;
kusano 2b45e8
	LD1.associative = 4;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x67 :
kusano 2b45e8
	LD1.size        = 16;
kusano 2b45e8
	LD1.associative = 4;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x68 :
kusano 2b45e8
	LD1.size        = 32;
kusano 2b45e8
	LD1.associative = 4;
kusano 2b45e8
	LD1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x70 :
kusano 2b45e8
	LC1.size        = 12;
kusano 2b45e8
	LC1.associative = 8;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x71 :
kusano 2b45e8
	LC1.size        = 16;
kusano 2b45e8
	LC1.associative = 8;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x72 :
kusano 2b45e8
	LC1.size        = 32;
kusano 2b45e8
	LC1.associative = 8;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x73 :
kusano 2b45e8
	LC1.size        = 64;
kusano 2b45e8
	LC1.associative = 8;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x77 :
kusano 2b45e8
	LC1.size        = 16;
kusano 2b45e8
	LC1.associative = 4;
kusano 2b45e8
	LC1.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x78 :
kusano 2b45e8
	L2.size        = 1024;
kusano 2b45e8
	L2.associative = 4;
kusano 2b45e8
	L2.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x79 :
kusano 2b45e8
	L2.size         = 128;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x7a :
kusano 2b45e8
	L2.size         = 256;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x7b :
kusano 2b45e8
	L2.size         = 512;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x7c :
kusano 2b45e8
	L2.size         = 1024;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x7d :
kusano 2b45e8
	L2.size         = 2048;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x7e :
kusano 2b45e8
	L2.size         = 256;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 128;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x7f :
kusano 2b45e8
	L2.size         = 512;
kusano 2b45e8
	L2.associative  = 2;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x81 :
kusano 2b45e8
	L2.size         = 128;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x82 :
kusano 2b45e8
	L2.size         = 256;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x83 :
kusano 2b45e8
	L2.size         = 512;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x84 :
kusano 2b45e8
	L2.size         = 1024;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x85 :
kusano 2b45e8
	L2.size         = 2048;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x86 :
kusano 2b45e8
	L2.size         = 512;
kusano 2b45e8
	L2.associative  = 4;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x87 :
kusano 2b45e8
	L2.size         = 1024;
kusano 2b45e8
	L2.associative  = 8;
kusano 2b45e8
	L2.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x88 :
kusano 2b45e8
	L3.size         = 2048;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x89 :
kusano 2b45e8
	L3.size         = 4096;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x8a :
kusano 2b45e8
	L3.size         = 8192;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x8d :
kusano 2b45e8
	L3.size         = 3096;
kusano 2b45e8
	L3.associative  = 12;
kusano 2b45e8
	L3.linesize     = 128;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x90 :
kusano 2b45e8
	ITB.size        = 4;
kusano 2b45e8
	ITB.associative = 0;
kusano 2b45e8
	ITB.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x96 :
kusano 2b45e8
	DTB.size        = 4;
kusano 2b45e8
	DTB.associative = 0;
kusano 2b45e8
	DTB.linesize    = 32;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0x9b :
kusano 2b45e8
	L2DTB.size        = 4;
kusano 2b45e8
	L2DTB.associative = 0;
kusano 2b45e8
	L2DTB.linesize    = 96;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xb0 :
kusano 2b45e8
	ITB.size        = 4;
kusano 2b45e8
	ITB.associative = 4;
kusano 2b45e8
	ITB.linesize    = 128;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xb1 :
kusano 2b45e8
	LITB.size        = 4096;
kusano 2b45e8
	LITB.associative = 4;
kusano 2b45e8
	LITB.linesize    = 4;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xb2 :
kusano 2b45e8
	ITB.size        = 4;
kusano 2b45e8
	ITB.associative = 4;
kusano 2b45e8
	ITB.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xb3 :
kusano 2b45e8
	DTB.size        = 4;
kusano 2b45e8
	DTB.associative = 4;
kusano 2b45e8
	DTB.linesize    = 128;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xb4 :
kusano 2b45e8
	DTB.size        = 4;
kusano 2b45e8
	DTB.associative = 4;
kusano 2b45e8
	DTB.linesize    = 256;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xba :
kusano 2b45e8
	DTB.size        = 4;
kusano 2b45e8
	DTB.associative = 4;
kusano 2b45e8
	DTB.linesize    = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xd0 :
kusano 2b45e8
	L3.size         = 512;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xd1 :
kusano 2b45e8
	L3.size         = 1024;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xd2 :
kusano 2b45e8
	L3.size         = 2048;
kusano 2b45e8
	L3.associative  = 4;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xd6 :
kusano 2b45e8
	L3.size         = 1024;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xd7 :
kusano 2b45e8
	L3.size         = 2048;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xd8 :
kusano 2b45e8
	L3.size         = 4096;
kusano 2b45e8
	L3.associative  = 8;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xdc :
kusano 2b45e8
	L3.size         = 2048;
kusano 2b45e8
	L3.associative  = 12;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xdd :
kusano 2b45e8
	L3.size         = 4096;
kusano 2b45e8
	L3.associative  = 12;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xde :
kusano 2b45e8
	L3.size         = 8192;
kusano 2b45e8
	L3.associative  = 12;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xe2 :
kusano 2b45e8
	L3.size         = 2048;
kusano 2b45e8
	L3.associative  = 16;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xe3 :
kusano 2b45e8
	L3.size         = 4096;
kusano 2b45e8
	L3.associative  = 16;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      case 0xe4 :
kusano 2b45e8
	L3.size         = 8192;
kusano 2b45e8
	L3.associative  = 16;
kusano 2b45e8
	L3.linesize     = 64;
kusano 2b45e8
	break;
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (get_vendor() == VENDOR_INTEL) {
kusano 2b45e8
    cpuid(0x80000000, &cpuid_level, &ebx, &ecx, &edx);
kusano 2b45e8
    if (cpuid_level >= 0x80000006) {
kusano 2b45e8
      cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
kusano 2b45e8
      L2.size         = BITMASK(ecx, 16, 0xffff);
kusano 2b45e8
      L2.associative  = BITMASK(ecx, 12, 0x0f);
kusano 2b45e8
      L2.linesize     = BITMASK(ecx,  0, 0xff);
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if ((get_vendor() == VENDOR_AMD) || (get_vendor() == VENDOR_CENTAUR)) {
kusano 2b45e8
    cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
kusano 2b45e8
    LDTB.size        = 4096;
kusano 2b45e8
    LDTB.associative = BITMASK(eax, 24, 0xff);
kusano 2b45e8
    if (LDTB.associative == 0xff) LDTB.associative = 0;
kusano 2b45e8
    LDTB.linesize    = BITMASK(eax, 16, 0xff);
kusano 2b45e8
kusano 2b45e8
    LITB.size        = 4096;
kusano 2b45e8
    LITB.associative = BITMASK(eax,  8, 0xff);
kusano 2b45e8
    if (LITB.associative == 0xff) LITB.associative = 0;
kusano 2b45e8
    LITB.linesize    = BITMASK(eax,  0, 0xff);
kusano 2b45e8
    
kusano 2b45e8
    DTB.size        = 4;
kusano 2b45e8
    DTB.associative = BITMASK(ebx, 24, 0xff);
kusano 2b45e8
    if (DTB.associative == 0xff) DTB.associative = 0;
kusano 2b45e8
    DTB.linesize    = BITMASK(ebx, 16, 0xff);
kusano 2b45e8
kusano 2b45e8
    ITB.size        = 4;
kusano 2b45e8
    ITB.associative = BITMASK(ebx,  8, 0xff);
kusano 2b45e8
    if (ITB.associative == 0xff) ITB.associative = 0;
kusano 2b45e8
    ITB.linesize    = BITMASK(ebx,  0, 0xff);
kusano 2b45e8
kusano 2b45e8
    LD1.size        = BITMASK(ecx, 24, 0xff);
kusano 2b45e8
    LD1.associative = BITMASK(ecx, 16, 0xff);
kusano 2b45e8
    if (LD1.associative == 0xff) LD1.associative = 0;
kusano 2b45e8
    LD1.linesize    = BITMASK(ecx,  0, 0xff);
kusano 2b45e8
kusano 2b45e8
    LC1.size        = BITMASK(ecx, 24, 0xff);
kusano 2b45e8
    LC1.associative = BITMASK(ecx, 16, 0xff);
kusano 2b45e8
    if (LC1.associative == 0xff) LC1.associative = 0;
kusano 2b45e8
    LC1.linesize    = BITMASK(ecx,  0, 0xff);
kusano 2b45e8
kusano 2b45e8
    cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
kusano 2b45e8
kusano 2b45e8
    L2LDTB.size        = 4096;
kusano 2b45e8
    L2LDTB.associative = BITMASK(eax, 24, 0xff);
kusano 2b45e8
    if (L2LDTB.associative == 0xff) L2LDTB.associative = 0;
kusano 2b45e8
    L2LDTB.linesize    = BITMASK(eax, 16, 0xff);
kusano 2b45e8
kusano 2b45e8
    L2LITB.size        = 4096;
kusano 2b45e8
    L2LITB.associative = BITMASK(eax,  8, 0xff);
kusano 2b45e8
    if (L2LITB.associative == 0xff) L2LITB.associative = 0;
kusano 2b45e8
    L2LITB.linesize    = BITMASK(eax,  0, 0xff);
kusano 2b45e8
    
kusano 2b45e8
    L2DTB.size        = 4;
kusano 2b45e8
    L2DTB.associative = BITMASK(ebx, 24, 0xff);
kusano 2b45e8
    if (L2DTB.associative == 0xff) L2DTB.associative = 0;
kusano 2b45e8
    L2DTB.linesize    = BITMASK(ebx, 16, 0xff);
kusano 2b45e8
kusano 2b45e8
    L2ITB.size        = 4;
kusano 2b45e8
    L2ITB.associative = BITMASK(ebx,  8, 0xff);
kusano 2b45e8
    if (L2ITB.associative == 0xff) L2ITB.associative = 0;
kusano 2b45e8
    L2ITB.linesize    = BITMASK(ebx,  0, 0xff);
kusano 2b45e8
kusano 2b45e8
    L2.size        = BITMASK(ecx, 16, 0xffff);
kusano 2b45e8
    L2.associative = BITMASK(ecx, 12, 0xf);
kusano 2b45e8
    if (L2.associative == 0xff) L2.associative = 0;
kusano 2b45e8
    L2.linesize    = BITMASK(ecx,  0, 0xff);
kusano 2b45e8
kusano 2b45e8
    L3.size        = BITMASK(edx, 18, 0x3fff) * 512;
kusano 2b45e8
    L3.associative = BITMASK(edx, 12, 0xf);
kusano 2b45e8
    if (L3.associative == 0xff) L2.associative = 0;
kusano 2b45e8
    L3.linesize    = BITMASK(edx,  0, 0xff);
kusano 2b45e8
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
    switch (type) {
kusano 2b45e8
      
kusano 2b45e8
    case CACHE_INFO_L1_I :
kusano 2b45e8
      *cacheinfo = LC1;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L1_D :
kusano 2b45e8
      *cacheinfo = LD1;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L2 :
kusano 2b45e8
      *cacheinfo = L2;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L3 :
kusano 2b45e8
      *cacheinfo = L3;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L1_DTB :
kusano 2b45e8
      *cacheinfo = DTB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L1_ITB :
kusano 2b45e8
      *cacheinfo = ITB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L1_LDTB :
kusano 2b45e8
      *cacheinfo = LDTB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L1_LITB :
kusano 2b45e8
      *cacheinfo = LITB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L2_DTB :
kusano 2b45e8
      *cacheinfo = L2DTB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L2_ITB :
kusano 2b45e8
      *cacheinfo = L2ITB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L2_LDTB :
kusano 2b45e8
      *cacheinfo = L2LDTB;
kusano 2b45e8
      break;
kusano 2b45e8
    case CACHE_INFO_L2_LITB :
kusano 2b45e8
      *cacheinfo = L2LITB;
kusano 2b45e8
      break;
kusano 2b45e8
    }
kusano 2b45e8
  return 0;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
int get_cpuname(void){
kusano 2b45e8
kusano 2b45e8
  int family, exfamily, model, vendor, exmodel;
kusano 2b45e8
kusano 2b45e8
  if (!have_cpuid()) return CPUTYPE_80386;
kusano 2b45e8
kusano 2b45e8
  family   = get_cputype(GET_FAMILY);
kusano 2b45e8
  exfamily = get_cputype(GET_EXFAMILY);
kusano 2b45e8
  model    = get_cputype(GET_MODEL);
kusano 2b45e8
  exmodel  = get_cputype(GET_EXMODEL);
kusano 2b45e8
kusano 2b45e8
  vendor = get_vendor();
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_INTEL){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x4:
kusano 2b45e8
      return CPUTYPE_80486;
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_PENTIUM;
kusano 2b45e8
    case 0x6:
kusano 2b45e8
      switch (exmodel) {
kusano 2b45e8
      case 0: 
kusano 2b45e8
	switch (model) {
kusano 2b45e8
	case  1:
kusano 2b45e8
	case  3:
kusano 2b45e8
	case  5:
kusano 2b45e8
	case  6:
kusano 2b45e8
	  return CPUTYPE_PENTIUM2;
kusano 2b45e8
	case  7:
kusano 2b45e8
	case  8:
kusano 2b45e8
	case 10:
kusano 2b45e8
	case 11:
kusano 2b45e8
	  return CPUTYPE_PENTIUM3;
kusano 2b45e8
	case  9:
kusano 2b45e8
	case 13:
kusano 2b45e8
	case 14:
kusano 2b45e8
	  return CPUTYPE_PENTIUMM;
kusano 2b45e8
	case 15:
kusano 2b45e8
	  return CPUTYPE_CORE2;
kusano 2b45e8
	}
kusano 2b45e8
	break;
kusano 2b45e8
      case 1:
kusano 2b45e8
	switch (model) {
kusano 2b45e8
	case  6:
kusano 2b45e8
	  return CPUTYPE_CORE2;
kusano 2b45e8
	case  7:
kusano 2b45e8
	  return CPUTYPE_PENRYN;
kusano 2b45e8
	case 10:
kusano 2b45e8
	case 11:
kusano 2b45e8
	case 14:
kusano 2b45e8
	case 15:
kusano 2b45e8
	  return CPUTYPE_NEHALEM;
kusano 2b45e8
	case 12:
kusano 2b45e8
	  return CPUTYPE_ATOM;
kusano 2b45e8
	case 13:
kusano 2b45e8
	  return CPUTYPE_DUNNINGTON;
kusano 2b45e8
	}
kusano 2b45e8
	break;
kusano 2b45e8
	  case  2:
kusano 2b45e8
		  switch (model) {
kusano 2b45e8
		  case 5:
kusano 2b45e8
			  //Intel Core (Clarkdale) / Core (Arrandale) 
kusano 2b45e8
			  // Pentium (Clarkdale) / Pentium Mobile (Arrandale) 
kusano 2b45e8
			  // Xeon (Clarkdale), 32nm
kusano 2b45e8
			  return CPUTYPE_NEHALEM;
kusano 2b45e8
		  case 10:
kusano 2b45e8
                          //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
kusano 2b45e8
                          return CPUTYPE_NEHALEM;
kusano 2b45e8
		  case 12:
kusano 2b45e8
			  //Xeon Processor 5600 (Westmere-EP)
kusano 2b45e8
			  return CPUTYPE_NEHALEM;
kusano 2b45e8
		  case 13:
kusano 2b45e8
                          //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
kusano 2b45e8
                          return CPUTYPE_NEHALEM;
kusano 2b45e8
		  case 15:
kusano 2b45e8
			  //Xeon Processor E7 (Westmere-EX)
kusano 2b45e8
			  return CPUTYPE_NEHALEM;
kusano 2b45e8
		  }
kusano 2b45e8
		  break;
kusano 2b45e8
      }
kusano 2b45e8
      break;
kusano 2b45e8
    case 0x7:
kusano 2b45e8
      return CPUTYPE_ITANIUM;
kusano 2b45e8
    case 0xf:
kusano 2b45e8
      switch (exfamily) {
kusano 2b45e8
      case 0 :
kusano 2b45e8
	return CPUTYPE_PENTIUM4;
kusano 2b45e8
      case 1 :
kusano 2b45e8
	return CPUTYPE_ITANIUM;
kusano 2b45e8
      }
kusano 2b45e8
      break;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_INTEL_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_AMD){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x4:
kusano 2b45e8
      return CPUTYPE_AMD5X86;
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_AMDK6;
kusano 2b45e8
    case 0x6:
kusano 2b45e8
      return CPUTYPE_ATHLON;
kusano 2b45e8
    case 0xf:
kusano 2b45e8
      switch (exfamily) {
kusano 2b45e8
      case  0:
kusano 2b45e8
      case  2:
kusano 2b45e8
	return CPUTYPE_OPTERON;
kusano 2b45e8
      case  1:
kusano 2b45e8
      case 10:
kusano 2b45e8
	return CPUTYPE_BARCELONA;
kusano 2b45e8
      }
kusano 2b45e8
      break;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_AMD_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_CYRIX){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x4:
kusano 2b45e8
      return CPUTYPE_CYRIX5X86;
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_CYRIXM1;
kusano 2b45e8
    case 0x6:
kusano 2b45e8
      return CPUTYPE_CYRIXM2;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_CYRIX_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_NEXGEN){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_NEXGENNX586;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_NEXGEN_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_CENTAUR){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_CENTAURC6;
kusano 2b45e8
      break;
kusano 2b45e8
    case 0x6:
kusano 2b45e8
      return CPUTYPE_NANO;
kusano 2b45e8
      break;
kusano 2b45e8
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_VIAC3;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_RISE){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_RISEMP6;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_RISE_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_SIS){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_SYS55X;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_SIS_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_TRANSMETA){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_CRUSOETM3X;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_TRANSMETA_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_NSC){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x5:
kusano 2b45e8
      return CPUTYPE_NSGEODE;
kusano 2b45e8
    }
kusano 2b45e8
    return CPUTYPE_NSC_UNKNOWN;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return CPUTYPE_UNKNOWN;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
static char *cpuname[] = {
kusano 2b45e8
  "UNKNOWN",
kusano 2b45e8
  "INTEL_UNKNOWN",
kusano 2b45e8
  "UMC_UNKNOWN",
kusano 2b45e8
  "AMD_UNKNOWN",
kusano 2b45e8
  "CYRIX_UNKNOWN",
kusano 2b45e8
  "NEXGEN_UNKNOWN",
kusano 2b45e8
  "CENTAUR_UNKNOWN",
kusano 2b45e8
  "RISE_UNKNOWN",
kusano 2b45e8
  "SIS_UNKNOWN",
kusano 2b45e8
  "TRANSMETA_UNKNOWN",
kusano 2b45e8
  "NSC_UNKNOWN",
kusano 2b45e8
  "80386",
kusano 2b45e8
  "80486",
kusano 2b45e8
  "PENTIUM",
kusano 2b45e8
  "PENTIUM2",
kusano 2b45e8
  "PENTIUM3",
kusano 2b45e8
  "PENTIUMM",
kusano 2b45e8
  "PENTIUM4",
kusano 2b45e8
  "CORE2",
kusano 2b45e8
  "PENRYN",
kusano 2b45e8
  "DUNNINGTON",
kusano 2b45e8
  "NEHALEM",
kusano 2b45e8
  "ATOM",
kusano 2b45e8
  "ITANIUM",
kusano 2b45e8
  "ITANIUM2",
kusano 2b45e8
  "5X86",
kusano 2b45e8
  "K6",
kusano 2b45e8
  "ATHLON",
kusano 2b45e8
  "DURON",
kusano 2b45e8
  "OPTERON",
kusano 2b45e8
  "BARCELONA",
kusano 2b45e8
  "SHANGHAI",
kusano 2b45e8
  "ISTANBUL",
kusano 2b45e8
  "CYRIX5X86",
kusano 2b45e8
  "CYRIXM1",
kusano 2b45e8
  "CYRIXM2",
kusano 2b45e8
  "NEXGENNX586",
kusano 2b45e8
  "CENTAURC6",
kusano 2b45e8
  "RISEMP6",
kusano 2b45e8
  "SYS55X",
kusano 2b45e8
  "TM3X00",
kusano 2b45e8
  "NSGEODE",
kusano 2b45e8
  "VIAC3",
kusano 2b45e8
  "NANO",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
static char *lowercpuname[] = {
kusano 2b45e8
  "unknown",
kusano 2b45e8
  "intel_unknown",
kusano 2b45e8
  "umc_unknown",
kusano 2b45e8
  "amd_unknown",
kusano 2b45e8
  "cyrix_unknown",
kusano 2b45e8
  "nexgen_unknown",
kusano 2b45e8
  "centaur_unknown",
kusano 2b45e8
  "rise_unknown",
kusano 2b45e8
  "sis_unknown",
kusano 2b45e8
  "transmeta_unknown",
kusano 2b45e8
  "nsc_unknown",
kusano 2b45e8
  "80386",
kusano 2b45e8
  "80486",
kusano 2b45e8
  "pentium",
kusano 2b45e8
  "pentium2",
kusano 2b45e8
  "pentium3",
kusano 2b45e8
  "pentiumm",
kusano 2b45e8
  "pentium4",
kusano 2b45e8
  "core2",
kusano 2b45e8
  "penryn",
kusano 2b45e8
  "dunnington",
kusano 2b45e8
  "nehalem",
kusano 2b45e8
  "atom",
kusano 2b45e8
  "itanium",
kusano 2b45e8
  "itanium2",
kusano 2b45e8
  "5x86",
kusano 2b45e8
  "k6",
kusano 2b45e8
  "athlon",
kusano 2b45e8
  "duron",
kusano 2b45e8
  "opteron",
kusano 2b45e8
  "barcelona",
kusano 2b45e8
  "shanghai",
kusano 2b45e8
  "istanbul",
kusano 2b45e8
  "cyrix5x86",
kusano 2b45e8
  "cyrixm1",
kusano 2b45e8
  "cyrixm2",
kusano 2b45e8
  "nexgennx586",
kusano 2b45e8
  "centaurc6",
kusano 2b45e8
  "risemp6",
kusano 2b45e8
  "sys55x",
kusano 2b45e8
  "tms3x00",
kusano 2b45e8
  "nsgeode",
kusano 2b45e8
  "nano",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
static char *corename[] = {
kusano 2b45e8
  "UNKOWN",
kusano 2b45e8
  "80486", 
kusano 2b45e8
  "P5",
kusano 2b45e8
  "P6",
kusano 2b45e8
  "KATMAI",
kusano 2b45e8
  "COPPERMINE",
kusano 2b45e8
  "NORTHWOOD",
kusano 2b45e8
  "PRESCOTT",
kusano 2b45e8
  "BANIAS",
kusano 2b45e8
  "ATHLON",
kusano 2b45e8
  "OPTERON",
kusano 2b45e8
  "BARCELONA",
kusano 2b45e8
  "VIAC3",
kusano 2b45e8
  "YONAH",
kusano 2b45e8
  "CORE2",
kusano 2b45e8
  "PENRYN",
kusano 2b45e8
  "DUNNINGTON",
kusano 2b45e8
  "NEHALEM",
kusano 2b45e8
  "ATOM",
kusano 2b45e8
  "NANO",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
static char *corename_lower[] = {
kusano 2b45e8
  "unknown",
kusano 2b45e8
  "80486", 
kusano 2b45e8
  "p5",
kusano 2b45e8
  "p6",
kusano 2b45e8
  "katmai",
kusano 2b45e8
  "coppermine",
kusano 2b45e8
  "northwood",
kusano 2b45e8
  "prescott",
kusano 2b45e8
  "banias",
kusano 2b45e8
  "athlon",
kusano 2b45e8
  "opteron",
kusano 2b45e8
  "barcelona",
kusano 2b45e8
  "viac3",
kusano 2b45e8
  "yonah",
kusano 2b45e8
  "core2",
kusano 2b45e8
  "penryn",
kusano 2b45e8
  "dunnington",
kusano 2b45e8
  "nehalem",
kusano 2b45e8
  "atom",
kusano 2b45e8
  "nano",
kusano 2b45e8
};
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
char *get_cpunamechar(void){
kusano 2b45e8
  return cpuname[get_cpuname()];
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
char *get_lower_cpunamechar(void){
kusano 2b45e8
  return lowercpuname[get_cpuname()];
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
int get_coretype(void){
kusano 2b45e8
kusano 2b45e8
  int family, exfamily, model, exmodel, vendor;
kusano 2b45e8
kusano 2b45e8
  if (!have_cpuid()) return CORE_80486;
kusano 2b45e8
kusano 2b45e8
  family   = get_cputype(GET_FAMILY);
kusano 2b45e8
  exfamily = get_cputype(GET_EXFAMILY);
kusano 2b45e8
  model    = get_cputype(GET_MODEL);
kusano 2b45e8
  exmodel  = get_cputype(GET_EXMODEL);
kusano 2b45e8
kusano 2b45e8
  vendor = get_vendor();
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_INTEL){
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case  4:
kusano 2b45e8
      return CORE_80486;
kusano 2b45e8
    case  5:
kusano 2b45e8
      return CORE_P5;
kusano 2b45e8
    case  6:
kusano 2b45e8
      switch (exmodel) {
kusano 2b45e8
      case  0:
kusano 2b45e8
	switch (model) {
kusano 2b45e8
	case  0:
kusano 2b45e8
	case  1:
kusano 2b45e8
	case  2:
kusano 2b45e8
	case  3:
kusano 2b45e8
	case  4:
kusano 2b45e8
	case  5:
kusano 2b45e8
	case  6:
kusano 2b45e8
	  return CORE_P6;
kusano 2b45e8
	case  7:
kusano 2b45e8
	  return CORE_KATMAI;
kusano 2b45e8
	case  8:
kusano 2b45e8
	case 10:
kusano 2b45e8
	case 11:
kusano 2b45e8
	  return CORE_COPPERMINE;
kusano 2b45e8
	case  9:
kusano 2b45e8
	case 13:
kusano 2b45e8
	case 14:
kusano 2b45e8
	  return CORE_BANIAS;
kusano 2b45e8
	case 15:
kusano 2b45e8
	  return CORE_CORE2;
kusano 2b45e8
	}
kusano 2b45e8
	break;
kusano 2b45e8
      case  1:
kusano 2b45e8
	switch (model) {
kusano 2b45e8
	case  6:
kusano 2b45e8
	  return CORE_CORE2;
kusano 2b45e8
	case  7:
kusano 2b45e8
	  return CORE_PENRYN;
kusano 2b45e8
	case 10:
kusano 2b45e8
	case 11:
kusano 2b45e8
	case 14:
kusano 2b45e8
	case 15:
kusano 2b45e8
	  return CORE_NEHALEM;
kusano 2b45e8
	case 12:
kusano 2b45e8
	  return CORE_ATOM;
kusano 2b45e8
	case 13:
kusano 2b45e8
	  return CORE_DUNNINGTON;
kusano 2b45e8
	}
kusano 2b45e8
	break;
kusano 2b45e8
      case  2:
kusano 2b45e8
	switch (model) {
kusano 2b45e8
	case 5:
kusano 2b45e8
	  //Intel Core (Clarkdale) / Core (Arrandale) 
kusano 2b45e8
	  // Pentium (Clarkdale) / Pentium Mobile (Arrandale) 
kusano 2b45e8
	  // Xeon (Clarkdale), 32nm
kusano 2b45e8
	  return CORE_NEHALEM;
kusano 2b45e8
	case 10:
kusano 2b45e8
          //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
kusano 2b45e8
          return CORE_NEHALEM;
kusano 2b45e8
	case 12:
kusano 2b45e8
	  //Xeon Processor 5600 (Westmere-EP)
kusano 2b45e8
	  return CORE_NEHALEM;
kusano 2b45e8
	case 13:
kusano 2b45e8
          //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
kusano 2b45e8
          return CORE_NEHALEM;
kusano 2b45e8
	case 15:
kusano 2b45e8
	  //Xeon Processor E7 (Westmere-EX)
kusano 2b45e8
	  return CORE_NEHALEM;
kusano 2b45e8
	}
kusano 2b45e8
	break;
kusano 2b45e8
      }
kusano 2b45e8
      break;
kusano 2b45e8
kusano 2b45e8
      case 15:
kusano 2b45e8
	if (model <= 0x2) return CORE_NORTHWOOD;
kusano 2b45e8
	else return CORE_PRESCOTT;
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_AMD){
kusano 2b45e8
    if (family <= 0x5) return CORE_80486;
kusano 2b45e8
    if (family <= 0xe) return CORE_ATHLON;
kusano 2b45e8
    if (family == 0xf){
kusano 2b45e8
      if ((exfamily == 0) || (exfamily == 2)) return CORE_OPTERON; else return CORE_BARCELONA;
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (vendor == VENDOR_CENTAUR) {
kusano 2b45e8
    switch (family) {
kusano 2b45e8
    case 0x6:
kusano 2b45e8
      return CORE_NANO;
kusano 2b45e8
      break;
kusano 2b45e8
    }
kusano 2b45e8
    return CORE_VIAC3;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return CORE_UNKNOWN;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_cpuconfig(void){
kusano 2b45e8
kusano 2b45e8
  cache_info_t info;
kusano 2b45e8
  int features;
kusano 2b45e8
kusano 2b45e8
  printf("#define %s\n", cpuname[get_cpuname()]);
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
  if (get_coretype() != CORE_P5) {
kusano 2b45e8
kusano 2b45e8
    get_cacheinfo(CACHE_INFO_L1_I, &info);
kusano 2b45e8
    if (info.size > 0) {
kusano 2b45e8
      printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
kusano 2b45e8
      printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
kusano 2b45e8
      printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    get_cacheinfo(CACHE_INFO_L1_D, &info);
kusano 2b45e8
    if (info.size > 0) {
kusano 2b45e8
      printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
kusano 2b45e8
      printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
kusano 2b45e8
      printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    get_cacheinfo(CACHE_INFO_L2, &info);
kusano 2b45e8
    if (info.size > 0) {
kusano 2b45e8
      printf("#define L2_SIZE %d\n", info.size * 1024);
kusano 2b45e8
      printf("#define L2_ASSOCIATIVE %d\n", info.associative);
kusano 2b45e8
      printf("#define L2_LINESIZE %d\n", info.linesize);
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    get_cacheinfo(CACHE_INFO_L3, &info);
kusano 2b45e8
    if (info.size > 0) {
kusano 2b45e8
      printf("#define L3_SIZE %d\n", info.size * 1024);
kusano 2b45e8
      printf("#define L3_ASSOCIATIVE %d\n", info.associative);
kusano 2b45e8
      printf("#define L3_LINESIZE %d\n", info.linesize);
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    get_cacheinfo(CACHE_INFO_L1_ITB, &info);
kusano 2b45e8
    if (info.size > 0) {
kusano 2b45e8
      printf("#define ITB_SIZE %d\n", info.size * 1024);
kusano 2b45e8
      printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
kusano 2b45e8
      printf("#define ITB_ENTRIES %d\n", info.linesize);
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    get_cacheinfo(CACHE_INFO_L1_DTB, &info);
kusano 2b45e8
    if (info.size > 0) {
kusano 2b45e8
      printf("#define DTB_SIZE %d\n", info.size * 1024);
kusano 2b45e8
      printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
kusano 2b45e8
      printf("#define DTB_DEFAULT_ENTRIES %d\n", info.linesize);
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    features = get_cputype(GET_FEATURE);
kusano 2b45e8
kusano 2b45e8
    if (features & HAVE_CMOV )   printf("#define HAVE_CMOV\n");
kusano 2b45e8
    if (features & HAVE_MMX  )   printf("#define HAVE_MMX\n");
kusano 2b45e8
    if (features & HAVE_SSE  )   printf("#define HAVE_SSE\n");
kusano 2b45e8
    if (features & HAVE_SSE2 )   printf("#define HAVE_SSE2\n");
kusano 2b45e8
    if (features & HAVE_SSE3 )   printf("#define HAVE_SSE3\n");
kusano 2b45e8
    if (features & HAVE_SSSE3)   printf("#define HAVE_SSSE3\n");
kusano 2b45e8
    if (features & HAVE_SSE4_1)   printf("#define HAVE_SSE4_1\n");
kusano 2b45e8
    if (features & HAVE_SSE4_2)   printf("#define HAVE_SSE4_2\n");
kusano 2b45e8
    if (features & HAVE_SSE4A)   printf("#define HAVE_SSE4A\n");
kusano 2b45e8
    if (features & HAVE_SSE5 )   printf("#define HAVE_SSSE5\n");
kusano 2b45e8
    if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
kusano 2b45e8
    if (features & HAVE_3DNOW)   printf("#define HAVE_3DNOW\n");
kusano 2b45e8
    if (features & HAVE_CFLUSH)  printf("#define HAVE_CFLUSH\n");
kusano 2b45e8
    if (features & HAVE_HIT)     printf("#define HAVE_HIT 1\n");
kusano 2b45e8
    if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
kusano 2b45e8
    if (features & HAVE_128BITFPU)   printf("#define HAVE_128BITFPU\n");
kusano 2b45e8
    if (features & HAVE_FASTMOVU)    printf("#define HAVE_FASTMOVU\n");
kusano 2b45e8
    
kusano 2b45e8
    printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
kusano 2b45e8
    printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
kusano 2b45e8
kusano 2b45e8
    features = get_coretype();
kusano 2b45e8
    if (features > 0) printf("#define CORE_%s\n", corename[features]);
kusano 2b45e8
  } else {
kusano 2b45e8
    printf("#define DTB_DEFAULT_ENTRIES 16\n");
kusano 2b45e8
    printf("#define L1_CODE_SIZE 8192\n");
kusano 2b45e8
    printf("#define L1_DATA_SIZE 8192\n");
kusano 2b45e8
    printf("#define L2_SIZE 0\n");
kusano 2b45e8
  }
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_architecture(void){
kusano 2b45e8
#ifndef __64BIT__
kusano 2b45e8
    printf("X86");
kusano 2b45e8
#else
kusano 2b45e8
    printf("X86_64");
kusano 2b45e8
#endif
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
#ifndef __64BIT__
kusano 2b45e8
    printf("x86");
kusano 2b45e8
#else
kusano 2b45e8
    printf("x86_64");
kusano 2b45e8
#endif
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
char *get_corename(void){
kusano 2b45e8
  return corename[get_coretype()];
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void get_libname(void){
kusano 2b45e8
  printf("%s",   corename_lower[get_coretype()]);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
/* This if for Makefile */
kusano 2b45e8
void get_sse(void){
kusano 2b45e8
kusano 2b45e8
  int features;
kusano 2b45e8
kusano 2b45e8
  features = get_cputype(GET_FEATURE);
kusano 2b45e8
kusano 2b45e8
  if (features & HAVE_MMX  )   printf("HAVE_MMX=1\n");
kusano 2b45e8
  if (features & HAVE_SSE  )   printf("HAVE_SSE=1\n");
kusano 2b45e8
  if (features & HAVE_SSE2 )   printf("HAVE_SSE2=1\n");
kusano 2b45e8
  if (features & HAVE_SSE3 )   printf("HAVE_SSE3=1\n");
kusano 2b45e8
  if (features & HAVE_SSSE3)   printf("HAVE_SSSE3=1\n");
kusano 2b45e8
  if (features & HAVE_SSE4_1)   printf("HAVE_SSE4_1=1\n");
kusano 2b45e8
  if (features & HAVE_SSE4_2)   printf("HAVE_SSE4_2=1\n");
kusano 2b45e8
  if (features & HAVE_SSE4A)   printf("HAVE_SSE4A=1\n");
kusano 2b45e8
  if (features & HAVE_SSE5 )   printf("HAVE_SSSE5=1\n");
kusano 2b45e8
  if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
kusano 2b45e8
  if (features & HAVE_3DNOW)   printf("HAVE_3DNOW=1\n");
kusano 2b45e8
kusano 2b45e8
}