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