Home | History | Annotate | Line # | Download | only in dist
config.guess revision 1.2.2.1
      1      1.1       mrg #! /bin/sh
      2      1.1       mrg #
      3      1.1       mrg # GMP config.guess wrapper.
      4      1.1       mrg 
      5      1.1       mrg 
      6  1.2.2.1       tls # Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2011, 2012 Free
      7  1.2.2.1       tls # Software Foundation, Inc.
      8      1.1       mrg #
      9      1.1       mrg # This file is part of the GNU MP Library.
     10      1.1       mrg #
     11      1.1       mrg # The GNU MP Library is free software; you can redistribute it and/or modify
     12      1.1       mrg # it under the terms of the GNU Lesser General Public License as published
     13      1.1       mrg # by the Free Software Foundation; either version 3 of the License, or (at
     14      1.1       mrg # your option) any later version.
     15      1.1       mrg #
     16      1.1       mrg # The GNU MP Library is distributed in the hope that it will be useful, but
     17      1.1       mrg # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     18      1.1       mrg # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     19      1.1       mrg # License for more details.
     20      1.1       mrg #
     21      1.1       mrg # You should have received a copy of the GNU Lesser General Public License
     22      1.1       mrg # along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
     23      1.1       mrg 
     24      1.1       mrg 
     25      1.1       mrg # Usage: config.guess
     26      1.1       mrg #
     27      1.1       mrg # Print the host system CPU-VENDOR-OS.
     28      1.1       mrg #
     29      1.1       mrg # configfsf.guess is run and its guess then sharpened up to take advantage
     30      1.1       mrg # of the finer grained CPU types that GMP knows.
     31      1.1       mrg 
     32      1.1       mrg 
     33      1.1       mrg # Expect to find configfsf.guess in the same directory as this config.guess
     34      1.1       mrg configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
     35      1.1       mrg if test "$configfsf_guess" = "$0"; then
     36      1.1       mrg   echo "Cannot derive configfsf.guess from $0" 1>&2
     37      1.1       mrg   exit 1
     38      1.1       mrg fi
     39      1.1       mrg if test -f "$configfsf_guess"; then
     40      1.1       mrg   :
     41      1.1       mrg else
     42      1.1       mrg   echo "$configfsf_guess not found" 1>&2
     43      1.1       mrg   exit 1
     44      1.1       mrg fi
     45      1.1       mrg 
     46      1.1       mrg # Setup a $SHELL with which to run configfsf.guess, using the same
     47      1.1       mrg # $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess
     48      1.1       mrg SHELL=${CONFIG_SHELL-/bin/sh}
     49      1.1       mrg 
     50      1.1       mrg # Identify ourselves on --version, --help or errors
     51      1.1       mrg if test $# != 0; then
     52      1.1       mrg   echo "(GNU MP wrapped config.guess)"
     53      1.1       mrg   $SHELL $configfsf_guess "$@"
     54      1.1       mrg   exit 1
     55      1.1       mrg fi
     56      1.1       mrg 
     57      1.1       mrg guess_full=`$SHELL $configfsf_guess`
     58      1.1       mrg if test $? != 0; then
     59      1.1       mrg   exit 1
     60      1.1       mrg fi
     61      1.1       mrg 
     62      1.1       mrg guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
     63      1.1       mrg guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
     64      1.1       mrg exact_cpu=
     65      1.1       mrg 
     66      1.1       mrg 
     67      1.1       mrg # -------------------------------------------------------------------------
     68      1.1       mrg # The following should look at the current guess and probe the system to
     69      1.1       mrg # establish a better guess in exact_cpu.  Leave exact_cpu empty if probes
     70      1.1       mrg # can't be done, or don't work.
     71      1.1       mrg #
     72      1.1       mrg # When a number of probes are done, test -z "$exact_cpu" can be used instead
     73      1.1       mrg # of putting each probe under an "else" of the preceeding.  That can stop
     74      1.1       mrg # the code getting horribly nested and marching off the right side of the
     75      1.1       mrg # screen.
     76      1.1       mrg 
     77      1.1       mrg # Note that when a compile-and-link is done in one step we need to remove .o
     78      1.1       mrg # files, since lame C compilers generate these even when not asked.
     79      1.1       mrg #
     80      1.1       mrg 
     81      1.1       mrg dummy=dummy-$$
     82      1.1       mrg trap 'rm -f $dummy.c $dummy.o $dummy.core $dummy ${dummy}1.s ${dummy}2.c ; exit 1' 1 2 15
     83      1.1       mrg 
     84      1.1       mrg # Use $HOST_CC if defined. $CC may point to a cross-compiler
     85      1.1       mrg if test x"$CC_FOR_BUILD" = x; then
     86      1.1       mrg   if test x"$HOST_CC" != x; then
     87      1.1       mrg     CC_FOR_BUILD="$HOST_CC"
     88      1.1       mrg   else
     89      1.1       mrg     if test x"$CC" != x; then
     90      1.1       mrg       CC_FOR_BUILD="$CC"
     91      1.1       mrg     else
     92      1.1       mrg       echo 'dummy(){}' >$dummy.c
     93      1.1       mrg       for c in cc gcc c89 c99; do
     94      1.1       mrg 	  ($c $dummy.c -c) >/dev/null 2>&1
     95      1.1       mrg 	  if test $? = 0; then
     96      1.1       mrg 	      CC_FOR_BUILD="$c"; break
     97      1.1       mrg 	  fi
     98      1.1       mrg       done
     99      1.1       mrg       rm -f $dummy.c $dummy.o
    100      1.1       mrg       if test x"$CC_FOR_BUILD" = x; then
    101      1.1       mrg 	CC_FOR_BUILD=no_compiler_found
    102      1.1       mrg       fi
    103      1.1       mrg     fi
    104      1.1       mrg   fi
    105      1.1       mrg fi
    106      1.1       mrg 
    107      1.1       mrg 
    108      1.1       mrg case "$guess_full" in
    109      1.1       mrg 
    110      1.1       mrg alpha-*-*)
    111      1.1       mrg   # configfsf.guess detects exact alpha cpu types for OSF and GNU/Linux, but
    112      1.1       mrg   # not for *BSD and other systems.  We try to get an exact type for any
    113      1.1       mrg   # plain "alpha" it leaves.
    114      1.1       mrg   #
    115      1.1       mrg   # configfsf.guess used to have a block of code not unlike this, but these
    116      1.1       mrg   # days does its thing with Linux kernel /proc/cpuinfo or OSF psrinfo.
    117      1.1       mrg   #
    118      1.1       mrg   cat <<EOF >$dummy.s
    119      1.1       mrg 	.data
    120      1.1       mrg Lformat:
    121      1.1       mrg 	.byte 37,100,45,37,120,10,0	# "%d-%x\n"
    122      1.1       mrg 	.text
    123      1.1       mrg 	.globl main
    124      1.1       mrg 	.align 4
    125      1.1       mrg 	.ent main
    126      1.1       mrg main:
    127      1.1       mrg 	.frame \$30,16,\$26,0
    128      1.1       mrg 	ldgp \$29,0(\$27)
    129      1.1       mrg 	.prologue 1
    130      1.1       mrg 	.long 0x47e03d91 # implver \$17
    131      1.1       mrg 	lda \$2,-1
    132      1.1       mrg 	.long 0x47e20c21 # amask \$2,\$1
    133      1.1       mrg 	lda \$16,Lformat
    134      1.1       mrg 	not \$1,\$18
    135      1.1       mrg 	jsr \$26,printf
    136      1.1       mrg 	ldgp \$29,0(\$26)
    137      1.1       mrg 	mov 0,\$16
    138      1.1       mrg 	jsr \$26,exit
    139      1.1       mrg 	.end main
    140      1.1       mrg EOF
    141      1.1       mrg   $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
    142      1.1       mrg   if test "$?" = 0 ; then
    143      1.1       mrg     case `./$dummy` in
    144      1.1       mrg     0-0)	exact_cpu=alpha      ;;
    145      1.1       mrg     1-0)	exact_cpu=alphaev5   ;;
    146      1.1       mrg     1-1)	exact_cpu=alphaev56  ;;
    147      1.1       mrg     1-101)	exact_cpu=alphapca56 ;;
    148      1.1       mrg     2-303)	exact_cpu=alphaev6   ;;
    149      1.1       mrg     2-307)	exact_cpu=alphaev67  ;;
    150      1.1       mrg     2-1307)	exact_cpu=alphaev68  ;;
    151      1.1       mrg     esac
    152      1.1       mrg   fi
    153      1.1       mrg   rm -f $dummy.s $dummy.o $dummy
    154      1.1       mrg   ;;
    155      1.1       mrg 
    156  1.2.2.1       tls arm*-*-*)
    157  1.2.2.1       tls   cpu_code=`sed -n 's/^CPU part.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null`
    158  1.2.2.1       tls   case "$cpu_code" in
    159  1.2.2.1       tls       0x210)	exact_cpu="armxscale";;		# v5 pxa250
    160  1.2.2.1       tls       0x290)	exact_cpu="armxscale";;		# v5 pxa260
    161  1.2.2.1       tls       0x2d0)	exact_cpu="armxscale";;		# v5 pxa255
    162  1.2.2.1       tls       0x2d0)	exact_cpu="armxscale";;		# v5 pxa261
    163  1.2.2.1       tls       0x2d0)	exact_cpu="armxscale";;		# v5 pxa262
    164  1.2.2.1       tls       0x411)	exact_cpu="armxscale";;		# v5 pxa270
    165  1.2.2.1       tls       0x915)	exact_cpu="armti915t";;		# v?
    166  1.2.2.1       tls       0x925)	exact_cpu="armti925t";;		# v?
    167  1.2.2.1       tls       0x926)	exact_cpu="arm926";;		# v5
    168  1.2.2.1       tls       0x946)	exact_cpu="arm946";;		# v5
    169  1.2.2.1       tls       0x966)	exact_cpu="arm966";;		# v5
    170  1.2.2.1       tls       0xa11)	exact_cpu="armsa1";;		# v4 strongarm/sa1100
    171  1.2.2.1       tls       0xa26)	exact_cpu="arm1026";;		# v5
    172  1.2.2.1       tls       0xb02)	exact_cpu="arm11mpcore";;	# v6
    173  1.2.2.1       tls       0xb11)	exact_cpu="armsa1";;		# v4 strongarm/sa1110
    174  1.2.2.1       tls       0xb36)	exact_cpu="arm1136";;		# v6
    175  1.2.2.1       tls       0xb56)	exact_cpu="arm1156";;		# v6t2
    176  1.2.2.1       tls       0xb76)	exact_cpu="arm1176";;		# v6
    177  1.2.2.1       tls       0xc05)	exact_cpu="armcortexa5";;	# v7a
    178  1.2.2.1       tls       0xc08)	exact_cpu="armcortexa8";;	# v7a
    179  1.2.2.1       tls       0xc09)	exact_cpu="armcortexa9";;	# v7a
    180  1.2.2.1       tls       0xc0f)	exact_cpu="armcortexa15";;	# v7a
    181  1.2.2.1       tls       0xc14)	exact_cpu="armcortexr4";;	# v7r
    182  1.2.2.1       tls       0xc15)	exact_cpu="armcortexr5";;	# v7r
    183  1.2.2.1       tls       0xc23)	exact_cpu="armcortexm3";;	# v7m
    184  1.2.2.1       tls   esac
    185  1.2.2.1       tls   ;;
    186  1.2.2.1       tls 
    187      1.1       mrg ia64*-*-*)
    188      1.1       mrg   # CPUID[3] bits 24 to 31 is the processor family.  itanium2 is documented
    189      1.1       mrg   # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
    190      1.1       mrg   # haven't found any documentation on it as such.
    191      1.1       mrg   #
    192      1.1       mrg   # Defining both getcpuid and _getcpuid lets us ignore whether the system
    193      1.1       mrg   # expects underscores or not.
    194      1.1       mrg   #
    195      1.1       mrg   # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
    196      1.1       mrg   # (which is the default there), it's the only 64-bit type.
    197      1.1       mrg   #
    198      1.1       mrg   cat >${dummy}a.s <<EOF
    199      1.1       mrg 	.text
    200      1.1       mrg 	.global	_getcpuid
    201      1.1       mrg 	.proc	_getcpuid
    202      1.1       mrg _getcpuid:
    203      1.1       mrg 	mov	r8 = CPUID[r32] ;;
    204      1.1       mrg 	br.ret.sptk.many rp ;;
    205      1.1       mrg 	.endp	_getcpuid
    206      1.1       mrg 	.global	getcpuid
    207      1.1       mrg 	.proc	getcpuid
    208      1.1       mrg getcpuid:
    209      1.1       mrg 	mov	r8 = CPUID[r32] ;;
    210      1.1       mrg 	br.ret.sptk.many rp ;;
    211      1.1       mrg 	.endp	getcpuid
    212      1.1       mrg EOF
    213      1.1       mrg   cat >${dummy}b.c <<EOF
    214      1.1       mrg #include <stdio.h>
    215      1.1       mrg unsigned long long getcpuid ();
    216      1.1       mrg int
    217      1.1       mrg main ()
    218      1.1       mrg {
    219      1.1       mrg   if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
    220      1.1       mrg     {
    221      1.1       mrg       /* "GenuineIntel" */
    222      1.1       mrg       switch ((getcpuid(3LL) >> 24) & 0xFF) {
    223      1.1       mrg       case 0x07: puts ("itanium");  break;
    224      1.1       mrg       case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */
    225      1.1       mrg       case 0x20: puts ("itanium2"); break; /* Montecito */
    226      1.1       mrg       }
    227      1.1       mrg     }
    228      1.1       mrg   return 0;
    229      1.1       mrg }
    230      1.1       mrg EOF
    231      1.1       mrg   if $CC_FOR_BUILD ${dummy}a.s ${dummy}b.c -o $dummy >/dev/null 2>&1; then
    232      1.1       mrg     exact_cpu=`./$dummy`
    233      1.1       mrg   fi
    234      1.1       mrg   rm -f ${dummy}a.s ${dummy}a.o ${dummy}b.c ${dummy}b.o $dummy $dummy.core core
    235      1.1       mrg   ;;
    236      1.1       mrg 
    237      1.1       mrg mips-*-irix[6789]*)
    238      1.1       mrg   # IRIX 6 and up always has a 64-bit mips cpu
    239      1.1       mrg   exact_cpu=mips64
    240      1.1       mrg   ;;
    241      1.1       mrg 
    242      1.1       mrg m68k-*-*)
    243      1.1       mrg   # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
    244      1.1       mrg   #   hw.model = Apple Macintosh Quadra 610  (68040)
    245      1.1       mrg   exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
    246      1.1       mrg   if test -z "$exact_cpu"; then
    247      1.1       mrg     # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
    248      1.1       mrg     exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
    249      1.1       mrg   fi
    250      1.1       mrg   if test -z "$exact_cpu"; then
    251      1.1       mrg     # Try: movel #0,%d0; rts
    252      1.1       mrg     # This is to check the compiler and our asm code works etc, before
    253      1.1       mrg     # assuming failures below indicate cpu characteristics.
    254      1.1       mrg     # .byte is used to avoid problems with assembler syntax variations.
    255      1.1       mrg     # For testing, provoke failures by adding "illegal" possibly as
    256      1.1       mrg     # ".byte 0x4A, 0xFC"
    257      1.1       mrg     cat >$dummy.s <<EOF
    258      1.1       mrg 	.text
    259      1.1       mrg 	.globl main
    260      1.1       mrg 	.globl _main
    261      1.1       mrg main:
    262      1.1       mrg _main:
    263      1.1       mrg 	.byte	0x70, 0x00
    264      1.1       mrg 	.byte	0x4e, 0x75
    265      1.1       mrg EOF
    266      1.1       mrg     if ($CC_FOR_BUILD $dummy.s -o $dummy && ./$dummy) >/dev/null 2>&1; then
    267      1.1       mrg 
    268      1.1       mrg       # $SHELL -c is used to execute ./$dummy below, since (./$dummy)
    269      1.1       mrg       # 2>/dev/null still prints the SIGILL message on some shells.
    270      1.1       mrg       #
    271      1.1       mrg         # Try: movel #0,%d0
    272      1.1       mrg         #      rtd #0
    273      1.1       mrg         cat >$dummy.s <<EOF
    274      1.1       mrg 	.text
    275      1.1       mrg 	.globl main
    276      1.1       mrg 	.globl _main
    277      1.1       mrg main:
    278      1.1       mrg _main:
    279      1.1       mrg 	.byte	0x70, 0x00
    280      1.1       mrg 	.byte	0x4e, 0x74, 0x00, 0x00
    281      1.1       mrg EOF
    282      1.1       mrg         if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
    283      1.1       mrg           $SHELL -c ./$dummy >/dev/null 2>&1
    284      1.1       mrg 	  if test $? != 0; then
    285      1.1       mrg             exact_cpu=m68000    # because rtd didn't work
    286      1.1       mrg           fi
    287      1.1       mrg         fi
    288      1.1       mrg       #
    289      1.1       mrg 
    290      1.1       mrg       if test -z "$exact_cpu"; then
    291      1.1       mrg         # Try: trapf
    292      1.1       mrg         #      movel #0,%d0
    293      1.1       mrg         #      rts
    294      1.1       mrg         # Another possibility for identifying 68000 and 68010 is the
    295      1.1       mrg         # different value stored by "movem a0,(a0)+"
    296      1.1       mrg         cat >$dummy.s <<EOF
    297      1.1       mrg 	.text
    298      1.1       mrg 	.globl main
    299      1.1       mrg 	.globl _main
    300      1.1       mrg main:
    301      1.1       mrg _main:
    302      1.1       mrg 	.byte	0x51, 0xFC
    303      1.1       mrg 	.byte	0x70, 0x00
    304      1.1       mrg 	.byte	0x4e, 0x75
    305      1.1       mrg EOF
    306      1.1       mrg         if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
    307      1.1       mrg           $SHELL -c ./$dummy >/dev/null 2>&1
    308      1.1       mrg 	  if test $? != 0; then
    309      1.1       mrg             exact_cpu=m68010    # because trapf didn't work
    310      1.1       mrg           fi
    311      1.1       mrg         fi
    312      1.1       mrg       fi
    313      1.1       mrg 
    314      1.1       mrg       if test -z "$exact_cpu"; then
    315      1.1       mrg         # Try: bfffo %d1{0:31},%d0
    316      1.1       mrg         #      movel #0,%d0
    317      1.1       mrg         #      rts
    318      1.1       mrg         cat >$dummy.s <<EOF
    319      1.1       mrg 	.text
    320      1.1       mrg 	.globl main
    321      1.1       mrg 	.globl _main
    322      1.1       mrg main:
    323      1.1       mrg _main:
    324      1.1       mrg 	.byte	0xED, 0xC1, 0x00, 0x1F
    325      1.1       mrg 	.byte	0x70, 0x00
    326      1.1       mrg 	.byte	0x4e, 0x75
    327      1.1       mrg EOF
    328      1.1       mrg         if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
    329      1.1       mrg           $SHELL -c ./$dummy >/dev/null 2>&1
    330      1.1       mrg 	  if test $? != 0; then
    331      1.1       mrg             exact_cpu=m68360  # cpu32, because bfffo didn't work
    332      1.1       mrg           fi
    333      1.1       mrg         fi
    334      1.1       mrg       fi
    335      1.1       mrg 
    336      1.1       mrg       if test -z "$exact_cpu"; then
    337      1.1       mrg         # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
    338      1.1       mrg         exact_cpu=m68020
    339      1.1       mrg       fi
    340      1.1       mrg     fi
    341      1.1       mrg     rm -f $dummy.s $dummy.o $dummy $dummy.core core
    342      1.1       mrg   fi
    343      1.1       mrg   if test -z "$exact_cpu"; then
    344      1.1       mrg     case "$guess_full" in
    345      1.1       mrg       *-*-next* | *-*-openstep*)  # NeXTs are 68020 or better
    346      1.1       mrg         exact_cpu=m68020 ;;
    347      1.1       mrg     esac
    348      1.1       mrg   fi
    349      1.1       mrg   ;;
    350      1.1       mrg 
    351      1.1       mrg 
    352      1.1       mrg rs6000-*-* | powerpc*-*-*)
    353      1.1       mrg   # Enhancement: On MacOS the "machine" command prints for instance
    354      1.1       mrg   # "ppc750".  Interestingly on powerpc970-apple-darwin6.8.5 it prints
    355      1.1       mrg   # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
    356      1.1       mrg   # (as noted below).  But the man page says the command is still "under
    357      1.1       mrg   # development", so it doesn't seem wise to use it just yet, not while
    358      1.1       mrg   # there's an alternative.
    359      1.1       mrg   #
    360      1.1       mrg   # Try to read the PVR.  mfpvr is a protected instruction, NetBSD, MacOS
    361      1.1       mrg   # and AIX don't allow it in user mode, but the Linux kernel does.
    362      1.1       mrg   #
    363      1.1       mrg   # Using explicit bytes for mfpvr avoids worrying about assembler syntax
    364      1.1       mrg   # and underscores.  "char"s are used instead of "int"s to avoid worrying
    365      1.1       mrg   # whether sizeof(int)==4 or if it's the right endianness.
    366      1.1       mrg   #
    367      1.1       mrg   # Note this is no good on AIX, since a C function there is the address of
    368      1.1       mrg   # a function descriptor, not actual code.  But this doesn't matter since
    369      1.1       mrg   # AIX doesn't allow mfpvr anyway.
    370      1.1       mrg   #
    371      1.1       mrg   cat >$dummy.c <<\EOF
    372      1.1       mrg #include <stdio.h>
    373      1.1       mrg struct {
    374      1.1       mrg   int   n;  /* force 4-byte alignment */
    375      1.1       mrg   char  a[8];
    376      1.1       mrg } getpvr = {
    377      1.1       mrg   0,
    378      1.1       mrg   {
    379      1.1       mrg     0x7c, 0x7f, 0x42, 0xa6,  /* mfpvr r3 */
    380      1.1       mrg     0x4e, 0x80, 0x00, 0x20,  /* blr      */
    381      1.1       mrg   }
    382      1.1       mrg };
    383      1.1       mrg int
    384      1.1       mrg main ()
    385      1.1       mrg {
    386      1.1       mrg   unsigned  (*fun)();
    387      1.1       mrg   unsigned  pvr;
    388      1.1       mrg 
    389      1.1       mrg   /* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS,
    390      1.1       mrg      it gets a compiler error on a combined cast and call */
    391      1.1       mrg   fun = (unsigned (*)()) getpvr.a;
    392      1.1       mrg   pvr = (*fun) ();
    393      1.1       mrg 
    394      1.1       mrg   switch (pvr >> 16) {
    395      1.1       mrg   case 0x0001: puts ("powerpc601");  break;
    396      1.1       mrg   case 0x0003: puts ("powerpc603");  break;
    397      1.1       mrg   case 0x0004: puts ("powerpc604");  break;
    398      1.1       mrg   case 0x0006: puts ("powerpc603e"); break;
    399      1.1       mrg   case 0x0007: puts ("powerpc603e"); break;  /* 603ev */
    400      1.1       mrg   case 0x0008: puts ("powerpc750");  break;
    401      1.1       mrg   case 0x0009: puts ("powerpc604e"); break;
    402      1.1       mrg   case 0x000a: puts ("powerpc604e"); break;  /* 604ev5 */
    403      1.1       mrg   case 0x000c: puts ("powerpc7400"); break;
    404      1.1       mrg   case 0x0041: puts ("powerpc630");  break;
    405      1.1       mrg   case 0x0050: puts ("powerpc860");  break;
    406      1.1       mrg   case 0x8000: puts ("powerpc7450"); break;
    407      1.1       mrg   case 0x8001: puts ("powerpc7455"); break;
    408      1.1       mrg   case 0x8002: puts ("powerpc7457"); break;
    409      1.1       mrg   case 0x8003: puts ("powerpc7447"); break; /* really 7447A */
    410      1.1       mrg   case 0x800c: puts ("powerpc7410"); break;
    411      1.1       mrg   }
    412      1.1       mrg   return 0;
    413      1.1       mrg }
    414      1.1       mrg EOF
    415      1.1       mrg   if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
    416      1.1       mrg     # This style construct is needed on AIX 4.3 to suppress the SIGILL error
    417      1.1       mrg     # from (*fun)().  Using $SHELL -c ./$dummy 2>/dev/null doesn't work.
    418      1.1       mrg     { x=`./$dummy`; } 2>/dev/null
    419      1.1       mrg     if test -n "$x"; then
    420      1.1       mrg       exact_cpu=$x
    421      1.1       mrg     fi
    422      1.1       mrg   fi
    423      1.1       mrg   rm -f $dummy.c $dummy.o $dummy $dummy.core
    424      1.1       mrg 
    425      1.1       mrg   # Grep the linux kernel /proc/cpuinfo pseudo-file.
    426      1.1       mrg   # Anything unrecognised is ignored, since of course we mustn't spit out
    427      1.1       mrg   # a cpu type config.sub doesn't know.
    428      1.1       mrg   if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
    429      1.1       mrg     x=`grep "^cpu[ 	]" /proc/cpuinfo | head -n 1`
    430      1.1       mrg     x=`echo $x | sed -n 's/^cpu[ 	]*:[ 	]*\([A-Za-z0-9]*\).*/\1/p'`
    431      1.1       mrg     x=`echo $x | sed 's/PPC//'`
    432      1.1       mrg     case $x in
    433      1.1       mrg       601)     exact_cpu="power" ;;
    434      1.1       mrg       603ev)   exact_cpu="powerpc603e" ;;
    435      1.1       mrg       604ev5)  exact_cpu="powerpc604e" ;;
    436      1.1       mrg       603 | 603e | 604 | 604e | 750 | 821 | 860 | 970)
    437      1.1       mrg         exact_cpu="powerpc$x" ;;
    438      1.1       mrg       POWER[4-9])
    439      1.1       mrg         exact_cpu=`echo $x | sed "s;POWER;power;"` ;;
    440      1.1       mrg     esac
    441      1.1       mrg   fi
    442      1.1       mrg 
    443      1.1       mrg   if test -z "$exact_cpu"; then
    444      1.1       mrg     # On AIX, try looking at _system_configuration.  This is present in
    445      1.1       mrg     # version 4 at least.
    446      1.1       mrg     cat >$dummy.c <<EOF
    447      1.1       mrg #include <stdio.h>
    448      1.1       mrg #include <sys/systemcfg.h>
    449      1.1       mrg int
    450      1.1       mrg main ()
    451      1.1       mrg {
    452      1.1       mrg   switch (_system_configuration.implementation) {
    453      1.1       mrg   /* Old versions of AIX don't have all these constants,
    454      1.1       mrg      use ifdef for safety. */
    455      1.1       mrg #ifdef POWER_RS2
    456      1.1       mrg   case POWER_RS2:    puts ("power2");     break;
    457      1.1       mrg #endif
    458      1.1       mrg #ifdef POWER_601
    459      1.1       mrg   case POWER_601:    puts ("power");      break;
    460      1.1       mrg #endif
    461      1.1       mrg #ifdef POWER_603
    462      1.1       mrg   case POWER_603:    puts ("powerpc603"); break;
    463      1.1       mrg #endif
    464      1.1       mrg #ifdef POWER_604
    465      1.1       mrg   case POWER_604:    puts ("powerpc604"); break;
    466      1.1       mrg #endif
    467      1.1       mrg #ifdef POWER_620
    468      1.1       mrg   case POWER_620:    puts ("powerpc620"); break;
    469      1.1       mrg #endif
    470      1.1       mrg #ifdef POWER_630
    471      1.1       mrg   case POWER_630:    puts ("powerpc630"); break;
    472      1.1       mrg #endif
    473      1.1       mrg   /* Dunno what this is, leave it out for now.
    474      1.1       mrg   case POWER_A35:    puts ("powerpca35"); break;
    475      1.1       mrg   */
    476      1.1       mrg   /* This is waiting for a bit more info.
    477      1.1       mrg   case POWER_RS64II: puts ("powerpcrs64ii"); break;
    478      1.1       mrg   */
    479      1.1       mrg #ifdef POWER_4
    480      1.1       mrg   case POWER_4:    puts ("power4"); break;
    481      1.1       mrg #endif
    482      1.1       mrg #ifdef POWER_5
    483      1.1       mrg   case POWER_5:    puts ("power5"); break;
    484      1.1       mrg #endif
    485      1.1       mrg #ifdef POWER_6
    486      1.1       mrg   case POWER_6:    puts ("power6"); break;
    487      1.1       mrg #endif
    488  1.2.2.1       tls #ifdef POWER_7
    489  1.2.2.1       tls   case POWER_7:    puts ("power7"); break;
    490  1.2.2.1       tls #endif
    491      1.1       mrg   default:
    492      1.1       mrg     if (_system_configuration.architecture == POWER_RS)
    493      1.1       mrg       puts ("power");
    494      1.1       mrg     else if (_system_configuration.width == 64)
    495      1.1       mrg       puts ("powerpc64");
    496      1.1       mrg   }
    497      1.1       mrg   return 0;
    498      1.1       mrg }
    499      1.1       mrg EOF
    500      1.1       mrg     if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
    501      1.1       mrg       x=`./$dummy`
    502      1.1       mrg       if test -n "$x"; then
    503      1.1       mrg         exact_cpu=$x
    504      1.1       mrg       fi
    505      1.1       mrg     fi
    506      1.1       mrg     rm -f $dummy.c $dummy.o $dummy
    507      1.1       mrg   fi
    508      1.1       mrg 
    509      1.1       mrg   if test -z "$exact_cpu"; then
    510      1.1       mrg     # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
    511      1.1       mrg     # can tell us the exact cpu.
    512      1.1       mrg     cat >$dummy.c <<EOF
    513      1.1       mrg #include <stdio.h>
    514      1.1       mrg #include <mach-o/arch.h>
    515      1.1       mrg int
    516      1.1       mrg main (void)
    517      1.1       mrg {
    518      1.1       mrg   const NXArchInfo *a = NXGetLocalArchInfo();
    519      1.1       mrg   if (a->cputype == CPU_TYPE_POWERPC)
    520      1.1       mrg     {
    521      1.1       mrg       switch (a->cpusubtype) {
    522      1.1       mrg       /* The following known to Darwin 1.3. */
    523      1.1       mrg       case CPU_SUBTYPE_POWERPC_601:   puts ("powerpc601");  break;
    524      1.1       mrg       case CPU_SUBTYPE_POWERPC_602:   puts ("powerpc602");  break;
    525      1.1       mrg       case CPU_SUBTYPE_POWERPC_603:   puts ("powerpc603");  break;
    526      1.1       mrg       case CPU_SUBTYPE_POWERPC_603e:  puts ("powerpc603e"); break;
    527      1.1       mrg       case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
    528      1.1       mrg       case CPU_SUBTYPE_POWERPC_604:   puts ("powerpc604");  break;
    529      1.1       mrg       case CPU_SUBTYPE_POWERPC_604e:  puts ("powerpc604e"); break;
    530      1.1       mrg       case CPU_SUBTYPE_POWERPC_620:   puts ("powerpc620");  break;
    531      1.1       mrg       case CPU_SUBTYPE_POWERPC_750:   puts ("powerpc750");  break;
    532      1.1       mrg       case CPU_SUBTYPE_POWERPC_7400:  puts ("powerpc7400"); break;
    533      1.1       mrg       case CPU_SUBTYPE_POWERPC_7450:  puts ("powerpc7450"); break;
    534      1.1       mrg       /* Darwin 6.8.5 doesn't define the following */
    535      1.1       mrg       case 0x8001:                    puts ("powerpc7455"); break;
    536      1.1       mrg       case 0x8002:                    puts ("powerpc7457"); break;
    537      1.1       mrg       case 0x8003:                    puts ("powerpc7447"); break;
    538      1.1       mrg       case 100:                       puts ("powerpc970");  break;
    539      1.1       mrg       }
    540      1.1       mrg     }
    541      1.1       mrg   return 0;
    542      1.1       mrg }
    543      1.1       mrg EOF
    544      1.1       mrg     if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
    545      1.1       mrg       x=`./$dummy`
    546      1.1       mrg       if test -n "$x"; then
    547      1.1       mrg         exact_cpu=$x
    548      1.1       mrg       fi
    549      1.1       mrg     fi
    550      1.1       mrg     rm -f $dummy.c $dummy.o $dummy
    551      1.1       mrg   fi
    552      1.1       mrg   ;;
    553      1.1       mrg 
    554      1.1       mrg sparc-*-* | sparc64-*-*)
    555      1.1       mrg   # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
    556      1.1       mrg   # to short-circuit subsequent tests.
    557      1.1       mrg 
    558      1.1       mrg   # Grep the linux kernel /proc/cpuinfo pseudo-file.
    559      1.1       mrg   # A typical line is "cpu\t\t: TI UltraSparc II  (BlackBird)"
    560      1.1       mrg   # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
    561      1.1       mrg   #
    562      1.1       mrg   if test -f /proc/cpuinfo; then
    563      1.1       mrg     if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
    564      1.1       mrg       exact_cpu="sparc"   # ie. v7
    565      1.1       mrg     elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
    566      1.1       mrg       exact_cpu="sparc"   # ie. v7
    567      1.1       mrg     elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
    568      1.1       mrg       exact_cpu="sparcv8"
    569      1.1       mrg     elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
    570      1.1       mrg       exact_cpu="supersparc"
    571      1.1       mrg     elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
    572      1.1       mrg       exact_cpu="microsparc"
    573      1.1       mrg     elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
    574      1.1       mrg       # actually MicroSPARC-II
    575      1.1       mrg       exact_cpu=microsparc
    576  1.2.2.1       tls     elif grep 'cpu.*UltraSparc T3' /proc/cpuinfo >/dev/null; then
    577  1.2.2.1       tls       exact_cpu="ultrasparct3"
    578  1.2.2.1       tls     elif grep 'cpu.*UltraSparc T2' /proc/cpuinfo >/dev/null; then
    579  1.2.2.1       tls       exact_cpu="ultrasparct2"
    580      1.1       mrg     elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
    581      1.1       mrg       exact_cpu="ultrasparct1"
    582      1.1       mrg     elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
    583      1.1       mrg       exact_cpu="ultrasparc3"
    584      1.1       mrg     elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
    585      1.1       mrg       exact_cpu="ultrasparc2i"
    586      1.1       mrg     elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
    587      1.1       mrg       exact_cpu="ultrasparc2"
    588      1.1       mrg     elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
    589      1.1       mrg       exact_cpu="ultrasparc"
    590      1.1       mrg     fi
    591      1.1       mrg   fi
    592      1.1       mrg 
    593      1.1       mrg   # Grep the output from sysinfo on SunOS.
    594      1.1       mrg   # sysinfo has been seen living in /bin or in /usr/kvm
    595      1.1       mrg   #	cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
    596      1.1       mrg   #	cpu0 is a "75 MHz TI,TMS390Z55" CPU
    597      1.1       mrg   #
    598      1.1       mrg   if test -z "$exact_cpu"; then
    599      1.1       mrg     for i in sysinfo /usr/kvm/sysinfo; do
    600      1.1       mrg       if $SHELL -c $i 2>/dev/null >conftest.dat; then
    601      1.1       mrg         if grep 'cpu0 is a "SuperSPARC' conftest.dat >/dev/null; then
    602      1.1       mrg           exact_cpu=supersparc
    603      1.1       mrg           break
    604      1.1       mrg         elif grep 'cpu0 is a .*TMS390Z5.' conftest.dat >/dev/null; then
    605      1.1       mrg           # TMS390Z50 and TMS390Z55
    606      1.1       mrg           exact_cpu=supersparc
    607      1.1       mrg           break
    608      1.1       mrg         fi
    609      1.1       mrg       fi
    610      1.1       mrg     done
    611      1.1       mrg     rm -f conftest.dat
    612      1.1       mrg   fi
    613      1.1       mrg 
    614      1.1       mrg   # Grep the output from prtconf on Solaris.
    615      1.1       mrg   # Use an explicit /usr/sbin, since that directory might not be in a normal
    616      1.1       mrg   # user's path.
    617      1.1       mrg   #
    618      1.1       mrg   #     SUNW,UltraSPARC (driver not attached)
    619      1.1       mrg   #     SUNW,UltraSPARC-II (driver not attached)
    620      1.1       mrg   #     SUNW,UltraSPARC-IIi (driver not attached)
    621      1.1       mrg   #     SUNW,UltraSPARC-III+ (driver not attached)
    622      1.1       mrg   #     Ross,RT625 (driver not attached)
    623      1.1       mrg   #     TI,TMS390Z50 (driver not attached)
    624      1.1       mrg   #
    625      1.1       mrg   # /usr/sbin/sysdef prints similar information, but includes all loadable
    626      1.1       mrg   # cpu modules, not just the real cpu.
    627      1.1       mrg   #
    628      1.1       mrg   # We first try a plain prtconf, since that is known to work on older systems.
    629      1.1       mrg   # But for newer T1 systems, that doesn't produce any useful output, we need
    630      1.1       mrg   # "prtconf -vp" there.
    631      1.1       mrg   #
    632      1.1       mrg   for prtconfopt in "" "-vp"; do
    633      1.1       mrg     if test -z "$exact_cpu"; then
    634      1.1       mrg       if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >conftest.dat; then
    635  1.2.2.1       tls 	if grep 'SUNW,UltraSPARC-T3' conftest.dat >/dev/null; then
    636  1.2.2.1       tls 	  exact_cpu=ultrasparct3
    637  1.2.2.1       tls 	elif grep 'SUNW,UltraSPARC-T2' conftest.dat >/dev/null; then
    638  1.2.2.1       tls 	  exact_cpu=ultrasparct2
    639  1.2.2.1       tls 	elif grep 'SUNW,UltraSPARC-T1' conftest.dat >/dev/null; then
    640      1.1       mrg 	  exact_cpu=ultrasparct1
    641      1.1       mrg 	elif grep 'SUNW,UltraSPARC-III' conftest.dat >/dev/null; then
    642      1.1       mrg 	  exact_cpu=ultrasparc3
    643      1.1       mrg 	elif grep 'SUNW,UltraSPARC-IIi' conftest.dat >/dev/null; then
    644      1.1       mrg 	  exact_cpu=ultrasparc2i
    645      1.1       mrg 	elif grep 'SUNW,UltraSPARC-II' conftest.dat >/dev/null; then
    646      1.1       mrg 	  exact_cpu=ultrasparc2
    647      1.1       mrg 	elif grep 'SUNW,UltraSPARC' conftest.dat >/dev/null; then
    648      1.1       mrg 	  exact_cpu=ultrasparc
    649      1.1       mrg 	elif grep 'Ross,RT62.' conftest.dat >/dev/null; then
    650      1.1       mrg 	  # RT620, RT625, RT626 hypersparcs (v8).
    651      1.1       mrg 	  exact_cpu=sparcv8
    652      1.1       mrg 	elif grep 'TI,TMS390Z5.' conftest.dat >/dev/null; then
    653      1.1       mrg 	  # TMS390Z50 and TMS390Z55
    654      1.1       mrg 	  exact_cpu=supersparc
    655      1.1       mrg 	elif grep 'TI,TMS390S10' conftest.dat >/dev/null; then
    656      1.1       mrg 	  exact_cpu=microsparc
    657      1.1       mrg 	elif grep 'FMI,MB86904' conftest.dat >/dev/null; then
    658      1.1       mrg 	  # actually MicroSPARC-II
    659      1.1       mrg 	  exact_cpu=microsparc
    660      1.1       mrg 	fi
    661      1.1       mrg       fi
    662      1.1       mrg       rm -f conftest.dat
    663      1.1       mrg     fi
    664      1.1       mrg   done
    665      1.1       mrg 
    666      1.1       mrg   # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
    667      1.1       mrg   # Use an explicit /sbin, since that directory might not be in a normal
    668      1.1       mrg   # user's path.  Example outputs,
    669      1.1       mrg   #
    670      1.1       mrg   #     hw.model: Sun Microsystems UltraSparc-IIi
    671      1.1       mrg   #
    672      1.1       mrg   if test -z "$exact_cpu"; then
    673      1.1       mrg     if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >conftest.dat; then
    674  1.2.2.1       tls       if grep -i 'UltraSparc-T3' conftest.dat >/dev/null; then
    675  1.2.2.1       tls         exact_cpu=ultrasparct3
    676  1.2.2.1       tls       elif grep -i 'UltraSparc-T2' conftest.dat >/dev/null; then
    677  1.2.2.1       tls         exact_cpu=ultrasparct2
    678  1.2.2.1       tls       elif grep -i 'UltraSparc-T1' conftest.dat >/dev/null; then
    679      1.1       mrg         exact_cpu=ultrasparct1
    680  1.2.2.1       tls       elif grep -i 'UltraSparc-III' conftest.dat >/dev/null; then
    681      1.1       mrg         exact_cpu=ultrasparc3
    682  1.2.2.1       tls       elif grep -i 'UltraSparc-IIi' conftest.dat >/dev/null; then
    683      1.1       mrg         exact_cpu=ultrasparc2i
    684  1.2.2.1       tls       elif grep -i 'UltraSparc-II' conftest.dat >/dev/null; then
    685      1.1       mrg         exact_cpu=ultrasparc2
    686  1.2.2.1       tls       elif grep -i 'UltraSparc' conftest.dat >/dev/null; then
    687      1.1       mrg         exact_cpu=ultrasparc
    688      1.1       mrg       elif grep 'TMS390Z5.' conftest.dat >/dev/null; then
    689      1.1       mrg         # TMS390Z50 and TMS390Z55
    690      1.1       mrg         exact_cpu=supersparc
    691      1.1       mrg       elif grep 'TMS390S10' conftest.dat >/dev/null; then
    692      1.1       mrg         exact_cpu=microsparc
    693      1.1       mrg       elif grep 'MB86904' conftest.dat >/dev/null; then
    694      1.1       mrg         # actually MicroSPARC-II
    695      1.1       mrg         exact_cpu=microsparc
    696      1.1       mrg       elif grep 'MB86907' conftest.dat >/dev/null; then
    697      1.1       mrg         exact_cpu=turbosparc
    698      1.1       mrg       fi
    699      1.1       mrg     fi
    700      1.1       mrg     rm -f conftest.dat
    701      1.1       mrg   fi
    702      1.1       mrg 
    703      1.1       mrg   # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
    704      1.1       mrg   #
    705      1.1       mrg   if test -z "$exact_cpu"; then
    706      1.1       mrg     case `uname -m` in
    707      1.1       mrg       sun4[md]) exact_cpu=sparcv8 ;;
    708      1.1       mrg       sun4u)    exact_cpu=sparcv9 ;;
    709      1.1       mrg     esac
    710      1.1       mrg   fi
    711      1.1       mrg   ;;
    712      1.1       mrg 
    713  1.2.2.1       tls 
    714  1.2.2.1       tls # Recognise x86 processors using a tricky cpuid with 4 arguments, repeating
    715  1.2.2.1       tls # arguments; for x86-64 we effectively pass the 1st in rdx and the 2nd in rcx.
    716  1.2.2.1       tls # This allows the same asm to work for both standard and Windoze calling
    717  1.2.2.1       tls # conventions.
    718  1.2.2.1       tls 
    719      1.1       mrg i?86-*-* | amd64-*-* | x86_64-*-*)
    720      1.1       mrg   cat <<EOF >${dummy}0.s
    721      1.1       mrg 	.globl cpuid
    722      1.1       mrg 	.globl _cpuid
    723      1.1       mrg cpuid:
    724      1.1       mrg _cpuid:
    725      1.1       mrg 	pushl %esi
    726      1.1       mrg 	pushl %ebx
    727  1.2.2.1       tls 	movl 24(%esp),%eax
    728      1.1       mrg 	.byte 0x0f
    729      1.1       mrg 	.byte 0xa2
    730  1.2.2.1       tls 	movl 20(%esp),%esi
    731      1.1       mrg 	movl %ebx,(%esi)
    732      1.1       mrg 	movl %edx,4(%esi)
    733      1.1       mrg 	movl %ecx,8(%esi)
    734      1.1       mrg 	popl %ebx
    735      1.1       mrg 	popl %esi
    736      1.1       mrg 	ret
    737      1.1       mrg EOF
    738      1.1       mrg   cat <<EOF >${dummy}1.s
    739      1.1       mrg 	.globl cpuid
    740      1.1       mrg 	.globl _cpuid
    741      1.1       mrg cpuid:
    742      1.1       mrg _cpuid:
    743  1.2.2.1       tls 	push	%rbx
    744  1.2.2.1       tls 	mov	%rdx, %r8
    745  1.2.2.1       tls 	mov	%ecx, %eax
    746  1.2.2.1       tls 	.byte	0x0f
    747  1.2.2.1       tls 	.byte	0xa2
    748  1.2.2.1       tls 	mov	%ebx, (%r8)
    749  1.2.2.1       tls 	mov	%edx, 4(%r8)
    750  1.2.2.1       tls 	mov	%ecx, 8(%r8)
    751  1.2.2.1       tls 	pop	%rbx
    752      1.1       mrg 	ret
    753      1.1       mrg EOF
    754      1.1       mrg   cat <<EOF >${dummy}2.c
    755  1.2.2.1       tls #include <string.h>
    756  1.2.2.1       tls #include <stdio.h>
    757  1.2.2.1       tls #define CPUID(a,b) cpuid(b,a,a,b)
    758  1.2.2.1       tls #if __cplusplus
    759  1.2.2.1       tls extern "C"
    760  1.2.2.1       tls #endif
    761  1.2.2.1       tls unsigned int cpuid (int, char *, char *, int);
    762  1.2.2.1       tls int
    763      1.1       mrg main ()
    764      1.1       mrg {
    765      1.1       mrg   char vendor_string[13];
    766      1.1       mrg   char dummy_string[12];
    767      1.1       mrg   long fms;
    768      1.1       mrg   int family, model, stepping;
    769  1.2.2.1       tls   const char *modelstr;
    770  1.2.2.1       tls   int cpu_64bit = 0;
    771      1.1       mrg 
    772  1.2.2.1       tls   CPUID (vendor_string, 0);
    773      1.1       mrg   vendor_string[12] = 0;
    774      1.1       mrg 
    775  1.2.2.1       tls   fms = CPUID (dummy_string, 1);
    776      1.1       mrg 
    777      1.1       mrg   family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff);
    778      1.1       mrg   model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0);
    779      1.1       mrg   stepping = fms & 0xf;
    780      1.1       mrg 
    781      1.1       mrg   modelstr = "$guess_cpu";
    782  1.2.2.1       tls 
    783  1.2.2.1       tls   /**************************************************/
    784  1.2.2.1       tls   /*** WARNING: keep this list in sync with fat.c ***/
    785  1.2.2.1       tls   /**************************************************/
    786      1.1       mrg   if (strcmp (vendor_string, "GenuineIntel") == 0)
    787      1.1       mrg     {
    788      1.1       mrg       switch (family)
    789      1.1       mrg 	{
    790      1.1       mrg 	case 5:
    791      1.1       mrg 	  if (model <= 2)	modelstr = "pentium";
    792      1.1       mrg 	  else if (model >= 4)	modelstr = "pentiummmx";
    793      1.1       mrg 	  break;
    794      1.1       mrg 	case 6:
    795      1.1       mrg 	  if (model <= 1)		modelstr = "pentiumpro";
    796      1.1       mrg 	  else if (model <= 6)		modelstr = "pentium2";
    797      1.1       mrg 	  else if (model <= 8)		modelstr = "pentium3";
    798      1.1       mrg 	  else if (model <= 9)		modelstr = "pentiumm";
    799      1.1       mrg 	  else if (model <= 0x0c)	modelstr = "pentium3";
    800      1.1       mrg 	  else if (model <= 0x0e)	modelstr = "pentiumm";
    801  1.2.2.1       tls 	  else if (model <= 0x19)	cpu_64bit = 1, modelstr = "core2";
    802  1.2.2.1       tls 	  else if (model == 0x1a)	cpu_64bit = 1, modelstr = "coreinhm"; /* NHM Gainestown */
    803  1.2.2.1       tls 	  else if (model == 0x1c)	cpu_64bit = 1, modelstr = "atom";  /* Silverthorne */
    804  1.2.2.1       tls 	  else if (model == 0x1d)	cpu_64bit = 1, modelstr = "core2"; /* PNR Dunnington */
    805  1.2.2.1       tls 	  else if (model == 0x1e)	cpu_64bit = 1, modelstr = "coreinhm"; /* NHM Lynnfield/Jasper */
    806  1.2.2.1       tls 	  else if (model == 0x25)	cpu_64bit = 1, modelstr = "coreiwsm"; /* WSM Clarkdale/Arrandale */
    807  1.2.2.1       tls 	  else if (model == 0x26)	cpu_64bit = 1, modelstr = "atom";  /* Lincroft */
    808  1.2.2.1       tls 	  else if (model == 0x27)	cpu_64bit = 1, modelstr = "atom";  /* Saltwell */
    809  1.2.2.1       tls 	  else if (model == 0x2a)	cpu_64bit = 1, modelstr = "coreisbr"; /* SB */
    810  1.2.2.1       tls 	  else if (model == 0x2c)	cpu_64bit = 1, modelstr = "coreiwsm"; /* WSM Gulftown */
    811  1.2.2.1       tls 	  else if (model == 0x2d)	cpu_64bit = 1, modelstr = "coreisbr"; /* SBC-EP */
    812  1.2.2.1       tls 	  else if (model == 0x2e)	cpu_64bit = 1, modelstr = "coreinhm"; /* NHM Beckton */
    813  1.2.2.1       tls 	  else if (model == 0x2f)	cpu_64bit = 1, modelstr = "coreiwsm"; /* WSM Eagleton */
    814  1.2.2.1       tls 	  else if (model == 0x3a)	cpu_64bit = 1, modelstr = "coreisbr"; /* IBR */
    815  1.2.2.1       tls 	  else if (model == 0x3c)	cpu_64bit = 1, modelstr = "coreisbr"; /* Haswell */
    816  1.2.2.1       tls 	  else if (model == 0x36)	cpu_64bit = 1, modelstr = "atom";  /* Cedarview/Saltwell */
    817  1.2.2.1       tls 	  else cpu_64bit = 1, modelstr = "corei"; /* default */
    818      1.1       mrg 	  break;
    819      1.1       mrg 	case 15:
    820  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "pentium4";
    821      1.1       mrg 	  break;
    822      1.1       mrg 	}
    823      1.1       mrg     }
    824      1.1       mrg   else if (strcmp (vendor_string, "AuthenticAMD") == 0)
    825      1.1       mrg     {
    826      1.1       mrg       switch (family)
    827      1.1       mrg 	{
    828      1.1       mrg 	case 5:
    829      1.1       mrg 	  if (model <= 3)	modelstr = "k5";
    830      1.1       mrg 	  else if (model <= 7)	modelstr = "k6";
    831      1.1       mrg 	  else if (model == 8)	modelstr = "k62";
    832      1.1       mrg 	  else if (model == 9)	modelstr = "k63";
    833      1.1       mrg 	  else if (model == 10) modelstr = "geode";
    834      1.1       mrg 	  else if (model == 13) modelstr = "k63";
    835      1.1       mrg 	  break;
    836      1.1       mrg 	case 6:
    837      1.1       mrg 	  modelstr = "athlon";
    838      1.1       mrg 	  break;
    839  1.2.2.1       tls 	case 15:		/* K8, K9 */
    840  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "k8";
    841  1.2.2.1       tls 	  break;
    842  1.2.2.1       tls 	case 16:		/* K10 */
    843  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "k10";
    844  1.2.2.1       tls 	  break;
    845  1.2.2.1       tls 	case 17:		/* Hybrid k8/k10, claim k8 */
    846  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "k8";
    847  1.2.2.1       tls 	  break;
    848  1.2.2.1       tls 	case 18:		/* Llano, uses K10 core */
    849  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "k10";
    850  1.2.2.1       tls 	  break;
    851  1.2.2.1       tls 	case 19:		/* AMD Internal, assume future K10 */
    852  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "k10";
    853  1.2.2.1       tls 	  break;
    854  1.2.2.1       tls 	case 20:		/* Bobcat */
    855  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "bobcat";
    856  1.2.2.1       tls 	  break;
    857  1.2.2.1       tls 	case 21:		/* Bulldozer */
    858  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "bulldozer";
    859  1.2.2.1       tls 	  break;
    860  1.2.2.1       tls 	case 22:		/* jaguar, an improved bobcat */
    861  1.2.2.1       tls 	  cpu_64bit = 1, modelstr = "bobcat";
    862      1.1       mrg 	  break;
    863      1.1       mrg 	}
    864      1.1       mrg     }
    865      1.1       mrg   else if (strcmp (vendor_string, "CyrixInstead") == 0)
    866      1.1       mrg     {
    867      1.1       mrg       /* Should recognize Cyrix' processors too.  */
    868      1.1       mrg     }
    869      1.1       mrg   else if (strcmp (vendor_string, "CentaurHauls") == 0)
    870      1.1       mrg     {
    871      1.1       mrg       switch (family)
    872      1.1       mrg 	{
    873      1.1       mrg 	case 6:
    874      1.1       mrg 	  if (model < 9)	modelstr = "viac3";
    875      1.1       mrg 	  else if (model < 15)	modelstr = "viac32";
    876  1.2.2.1       tls 	  else			cpu_64bit = 1, modelstr = "nano";
    877      1.1       mrg 	  break;
    878      1.1       mrg 	}
    879      1.1       mrg     }
    880      1.1       mrg 
    881  1.2.2.1       tls   /* If our cpuid-based exact guess is more conservative than the previous
    882  1.2.2.1       tls      guess, revert.  This is of course wrong, but it can happen in an emulator,
    883  1.2.2.1       tls      so this workaround allows for successful 64-bit builds.  */
    884  1.2.2.1       tls   if (strcmp ("$guess_cpu", "x86_64") == 0 && ! cpu_64bit)
    885  1.2.2.1       tls     modelstr = "$guess_cpu";
    886  1.2.2.1       tls 
    887  1.2.2.1       tls   printf ("%s", modelstr);
    888      1.1       mrg   return 0;
    889      1.1       mrg }
    890      1.1       mrg EOF
    891      1.1       mrg 
    892      1.1       mrg   if ($CC_FOR_BUILD ${dummy}1.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
    893      1.1       mrg     # On 80386 and early 80486 cpuid is not available and will result in a
    894      1.1       mrg     # SIGILL message, hence 2>/dev/null.
    895      1.1       mrg     #
    896      1.1       mrg     # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
    897      1.1       mrg     # "Illegal instruction (core dumped)" message to stdout, so we test $?
    898      1.1       mrg     # to check if the program run was successful.
    899      1.1       mrg     #
    900      1.1       mrg     x=`$SHELL -c ./$dummy 2>/dev/null`
    901      1.1       mrg     if test $? = 0 && test -n "$x"; then
    902      1.1       mrg       exact_cpu=$x
    903      1.1       mrg     fi
    904      1.1       mrg   fi
    905      1.1       mrg 
    906      1.1       mrg   if test -z "$exact_cpu"; then
    907      1.1       mrg   if ($CC_FOR_BUILD ${dummy}0.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
    908      1.1       mrg     # On 80386 and early 80486 cpuid is not available and will result in a
    909      1.1       mrg     # SIGILL message, hence 2>/dev/null.
    910      1.1       mrg     #
    911      1.1       mrg     # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
    912      1.1       mrg     # "Illegal instruction (core dumped)" message to stdout, so we test $?
    913      1.1       mrg     # to check if the program run was successful.
    914      1.1       mrg     #
    915      1.1       mrg     x=`$SHELL -c ./$dummy 2>/dev/null`
    916      1.1       mrg     if test $? = 0 && test -n "$x"; then
    917      1.1       mrg       exact_cpu=$x
    918      1.1       mrg     fi
    919      1.1       mrg   fi
    920      1.1       mrg   fi
    921      1.1       mrg 
    922      1.1       mrg   # We need to remove some .o files here since lame C compilers
    923      1.1       mrg   # generate these even when not asked.
    924      1.1       mrg   rm -f ${dummy}0.s ${dummy}0.o ${dummy}1.s ${dummy}1.o ${dummy}2.c ${dummy}2.o $dummy
    925      1.1       mrg   ;;
    926      1.1       mrg 
    927  1.2.2.1       tls s390*-*-*)
    928  1.2.2.1       tls   model=`grep "^processor 0: version =" /proc/cpuinfo | sed -e 's/.*machine = //'`
    929  1.2.2.1       tls   case $model in
    930  1.2.2.1       tls     2064 | 2066) zcpu="z900" ;;
    931  1.2.2.1       tls     2084 | 2086) zcpu="z990" ;;
    932  1.2.2.1       tls     2094 | 2096) zcpu="z9"   ;;
    933  1.2.2.1       tls     2097 | 2098) zcpu="z10"  ;;
    934  1.2.2.1       tls     2817 | 2818 | *) zcpu="z196" ;;
    935  1.2.2.1       tls   esac
    936  1.2.2.1       tls   case "$guess_full" in
    937  1.2.2.1       tls     s390x-*-*) exact_cpu=${zcpu}    ;;
    938  1.2.2.1       tls     s390-*-*)  exact_cpu=${zcpu}esa ;;
    939  1.2.2.1       tls   esac
    940  1.2.2.1       tls   ;;
    941  1.2.2.1       tls 
    942      1.1       mrg esac
    943      1.1       mrg 
    944      1.1       mrg 
    945      1.1       mrg 
    946      1.1       mrg # -------------------------------------------------------------------------
    947      1.1       mrg # Use an exact cpu, if possible
    948      1.2  christos # Disabled for NetBSD cross builds
    949      1.2  christos if false && test -n "$exact_cpu"; then
    950      1.1       mrg   echo "$exact_cpu$guess_rest"
    951      1.1       mrg else
    952      1.1       mrg   echo "$guess_full"
    953      1.1       mrg fi
    954      1.1       mrg exit 0
    955      1.1       mrg 
    956      1.1       mrg 
    957      1.1       mrg 
    958      1.1       mrg # Local variables:
    959      1.1       mrg # fill-column: 76
    960      1.1       mrg # End:
    961