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