[15293] | 1 | #! /bin/sh |
---|
| 2 | # |
---|
[18190] | 3 | # GMP config.guess wrapper. |
---|
| 4 | |
---|
| 5 | |
---|
[22253] | 6 | # Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
---|
[15293] | 7 | # |
---|
[18190] | 8 | # This file is part of the GNU MP Library. |
---|
[15293] | 9 | # |
---|
[18190] | 10 | # The GNU MP Library is free software; you can redistribute it and/or modify |
---|
| 11 | # it under the terms of the GNU Lesser General Public License as published |
---|
| 12 | # by the Free Software Foundation; either version 2.1 of the License, or (at |
---|
| 13 | # your option) any later version. |
---|
[15293] | 14 | # |
---|
[18190] | 15 | # The GNU MP Library is distributed in the hope that it will be useful, but |
---|
| 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 17 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
---|
| 18 | # License for more details. |
---|
[15293] | 19 | # |
---|
[18190] | 20 | # You should have received a copy of the GNU Lesser General Public License |
---|
| 21 | # along with the GNU MP Library; see the file COPYING.LIB. If not, write to |
---|
| 22 | # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
---|
| 23 | # MA 02111-1307, USA. |
---|
[15293] | 24 | |
---|
[18190] | 25 | |
---|
| 26 | # Usage: config.guess |
---|
[15293] | 27 | # |
---|
[18190] | 28 | # Print the host system CPU-VENDOR-OS. configfsf.guess is run and its |
---|
| 29 | # guess then sharpened up to take advantage of the finer grained CPU |
---|
| 30 | # types GMP knows. |
---|
[15293] | 31 | |
---|
| 32 | |
---|
[18190] | 33 | # Expect to find configfsf.guess in the same directory as this config.guess |
---|
| 34 | configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`" |
---|
| 35 | if test "$configfsf_guess" = "$0"; then |
---|
| 36 | echo "Cannot derive configfsf.guess from $0" 1>&2 |
---|
| 37 | exit 1 |
---|
[15293] | 38 | fi |
---|
[18190] | 39 | if test -f "$configfsf_guess"; then |
---|
| 40 | : |
---|
| 41 | else |
---|
| 42 | echo "$configfsf_guess not found" 1>&2 |
---|
| 43 | exit 1 |
---|
| 44 | fi |
---|
[15293] | 45 | |
---|
[18190] | 46 | # Always run configfsf.guess with $SHELL, like autoconf does for config.guess |
---|
| 47 | SHELL=${CONFIG_SHELL-/bin/sh} |
---|
[15293] | 48 | |
---|
[18190] | 49 | # Identify ourselves on --version, --help or errors |
---|
| 50 | if test $# != 0; then |
---|
| 51 | echo "(GNU MP wrapped config.guess)" |
---|
| 52 | $SHELL $configfsf_guess "$@" |
---|
| 53 | exit 1 |
---|
| 54 | fi |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | guess_full=`$SHELL $configfsf_guess` |
---|
| 58 | if test $? != 0; then |
---|
| 59 | exit 1 |
---|
| 60 | fi |
---|
| 61 | |
---|
| 62 | guess_cpu=`echo "$guess_full" | sed 's/-.*$//'` |
---|
| 63 | guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'` |
---|
| 64 | exact_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 | |
---|
[15293] | 78 | dummy=dummy-$$ |
---|
[22253] | 79 | trap 'rm -f $dummy.c $dummy.o $dummy.core $dummy ${dummy}1.s ${dummy}2.c ; exit 1' 1 2 15 |
---|
[15293] | 80 | |
---|
| 81 | # Use $HOST_CC if defined. $CC may point to a cross-compiler |
---|
| 82 | if test x"$CC_FOR_BUILD" = x; then |
---|
| 83 | if test x"$HOST_CC" != x; then |
---|
| 84 | CC_FOR_BUILD="$HOST_CC" |
---|
| 85 | else |
---|
| 86 | if test x"$CC" != x; then |
---|
| 87 | CC_FOR_BUILD="$CC" |
---|
| 88 | else |
---|
| 89 | echo 'dummy(){}' >$dummy.c |
---|
[22253] | 90 | for c in cc gcc c89 c99; do |
---|
[15293] | 91 | ($c $dummy.c -c) >/dev/null 2>&1 |
---|
| 92 | if test $? = 0; then |
---|
| 93 | CC_FOR_BUILD="$c"; break |
---|
| 94 | fi |
---|
| 95 | done |
---|
| 96 | rm -f $dummy.c $dummy.o |
---|
| 97 | if test x"$CC_FOR_BUILD" = x; then |
---|
| 98 | CC_FOR_BUILD=no_compiler_found |
---|
| 99 | fi |
---|
| 100 | fi |
---|
| 101 | fi |
---|
| 102 | fi |
---|
| 103 | |
---|
| 104 | |
---|
[18190] | 105 | case "$guess_full" in |
---|
[15293] | 106 | |
---|
[18190] | 107 | alpha-*-*) |
---|
| 108 | # configfsf.guess has a block of code not unlike this for OSF and linsux. |
---|
| 109 | # Perhaps it'll support *BSD too some time, in which case the code here |
---|
| 110 | # can be removed. |
---|
| 111 | |
---|
| 112 | cat <<EOF >$dummy.s |
---|
| 113 | .data |
---|
| 114 | Lformat: |
---|
| 115 | .byte 37,100,45,37,120,10,0 # "%d-%x\n" |
---|
| 116 | .text |
---|
| 117 | .globl main |
---|
| 118 | .align 4 |
---|
| 119 | .ent main |
---|
| 120 | main: |
---|
| 121 | .frame \$30,16,\$26,0 |
---|
| 122 | ldgp \$29,0(\$27) |
---|
| 123 | .prologue 1 |
---|
| 124 | .long 0x47e03d91 # implver \$17 |
---|
| 125 | lda \$2,-1 |
---|
| 126 | .long 0x47e20c21 # amask \$2,\$1 |
---|
| 127 | lda \$16,Lformat |
---|
| 128 | not \$1,\$18 |
---|
| 129 | jsr \$26,printf |
---|
| 130 | ldgp \$29,0(\$26) |
---|
| 131 | mov 0,\$16 |
---|
| 132 | jsr \$26,exit |
---|
| 133 | .end main |
---|
| 134 | EOF |
---|
| 135 | $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null |
---|
| 136 | if test "$?" = 0 ; then |
---|
| 137 | case `./$dummy` in |
---|
| 138 | 0-0) exact_cpu=alpha ;; |
---|
| 139 | 1-0) exact_cpu=alphaev5 ;; |
---|
| 140 | 1-1) exact_cpu=alphaev56 ;; |
---|
| 141 | 1-101) exact_cpu=alphapca56 ;; |
---|
| 142 | 2-303) exact_cpu=alphaev6 ;; |
---|
| 143 | 2-307) exact_cpu=alphaev67 ;; |
---|
| 144 | 2-1307) exact_cpu=alphaev68 ;; |
---|
| 145 | esac |
---|
| 146 | fi |
---|
[22253] | 147 | rm -f $dummy.s $dummy.o $dummy |
---|
[18190] | 148 | ;; |
---|
| 149 | |
---|
| 150 | mips-*-irix[6789]*) |
---|
| 151 | # IRIX 6 and up always has a 64-bit mips cpu |
---|
| 152 | exact_cpu=mips64 |
---|
| 153 | ;; |
---|
| 154 | |
---|
| 155 | m68k-*-*) |
---|
| 156 | # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example |
---|
| 157 | # hw.model = Apple Macintosh Quadra 610 (68040) |
---|
| 158 | exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'` |
---|
| 159 | if test -z "$exact_cpu"; then |
---|
| 160 | # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between). |
---|
| 161 | exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null` |
---|
| 162 | fi |
---|
| 163 | if test -z "$exact_cpu"; then |
---|
| 164 | # Try: movel #0,%d0; rts |
---|
| 165 | # This is to check the compiler and our asm code works etc, before |
---|
| 166 | # assuming failures below indicate cpu characteristics. |
---|
| 167 | # .byte is used to avoid problems with assembler syntax variations. |
---|
| 168 | # For testing, provoke failures by adding "illegal" possibly as |
---|
| 169 | # ".byte 0x4A, 0xFC" |
---|
| 170 | cat >$dummy.s <<EOF |
---|
| 171 | .text |
---|
| 172 | .globl main |
---|
| 173 | .globl _main |
---|
| 174 | main: |
---|
| 175 | _main: |
---|
| 176 | .byte 0x70, 0x00 |
---|
| 177 | .byte 0x4e, 0x75 |
---|
| 178 | EOF |
---|
| 179 | if ($CC_FOR_BUILD $dummy.s -o $dummy && ./$dummy) >/dev/null 2>&1; then |
---|
| 180 | |
---|
| 181 | # $SHELL -c is used to execute ./$dummy below, since (./$dummy) |
---|
| 182 | # 2>/dev/null still prints the SIGILL message on some shells. |
---|
| 183 | # |
---|
| 184 | # Try: movel #0,%d0 |
---|
| 185 | # rtd #0 |
---|
| 186 | cat >$dummy.s <<EOF |
---|
| 187 | .text |
---|
| 188 | .globl main |
---|
| 189 | .globl _main |
---|
| 190 | main: |
---|
| 191 | _main: |
---|
| 192 | .byte 0x70, 0x00 |
---|
| 193 | .byte 0x4e, 0x74, 0x00, 0x00 |
---|
| 194 | EOF |
---|
| 195 | if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then |
---|
| 196 | $SHELL -c ./$dummy >/dev/null 2>&1 |
---|
| 197 | if test $? != 0; then |
---|
| 198 | exact_cpu=m68000 # because rtd didn't work |
---|
| 199 | fi |
---|
| 200 | fi |
---|
| 201 | # |
---|
| 202 | |
---|
| 203 | if test -z "$exact_cpu"; then |
---|
| 204 | # Try: trapf |
---|
| 205 | # movel #0,%d0 |
---|
| 206 | # rts |
---|
| 207 | # Another possibility for identifying 68000 and 68010 is the |
---|
| 208 | # different value stored by "movem a0,(a0)+" |
---|
| 209 | cat >$dummy.s <<EOF |
---|
| 210 | .text |
---|
| 211 | .globl main |
---|
| 212 | .globl _main |
---|
| 213 | main: |
---|
| 214 | _main: |
---|
| 215 | .byte 0x51, 0xFC |
---|
| 216 | .byte 0x70, 0x00 |
---|
| 217 | .byte 0x4e, 0x75 |
---|
| 218 | EOF |
---|
| 219 | if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then |
---|
| 220 | $SHELL -c ./$dummy >/dev/null 2>&1 |
---|
| 221 | if test $? != 0; then |
---|
| 222 | exact_cpu=m68010 # because trapf didn't work |
---|
| 223 | fi |
---|
| 224 | fi |
---|
| 225 | fi |
---|
| 226 | |
---|
| 227 | if test -z "$exact_cpu"; then |
---|
| 228 | # Try: bfffo %d1{0:31},%d0 |
---|
| 229 | # movel #0,%d0 |
---|
| 230 | # rts |
---|
| 231 | cat >$dummy.s <<EOF |
---|
| 232 | .text |
---|
| 233 | .globl main |
---|
| 234 | .globl _main |
---|
| 235 | main: |
---|
| 236 | _main: |
---|
| 237 | .byte 0xED, 0xC1, 0x00, 0x1F |
---|
| 238 | .byte 0x70, 0x00 |
---|
| 239 | .byte 0x4e, 0x75 |
---|
| 240 | EOF |
---|
| 241 | if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then |
---|
| 242 | $SHELL -c ./$dummy >/dev/null 2>&1 |
---|
| 243 | if test $? != 0; then |
---|
| 244 | exact_cpu=m68360 # cpu32, because bfffo didn't work |
---|
| 245 | fi |
---|
| 246 | fi |
---|
| 247 | fi |
---|
| 248 | |
---|
| 249 | if test -z "$exact_cpu"; then |
---|
| 250 | # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060? |
---|
| 251 | exact_cpu=m68020 |
---|
| 252 | fi |
---|
| 253 | fi |
---|
[22253] | 254 | rm -f $dummy.s $dummy.o $dummy $dummy.core core |
---|
[18190] | 255 | fi |
---|
| 256 | if test -z "$exact_cpu"; then |
---|
| 257 | case "$guess_full" in |
---|
| 258 | *-*-next* | *-*-openstep*) # NeXTs are 68020 or better |
---|
| 259 | exact_cpu=m68020 ;; |
---|
| 260 | esac |
---|
| 261 | fi |
---|
| 262 | ;; |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | rs6000-*-* | powerpc*-*-*) |
---|
| 266 | # Try to read the PVR. mfpvr is a protected instruction, MacOS and AIX |
---|
| 267 | # don't allow it in user mode, but the Linux kernel does. |
---|
| 268 | # |
---|
| 269 | # Using explicit bytes for mfpvr avoids worrying about assembler syntax |
---|
| 270 | # and underscores. "char"s are used instead of "int"s to avoid worrying |
---|
| 271 | # whether sizeof(int)==4 or if it's the right endianness. |
---|
| 272 | # |
---|
| 273 | # Note this is no good on AIX, since a C function there is the address of |
---|
| 274 | # a function descriptor, not actual code. But this doesn't matter since |
---|
| 275 | # AIX doesn't allow mfpvr anyway. |
---|
| 276 | # |
---|
| 277 | cat >$dummy.c <<\EOF |
---|
| 278 | #include <stdio.h> |
---|
| 279 | struct { |
---|
| 280 | int n; /* force 4-byte alignment */ |
---|
| 281 | char a[8]; |
---|
| 282 | } getpvr = { |
---|
| 283 | 0, |
---|
| 284 | { |
---|
| 285 | 0x7c, 0x7f, 0x42, 0xa6, /* mfpvr r3 */ |
---|
| 286 | 0x4e, 0x80, 0x00, 0x20, /* blr */ |
---|
| 287 | } |
---|
| 288 | }; |
---|
| 289 | int |
---|
| 290 | main () |
---|
| 291 | { |
---|
| 292 | unsigned (*fun)(); |
---|
| 293 | unsigned pvr; |
---|
| 294 | |
---|
| 295 | /* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS, |
---|
| 296 | it gets a compiler error on a combined cast and call */ |
---|
| 297 | fun = (unsigned (*)()) getpvr.a; |
---|
| 298 | pvr = (*fun) (); |
---|
| 299 | |
---|
| 300 | switch (pvr >> 16) { |
---|
| 301 | case 1: puts ("powerpc601"); break; |
---|
| 302 | case 3: puts ("powerpc603"); break; |
---|
| 303 | case 4: puts ("powerpc604"); break; |
---|
| 304 | case 6: puts ("powerpc603e"); break; |
---|
| 305 | case 7: puts ("powerpc603e"); break; /* 603ev */ |
---|
| 306 | case 8: puts ("powerpc750"); break; |
---|
| 307 | case 9: puts ("powerpc604e"); break; |
---|
| 308 | case 10: puts ("powerpc604e"); break; /* 604ev5 */ |
---|
| 309 | case 50: puts ("powerpc821"); break; |
---|
| 310 | case 80: puts ("powerpc860"); break; |
---|
| 311 | } |
---|
| 312 | return 0; |
---|
| 313 | } |
---|
| 314 | EOF |
---|
| 315 | if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then |
---|
[22253] | 316 | # This style construct is needed on AIX 4.3 to suppress the SIGILL error |
---|
| 317 | # from (*fun)(). Using $SHELL -c ./$dummy 2>/dev/null doesn't work. |
---|
| 318 | { x=`./$dummy`; } 2>/dev/null |
---|
[18190] | 319 | if test -n "$x"; then |
---|
| 320 | exact_cpu=$x |
---|
| 321 | fi |
---|
| 322 | fi |
---|
[22253] | 323 | rm -f $dummy.c $dummy.o $dummy $dummy.core |
---|
[18190] | 324 | |
---|
| 325 | # Grep the linux kernel /proc/cpuinfo pseudo-file. |
---|
| 326 | # Anything unrecognised is ignored, since of course we mustn't spit out |
---|
| 327 | # a cpu type config.sub doesn't know. |
---|
| 328 | if test -z "$exact_cpu" && test -f /proc/cpuinfo; then |
---|
| 329 | x=`sed -n 's/^cpu[ ]*:[ ]*\([a-z0-9]*\).*/\1/p' /proc/cpuinfo` |
---|
| 330 | case $x in |
---|
| 331 | 601) exact_cpu="power" ;; |
---|
| 332 | 603ev) exact_cpu="powerpc603e" ;; |
---|
| 333 | 604ev5) exact_cpu="powerpc604e" ;; |
---|
| 334 | 603 | 603e | 604 | 604e | 750 | 821 | 860) |
---|
| 335 | exact_cpu="powerpc$x" ;; |
---|
| 336 | esac |
---|
| 337 | fi |
---|
| 338 | |
---|
| 339 | if test -z "$exact_cpu"; then |
---|
| 340 | # On AIX, try looking at _system_configuration. This is present in |
---|
| 341 | # version 4 at least. |
---|
| 342 | cat >$dummy.c <<EOF |
---|
| 343 | #include <stdio.h> |
---|
| 344 | #include <sys/systemcfg.h> |
---|
| 345 | int |
---|
| 346 | main () |
---|
| 347 | { |
---|
| 348 | switch (_system_configuration.implementation) { |
---|
| 349 | /* Old versions of AIX don't have all these constants, |
---|
| 350 | use ifdef for safety. */ |
---|
| 351 | #ifdef POWER_601 |
---|
| 352 | case POWER_601: puts ("power"); break; |
---|
| 353 | #endif |
---|
| 354 | #ifdef POWER_603 |
---|
| 355 | case POWER_603: puts ("powerpc603"); break; |
---|
| 356 | #endif |
---|
| 357 | #ifdef POWER_604 |
---|
| 358 | case POWER_604: puts ("powerpc604"); break; |
---|
| 359 | #endif |
---|
| 360 | #ifdef POWER_620 |
---|
| 361 | case POWER_620: puts ("powerpc620"); break; |
---|
| 362 | #endif |
---|
| 363 | #ifdef POWER_630 |
---|
| 364 | case POWER_630: puts ("powerpc630"); break; |
---|
| 365 | #endif |
---|
| 366 | /* Dunno what this is, leave it out for now. |
---|
| 367 | case POWER_A35: puts ("powerpca35"); break; |
---|
| 368 | */ |
---|
| 369 | /* This is waiting for a bit more info. |
---|
| 370 | case POWER_RS64II: puts ("powerpcrs64ii"); break; |
---|
| 371 | */ |
---|
| 372 | default: |
---|
| 373 | if (_system_configuration.architecture == POWER_RS) |
---|
| 374 | puts ("power"); |
---|
| 375 | else if (_system_configuration.width == 64) |
---|
| 376 | puts ("powerpc64"); |
---|
| 377 | } |
---|
| 378 | return 0; |
---|
| 379 | } |
---|
| 380 | EOF |
---|
| 381 | if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then |
---|
| 382 | x=`./$dummy` |
---|
| 383 | if test -n "$x"; then |
---|
| 384 | exact_cpu=$x |
---|
| 385 | fi |
---|
| 386 | fi |
---|
[22253] | 387 | rm -f $dummy.c $dummy.o $dummy |
---|
[18190] | 388 | fi |
---|
| 389 | |
---|
| 390 | if test -z "$exact_cpu"; then |
---|
| 391 | # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype |
---|
| 392 | # can tell us the exact cpu. |
---|
| 393 | cat >$dummy.c <<EOF |
---|
| 394 | #include <stdio.h> |
---|
| 395 | #include <mach-o/arch.h> |
---|
| 396 | int |
---|
| 397 | main (void) |
---|
| 398 | { |
---|
| 399 | const NXArchInfo *a = NXGetLocalArchInfo(); |
---|
| 400 | if (a->cputype == CPU_TYPE_POWERPC) |
---|
| 401 | { |
---|
| 402 | switch (a->cpusubtype) { |
---|
| 403 | /* The following known to Darwin 1.3. */ |
---|
| 404 | case CPU_SUBTYPE_POWERPC_601: puts ("powerpc601"); break; |
---|
| 405 | case CPU_SUBTYPE_POWERPC_602: puts ("powerpc602"); break; |
---|
| 406 | case CPU_SUBTYPE_POWERPC_603: puts ("powerpc603"); break; |
---|
| 407 | case CPU_SUBTYPE_POWERPC_603e: puts ("powerpc603e"); break; |
---|
| 408 | case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break; |
---|
| 409 | case CPU_SUBTYPE_POWERPC_604: puts ("powerpc604"); break; |
---|
| 410 | case CPU_SUBTYPE_POWERPC_604e: puts ("powerpc604e"); break; |
---|
| 411 | case CPU_SUBTYPE_POWERPC_620: puts ("powerpc620"); break; |
---|
| 412 | case CPU_SUBTYPE_POWERPC_750: puts ("powerpc750"); break; |
---|
| 413 | case CPU_SUBTYPE_POWERPC_7400: puts ("powerpc7400"); break; |
---|
| 414 | case CPU_SUBTYPE_POWERPC_7450: puts ("powerpc7450"); break; |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | return 0; |
---|
| 418 | } |
---|
| 419 | EOF |
---|
| 420 | if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then |
---|
| 421 | x=`./$dummy` |
---|
| 422 | if test -n "$x"; then |
---|
| 423 | exact_cpu=$x |
---|
| 424 | fi |
---|
| 425 | fi |
---|
[22253] | 426 | rm -f $dummy.c $dummy.o $dummy |
---|
[18190] | 427 | fi |
---|
| 428 | ;; |
---|
| 429 | |
---|
| 430 | sparc-*-* | sparc64-*-*) |
---|
| 431 | # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as |
---|
| 432 | # to short-circuit subsequent tests. |
---|
| 433 | |
---|
| 434 | # Grep the linux kernel /proc/cpuinfo pseudo-file. |
---|
| 435 | # A typical line is "cpu\t\t: TI UltraSparc II (BlackBird)" |
---|
| 436 | # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c. |
---|
| 437 | # |
---|
| 438 | if test -f /proc/cpuinfo; then |
---|
| 439 | if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then |
---|
| 440 | exact_cpu="sparc" # ie. v7 |
---|
| 441 | elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then |
---|
| 442 | exact_cpu="sparc" # ie. v7 |
---|
| 443 | elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then |
---|
| 444 | exact_cpu="sparcv8" |
---|
| 445 | elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then |
---|
| 446 | exact_cpu="supersparc" |
---|
| 447 | elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then |
---|
| 448 | exact_cpu="microsparc" |
---|
| 449 | elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then |
---|
| 450 | # actually MicroSPARC-II |
---|
| 451 | exact_cpu=microsparc |
---|
| 452 | elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then |
---|
| 453 | exact_cpu="ultrasparc3" |
---|
| 454 | elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then |
---|
| 455 | exact_cpu="ultrasparc2i" |
---|
| 456 | elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then |
---|
| 457 | exact_cpu="ultrasparc2" |
---|
| 458 | elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then |
---|
| 459 | exact_cpu="ultrasparc" |
---|
| 460 | fi |
---|
| 461 | fi |
---|
| 462 | |
---|
| 463 | # Grep the output from sysinfo on SunOS. |
---|
| 464 | # sysinfo has been seen living in /bin or in /usr/kvm |
---|
| 465 | # cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU |
---|
| 466 | # cpu0 is a "75 MHz TI,TMS390Z55" CPU |
---|
| 467 | # |
---|
| 468 | if test -z "$exact_cpu"; then |
---|
| 469 | for i in sysinfo /usr/kvm/sysinfo; do |
---|
| 470 | if $SHELL -c $i 2>/dev/null >conftest.dat; then |
---|
| 471 | if grep 'cpu0 is a "SuperSPARC' conftest.dat >/dev/null; then |
---|
| 472 | exact_cpu=supersparc |
---|
| 473 | break |
---|
| 474 | elif grep 'cpu0 is a .*TMS390Z55' conftest.dat >/dev/null; then |
---|
| 475 | # TMS390Z55 is a supersparc |
---|
| 476 | exact_cpu=supersparc |
---|
| 477 | break |
---|
| 478 | fi |
---|
| 479 | fi |
---|
| 480 | done |
---|
| 481 | rm -f conftest.dat |
---|
| 482 | fi |
---|
| 483 | |
---|
| 484 | # Grep the output from prtconf on Solaris. |
---|
| 485 | # Use an explicit /usr/sbin, since that directory might not be in a normal |
---|
| 486 | # user's path. |
---|
| 487 | # |
---|
| 488 | # SUNW,UltraSPARC (driver not attached) |
---|
| 489 | # SUNW,UltraSPARC-II (driver not attached) |
---|
| 490 | # SUNW,UltraSPARC-IIi (driver not attached) |
---|
| 491 | # SUNW,UltraSPARC-III+ (driver not attached) |
---|
| 492 | # Ross,RT625 (driver not attached) |
---|
| 493 | # TI,TMS390Z50 (driver not attached) |
---|
| 494 | # |
---|
| 495 | # /usr/sbin/sysdef prints similar information, but includes all loadable |
---|
| 496 | # cpu modules, not just the real cpu. |
---|
| 497 | # |
---|
| 498 | if test -z "$exact_cpu"; then |
---|
| 499 | if $SHELL -c /usr/sbin/prtconf 2>/dev/null >conftest.dat; then |
---|
| 500 | if grep 'SUNW,UltraSPARC-III' conftest.dat >/dev/null; then |
---|
| 501 | exact_cpu=ultrasparc3 |
---|
| 502 | elif grep 'SUNW,UltraSPARC-IIi' conftest.dat >/dev/null; then |
---|
| 503 | exact_cpu=ultrasparc2i |
---|
| 504 | elif grep 'SUNW,UltraSPARC-II' conftest.dat >/dev/null; then |
---|
| 505 | exact_cpu=ultrasparc2 |
---|
| 506 | elif grep 'SUNW,UltraSPARC' conftest.dat >/dev/null; then |
---|
| 507 | exact_cpu=ultrasparc |
---|
| 508 | elif grep 'Ross,RT62.' conftest.dat >/dev/null; then |
---|
| 509 | # RT620, RT625, RT626 hypersparcs (v8). |
---|
| 510 | exact_cpu=sparcv8 |
---|
| 511 | elif grep 'TI,TMS390Z5.' conftest.dat >/dev/null; then |
---|
| 512 | # TMS390Z50 and TMS390Z55 |
---|
| 513 | exact_cpu=supersparc |
---|
| 514 | elif grep 'TI,TMS390S10' conftest.dat >/dev/null; then |
---|
| 515 | exact_cpu=microsparc |
---|
| 516 | elif grep 'FMI,MB86904' conftest.dat >/dev/null; then |
---|
| 517 | # actually MicroSPARC-II |
---|
| 518 | exact_cpu=microsparc |
---|
| 519 | fi |
---|
| 520 | fi |
---|
| 521 | rm -f conftest.dat |
---|
| 522 | fi |
---|
| 523 | |
---|
| 524 | # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort |
---|
| 525 | # |
---|
| 526 | if test -z "$exact_cpu"; then |
---|
| 527 | case `uname -m` in |
---|
| 528 | sun4[md]) exact_cpu=sparcv8 ;; |
---|
| 529 | sun4u) exact_cpu=sparcv9 ;; |
---|
| 530 | esac |
---|
| 531 | fi |
---|
| 532 | ;; |
---|
| 533 | |
---|
| 534 | i?86-*-*) |
---|
| 535 | cat <<EOF >${dummy}1.s |
---|
[15293] | 536 | .globl cpuid |
---|
| 537 | .globl _cpuid |
---|
| 538 | cpuid: |
---|
| 539 | _cpuid: |
---|
| 540 | pushl %esi |
---|
| 541 | pushl %ebx |
---|
| 542 | movl 16(%esp),%eax |
---|
| 543 | .byte 0x0f |
---|
| 544 | .byte 0xa2 |
---|
| 545 | movl 12(%esp),%esi |
---|
| 546 | movl %ebx,(%esi) |
---|
| 547 | movl %edx,4(%esi) |
---|
| 548 | movl %ecx,8(%esi) |
---|
| 549 | popl %ebx |
---|
| 550 | popl %esi |
---|
| 551 | ret |
---|
| 552 | EOF |
---|
[18190] | 553 | cat <<EOF >${dummy}2.c |
---|
[15293] | 554 | main () |
---|
| 555 | { |
---|
| 556 | char vendor_string[13]; |
---|
| 557 | char dummy_string[12]; |
---|
| 558 | long fms; |
---|
| 559 | int family, model; |
---|
| 560 | char *modelstr; |
---|
| 561 | |
---|
| 562 | cpuid (vendor_string, 0); |
---|
| 563 | vendor_string[12] = 0; |
---|
| 564 | |
---|
| 565 | fms = cpuid (dummy_string, 1); |
---|
| 566 | |
---|
| 567 | family = (fms >> 8) & 15; |
---|
| 568 | model = (fms >> 4) & 15; |
---|
| 569 | |
---|
| 570 | modelstr = "i486"; |
---|
| 571 | if (strcmp (vendor_string, "GenuineIntel") == 0) |
---|
| 572 | { |
---|
| 573 | switch (family) |
---|
| 574 | { |
---|
| 575 | case 5: |
---|
[18190] | 576 | if (model <= 2) modelstr = "pentium"; |
---|
| 577 | else if (model >= 4) modelstr = "pentiummmx"; |
---|
[15293] | 578 | break; |
---|
| 579 | case 6: |
---|
[18190] | 580 | if (model == 1) modelstr = "pentiumpro"; |
---|
| 581 | else if (model <= 6) modelstr = "pentium2"; |
---|
| 582 | else modelstr = "pentium3"; |
---|
[15293] | 583 | break; |
---|
[18190] | 584 | case 15: |
---|
| 585 | modelstr = "pentium4"; |
---|
| 586 | break; |
---|
[15293] | 587 | } |
---|
| 588 | } |
---|
| 589 | else if (strcmp (vendor_string, "AuthenticAMD") == 0) |
---|
| 590 | { |
---|
| 591 | switch (family) |
---|
| 592 | { |
---|
| 593 | case 5: |
---|
[18190] | 594 | if (model <= 3) modelstr = "k5"; |
---|
| 595 | else if (model <= 7) modelstr = "k6"; |
---|
| 596 | else if (model <= 8) modelstr = "k62"; |
---|
| 597 | else if (model <= 9) modelstr = "k63"; |
---|
[15293] | 598 | break; |
---|
| 599 | case 6: |
---|
| 600 | modelstr = "athlon"; |
---|
| 601 | break; |
---|
[22253] | 602 | case 15: |
---|
| 603 | /* We might want to return opteron, athlon64, or the CPU core name |
---|
| 604 | hammer here instead of the architecture name x86_64. */ |
---|
| 605 | modelstr = "x86_64"; |
---|
| 606 | break; |
---|
[15293] | 607 | } |
---|
| 608 | } |
---|
| 609 | else if (strcmp (vendor_string, "CyrixInstead") == 0) |
---|
| 610 | { |
---|
| 611 | /* Should recognize Cyrix' processors too. */ |
---|
| 612 | } |
---|
[22253] | 613 | else if (strcmp (vendor_string, "CentaurHauls") == 0) |
---|
| 614 | { |
---|
| 615 | switch (family) |
---|
| 616 | { |
---|
| 617 | case 6: |
---|
| 618 | if (model < 9) modelstr = "viac3"; |
---|
| 619 | else modelstr = "viac32"; |
---|
| 620 | break; |
---|
| 621 | } |
---|
| 622 | } |
---|
[15293] | 623 | |
---|
| 624 | printf ("%s\n", modelstr); |
---|
| 625 | return 0; |
---|
| 626 | } |
---|
| 627 | EOF |
---|
| 628 | |
---|
[18190] | 629 | if ($CC_FOR_BUILD ${dummy}1.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then |
---|
| 630 | # suppress SIGILL message on 80386 |
---|
| 631 | x=`$SHELL -c ./$dummy 2>/dev/null` |
---|
| 632 | if test -n "$x"; then |
---|
| 633 | exact_cpu=$x |
---|
| 634 | fi |
---|
| 635 | fi |
---|
[15293] | 636 | |
---|
[18190] | 637 | # We need to remove some .o files here since lame C compilers |
---|
| 638 | # generate these even when not asked. |
---|
| 639 | rm -f ${dummy}1.s ${dummy}1.o ${dummy}2.c ${dummy}2.o $dummy |
---|
[15293] | 640 | ;; |
---|
| 641 | |
---|
| 642 | esac |
---|
| 643 | |
---|
| 644 | |
---|
| 645 | |
---|
[18190] | 646 | # ------------------------------------------------------------------------- |
---|
| 647 | # Use an exact cpu, if possible |
---|
[15293] | 648 | |
---|
[18190] | 649 | if test -n "$exact_cpu"; then |
---|
| 650 | echo "$exact_cpu$guess_rest" |
---|
| 651 | else |
---|
| 652 | echo "$guess_full" |
---|
[15293] | 653 | fi |
---|
[18190] | 654 | exit 0 |
---|
[15293] | 655 | |
---|
| 656 | |
---|
[18190] | 657 | |
---|
| 658 | # Local variables: |
---|
| 659 | # fill-column: 76 |
---|
| 660 | # End: |
---|