config.guess revision 1.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.1 mrg # Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 Free Software
7 1.1 mrg # 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.1 mrg ia64*-*-*)
157 1.1 mrg # CPUID[3] bits 24 to 31 is the processor family. itanium2 is documented
158 1.1 mrg # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
159 1.1 mrg # haven't found any documentation on it as such.
160 1.1 mrg #
161 1.1 mrg # Defining both getcpuid and _getcpuid lets us ignore whether the system
162 1.1 mrg # expects underscores or not.
163 1.1 mrg #
164 1.1 mrg # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
165 1.1 mrg # (which is the default there), it's the only 64-bit type.
166 1.1 mrg #
167 1.1 mrg cat >${dummy}a.s <<EOF
168 1.1 mrg .text
169 1.1 mrg .global _getcpuid
170 1.1 mrg .proc _getcpuid
171 1.1 mrg _getcpuid:
172 1.1 mrg mov r8 = CPUID[r32] ;;
173 1.1 mrg br.ret.sptk.many rp ;;
174 1.1 mrg .endp _getcpuid
175 1.1 mrg .global getcpuid
176 1.1 mrg .proc getcpuid
177 1.1 mrg getcpuid:
178 1.1 mrg mov r8 = CPUID[r32] ;;
179 1.1 mrg br.ret.sptk.many rp ;;
180 1.1 mrg .endp getcpuid
181 1.1 mrg EOF
182 1.1 mrg cat >${dummy}b.c <<EOF
183 1.1 mrg #include <stdio.h>
184 1.1 mrg unsigned long long getcpuid ();
185 1.1 mrg int
186 1.1 mrg main ()
187 1.1 mrg {
188 1.1 mrg if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
189 1.1 mrg {
190 1.1 mrg /* "GenuineIntel" */
191 1.1 mrg switch ((getcpuid(3LL) >> 24) & 0xFF) {
192 1.1 mrg case 0x07: puts ("itanium"); break;
193 1.1 mrg case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */
194 1.1 mrg case 0x20: puts ("itanium2"); break; /* Montecito */
195 1.1 mrg }
196 1.1 mrg }
197 1.1 mrg return 0;
198 1.1 mrg }
199 1.1 mrg EOF
200 1.1 mrg if $CC_FOR_BUILD ${dummy}a.s ${dummy}b.c -o $dummy >/dev/null 2>&1; then
201 1.1 mrg exact_cpu=`./$dummy`
202 1.1 mrg fi
203 1.1 mrg rm -f ${dummy}a.s ${dummy}a.o ${dummy}b.c ${dummy}b.o $dummy $dummy.core core
204 1.1 mrg ;;
205 1.1 mrg
206 1.1 mrg mips-*-irix[6789]*)
207 1.1 mrg # IRIX 6 and up always has a 64-bit mips cpu
208 1.1 mrg exact_cpu=mips64
209 1.1 mrg ;;
210 1.1 mrg
211 1.1 mrg m68k-*-*)
212 1.1 mrg # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
213 1.1 mrg # hw.model = Apple Macintosh Quadra 610 (68040)
214 1.1 mrg exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
215 1.1 mrg if test -z "$exact_cpu"; then
216 1.1 mrg # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
217 1.1 mrg exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
218 1.1 mrg fi
219 1.1 mrg if test -z "$exact_cpu"; then
220 1.1 mrg # Try: movel #0,%d0; rts
221 1.1 mrg # This is to check the compiler and our asm code works etc, before
222 1.1 mrg # assuming failures below indicate cpu characteristics.
223 1.1 mrg # .byte is used to avoid problems with assembler syntax variations.
224 1.1 mrg # For testing, provoke failures by adding "illegal" possibly as
225 1.1 mrg # ".byte 0x4A, 0xFC"
226 1.1 mrg cat >$dummy.s <<EOF
227 1.1 mrg .text
228 1.1 mrg .globl main
229 1.1 mrg .globl _main
230 1.1 mrg main:
231 1.1 mrg _main:
232 1.1 mrg .byte 0x70, 0x00
233 1.1 mrg .byte 0x4e, 0x75
234 1.1 mrg EOF
235 1.1 mrg if ($CC_FOR_BUILD $dummy.s -o $dummy && ./$dummy) >/dev/null 2>&1; then
236 1.1 mrg
237 1.1 mrg # $SHELL -c is used to execute ./$dummy below, since (./$dummy)
238 1.1 mrg # 2>/dev/null still prints the SIGILL message on some shells.
239 1.1 mrg #
240 1.1 mrg # Try: movel #0,%d0
241 1.1 mrg # rtd #0
242 1.1 mrg cat >$dummy.s <<EOF
243 1.1 mrg .text
244 1.1 mrg .globl main
245 1.1 mrg .globl _main
246 1.1 mrg main:
247 1.1 mrg _main:
248 1.1 mrg .byte 0x70, 0x00
249 1.1 mrg .byte 0x4e, 0x74, 0x00, 0x00
250 1.1 mrg EOF
251 1.1 mrg if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
252 1.1 mrg $SHELL -c ./$dummy >/dev/null 2>&1
253 1.1 mrg if test $? != 0; then
254 1.1 mrg exact_cpu=m68000 # because rtd didn't work
255 1.1 mrg fi
256 1.1 mrg fi
257 1.1 mrg #
258 1.1 mrg
259 1.1 mrg if test -z "$exact_cpu"; then
260 1.1 mrg # Try: trapf
261 1.1 mrg # movel #0,%d0
262 1.1 mrg # rts
263 1.1 mrg # Another possibility for identifying 68000 and 68010 is the
264 1.1 mrg # different value stored by "movem a0,(a0)+"
265 1.1 mrg cat >$dummy.s <<EOF
266 1.1 mrg .text
267 1.1 mrg .globl main
268 1.1 mrg .globl _main
269 1.1 mrg main:
270 1.1 mrg _main:
271 1.1 mrg .byte 0x51, 0xFC
272 1.1 mrg .byte 0x70, 0x00
273 1.1 mrg .byte 0x4e, 0x75
274 1.1 mrg EOF
275 1.1 mrg if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
276 1.1 mrg $SHELL -c ./$dummy >/dev/null 2>&1
277 1.1 mrg if test $? != 0; then
278 1.1 mrg exact_cpu=m68010 # because trapf didn't work
279 1.1 mrg fi
280 1.1 mrg fi
281 1.1 mrg fi
282 1.1 mrg
283 1.1 mrg if test -z "$exact_cpu"; then
284 1.1 mrg # Try: bfffo %d1{0:31},%d0
285 1.1 mrg # movel #0,%d0
286 1.1 mrg # rts
287 1.1 mrg cat >$dummy.s <<EOF
288 1.1 mrg .text
289 1.1 mrg .globl main
290 1.1 mrg .globl _main
291 1.1 mrg main:
292 1.1 mrg _main:
293 1.1 mrg .byte 0xED, 0xC1, 0x00, 0x1F
294 1.1 mrg .byte 0x70, 0x00
295 1.1 mrg .byte 0x4e, 0x75
296 1.1 mrg EOF
297 1.1 mrg if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
298 1.1 mrg $SHELL -c ./$dummy >/dev/null 2>&1
299 1.1 mrg if test $? != 0; then
300 1.1 mrg exact_cpu=m68360 # cpu32, because bfffo didn't work
301 1.1 mrg fi
302 1.1 mrg fi
303 1.1 mrg fi
304 1.1 mrg
305 1.1 mrg if test -z "$exact_cpu"; then
306 1.1 mrg # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
307 1.1 mrg exact_cpu=m68020
308 1.1 mrg fi
309 1.1 mrg fi
310 1.1 mrg rm -f $dummy.s $dummy.o $dummy $dummy.core core
311 1.1 mrg fi
312 1.1 mrg if test -z "$exact_cpu"; then
313 1.1 mrg case "$guess_full" in
314 1.1 mrg *-*-next* | *-*-openstep*) # NeXTs are 68020 or better
315 1.1 mrg exact_cpu=m68020 ;;
316 1.1 mrg esac
317 1.1 mrg fi
318 1.1 mrg ;;
319 1.1 mrg
320 1.1 mrg
321 1.1 mrg rs6000-*-* | powerpc*-*-*)
322 1.1 mrg # Enhancement: On MacOS the "machine" command prints for instance
323 1.1 mrg # "ppc750". Interestingly on powerpc970-apple-darwin6.8.5 it prints
324 1.1 mrg # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
325 1.1 mrg # (as noted below). But the man page says the command is still "under
326 1.1 mrg # development", so it doesn't seem wise to use it just yet, not while
327 1.1 mrg # there's an alternative.
328 1.1 mrg #
329 1.1 mrg # Try to read the PVR. mfpvr is a protected instruction, NetBSD, MacOS
330 1.1 mrg # and AIX don't allow it in user mode, but the Linux kernel does.
331 1.1 mrg #
332 1.1 mrg # Using explicit bytes for mfpvr avoids worrying about assembler syntax
333 1.1 mrg # and underscores. "char"s are used instead of "int"s to avoid worrying
334 1.1 mrg # whether sizeof(int)==4 or if it's the right endianness.
335 1.1 mrg #
336 1.1 mrg # Note this is no good on AIX, since a C function there is the address of
337 1.1 mrg # a function descriptor, not actual code. But this doesn't matter since
338 1.1 mrg # AIX doesn't allow mfpvr anyway.
339 1.1 mrg #
340 1.1 mrg cat >$dummy.c <<\EOF
341 1.1 mrg #include <stdio.h>
342 1.1 mrg struct {
343 1.1 mrg int n; /* force 4-byte alignment */
344 1.1 mrg char a[8];
345 1.1 mrg } getpvr = {
346 1.1 mrg 0,
347 1.1 mrg {
348 1.1 mrg 0x7c, 0x7f, 0x42, 0xa6, /* mfpvr r3 */
349 1.1 mrg 0x4e, 0x80, 0x00, 0x20, /* blr */
350 1.1 mrg }
351 1.1 mrg };
352 1.1 mrg int
353 1.1 mrg main ()
354 1.1 mrg {
355 1.1 mrg unsigned (*fun)();
356 1.1 mrg unsigned pvr;
357 1.1 mrg
358 1.1 mrg /* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS,
359 1.1 mrg it gets a compiler error on a combined cast and call */
360 1.1 mrg fun = (unsigned (*)()) getpvr.a;
361 1.1 mrg pvr = (*fun) ();
362 1.1 mrg
363 1.1 mrg switch (pvr >> 16) {
364 1.1 mrg case 0x0001: puts ("powerpc601"); break;
365 1.1 mrg case 0x0003: puts ("powerpc603"); break;
366 1.1 mrg case 0x0004: puts ("powerpc604"); break;
367 1.1 mrg case 0x0006: puts ("powerpc603e"); break;
368 1.1 mrg case 0x0007: puts ("powerpc603e"); break; /* 603ev */
369 1.1 mrg case 0x0008: puts ("powerpc750"); break;
370 1.1 mrg case 0x0009: puts ("powerpc604e"); break;
371 1.1 mrg case 0x000a: puts ("powerpc604e"); break; /* 604ev5 */
372 1.1 mrg case 0x000c: puts ("powerpc7400"); break;
373 1.1 mrg case 0x0041: puts ("powerpc630"); break;
374 1.1 mrg case 0x0050: puts ("powerpc860"); break;
375 1.1 mrg case 0x8000: puts ("powerpc7450"); break;
376 1.1 mrg case 0x8001: puts ("powerpc7455"); break;
377 1.1 mrg case 0x8002: puts ("powerpc7457"); break;
378 1.1 mrg case 0x8003: puts ("powerpc7447"); break; /* really 7447A */
379 1.1 mrg case 0x800c: puts ("powerpc7410"); break;
380 1.1 mrg }
381 1.1 mrg return 0;
382 1.1 mrg }
383 1.1 mrg EOF
384 1.1 mrg if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
385 1.1 mrg # This style construct is needed on AIX 4.3 to suppress the SIGILL error
386 1.1 mrg # from (*fun)(). Using $SHELL -c ./$dummy 2>/dev/null doesn't work.
387 1.1 mrg { x=`./$dummy`; } 2>/dev/null
388 1.1 mrg if test -n "$x"; then
389 1.1 mrg exact_cpu=$x
390 1.1 mrg fi
391 1.1 mrg fi
392 1.1 mrg rm -f $dummy.c $dummy.o $dummy $dummy.core
393 1.1 mrg
394 1.1 mrg # Grep the linux kernel /proc/cpuinfo pseudo-file.
395 1.1 mrg # Anything unrecognised is ignored, since of course we mustn't spit out
396 1.1 mrg # a cpu type config.sub doesn't know.
397 1.1 mrg if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
398 1.1 mrg x=`grep "^cpu[ ]" /proc/cpuinfo | head -n 1`
399 1.1 mrg x=`echo $x | sed -n 's/^cpu[ ]*:[ ]*\([A-Za-z0-9]*\).*/\1/p'`
400 1.1 mrg x=`echo $x | sed 's/PPC//'`
401 1.1 mrg case $x in
402 1.1 mrg 601) exact_cpu="power" ;;
403 1.1 mrg 603ev) exact_cpu="powerpc603e" ;;
404 1.1 mrg 604ev5) exact_cpu="powerpc604e" ;;
405 1.1 mrg 603 | 603e | 604 | 604e | 750 | 821 | 860 | 970)
406 1.1 mrg exact_cpu="powerpc$x" ;;
407 1.1 mrg POWER[4-9])
408 1.1 mrg exact_cpu=`echo $x | sed "s;POWER;power;"` ;;
409 1.1 mrg esac
410 1.1 mrg fi
411 1.1 mrg
412 1.1 mrg if test -z "$exact_cpu"; then
413 1.1 mrg # On AIX, try looking at _system_configuration. This is present in
414 1.1 mrg # version 4 at least.
415 1.1 mrg cat >$dummy.c <<EOF
416 1.1 mrg #include <stdio.h>
417 1.1 mrg #include <sys/systemcfg.h>
418 1.1 mrg int
419 1.1 mrg main ()
420 1.1 mrg {
421 1.1 mrg switch (_system_configuration.implementation) {
422 1.1 mrg /* Old versions of AIX don't have all these constants,
423 1.1 mrg use ifdef for safety. */
424 1.1 mrg #ifdef POWER_RS2
425 1.1 mrg case POWER_RS2: puts ("power2"); break;
426 1.1 mrg #endif
427 1.1 mrg #ifdef POWER_601
428 1.1 mrg case POWER_601: puts ("power"); break;
429 1.1 mrg #endif
430 1.1 mrg #ifdef POWER_603
431 1.1 mrg case POWER_603: puts ("powerpc603"); break;
432 1.1 mrg #endif
433 1.1 mrg #ifdef POWER_604
434 1.1 mrg case POWER_604: puts ("powerpc604"); break;
435 1.1 mrg #endif
436 1.1 mrg #ifdef POWER_620
437 1.1 mrg case POWER_620: puts ("powerpc620"); break;
438 1.1 mrg #endif
439 1.1 mrg #ifdef POWER_630
440 1.1 mrg case POWER_630: puts ("powerpc630"); break;
441 1.1 mrg #endif
442 1.1 mrg /* Dunno what this is, leave it out for now.
443 1.1 mrg case POWER_A35: puts ("powerpca35"); break;
444 1.1 mrg */
445 1.1 mrg /* This is waiting for a bit more info.
446 1.1 mrg case POWER_RS64II: puts ("powerpcrs64ii"); break;
447 1.1 mrg */
448 1.1 mrg #ifdef POWER_4
449 1.1 mrg case POWER_4: puts ("power4"); break;
450 1.1 mrg #endif
451 1.1 mrg #ifdef POWER_5
452 1.1 mrg case POWER_5: puts ("power5"); break;
453 1.1 mrg #endif
454 1.1 mrg #ifdef POWER_6
455 1.1 mrg case POWER_6: puts ("power6"); break;
456 1.1 mrg #endif
457 1.1 mrg default:
458 1.1 mrg if (_system_configuration.architecture == POWER_RS)
459 1.1 mrg puts ("power");
460 1.1 mrg else if (_system_configuration.width == 64)
461 1.1 mrg puts ("powerpc64");
462 1.1 mrg }
463 1.1 mrg return 0;
464 1.1 mrg }
465 1.1 mrg EOF
466 1.1 mrg if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
467 1.1 mrg x=`./$dummy`
468 1.1 mrg if test -n "$x"; then
469 1.1 mrg exact_cpu=$x
470 1.1 mrg fi
471 1.1 mrg fi
472 1.1 mrg rm -f $dummy.c $dummy.o $dummy
473 1.1 mrg fi
474 1.1 mrg
475 1.1 mrg if test -z "$exact_cpu"; then
476 1.1 mrg # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
477 1.1 mrg # can tell us the exact cpu.
478 1.1 mrg cat >$dummy.c <<EOF
479 1.1 mrg #include <stdio.h>
480 1.1 mrg #include <mach-o/arch.h>
481 1.1 mrg int
482 1.1 mrg main (void)
483 1.1 mrg {
484 1.1 mrg const NXArchInfo *a = NXGetLocalArchInfo();
485 1.1 mrg if (a->cputype == CPU_TYPE_POWERPC)
486 1.1 mrg {
487 1.1 mrg switch (a->cpusubtype) {
488 1.1 mrg /* The following known to Darwin 1.3. */
489 1.1 mrg case CPU_SUBTYPE_POWERPC_601: puts ("powerpc601"); break;
490 1.1 mrg case CPU_SUBTYPE_POWERPC_602: puts ("powerpc602"); break;
491 1.1 mrg case CPU_SUBTYPE_POWERPC_603: puts ("powerpc603"); break;
492 1.1 mrg case CPU_SUBTYPE_POWERPC_603e: puts ("powerpc603e"); break;
493 1.1 mrg case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
494 1.1 mrg case CPU_SUBTYPE_POWERPC_604: puts ("powerpc604"); break;
495 1.1 mrg case CPU_SUBTYPE_POWERPC_604e: puts ("powerpc604e"); break;
496 1.1 mrg case CPU_SUBTYPE_POWERPC_620: puts ("powerpc620"); break;
497 1.1 mrg case CPU_SUBTYPE_POWERPC_750: puts ("powerpc750"); break;
498 1.1 mrg case CPU_SUBTYPE_POWERPC_7400: puts ("powerpc7400"); break;
499 1.1 mrg case CPU_SUBTYPE_POWERPC_7450: puts ("powerpc7450"); break;
500 1.1 mrg /* Darwin 6.8.5 doesn't define the following */
501 1.1 mrg case 0x8001: puts ("powerpc7455"); break;
502 1.1 mrg case 0x8002: puts ("powerpc7457"); break;
503 1.1 mrg case 0x8003: puts ("powerpc7447"); break;
504 1.1 mrg case 100: puts ("powerpc970"); break;
505 1.1 mrg }
506 1.1 mrg }
507 1.1 mrg return 0;
508 1.1 mrg }
509 1.1 mrg EOF
510 1.1 mrg if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
511 1.1 mrg x=`./$dummy`
512 1.1 mrg if test -n "$x"; then
513 1.1 mrg exact_cpu=$x
514 1.1 mrg fi
515 1.1 mrg fi
516 1.1 mrg rm -f $dummy.c $dummy.o $dummy
517 1.1 mrg fi
518 1.1 mrg ;;
519 1.1 mrg
520 1.1 mrg sparc-*-* | sparc64-*-*)
521 1.1 mrg # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
522 1.1 mrg # to short-circuit subsequent tests.
523 1.1 mrg
524 1.1 mrg # Grep the linux kernel /proc/cpuinfo pseudo-file.
525 1.1 mrg # A typical line is "cpu\t\t: TI UltraSparc II (BlackBird)"
526 1.1 mrg # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
527 1.1 mrg #
528 1.1 mrg if test -f /proc/cpuinfo; then
529 1.1 mrg if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
530 1.1 mrg exact_cpu="sparc" # ie. v7
531 1.1 mrg elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
532 1.1 mrg exact_cpu="sparc" # ie. v7
533 1.1 mrg elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
534 1.1 mrg exact_cpu="sparcv8"
535 1.1 mrg elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
536 1.1 mrg exact_cpu="supersparc"
537 1.1 mrg elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
538 1.1 mrg exact_cpu="microsparc"
539 1.1 mrg elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
540 1.1 mrg # actually MicroSPARC-II
541 1.1 mrg exact_cpu=microsparc
542 1.1 mrg elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
543 1.1 mrg # this grep pattern has not been tested against any Linux
544 1.1 mrg exact_cpu="ultrasparct1"
545 1.1 mrg elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
546 1.1 mrg exact_cpu="ultrasparc3"
547 1.1 mrg elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
548 1.1 mrg exact_cpu="ultrasparc2i"
549 1.1 mrg elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
550 1.1 mrg exact_cpu="ultrasparc2"
551 1.1 mrg elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
552 1.1 mrg exact_cpu="ultrasparc"
553 1.1 mrg fi
554 1.1 mrg fi
555 1.1 mrg
556 1.1 mrg # Grep the output from sysinfo on SunOS.
557 1.1 mrg # sysinfo has been seen living in /bin or in /usr/kvm
558 1.1 mrg # cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
559 1.1 mrg # cpu0 is a "75 MHz TI,TMS390Z55" CPU
560 1.1 mrg #
561 1.1 mrg if test -z "$exact_cpu"; then
562 1.1 mrg for i in sysinfo /usr/kvm/sysinfo; do
563 1.1 mrg if $SHELL -c $i 2>/dev/null >conftest.dat; then
564 1.1 mrg if grep 'cpu0 is a "SuperSPARC' conftest.dat >/dev/null; then
565 1.1 mrg exact_cpu=supersparc
566 1.1 mrg break
567 1.1 mrg elif grep 'cpu0 is a .*TMS390Z5.' conftest.dat >/dev/null; then
568 1.1 mrg # TMS390Z50 and TMS390Z55
569 1.1 mrg exact_cpu=supersparc
570 1.1 mrg break
571 1.1 mrg fi
572 1.1 mrg fi
573 1.1 mrg done
574 1.1 mrg rm -f conftest.dat
575 1.1 mrg fi
576 1.1 mrg
577 1.1 mrg # Grep the output from prtconf on Solaris.
578 1.1 mrg # Use an explicit /usr/sbin, since that directory might not be in a normal
579 1.1 mrg # user's path.
580 1.1 mrg #
581 1.1 mrg # SUNW,UltraSPARC (driver not attached)
582 1.1 mrg # SUNW,UltraSPARC-II (driver not attached)
583 1.1 mrg # SUNW,UltraSPARC-IIi (driver not attached)
584 1.1 mrg # SUNW,UltraSPARC-III+ (driver not attached)
585 1.1 mrg # Ross,RT625 (driver not attached)
586 1.1 mrg # TI,TMS390Z50 (driver not attached)
587 1.1 mrg #
588 1.1 mrg # /usr/sbin/sysdef prints similar information, but includes all loadable
589 1.1 mrg # cpu modules, not just the real cpu.
590 1.1 mrg #
591 1.1 mrg # We first try a plain prtconf, since that is known to work on older systems.
592 1.1 mrg # But for newer T1 systems, that doesn't produce any useful output, we need
593 1.1 mrg # "prtconf -vp" there.
594 1.1 mrg #
595 1.1 mrg for prtconfopt in "" "-vp"; do
596 1.1 mrg if test -z "$exact_cpu"; then
597 1.1 mrg if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >conftest.dat; then
598 1.1 mrg if grep 'SUNW,UltraSPARC-T1' conftest.dat >/dev/null; then
599 1.1 mrg exact_cpu=ultrasparct1
600 1.1 mrg elif grep 'SUNW,UltraSPARC-III' conftest.dat >/dev/null; then
601 1.1 mrg exact_cpu=ultrasparc3
602 1.1 mrg elif grep 'SUNW,UltraSPARC-IIi' conftest.dat >/dev/null; then
603 1.1 mrg exact_cpu=ultrasparc2i
604 1.1 mrg elif grep 'SUNW,UltraSPARC-II' conftest.dat >/dev/null; then
605 1.1 mrg exact_cpu=ultrasparc2
606 1.1 mrg elif grep 'SUNW,UltraSPARC' conftest.dat >/dev/null; then
607 1.1 mrg exact_cpu=ultrasparc
608 1.1 mrg elif grep 'Ross,RT62.' conftest.dat >/dev/null; then
609 1.1 mrg # RT620, RT625, RT626 hypersparcs (v8).
610 1.1 mrg exact_cpu=sparcv8
611 1.1 mrg elif grep 'TI,TMS390Z5.' conftest.dat >/dev/null; then
612 1.1 mrg # TMS390Z50 and TMS390Z55
613 1.1 mrg exact_cpu=supersparc
614 1.1 mrg elif grep 'TI,TMS390S10' conftest.dat >/dev/null; then
615 1.1 mrg exact_cpu=microsparc
616 1.1 mrg elif grep 'FMI,MB86904' conftest.dat >/dev/null; then
617 1.1 mrg # actually MicroSPARC-II
618 1.1 mrg exact_cpu=microsparc
619 1.1 mrg fi
620 1.1 mrg fi
621 1.1 mrg rm -f conftest.dat
622 1.1 mrg fi
623 1.1 mrg done
624 1.1 mrg
625 1.1 mrg # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
626 1.1 mrg # Use an explicit /sbin, since that directory might not be in a normal
627 1.1 mrg # user's path. Example outputs,
628 1.1 mrg #
629 1.1 mrg # hw.model: Sun Microsystems UltraSparc-IIi
630 1.1 mrg #
631 1.1 mrg if test -z "$exact_cpu"; then
632 1.1 mrg if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >conftest.dat; then
633 1.1 mrg if grep 'UltraSparc-T1' conftest.dat >/dev/null; then
634 1.1 mrg # this grep pattern has not been tested against any BSD
635 1.1 mrg exact_cpu=ultrasparct1
636 1.1 mrg elif grep 'UltraSparc-III' conftest.dat >/dev/null; then
637 1.1 mrg exact_cpu=ultrasparc3
638 1.1 mrg elif grep 'UltraSparc-IIi' conftest.dat >/dev/null; then
639 1.1 mrg exact_cpu=ultrasparc2i
640 1.1 mrg elif grep 'UltraSparc-II' conftest.dat >/dev/null; then
641 1.1 mrg exact_cpu=ultrasparc2
642 1.1 mrg elif grep 'UltraSparc' conftest.dat >/dev/null; then
643 1.1 mrg exact_cpu=ultrasparc
644 1.1 mrg elif grep 'TMS390Z5.' conftest.dat >/dev/null; then
645 1.1 mrg # TMS390Z50 and TMS390Z55
646 1.1 mrg exact_cpu=supersparc
647 1.1 mrg elif grep 'TMS390S10' conftest.dat >/dev/null; then
648 1.1 mrg exact_cpu=microsparc
649 1.1 mrg elif grep 'MB86904' conftest.dat >/dev/null; then
650 1.1 mrg # actually MicroSPARC-II
651 1.1 mrg exact_cpu=microsparc
652 1.1 mrg elif grep 'MB86907' conftest.dat >/dev/null; then
653 1.1 mrg exact_cpu=turbosparc
654 1.1 mrg fi
655 1.1 mrg fi
656 1.1 mrg rm -f conftest.dat
657 1.1 mrg fi
658 1.1 mrg
659 1.1 mrg # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
660 1.1 mrg #
661 1.1 mrg if test -z "$exact_cpu"; then
662 1.1 mrg case `uname -m` in
663 1.1 mrg sun4[md]) exact_cpu=sparcv8 ;;
664 1.1 mrg sun4u) exact_cpu=sparcv9 ;;
665 1.1 mrg esac
666 1.1 mrg fi
667 1.1 mrg ;;
668 1.1 mrg
669 1.1 mrg i?86-*-* | amd64-*-* | x86_64-*-*)
670 1.1 mrg cat <<EOF >${dummy}0.s
671 1.1 mrg .globl cpuid
672 1.1 mrg .globl _cpuid
673 1.1 mrg cpuid:
674 1.1 mrg _cpuid:
675 1.1 mrg pushl %esi
676 1.1 mrg pushl %ebx
677 1.1 mrg movl 16(%esp),%eax
678 1.1 mrg .byte 0x0f
679 1.1 mrg .byte 0xa2
680 1.1 mrg movl 12(%esp),%esi
681 1.1 mrg movl %ebx,(%esi)
682 1.1 mrg movl %edx,4(%esi)
683 1.1 mrg movl %ecx,8(%esi)
684 1.1 mrg popl %ebx
685 1.1 mrg popl %esi
686 1.1 mrg ret
687 1.1 mrg EOF
688 1.1 mrg cat <<EOF >${dummy}1.s
689 1.1 mrg .globl cpuid
690 1.1 mrg .globl _cpuid
691 1.1 mrg cpuid:
692 1.1 mrg _cpuid:
693 1.1 mrg push %rbx
694 1.1 mrg mov %esi,%eax
695 1.1 mrg .byte 0x0f
696 1.1 mrg .byte 0xa2
697 1.1 mrg mov %ebx,(%rdi)
698 1.1 mrg mov %edx,4(%rdi)
699 1.1 mrg mov %ecx,8(%rdi)
700 1.1 mrg pop %rbx
701 1.1 mrg ret
702 1.1 mrg EOF
703 1.1 mrg cat <<EOF >${dummy}2.c
704 1.1 mrg main ()
705 1.1 mrg {
706 1.1 mrg char vendor_string[13];
707 1.1 mrg char dummy_string[12];
708 1.1 mrg long fms;
709 1.1 mrg int family, model, stepping;
710 1.1 mrg char *modelstr;
711 1.1 mrg
712 1.1 mrg cpuid (vendor_string, 0);
713 1.1 mrg vendor_string[12] = 0;
714 1.1 mrg
715 1.1 mrg fms = cpuid (dummy_string, 1);
716 1.1 mrg
717 1.1 mrg family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff);
718 1.1 mrg model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0);
719 1.1 mrg stepping = fms & 0xf;
720 1.1 mrg
721 1.1 mrg modelstr = "$guess_cpu";
722 1.1 mrg if (strcmp (vendor_string, "GenuineIntel") == 0)
723 1.1 mrg {
724 1.1 mrg switch (family)
725 1.1 mrg {
726 1.1 mrg case 5:
727 1.1 mrg if (model <= 2) modelstr = "pentium";
728 1.1 mrg else if (model >= 4) modelstr = "pentiummmx";
729 1.1 mrg break;
730 1.1 mrg case 6:
731 1.1 mrg if (model <= 1) modelstr = "pentiumpro";
732 1.1 mrg else if (model <= 6) modelstr = "pentium2";
733 1.1 mrg else if (model <= 8) modelstr = "pentium3";
734 1.1 mrg else if (model <= 9) modelstr = "pentiumm";
735 1.1 mrg else if (model <= 0x0c) modelstr = "pentium3";
736 1.1 mrg else if (model <= 0x0e) modelstr = "pentiumm";
737 1.1 mrg else if (model <= 0x19) modelstr = "core2";
738 1.1 mrg else if (model == 0x1a) modelstr = "corei"; /* NHM Gainestown */
739 1.1 mrg else if (model == 0x1c) modelstr = "atom"; /* Silverthorne */
740 1.1 mrg else if (model == 0x1d) modelstr = "core2"; /* PNR Dunnington */
741 1.1 mrg else if (model == 0x1e) modelstr = "corei"; /* NHM Lynnfield/Jasper */
742 1.1 mrg else if (model == 0x25) modelstr = "corei"; /* WSM Clarkdale/Arrandale */
743 1.1 mrg else if (model == 0x26) modelstr = "atom"; /* Lincroft */
744 1.1 mrg else if (model == 0x27) modelstr = "atom"; /* Saltwell */
745 1.1 mrg else if (model == 0x2c) modelstr = "corei"; /* WSM Gulftown */
746 1.1 mrg else if (model == 0x2e) modelstr = "corei"; /* NHM Beckton */
747 1.1 mrg break;
748 1.1 mrg case 15:
749 1.1 mrg modelstr = "pentium4";
750 1.1 mrg break;
751 1.1 mrg }
752 1.1 mrg }
753 1.1 mrg else if (strcmp (vendor_string, "AuthenticAMD") == 0)
754 1.1 mrg {
755 1.1 mrg switch (family)
756 1.1 mrg {
757 1.1 mrg case 5:
758 1.1 mrg if (model <= 3) modelstr = "k5";
759 1.1 mrg else if (model <= 7) modelstr = "k6";
760 1.1 mrg else if (model == 8) modelstr = "k62";
761 1.1 mrg else if (model == 9) modelstr = "k63";
762 1.1 mrg else if (model == 10) modelstr = "geode";
763 1.1 mrg else if (model == 13) modelstr = "k63";
764 1.1 mrg break;
765 1.1 mrg case 6:
766 1.1 mrg modelstr = "athlon";
767 1.1 mrg break;
768 1.1 mrg case 15:
769 1.1 mrg case 16:
770 1.1 mrg modelstr = "athlon64";
771 1.1 mrg break;
772 1.1 mrg }
773 1.1 mrg }
774 1.1 mrg else if (strcmp (vendor_string, "CyrixInstead") == 0)
775 1.1 mrg {
776 1.1 mrg /* Should recognize Cyrix' processors too. */
777 1.1 mrg }
778 1.1 mrg else if (strcmp (vendor_string, "CentaurHauls") == 0)
779 1.1 mrg {
780 1.1 mrg switch (family)
781 1.1 mrg {
782 1.1 mrg case 6:
783 1.1 mrg if (model < 9) modelstr = "viac3";
784 1.1 mrg else if (model < 15) modelstr = "viac32";
785 1.1 mrg else modelstr = "nano";
786 1.1 mrg break;
787 1.1 mrg }
788 1.1 mrg }
789 1.1 mrg
790 1.1 mrg printf ("%s\n", modelstr);
791 1.1 mrg return 0;
792 1.1 mrg }
793 1.1 mrg EOF
794 1.1 mrg
795 1.1 mrg if ($CC_FOR_BUILD ${dummy}1.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
796 1.1 mrg # On 80386 and early 80486 cpuid is not available and will result in a
797 1.1 mrg # SIGILL message, hence 2>/dev/null.
798 1.1 mrg #
799 1.1 mrg # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
800 1.1 mrg # "Illegal instruction (core dumped)" message to stdout, so we test $?
801 1.1 mrg # to check if the program run was successful.
802 1.1 mrg #
803 1.1 mrg x=`$SHELL -c ./$dummy 2>/dev/null`
804 1.1 mrg if test $? = 0 && test -n "$x"; then
805 1.1 mrg exact_cpu=$x
806 1.1 mrg fi
807 1.1 mrg fi
808 1.1 mrg
809 1.1 mrg if test -z "$exact_cpu"; then
810 1.1 mrg if ($CC_FOR_BUILD ${dummy}0.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
811 1.1 mrg # On 80386 and early 80486 cpuid is not available and will result in a
812 1.1 mrg # SIGILL message, hence 2>/dev/null.
813 1.1 mrg #
814 1.1 mrg # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
815 1.1 mrg # "Illegal instruction (core dumped)" message to stdout, so we test $?
816 1.1 mrg # to check if the program run was successful.
817 1.1 mrg #
818 1.1 mrg x=`$SHELL -c ./$dummy 2>/dev/null`
819 1.1 mrg if test $? = 0 && test -n "$x"; then
820 1.1 mrg exact_cpu=$x
821 1.1 mrg fi
822 1.1 mrg fi
823 1.1 mrg fi
824 1.1 mrg
825 1.1 mrg # We need to remove some .o files here since lame C compilers
826 1.1 mrg # generate these even when not asked.
827 1.1 mrg rm -f ${dummy}0.s ${dummy}0.o ${dummy}1.s ${dummy}1.o ${dummy}2.c ${dummy}2.o $dummy
828 1.1 mrg ;;
829 1.1 mrg
830 1.1 mrg esac
831 1.1 mrg
832 1.1 mrg
833 1.1 mrg
834 1.1 mrg # -------------------------------------------------------------------------
835 1.1 mrg # Use an exact cpu, if possible
836 1.1 mrg
837 1.1 mrg if test -n "$exact_cpu"; then
838 1.1 mrg echo "$exact_cpu$guess_rest"
839 1.1 mrg else
840 1.1 mrg echo "$guess_full"
841 1.1 mrg fi
842 1.1 mrg exit 0
843 1.1 mrg
844 1.1 mrg
845 1.1 mrg
846 1.1 mrg # Local variables:
847 1.1 mrg # fill-column: 76
848 1.1 mrg # End:
849