1#! /bin/sh
2#
3# GMP config.guess wrapper.
4
5
6# Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
7# 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 2.1 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; see the file COPYING.LIB.  If not, write to
23# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24# MA 02110-1301, USA.
25
26
27# Usage: config.guess
28#
29# Print the host system CPU-VENDOR-OS.
30#
31# configfsf.guess is run and its guess then sharpened up to take advantage
32# of the finer grained CPU types that GMP knows.
33
34
35# Expect to find configfsf.guess in the same directory as this config.guess
36configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
37if test "$configfsf_guess" = "$0"; then
38  echo "Cannot derive configfsf.guess from $0" 1>&2
39  exit 1
40fi
41if test -f "$configfsf_guess"; then
42  :
43else
44  echo "$configfsf_guess not found" 1>&2
45  exit 1
46fi
47
48# Setup a $SHELL with which to run configfsf.guess, using the same
49# $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess
50SHELL=${CONFIG_SHELL-/bin/sh}
51
52# Identify ourselves on --version, --help or errors
53if test $# != 0; then
54  echo "(GNU MP wrapped config.guess)"
55  $SHELL $configfsf_guess "$@"
56  exit 1
57fi
58
59guess_full=`$SHELL $configfsf_guess`
60if test $? != 0; then
61  exit 1
62fi
63
64guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
65guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
66exact_cpu=
67
68
69# -------------------------------------------------------------------------
70# The following should look at the current guess and probe the system to
71# establish a better guess in exact_cpu.  Leave exact_cpu empty if probes
72# can't be done, or don't work.
73#
74# When a number of probes are done, test -z "$exact_cpu" can be used instead
75# of putting each probe under an "else" of the preceeding.  That can stop
76# the code getting horribly nested and marching off the right side of the
77# screen.
78
79# Note that when a compile-and-link is done in one step we need to remove .o
80# files, since lame C compilers generate these even when not asked.
81#
82
83dummy=dummy-$$
84trap 'rm -f $dummy.c $dummy.o $dummy.core $dummy ${dummy}1.s ${dummy}2.c ; exit 1' 1 2 15
85
86# Use $HOST_CC if defined. $CC may point to a cross-compiler
87if test x"$CC_FOR_BUILD" = x; then
88  if test x"$HOST_CC" != x; then
89    CC_FOR_BUILD="$HOST_CC"
90  else
91    if test x"$CC" != x; then
92      CC_FOR_BUILD="$CC"
93    else
94      echo 'dummy(){}' >$dummy.c
95      for c in cc gcc c89 c99; do
96	  ($c $dummy.c -c) >/dev/null 2>&1
97	  if test $? = 0; then
98	      CC_FOR_BUILD="$c"; break
99	  fi
100      done
101      rm -f $dummy.c $dummy.o
102      if test x"$CC_FOR_BUILD" = x; then
103	CC_FOR_BUILD=no_compiler_found
104      fi
105    fi
106  fi
107fi
108
109
110case "$guess_full" in
111
112alpha-*-*)
113  # configfsf.guess detects exact alpha cpu types for OSF and GNU/Linux, but
114  # not for *BSD and other systems.  We try to get an exact type for any
115  # plain "alpha" it leaves.
116  #
117  # configfsf.guess used to have a block of code not unlike this, but these
118  # days does its thing with Linux kernel /proc/cpuinfo or OSF psrinfo.
119  #
120  cat <<EOF >$dummy.s
121	.data
122Lformat:
123	.byte 37,100,45,37,120,10,0	# "%d-%x\n"
124	.text
125	.globl main
126	.align 4
127	.ent main
128main:
129	.frame \$30,16,\$26,0
130	ldgp \$29,0(\$27)
131	.prologue 1
132	.long 0x47e03d91 # implver \$17
133	lda \$2,-1
134	.long 0x47e20c21 # amask \$2,\$1
135	lda \$16,Lformat
136	not \$1,\$18
137	jsr \$26,printf
138	ldgp \$29,0(\$26)
139	mov 0,\$16
140	jsr \$26,exit
141	.end main
142EOF
143  $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
144  if test "$?" = 0 ; then
145    case `./$dummy` in
146    0-0)	exact_cpu=alpha      ;;
147    1-0)	exact_cpu=alphaev5   ;;
148    1-1)	exact_cpu=alphaev56  ;;
149    1-101)	exact_cpu=alphapca56 ;;
150    2-303)	exact_cpu=alphaev6   ;;
151    2-307)	exact_cpu=alphaev67  ;;
152    2-1307)	exact_cpu=alphaev68  ;;
153    esac
154  fi
155  rm -f $dummy.s $dummy.o $dummy
156  ;;
157
158ia64*-*-*)
159  # CPUID[3] bits 24 to 31 is the processor family.  itanium2 is documented
160  # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
161  # haven't found any documentation on it as such.
162  #
163  # Defining both getcpuid and _getcpuid lets us ignore whether the system
164  # expects underscores or not.
165  #
166  # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
167  # (which is the default there), it's the only 64-bit type.
168  #
169  cat >${dummy}a.s <<EOF
170	.text
171	.global	_getcpuid
172	.proc	_getcpuid
173_getcpuid:
174	mov	r8 = CPUID[r32] ;;
175	br.ret.sptk.many rp ;;
176	.endp	_getcpuid
177	.global	getcpuid
178	.proc	getcpuid
179getcpuid:
180	mov	r8 = CPUID[r32] ;;
181	br.ret.sptk.many rp ;;
182	.endp	getcpuid
183EOF
184  cat >${dummy}b.c <<EOF
185#include <stdio.h>
186unsigned long long getcpuid ();
187int
188main ()
189{
190  if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
191    {
192      /* "GenuineIntel" */
193      switch ((getcpuid(3LL) >> 24) & 0xFF) {
194      case 0x07: puts ("itanium");  break;
195      case 0x1F: puts ("itanium2"); break;
196      }
197    }
198  return 0;
199}
200EOF
201  if $CC_FOR_BUILD ${dummy}a.s ${dummy}b.c -o $dummy >/dev/null 2>&1; then
202    exact_cpu=`./$dummy`
203  fi
204  rm -f ${dummy}a.s ${dummy}a.o ${dummy}b.c ${dummy}b.o $dummy $dummy.core core
205  ;;
206
207mips-*-irix[6789]*)
208  # IRIX 6 and up always has a 64-bit mips cpu
209  exact_cpu=mips64
210  ;;
211
212m68k-*-*)
213  # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
214  #   hw.model = Apple Macintosh Quadra 610  (68040)
215  exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
216  if test -z "$exact_cpu"; then
217    # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
218    exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
219  fi
220  if test -z "$exact_cpu"; then
221    # Try: movel #0,%d0; rts
222    # This is to check the compiler and our asm code works etc, before
223    # assuming failures below indicate cpu characteristics.
224    # .byte is used to avoid problems with assembler syntax variations.
225    # For testing, provoke failures by adding "illegal" possibly as
226    # ".byte 0x4A, 0xFC"
227    cat >$dummy.s <<EOF
228	.text
229	.globl main
230	.globl _main
231main:
232_main:
233	.byte	0x70, 0x00
234	.byte	0x4e, 0x75
235EOF
236    if ($CC_FOR_BUILD $dummy.s -o $dummy && ./$dummy) >/dev/null 2>&1; then
237
238      # $SHELL -c is used to execute ./$dummy below, since (./$dummy)
239      # 2>/dev/null still prints the SIGILL message on some shells.
240      #
241        # Try: movel #0,%d0
242        #      rtd #0
243        cat >$dummy.s <<EOF
244	.text
245	.globl main
246	.globl _main
247main:
248_main:
249	.byte	0x70, 0x00
250	.byte	0x4e, 0x74, 0x00, 0x00
251EOF
252        if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
253          $SHELL -c ./$dummy >/dev/null 2>&1
254	  if test $? != 0; then
255            exact_cpu=m68000    # because rtd didn't work
256          fi
257        fi
258      #
259
260      if test -z "$exact_cpu"; then
261        # Try: trapf
262        #      movel #0,%d0
263        #      rts
264        # Another possibility for identifying 68000 and 68010 is the
265        # different value stored by "movem a0,(a0)+"
266        cat >$dummy.s <<EOF
267	.text
268	.globl main
269	.globl _main
270main:
271_main:
272	.byte	0x51, 0xFC
273	.byte	0x70, 0x00
274	.byte	0x4e, 0x75
275EOF
276        if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
277          $SHELL -c ./$dummy >/dev/null 2>&1
278	  if test $? != 0; then
279            exact_cpu=m68010    # because trapf didn't work
280          fi
281        fi
282      fi
283
284      if test -z "$exact_cpu"; then
285        # Try: bfffo %d1{0:31},%d0
286        #      movel #0,%d0
287        #      rts
288        cat >$dummy.s <<EOF
289	.text
290	.globl main
291	.globl _main
292main:
293_main:
294	.byte	0xED, 0xC1, 0x00, 0x1F
295	.byte	0x70, 0x00
296	.byte	0x4e, 0x75
297EOF
298        if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
299          $SHELL -c ./$dummy >/dev/null 2>&1
300	  if test $? != 0; then
301            exact_cpu=m68360  # cpu32, because bfffo didn't work
302          fi
303        fi
304      fi
305
306      if test -z "$exact_cpu"; then
307        # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
308        exact_cpu=m68020
309      fi
310    fi
311    rm -f $dummy.s $dummy.o $dummy $dummy.core core
312  fi
313  if test -z "$exact_cpu"; then
314    case "$guess_full" in
315      *-*-next* | *-*-openstep*)  # NeXTs are 68020 or better
316        exact_cpu=m68020 ;;
317    esac
318  fi
319  ;;
320
321
322rs6000-*-* | powerpc*-*-*)
323  # Enhancement: On MacOS the "machine" command prints for instance
324  # "ppc750".  Interestingly on powerpc970-apple-darwin6.8.5 it prints
325  # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
326  # (as noted below).  But the man page says the command is still "under
327  # development", so it doesn't seem wise to use it just yet, not while
328  # there's an alternative.
329  #
330  # Try to read the PVR.  mfpvr is a protected instruction, NetBSD, MacOS
331  # and AIX don't allow it in user mode, but the Linux kernel does.
332  #
333  # Using explicit bytes for mfpvr avoids worrying about assembler syntax
334  # and underscores.  "char"s are used instead of "int"s to avoid worrying
335  # whether sizeof(int)==4 or if it's the right endianness.
336  #
337  # Note this is no good on AIX, since a C function there is the address of
338  # a function descriptor, not actual code.  But this doesn't matter since
339  # AIX doesn't allow mfpvr anyway.
340  #
341  cat >$dummy.c <<\EOF
342#include <stdio.h>
343struct {
344  int   n;  /* force 4-byte alignment */
345  char  a[8];
346} getpvr = {
347  0,
348  {
349    0x7c, 0x7f, 0x42, 0xa6,  /* mfpvr r3 */
350    0x4e, 0x80, 0x00, 0x20,  /* blr      */
351  }
352};
353int
354main ()
355{
356  unsigned  (*fun)();
357  unsigned  pvr;
358
359  /* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS,
360     it gets a compiler error on a combined cast and call */
361  fun = (unsigned (*)()) getpvr.a;
362  pvr = (*fun) ();
363
364  switch (pvr >> 16) {
365  case 0x0001: puts ("powerpc601");  break;
366  case 0x0003: puts ("powerpc603");  break;
367  case 0x0004: puts ("powerpc604");  break;
368  case 0x0006: puts ("powerpc603e"); break;
369  case 0x0007: puts ("powerpc603e"); break;  /* 603ev */
370  case 0x0008: puts ("powerpc750");  break;
371  case 0x0009: puts ("powerpc604e"); break;
372  case 0x000a: puts ("powerpc604e"); break;  /* 604ev5 */
373  case 0x000c: puts ("powerpc7400"); break;
374  case 0x0041: puts ("powerpc630");  break;
375  case 0x0050: puts ("powerpc860");  break;
376  case 0x8000: puts ("powerpc7450"); break;
377  case 0x8001: puts ("powerpc7455"); break;
378  case 0x8002: puts ("powerpc7457"); break;
379  case 0x800c: puts ("powerpc7410"); break;
380  }
381  return 0;
382}
383EOF
384  if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
385    # This style construct is needed on AIX 4.3 to suppress the SIGILL error
386    # from (*fun)().  Using $SHELL -c ./$dummy 2>/dev/null doesn't work.
387    { x=`./$dummy`; } 2>/dev/null
388    if test -n "$x"; then
389      exact_cpu=$x
390    fi
391  fi
392  rm -f $dummy.c $dummy.o $dummy $dummy.core
393
394  # Grep the linux kernel /proc/cpuinfo pseudo-file.
395  # Anything unrecognised is ignored, since of course we mustn't spit out
396  # a cpu type config.sub doesn't know.
397  if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
398    x=`grep "^cpu[ 	]" /proc/cpuinfo | head -n 1`
399    x=`echo $x | sed -n 's/^cpu[ 	]*:[ 	]*\([A-Za-z0-9]*\).*/\1/p'`
400    x=`echo $x | sed 's/PPC//'`
401    case $x in
402      601)     exact_cpu="power" ;;
403      603ev)   exact_cpu="powerpc603e" ;;
404      604ev5)  exact_cpu="powerpc604e" ;;
405      603 | 603e | 604 | 604e | 750 | 821 | 860 | 970)
406        exact_cpu="powerpc$x" ;;
407      POWER[4-9])
408        exact_cpu=`echo $x | sed "s;POWER;power;"` ;;
409    esac
410  fi
411
412  if test -z "$exact_cpu"; then
413    # On AIX, try looking at _system_configuration.  This is present in
414    # version 4 at least.
415    cat >$dummy.c <<EOF
416#include <stdio.h>
417#include <sys/systemcfg.h>
418int
419main ()
420{
421  switch (_system_configuration.implementation) {
422  /* Old versions of AIX don't have all these constants,
423     use ifdef for safety. */
424#ifdef POWER_RS2
425  case POWER_RS2:    puts ("power2");     break;
426#endif
427#ifdef POWER_601
428  case POWER_601:    puts ("power");      break;
429#endif
430#ifdef POWER_603
431  case POWER_603:    puts ("powerpc603"); break;
432#endif
433#ifdef POWER_604
434  case POWER_604:    puts ("powerpc604"); break;
435#endif
436#ifdef POWER_620
437  case POWER_620:    puts ("powerpc620"); break;
438#endif
439#ifdef POWER_630
440  case POWER_630:    puts ("powerpc630"); break;
441#endif
442  /* Dunno what this is, leave it out for now.
443  case POWER_A35:    puts ("powerpca35"); break;
444  */
445  /* This is waiting for a bit more info.
446  case POWER_RS64II: puts ("powerpcrs64ii"); break;
447  */
448  default:
449    if (_system_configuration.architecture == POWER_RS)
450      puts ("power");
451    else if (_system_configuration.width == 64)
452      puts ("powerpc64");
453  }
454  return 0;
455}
456EOF
457    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
458      x=`./$dummy`
459      if test -n "$x"; then
460        exact_cpu=$x
461      fi
462    fi
463    rm -f $dummy.c $dummy.o $dummy
464  fi
465
466  if test -z "$exact_cpu"; then
467    # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
468    # can tell us the exact cpu.
469    cat >$dummy.c <<EOF
470#include <stdio.h>
471#include <mach-o/arch.h>
472int
473main (void)
474{
475  const NXArchInfo *a = NXGetLocalArchInfo();
476  if (a->cputype == CPU_TYPE_POWERPC)
477    {
478      switch (a->cpusubtype) {
479      /* The following known to Darwin 1.3. */
480      case CPU_SUBTYPE_POWERPC_601:   puts ("powerpc601");  break;
481      case CPU_SUBTYPE_POWERPC_602:   puts ("powerpc602");  break;
482      case CPU_SUBTYPE_POWERPC_603:   puts ("powerpc603");  break;
483      case CPU_SUBTYPE_POWERPC_603e:  puts ("powerpc603e"); break;
484      case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
485      case CPU_SUBTYPE_POWERPC_604:   puts ("powerpc604");  break;
486      case CPU_SUBTYPE_POWERPC_604e:  puts ("powerpc604e"); break;
487      case CPU_SUBTYPE_POWERPC_620:   puts ("powerpc620");  break;
488      case CPU_SUBTYPE_POWERPC_750:   puts ("powerpc750");  break;
489      case CPU_SUBTYPE_POWERPC_7400:  puts ("powerpc7400"); break;
490      case CPU_SUBTYPE_POWERPC_7450:  puts ("powerpc7450"); break;
491      /* Darwin 6.8.5 doesn't define a constant for 970, but gives 100 */
492      case 100:                       puts ("powerpc970");  break;
493      }
494    }
495  return 0;
496}
497EOF
498    if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
499      x=`./$dummy`
500      if test -n "$x"; then
501        exact_cpu=$x
502      fi
503    fi
504    rm -f $dummy.c $dummy.o $dummy
505  fi
506  ;;
507
508sparc-*-* | sparc64-*-*)
509  # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
510  # to short-circuit subsequent tests.
511
512  # Grep the linux kernel /proc/cpuinfo pseudo-file.
513  # A typical line is "cpu\t\t: TI UltraSparc II  (BlackBird)"
514  # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
515  #
516  if test -f /proc/cpuinfo; then
517    if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
518      exact_cpu="sparc"   # ie. v7
519    elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
520      exact_cpu="sparc"   # ie. v7
521    elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
522      exact_cpu="sparcv8"
523    elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
524      exact_cpu="supersparc"
525    elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
526      exact_cpu="microsparc"
527    elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
528      # actually MicroSPARC-II
529      exact_cpu=microsparc
530    elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
531      # this grep pattern has not been tested against any Linux
532      exact_cpu="ultrasparct1"
533    elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
534      exact_cpu="ultrasparc3"
535    elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
536      exact_cpu="ultrasparc2i"
537    elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
538      exact_cpu="ultrasparc2"
539    elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
540      exact_cpu="ultrasparc"
541    fi
542  fi
543
544  # Grep the output from sysinfo on SunOS.
545  # sysinfo has been seen living in /bin or in /usr/kvm
546  #	cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
547  #	cpu0 is a "75 MHz TI,TMS390Z55" CPU
548  #
549  if test -z "$exact_cpu"; then
550    for i in sysinfo /usr/kvm/sysinfo; do
551      if $SHELL -c $i 2>/dev/null >conftest.dat; then
552        if grep 'cpu0 is a "SuperSPARC' conftest.dat >/dev/null; then
553          exact_cpu=supersparc
554          break
555        elif grep 'cpu0 is a .*TMS390Z5.' conftest.dat >/dev/null; then
556          # TMS390Z50 and TMS390Z55
557          exact_cpu=supersparc
558          break
559        fi
560      fi
561    done
562    rm -f conftest.dat
563  fi
564
565  # Grep the output from prtconf on Solaris.
566  # Use an explicit /usr/sbin, since that directory might not be in a normal
567  # user's path.
568  #
569  #     SUNW,UltraSPARC (driver not attached)
570  #     SUNW,UltraSPARC-II (driver not attached)
571  #     SUNW,UltraSPARC-IIi (driver not attached)
572  #     SUNW,UltraSPARC-III+ (driver not attached)
573  #     Ross,RT625 (driver not attached)
574  #     TI,TMS390Z50 (driver not attached)
575  #
576  # /usr/sbin/sysdef prints similar information, but includes all loadable
577  # cpu modules, not just the real cpu.
578  #
579  # We first try a plain prtconf, since that is known to work on older systems.
580  # But for newer T1 systems, that doesn't produce any useful output, we need
581  # "prtconf -vp" there.
582  #
583  for prtconfopt in "" "-vp"; do
584    if test -z "$exact_cpu"; then
585      if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >conftest.dat; then
586	if grep 'SUNW,UltraSPARC-T1' conftest.dat >/dev/null; then
587	  exact_cpu=ultrasparct1
588	elif grep 'SUNW,UltraSPARC-III' conftest.dat >/dev/null; then
589	  exact_cpu=ultrasparc3
590	elif grep 'SUNW,UltraSPARC-IIi' conftest.dat >/dev/null; then
591	  exact_cpu=ultrasparc2i
592	elif grep 'SUNW,UltraSPARC-II' conftest.dat >/dev/null; then
593	  exact_cpu=ultrasparc2
594	elif grep 'SUNW,UltraSPARC' conftest.dat >/dev/null; then
595	  exact_cpu=ultrasparc
596	elif grep 'Ross,RT62.' conftest.dat >/dev/null; then
597	  # RT620, RT625, RT626 hypersparcs (v8).
598	  exact_cpu=sparcv8
599	elif grep 'TI,TMS390Z5.' conftest.dat >/dev/null; then
600	  # TMS390Z50 and TMS390Z55
601	  exact_cpu=supersparc
602	elif grep 'TI,TMS390S10' conftest.dat >/dev/null; then
603	  exact_cpu=microsparc
604	elif grep 'FMI,MB86904' conftest.dat >/dev/null; then
605	  # actually MicroSPARC-II
606	  exact_cpu=microsparc
607	fi
608      fi
609      rm -f conftest.dat
610    fi
611  done
612
613  # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
614  # Use an explicit /sbin, since that directory might not be in a normal
615  # user's path.  Example outputs,
616  #
617  #     hw.model: Sun Microsystems UltraSparc-IIi
618  #
619  if test -z "$exact_cpu"; then
620    if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >conftest.dat; then
621      if grep 'UltraSparc-T1' conftest.dat >/dev/null; then
622	# this grep pattern has not been tested against any BSD
623        exact_cpu=ultrasparct1
624      elif grep 'UltraSparc-III' conftest.dat >/dev/null; then
625        exact_cpu=ultrasparc3
626      elif grep 'UltraSparc-IIi' conftest.dat >/dev/null; then
627        exact_cpu=ultrasparc2i
628      elif grep 'UltraSparc-II' conftest.dat >/dev/null; then
629        exact_cpu=ultrasparc2
630      elif grep 'UltraSparc' conftest.dat >/dev/null; then
631        exact_cpu=ultrasparc
632      elif grep 'TMS390Z5.' conftest.dat >/dev/null; then
633        # TMS390Z50 and TMS390Z55
634        exact_cpu=supersparc
635      elif grep 'TMS390S10' conftest.dat >/dev/null; then
636        exact_cpu=microsparc
637      elif grep 'MB86904' conftest.dat >/dev/null; then
638        # actually MicroSPARC-II
639        exact_cpu=microsparc
640      elif grep 'MB86907' conftest.dat >/dev/null; then
641        exact_cpu=turbosparc
642      fi
643    fi
644    rm -f conftest.dat
645  fi
646
647  # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
648  #
649  if test -z "$exact_cpu"; then
650    case `uname -m` in
651      sun4[md]) exact_cpu=sparcv8 ;;
652      sun4u)    exact_cpu=sparcv9 ;;
653    esac
654  fi
655  ;;
656
657i?86-*-*)
658  cat <<EOF >${dummy}1.s
659	.globl cpuid
660	.globl _cpuid
661cpuid:
662_cpuid:
663	pushl %esi
664	pushl %ebx
665	movl 16(%esp),%eax
666	.byte 0x0f
667	.byte 0xa2
668	movl 12(%esp),%esi
669	movl %ebx,(%esi)
670	movl %edx,4(%esi)
671	movl %ecx,8(%esi)
672	popl %ebx
673	popl %esi
674	ret
675EOF
676  cat <<EOF >${dummy}2.c
677main ()
678{
679  char vendor_string[13];
680  char dummy_string[12];
681  long fms;
682  int family, model, stepping;
683  char *modelstr;
684
685  cpuid (vendor_string, 0);
686  vendor_string[12] = 0;
687
688  fms = cpuid (dummy_string, 1);
689
690  family = (fms >> 8) & 15;
691  model = (fms >> 4) & 15;
692  stepping = fms & 15;
693
694  modelstr = "i486";
695  if (strcmp (vendor_string, "GenuineIntel") == 0)
696    {
697      switch (family)
698	{
699	case 5:
700	  if (model <= 2)	modelstr = "pentium";
701	  else if (model >= 4)	modelstr = "pentiummmx";
702	  break;
703	case 6:
704	  if (model == 1)	modelstr = "pentiumpro";
705	  else if (model <= 6)	modelstr = "pentium2";
706	  else			modelstr = "pentium3";
707	  break;
708	case 15:
709	  modelstr = "pentium4";
710	  break;
711	}
712    }
713  else if (strcmp (vendor_string, "AuthenticAMD") == 0)
714    {
715      switch (family)
716	{
717	case 5:
718	  if (model <= 3)	modelstr = "k5";
719	  else if (model <= 7)	modelstr = "k6";
720	  else if (model <= 8)	modelstr = "k62";
721	  else if (model <= 9)	modelstr = "k63";
722	  break;
723	case 6:
724	  modelstr = "athlon";
725	  break;
726	case 15:
727	  /* We might want to return opteron, athlon64, or the CPU core name
728	     hammer here instead of the architecture name x86_64.  */
729	  modelstr = "x86_64";
730	  break;
731	}
732    }
733  else if (strcmp (vendor_string, "CyrixInstead") == 0)
734    {
735      /* Should recognize Cyrix' processors too.  */
736    }
737  else if (strcmp (vendor_string, "CentaurHauls") == 0)
738    {
739      switch (family)
740	{
741	case 6:
742	  if (model < 9)	modelstr = "viac3";
743	  else			modelstr = "viac32";
744	  break;
745	}
746    }
747
748  printf ("%s\n", modelstr);
749  return 0;
750}
751EOF
752
753  if ($CC_FOR_BUILD ${dummy}1.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
754    # On 80386 and early 80486 cpuid is not available and will result in a
755    # SIGILL message, hence 2>/dev/null.
756    #
757    # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
758    # "Illegal instruction (core dumped)" message to stdout, so we test $?
759    # to check if the program run was successful.
760    #
761    x=`$SHELL -c ./$dummy 2>/dev/null`
762    if test $? = 0 && test -n "$x"; then
763      exact_cpu=$x
764    fi
765  fi
766
767  # We need to remove some .o files here since lame C compilers
768  # generate these even when not asked.
769  rm -f ${dummy}1.s ${dummy}1.o ${dummy}2.c ${dummy}2.o $dummy
770  ;;
771
772esac
773
774
775
776# -------------------------------------------------------------------------
777# Use an exact cpu, if possible
778
779if test -n "$exact_cpu"; then
780  echo "$exact_cpu$guess_rest"
781else
782  echo "$guess_full"
783fi
784exit 0
785
786
787
788# Local variables:
789# fill-column: 76
790# End:
791