1 1.1 mrg #! /bin/sh 2 1.5 mrg # 3 1.5 mrg # GMP config.guess wrapper. 4 1.1 mrg 5 1.1 mrg 6 1.5 mrg # Copyright 2000-2019 Free Software Foundation, Inc. 7 1.5 mrg # 8 1.5 mrg # This file is part of the GNU MP Library. 9 1.5 mrg # 10 1.5 mrg # The GNU MP Library is free software; you can redistribute it and/or modify 11 1.5 mrg # it under the terms of either: 12 1.1 mrg # 13 1.5 mrg # * the GNU Lesser General Public License as published by the Free 14 1.5 mrg # Software Foundation; either version 3 of the License, or (at your 15 1.5 mrg # option) any later version. 16 1.1 mrg # 17 1.5 mrg # or 18 1.1 mrg # 19 1.5 mrg # * the GNU General Public License as published by the Free Software 20 1.5 mrg # Foundation; either version 2 of the License, or (at your option) any 21 1.5 mrg # later version. 22 1.1 mrg # 23 1.5 mrg # or both in parallel, as here. 24 1.1 mrg # 25 1.5 mrg # The GNU MP Library is distributed in the hope that it will be useful, but 26 1.5 mrg # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27 1.5 mrg # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 1.5 mrg # for more details. 29 1.1 mrg # 30 1.5 mrg # You should have received copies of the GNU General Public License and the 31 1.5 mrg # GNU Lesser General Public License along with the GNU MP Library. If not, 32 1.5 mrg # see https://www.gnu.org/licenses/. 33 1.1 mrg 34 1.1 mrg 35 1.5 mrg # Usage: config.guess 36 1.5 mrg # 37 1.5 mrg # Print the host system CPU-VENDOR-OS. 38 1.5 mrg # 39 1.5 mrg # configfsf.guess is run and its guess then sharpened up to take advantage 40 1.5 mrg # of the finer grained CPU types that GMP knows. 41 1.5 mrg 42 1.4 sevan 43 1.5 mrg # Expect to find configfsf.guess in the same directory as this config.guess 44 1.5 mrg configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`" 45 1.5 mrg if test "$configfsf_guess" = "$0"; then 46 1.5 mrg echo "Cannot derive configfsf.guess from $0" 1>&2 47 1.5 mrg exit 1 48 1.5 mrg fi 49 1.5 mrg if test -f "$configfsf_guess"; then 50 1.5 mrg : 51 1.5 mrg else 52 1.5 mrg echo "$configfsf_guess not found" 1>&2 53 1.5 mrg exit 1 54 1.5 mrg fi 55 1.1 mrg 56 1.5 mrg # Setup a $SHELL with which to run configfsf.guess, using the same 57 1.5 mrg # $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess 58 1.5 mrg SHELL=${CONFIG_SHELL-/bin/sh} 59 1.1 mrg 60 1.5 mrg # Identify ourselves on --version, --help or errors 61 1.1 mrg if test $# != 0; then 62 1.5 mrg echo "(GNU MP wrapped config.guess)" 63 1.5 mrg $SHELL $configfsf_guess "$@" 64 1.1 mrg exit 1 65 1.1 mrg fi 66 1.1 mrg 67 1.5 mrg guess_full=`$SHELL $configfsf_guess` 68 1.5 mrg if test $? != 0; then 69 1.5 mrg exit 1 70 1.5 mrg fi 71 1.5 mrg 72 1.5 mrg guess_cpu=`echo "$guess_full" | sed 's/-.*$//'` 73 1.5 mrg guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'` 74 1.5 mrg exact_cpu= 75 1.5 mrg 76 1.5 mrg 77 1.5 mrg # ------------------------------------------------------------------------- 78 1.5 mrg # The following should look at the current guess and probe the system to 79 1.5 mrg # establish a better guess in exact_cpu. Leave exact_cpu empty if probes 80 1.5 mrg # can't be done, or don't work. 81 1.5 mrg # 82 1.5 mrg # When a number of probes are done, test -z "$exact_cpu" can be used instead 83 1.5 mrg # of putting each probe under an "else" of the preceeding. That can stop 84 1.5 mrg # the code getting horribly nested and marching off the right side of the 85 1.5 mrg # screen. 86 1.5 mrg 87 1.5 mrg # Note that when a compile-and-link is done in one step we need to remove .o 88 1.5 mrg # files, since lame C compilers generate these even when not asked. 89 1.5 mrg # 90 1.1 mrg 91 1.4 sevan # CC_FOR_BUILD -- compiler used by this script. Note that the use of a 92 1.4 sevan # compiler to aid in system detection is discouraged as it requires 93 1.4 sevan # temporary files to be created and, as you can see below, it is a 94 1.4 sevan # headache to deal with in a portable fashion. 95 1.4 sevan 96 1.4 sevan # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still 97 1.4 sevan # use `HOST_CC' if defined, but it is deprecated. 98 1.4 sevan 99 1.4 sevan # Portable tmp directory creation inspired by the Autoconf team. 100 1.4 sevan 101 1.4 sevan set_cc_for_build=' 102 1.4 sevan trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; 103 1.4 sevan trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; 104 1.4 sevan : ${TMPDIR=/tmp} ; 105 1.4 sevan { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || 106 1.4 sevan { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || 107 1.4 sevan { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || 108 1.4 sevan { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; 109 1.4 sevan dummy=$tmp/dummy ; 110 1.5 mrg tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy $dummy.core ${dummy}0.s" ; 111 1.4 sevan case $CC_FOR_BUILD,$HOST_CC,$CC in 112 1.4 sevan ,,) echo "int x;" > $dummy.c ; 113 1.4 sevan for c in cc gcc c89 c99 ; do 114 1.4 sevan if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then 115 1.4 sevan CC_FOR_BUILD="$c"; break ; 116 1.4 sevan fi ; 117 1.4 sevan done ; 118 1.4 sevan if test x"$CC_FOR_BUILD" = x ; then 119 1.4 sevan CC_FOR_BUILD=no_compiler_found ; 120 1.4 sevan fi 121 1.4 sevan ;; 122 1.4 sevan ,,*) CC_FOR_BUILD=$CC ;; 123 1.4 sevan ,*,*) CC_FOR_BUILD=$HOST_CC ;; 124 1.4 sevan esac ; set_cc_for_build= ;' 125 1.4 sevan 126 1.1 mrg 127 1.5 mrg case "$guess_full" in 128 1.5 mrg 129 1.5 mrg alpha-*-*) 130 1.5 mrg eval $set_cc_for_build 131 1.5 mrg # configfsf.guess detects exact alpha cpu types for OSF and GNU/Linux, but 132 1.5 mrg # not for *BSD and other systems. We try to get an exact type for any 133 1.5 mrg # plain "alpha" it leaves. 134 1.5 mrg # 135 1.5 mrg # configfsf.guess used to have a block of code not unlike this, but these 136 1.5 mrg # days does its thing with Linux kernel /proc/cpuinfo or OSF psrinfo. 137 1.5 mrg # 138 1.5 mrg cat <<EOF >${dummy}0.s 139 1.5 mrg .data 140 1.5 mrg Lformat: 141 1.5 mrg .byte 37,100,45,37,120,10,0 # "%d-%x\n" 142 1.5 mrg .text 143 1.5 mrg .globl main 144 1.5 mrg .align 4 145 1.5 mrg .ent main 146 1.5 mrg main: 147 1.5 mrg .frame \$30,16,\$26,0 148 1.5 mrg ldgp \$29,0(\$27) 149 1.5 mrg .prologue 1 150 1.5 mrg .long 0x47e03d91 # implver \$17 151 1.5 mrg lda \$2,-1 152 1.5 mrg .long 0x47e20c21 # amask \$2,\$1 153 1.5 mrg lda \$16,Lformat 154 1.5 mrg not \$1,\$18 155 1.5 mrg jsr \$26,printf 156 1.5 mrg ldgp \$29,0(\$26) 157 1.5 mrg mov 0,\$16 158 1.5 mrg jsr \$26,exit 159 1.5 mrg .end main 160 1.5 mrg EOF 161 1.5 mrg $CC_FOR_BUILD ${dummy}0.s -o $dummy 2>/dev/null 162 1.5 mrg if test "$?" = 0 ; then 163 1.5 mrg case `$dummy` in 164 1.5 mrg 0-0) exact_cpu=alpha ;; 165 1.5 mrg 1-0) exact_cpu=alphaev5 ;; 166 1.5 mrg 1-1) exact_cpu=alphaev56 ;; 167 1.5 mrg 1-101) exact_cpu=alphapca56 ;; 168 1.5 mrg 2-303) exact_cpu=alphaev6 ;; 169 1.5 mrg 2-307) exact_cpu=alphaev67 ;; 170 1.5 mrg 2-1307) exact_cpu=alphaev68 ;; 171 1.5 mrg esac 172 1.5 mrg fi 173 1.5 mrg ;; 174 1.5 mrg 175 1.6 rin arm*-*-* | aarch64*-*-*) 176 1.5 mrg cpu_code=`sed -n 's/^CPU part.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | sort -r | head -n 1 2>/dev/null` 177 1.5 mrg cpu_implementer=`sed -n 's/^CPU implementer.*\(0x.*\)$/\1/p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null` 178 1.5 mrg case "${cpu_implementer}_${cpu_code}" in 179 1.5 mrg 0x53_0x001) exact_cpu=armexynosm1 ;; 180 1.5 mrg 0x51_0x800) exact_cpu=armcortexa57 ;; 181 1.5 mrg 0x43_0x0a1) exact_cpu=armthunderx ;; 182 1.5 mrg 0x50_0x000) exact_cpu=armxgene1 ;; 183 1.5 mrg esac 184 1.5 mrg if test -z "$exact_cpu"; then 185 1.5 mrg case "$cpu_code" in 186 1.5 mrg 0xa10 | 0xa11 | 0xb11) # v4 strongarm/sa1100 187 1.5 mrg exact_cpu="armsa1";; 188 1.5 mrg 0x915 | 0x925 | \ 189 1.5 mrg 0x920 | 0x922 | 0x940) # v4 190 1.5 mrg exact_cpu="arm9tdmi";; 191 1.5 mrg 0x210 | 0x290 | 0x2d0 | \ 192 1.5 mrg 0x212 | 0x292 | 0x2d2 | \ 193 1.5 mrg 0x411) exact_cpu="armxscale";; # v5 pxa2xx 194 1.5 mrg 0x926 | 0x946 | 0x966 | 0x968) # v5te/v5tej 195 1.5 mrg exact_cpu="arm9te";; 196 1.5 mrg 0xa20 | 0xa22 | 0xa26) # v5te 197 1.5 mrg exact_cpu="arm10";; 198 1.5 mrg 0xb02) exact_cpu="arm11mpcore";; # v6 199 1.5 mrg 0xb36) exact_cpu="arm1136";; # v6 200 1.5 mrg 0xb56) exact_cpu="arm1156";; # v6t2 201 1.5 mrg 0xb76) exact_cpu="arm1176";; # v6 202 1.5 mrg 0xc05) exact_cpu="armcortexa5";; # v7a 203 1.5 mrg 0xc07) exact_cpu="armcortexa7";; # v7a 204 1.5 mrg 0xc08) exact_cpu="armcortexa8";; # v7a 205 1.5 mrg 0xc09) exact_cpu="armcortexa9";; # v7a 206 1.5 mrg 0xc0f) exact_cpu="armcortexa15";; # v7a 207 1.5 mrg 0xc0d) exact_cpu="armcortexa12";; # v7a 208 1.5 mrg 0xc0e) exact_cpu="armcortexa17";; # v7a 209 1.5 mrg 0xc14) exact_cpu="armcortexr4";; # v7r 210 1.5 mrg 0xc15) exact_cpu="armcortexr5";; # v7r 211 1.5 mrg 0xc23) exact_cpu="armcortexm3";; # v7m 212 1.5 mrg 213 1.5 mrg 0xd04) exact_cpu="armcortexa35";; # v8 214 1.5 mrg 0xd03) exact_cpu="armcortexa53";; # v8 215 1.5 mrg 0xd05) exact_cpu="armcortexa55";; # v8.2 216 1.5 mrg 0xd07) exact_cpu="armcortexa57";; # v8 217 1.5 mrg 0xd08) exact_cpu="armcortexa72";; # v8 218 1.5 mrg 0xd09) exact_cpu="armcortexa73";; # v8 219 1.5 mrg 0xd0a) exact_cpu="armcortexa75";; # v8.2 220 1.5 mrg 0xd0b) exact_cpu="armcortexa76";; # v8.3 221 1.5 mrg *) exact_cpu=$guess_cpu;; 222 1.5 mrg esac 223 1.5 mrg fi 224 1.5 mrg exact_cpu="${exact_cpu}`sed -n 's;^Features.*\(neon\).*;\1;p' /proc/cpuinfo 2>/dev/null | head -n 1 2>/dev/null`" 225 1.5 mrg ;; 226 1.5 mrg 227 1.5 mrg ia64*-*-*) 228 1.5 mrg eval $set_cc_for_build 229 1.5 mrg # CPUID[3] bits 24 to 31 is the processor family. itanium2 is documented 230 1.5 mrg # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but 231 1.5 mrg # haven't found any documentation on it as such. 232 1.5 mrg # 233 1.5 mrg # Defining both getcpuid and _getcpuid lets us ignore whether the system 234 1.5 mrg # expects underscores or not. 235 1.5 mrg # 236 1.5 mrg # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode 237 1.5 mrg # (which is the default there), it's the only 64-bit type. 238 1.5 mrg # 239 1.5 mrg cat >${dummy}0.s <<EOF 240 1.5 mrg .text 241 1.5 mrg .global _getcpuid 242 1.5 mrg .proc _getcpuid 243 1.5 mrg _getcpuid: 244 1.5 mrg mov r8 = CPUID[r32] ;; 245 1.5 mrg br.ret.sptk.many rp ;; 246 1.5 mrg .endp _getcpuid 247 1.5 mrg .global getcpuid 248 1.5 mrg .proc getcpuid 249 1.5 mrg getcpuid: 250 1.5 mrg mov r8 = CPUID[r32] ;; 251 1.5 mrg br.ret.sptk.many rp ;; 252 1.5 mrg .endp getcpuid 253 1.5 mrg EOF 254 1.5 mrg cat >$dummy.c <<EOF 255 1.5 mrg #include <stdio.h> 256 1.5 mrg unsigned long long getcpuid (); 257 1.5 mrg int 258 1.5 mrg main () 259 1.5 mrg { 260 1.5 mrg if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL) 261 1.5 mrg { 262 1.5 mrg /* "GenuineIntel" */ 263 1.5 mrg switch ((getcpuid(3LL) >> 24) & 0xFF) { 264 1.5 mrg case 0x07: puts ("itanium"); break; 265 1.5 mrg case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */ 266 1.5 mrg case 0x20: puts ("itanium2"); break; /* Montecito, Montvale, Tukwila */ 267 1.5 mrg case 0x21: puts ("itanium2"); break; /* Poulson */ 268 1.5 mrg } 269 1.5 mrg } 270 1.5 mrg return 0; 271 1.5 mrg } 272 1.5 mrg EOF 273 1.5 mrg if $CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy >/dev/null 2>&1; then 274 1.5 mrg exact_cpu=`$dummy` 275 1.5 mrg fi 276 1.5 mrg ;; 277 1.5 mrg 278 1.5 mrg mips-*-irix[6789]*) 279 1.5 mrg # IRIX 6 and up always has a 64-bit mips cpu 280 1.5 mrg exact_cpu=mips64 281 1.5 mrg ;; 282 1.5 mrg 283 1.5 mrg mips-*-*) 284 1.5 mrg case $(uname -m) in 285 1.5 mrg mips64) exact_cpu=mips64;; 286 1.5 mrg esac 287 1.5 mrg ;; 288 1.5 mrg 289 1.5 mrg mipsel-*-*) 290 1.5 mrg case $(uname -m) in 291 1.5 mrg mips64) exact_cpu=mips64el;; 292 1.5 mrg esac 293 1.5 mrg ;; 294 1.5 mrg 295 1.5 mrg m68k-*-*) 296 1.5 mrg eval $set_cc_for_build 297 1.5 mrg # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example 298 1.5 mrg # hw.model = Apple Macintosh Quadra 610 (68040) 299 1.5 mrg exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'` 300 1.5 mrg if test -z "$exact_cpu"; then 301 1.5 mrg # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between). 302 1.5 mrg exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null` 303 1.5 mrg fi 304 1.5 mrg if test -z "$exact_cpu"; then 305 1.5 mrg # Try: movel #0,%d0; rts 306 1.5 mrg # This is to check the compiler and our asm code works etc, before 307 1.5 mrg # assuming failures below indicate cpu characteristics. 308 1.5 mrg # .byte is used to avoid problems with assembler syntax variations. 309 1.5 mrg # For testing, provoke failures by adding "illegal" possibly as 310 1.5 mrg # ".byte 0x4A, 0xFC" 311 1.5 mrg cat >${dummy}0.s <<EOF 312 1.5 mrg .text 313 1.5 mrg .globl main 314 1.5 mrg .globl _main 315 1.5 mrg main: 316 1.5 mrg _main: 317 1.5 mrg .byte 0x70, 0x00 318 1.5 mrg .byte 0x4e, 0x75 319 1.5 mrg EOF 320 1.1 mrg 321 1.5 mrg if ($CC_FOR_BUILD ${dummy}0.s -o $dummy && $dummy) >/dev/null 2>&1; then 322 1.1 mrg 323 1.5 mrg # $SHELL -c is used to execute $dummy below, since ($dummy) 324 1.5 mrg # 2>/dev/null still prints the SIGILL message on some shells. 325 1.5 mrg # 326 1.5 mrg # Try: movel #0,%d0 327 1.5 mrg # rtd #0 328 1.5 mrg cat >${dummy}0.s <<EOF 329 1.5 mrg .text 330 1.5 mrg .globl main 331 1.5 mrg .globl _main 332 1.5 mrg main: 333 1.5 mrg _main: 334 1.5 mrg .byte 0x70, 0x00 335 1.5 mrg .byte 0x4e, 0x74, 0x00, 0x00 336 1.5 mrg EOF 337 1.5 mrg if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then 338 1.5 mrg $SHELL -c $dummy >/dev/null 2>&1 339 1.5 mrg if test $? != 0; then 340 1.5 mrg exact_cpu=m68000 # because rtd didn't work 341 1.5 mrg fi 342 1.5 mrg fi 343 1.5 mrg # 344 1.5 mrg 345 1.5 mrg if test -z "$exact_cpu"; then 346 1.5 mrg # Try: trapf 347 1.5 mrg # movel #0,%d0 348 1.5 mrg # rts 349 1.5 mrg # Another possibility for identifying 68000 and 68010 is the 350 1.5 mrg # different value stored by "movem a0,(a0)+" 351 1.5 mrg cat >${dummy}0.s <<EOF 352 1.5 mrg .text 353 1.5 mrg .globl main 354 1.5 mrg .globl _main 355 1.5 mrg main: 356 1.5 mrg _main: 357 1.5 mrg .byte 0x51, 0xFC 358 1.5 mrg .byte 0x70, 0x00 359 1.5 mrg .byte 0x4e, 0x75 360 1.5 mrg EOF 361 1.5 mrg if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then 362 1.5 mrg $SHELL -c $dummy >/dev/null 2>&1 363 1.5 mrg if test $? != 0; then 364 1.5 mrg exact_cpu=m68010 # because trapf didn't work 365 1.5 mrg fi 366 1.5 mrg fi 367 1.5 mrg fi 368 1.5 mrg 369 1.5 mrg if test -z "$exact_cpu"; then 370 1.5 mrg # Try: bfffo %d1{0:31},%d0 371 1.5 mrg # movel #0,%d0 372 1.5 mrg # rts 373 1.5 mrg cat >${dummy}0.s <<EOF 374 1.5 mrg .text 375 1.5 mrg .globl main 376 1.5 mrg .globl _main 377 1.5 mrg main: 378 1.5 mrg _main: 379 1.5 mrg .byte 0xED, 0xC1, 0x00, 0x1F 380 1.5 mrg .byte 0x70, 0x00 381 1.5 mrg .byte 0x4e, 0x75 382 1.5 mrg EOF 383 1.5 mrg if $CC_FOR_BUILD ${dummy}0.s -o $dummy >/dev/null 2>&1; then 384 1.5 mrg $SHELL -c $dummy >/dev/null 2>&1 385 1.5 mrg if test $? != 0; then 386 1.5 mrg exact_cpu=m68360 # cpu32, because bfffo didn't work 387 1.5 mrg fi 388 1.5 mrg fi 389 1.5 mrg fi 390 1.5 mrg 391 1.5 mrg if test -z "$exact_cpu"; then 392 1.5 mrg # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060? 393 1.5 mrg exact_cpu=m68020 394 1.5 mrg fi 395 1.5 mrg fi 396 1.5 mrg fi 397 1.5 mrg if test -z "$exact_cpu"; then 398 1.5 mrg case "$guess_full" in 399 1.5 mrg *-*-next* | *-*-openstep*) # NeXTs are 68020 or better 400 1.5 mrg exact_cpu=m68020 ;; 401 1.5 mrg esac 402 1.5 mrg fi 403 1.5 mrg ;; 404 1.5 mrg 405 1.5 mrg 406 1.5 mrg rs6000-*-* | powerpc*-*-*) 407 1.5 mrg # Enhancement: On MacOS the "machine" command prints for instance 408 1.5 mrg # "ppc750". Interestingly on powerpc970-apple-darwin6.8.5 it prints 409 1.5 mrg # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo 410 1.5 mrg # (as noted below). But the man page says the command is still "under 411 1.5 mrg # development", so it doesn't seem wise to use it just yet, not while 412 1.5 mrg # there's an alternative. 413 1.5 mrg 414 1.5 mrg # Try to read the PVR. mfpvr is a protected instruction, NetBSD, MacOS and 415 1.5 mrg # AIX don't allow it in user mode, but the Linux kernel does. We prefer this 416 1.5 mrg # to /proc/cpuinfo since the latter lags for newer CPUs. 417 1.5 mrg # 418 1.5 mrg # Note this is no good on AIX, since a C function there is the address of 419 1.5 mrg # a function descriptor, not actual code. But this doesn't matter since 420 1.5 mrg # AIX doesn't allow mfpvr anyway. 421 1.5 mrg # 422 1.5 mrg if test -z "$exact_cpu"; then 423 1.5 mrg eval $set_cc_for_build 424 1.5 mrg cat >$dummy.c <<\EOF 425 1.5 mrg #include <stdio.h> 426 1.5 mrg int 427 1.5 mrg main () 428 1.5 mrg { 429 1.5 mrg unsigned pvr; 430 1.5 mrg 431 1.5 mrg asm ("mfpvr %0" : "=r" (pvr)); 432 1.5 mrg 433 1.5 mrg switch (pvr >> 16) { 434 1.5 mrg case 0x0001: puts ("powerpc601"); break; 435 1.5 mrg case 0x0003: puts ("powerpc603"); break; 436 1.5 mrg case 0x0004: puts ("powerpc604"); break; 437 1.5 mrg case 0x0006: puts ("powerpc603e"); break; 438 1.5 mrg case 0x0007: puts ("powerpc603e"); break; /* 603ev */ 439 1.5 mrg case 0x0008: puts ("powerpc750"); break; 440 1.5 mrg case 0x0009: puts ("powerpc604e"); break; 441 1.5 mrg case 0x000a: puts ("powerpc604e"); break; /* 604ev5 */ 442 1.5 mrg case 0x000c: puts ("powerpc7400"); break; 443 1.5 mrg case 0x0041: puts ("powerpc630"); break; 444 1.5 mrg case 0x003f: puts ("power7"); break; 445 1.5 mrg case 0x004b: 446 1.5 mrg case 0x004c: 447 1.5 mrg case 0x004d: puts ("power8"); break; 448 1.5 mrg case 0x004e: puts ("power9"); break; 449 1.5 mrg case 0x0050: puts ("powerpc860"); break; 450 1.5 mrg case 0x8000: puts ("powerpc7450"); break; 451 1.5 mrg case 0x8001: puts ("powerpc7455"); break; 452 1.5 mrg case 0x8002: puts ("powerpc7457"); break; 453 1.5 mrg case 0x8003: puts ("powerpc7447"); break; /* really 7447A */ 454 1.5 mrg case 0x800c: puts ("powerpc7410"); break; 455 1.5 mrg } 456 1.5 mrg return 0; 457 1.5 mrg } 458 1.5 mrg EOF 459 1.5 mrg if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then 460 1.5 mrg # This style construct is needed on AIX 4.3 to suppress the SIGILL error 461 1.5 mrg # from (*fun)(). Using $SHELL -c $dummy 2>/dev/null doesn't work. 462 1.5 mrg { x=`$dummy`; } 2>/dev/null 463 1.5 mrg if test -n "$x"; then 464 1.5 mrg exact_cpu=$x 465 1.5 mrg fi 466 1.5 mrg fi 467 1.5 mrg fi 468 1.5 mrg 469 1.5 mrg 470 1.5 mrg # Grep the /proc/cpuinfo pseudo-file. 471 1.5 mrg # Anything unrecognised is ignored, since of course we mustn't spit out 472 1.5 mrg # a cpu type config.sub doesn't know. 473 1.5 mrg if test -z "$exact_cpu" && test -f /proc/cpuinfo; then 474 1.5 mrg x=`grep "^cpu[ ]" /proc/cpuinfo | head -n 1` 475 1.5 mrg x=`echo $x | sed -n 's/^cpu[ ]*:[ ]*\([A-Za-z0-9]*\).*/\1/p'` 476 1.5 mrg x=`echo $x | sed 's/PPC//'` 477 1.5 mrg case $x in 478 1.5 mrg 601) exact_cpu="power" ;; 479 1.5 mrg 603ev) exact_cpu="powerpc603e" ;; 480 1.5 mrg 604ev5) exact_cpu="powerpc604e" ;; 481 1.5 mrg 970??) exact_cpu="powerpc970" ;; 482 1.5 mrg 603 | 603e | 604 | 604e | 750 | 821 | 860) 483 1.5 mrg exact_cpu="powerpc$x" ;; 484 1.5 mrg POWER[4-9]*) 485 1.5 mrg exact_cpu=`echo $x | sed -e "s;POWER;power;" -e "s;[a-zA-Z]*$;;"` ;; 486 1.5 mrg esac 487 1.5 mrg fi 488 1.5 mrg 489 1.5 mrg 490 1.5 mrg if test -z "$exact_cpu"; then 491 1.5 mrg # On AIX, try looking at _system_configuration. This is present in 492 1.5 mrg # version 4 at least. 493 1.5 mrg cat >$dummy.c <<EOF 494 1.5 mrg #include <stdio.h> 495 1.5 mrg #include <sys/systemcfg.h> 496 1.5 mrg int 497 1.5 mrg main () 498 1.5 mrg { 499 1.5 mrg switch (_system_configuration.implementation) { 500 1.5 mrg /* Old versions of AIX don't have all these constants, 501 1.5 mrg use ifdef for safety. */ 502 1.5 mrg #ifdef POWER_RS2 503 1.5 mrg case POWER_RS2: puts ("power2"); break; 504 1.5 mrg #endif 505 1.5 mrg #ifdef POWER_601 506 1.5 mrg case POWER_601: puts ("power"); break; 507 1.5 mrg #endif 508 1.5 mrg #ifdef POWER_603 509 1.5 mrg case POWER_603: puts ("powerpc603"); break; 510 1.5 mrg #endif 511 1.5 mrg #ifdef POWER_604 512 1.5 mrg case POWER_604: puts ("powerpc604"); break; 513 1.5 mrg #endif 514 1.5 mrg #ifdef POWER_620 515 1.5 mrg case POWER_620: puts ("powerpc620"); break; 516 1.5 mrg #endif 517 1.5 mrg #ifdef POWER_630 518 1.5 mrg case POWER_630: puts ("powerpc630"); break; 519 1.5 mrg #endif 520 1.5 mrg /* Dunno what this is, leave it out for now. 521 1.5 mrg case POWER_A35: puts ("powerpca35"); break; 522 1.5 mrg */ 523 1.5 mrg /* This is waiting for a bit more info. 524 1.5 mrg case POWER_RS64II: puts ("powerpcrs64ii"); break; 525 1.5 mrg */ 526 1.5 mrg #ifdef POWER_4 527 1.5 mrg case POWER_4: puts ("power4"); break; 528 1.5 mrg #endif 529 1.5 mrg #ifdef POWER_5 530 1.5 mrg case POWER_5: puts ("power5"); break; 531 1.5 mrg #endif 532 1.5 mrg #ifdef POWER_6 533 1.5 mrg case POWER_6: puts ("power6"); break; 534 1.5 mrg #endif 535 1.5 mrg #ifdef POWER_7 536 1.5 mrg case POWER_7: puts ("power7"); break; 537 1.5 mrg #endif 538 1.5 mrg #ifdef POWER_8 539 1.5 mrg case POWER_8: puts ("power8"); break; 540 1.5 mrg #endif 541 1.5 mrg #ifdef POWER_9 542 1.5 mrg case POWER_9: puts ("power9"); break; 543 1.1 mrg #endif 544 1.5 mrg default: 545 1.5 mrg if (_system_configuration.architecture == POWER_RS) 546 1.5 mrg puts ("power"); 547 1.5 mrg else if (_system_configuration.width == 64) 548 1.5 mrg puts ("powerpc64"); 549 1.5 mrg } 550 1.5 mrg return 0; 551 1.5 mrg } 552 1.1 mrg EOF 553 1.5 mrg if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then 554 1.5 mrg x=`$dummy` 555 1.5 mrg if test -n "$x"; then 556 1.5 mrg exact_cpu=$x 557 1.5 mrg fi 558 1.5 mrg fi 559 1.5 mrg fi 560 1.5 mrg 561 1.5 mrg if test -z "$exact_cpu"; then 562 1.5 mrg # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype 563 1.5 mrg # can tell us the exact cpu. 564 1.5 mrg cat >$dummy.c <<EOF 565 1.5 mrg #include <stdio.h> 566 1.5 mrg #include <mach-o/arch.h> 567 1.5 mrg int 568 1.5 mrg main (void) 569 1.5 mrg { 570 1.5 mrg const NXArchInfo *a = NXGetLocalArchInfo(); 571 1.5 mrg if (a->cputype == CPU_TYPE_POWERPC) 572 1.5 mrg { 573 1.5 mrg switch (a->cpusubtype) { 574 1.5 mrg /* The following known to Darwin 1.3. */ 575 1.5 mrg case CPU_SUBTYPE_POWERPC_601: puts ("powerpc601"); break; 576 1.5 mrg case CPU_SUBTYPE_POWERPC_602: puts ("powerpc602"); break; 577 1.5 mrg case CPU_SUBTYPE_POWERPC_603: puts ("powerpc603"); break; 578 1.5 mrg case CPU_SUBTYPE_POWERPC_603e: puts ("powerpc603e"); break; 579 1.5 mrg case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break; 580 1.5 mrg case CPU_SUBTYPE_POWERPC_604: puts ("powerpc604"); break; 581 1.5 mrg case CPU_SUBTYPE_POWERPC_604e: puts ("powerpc604e"); break; 582 1.5 mrg case CPU_SUBTYPE_POWERPC_620: puts ("powerpc620"); break; 583 1.5 mrg case CPU_SUBTYPE_POWERPC_750: puts ("powerpc750"); break; 584 1.5 mrg case CPU_SUBTYPE_POWERPC_7400: puts ("powerpc7400"); break; 585 1.5 mrg case CPU_SUBTYPE_POWERPC_7450: puts ("powerpc7450"); break; 586 1.5 mrg /* Darwin 6.8.5 doesn't define the following */ 587 1.5 mrg case 0x8001: puts ("powerpc7455"); break; 588 1.5 mrg case 0x8002: puts ("powerpc7457"); break; 589 1.5 mrg case 0x8003: puts ("powerpc7447"); break; 590 1.5 mrg case 100: puts ("powerpc970"); break; 591 1.5 mrg } 592 1.5 mrg } 593 1.5 mrg return 0; 594 1.5 mrg } 595 1.1 mrg EOF 596 1.5 mrg if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then 597 1.5 mrg x=`$dummy` 598 1.5 mrg if test -n "$x"; then 599 1.5 mrg exact_cpu=$x 600 1.5 mrg fi 601 1.5 mrg fi 602 1.5 mrg fi 603 1.5 mrg ;; 604 1.5 mrg 605 1.5 mrg sparc-*-* | sparc64-*-*) 606 1.5 mrg # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as 607 1.5 mrg # to short-circuit subsequent tests. 608 1.5 mrg 609 1.5 mrg # Grep the linux kernel /proc/cpuinfo pseudo-file. 610 1.5 mrg # A typical line is "cpu\t\t: TI UltraSparc II (BlackBird)" 611 1.5 mrg # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c. 612 1.5 mrg # 613 1.5 mrg if test -f /proc/cpuinfo; then 614 1.5 mrg if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then 615 1.5 mrg exact_cpu="sparc" # ie. v7 616 1.5 mrg elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then 617 1.5 mrg exact_cpu="sparc" # ie. v7 618 1.5 mrg elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then 619 1.5 mrg exact_cpu="sparcv8" 620 1.5 mrg elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then 621 1.5 mrg exact_cpu="supersparc" 622 1.5 mrg elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then 623 1.5 mrg exact_cpu="microsparc" 624 1.5 mrg elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then 625 1.5 mrg # actually MicroSPARC-II 626 1.5 mrg exact_cpu=microsparc 627 1.5 mrg elif grep 'cpu.*UltraSparc T5' /proc/cpuinfo >/dev/null; then 628 1.5 mrg exact_cpu="ultrasparct5" 629 1.5 mrg elif grep 'cpu.*UltraSparc T4' /proc/cpuinfo >/dev/null; then 630 1.5 mrg exact_cpu="ultrasparct4" 631 1.5 mrg elif grep 'cpu.*UltraSparc T3' /proc/cpuinfo >/dev/null; then 632 1.5 mrg exact_cpu="ultrasparct3" 633 1.5 mrg elif grep 'cpu.*UltraSparc T2' /proc/cpuinfo >/dev/null; then 634 1.5 mrg exact_cpu="ultrasparct2" 635 1.5 mrg elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then 636 1.5 mrg exact_cpu="ultrasparct1" 637 1.5 mrg elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then 638 1.5 mrg exact_cpu="ultrasparc3" 639 1.5 mrg elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then 640 1.5 mrg exact_cpu="ultrasparc2i" 641 1.5 mrg elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then 642 1.5 mrg exact_cpu="ultrasparc2" 643 1.5 mrg elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then 644 1.5 mrg exact_cpu="ultrasparc" 645 1.5 mrg fi 646 1.5 mrg fi 647 1.5 mrg 648 1.5 mrg # Need to invoke this for setup of $dummy 649 1.5 mrg eval $set_cc_for_build 650 1.5 mrg 651 1.5 mrg # Grep the output from sysinfo on SunOS. 652 1.5 mrg # sysinfo has been seen living in /bin or in /usr/kvm 653 1.5 mrg # cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU 654 1.5 mrg # cpu0 is a "75 MHz TI,TMS390Z55" CPU 655 1.5 mrg # 656 1.5 mrg if test -z "$exact_cpu"; then 657 1.5 mrg for i in sysinfo /usr/kvm/sysinfo; do 658 1.5 mrg if $SHELL -c $i 2>/dev/null >$dummy; then 659 1.5 mrg if grep 'cpu0 is a "SuperSPARC' $dummy >/dev/null; then 660 1.5 mrg exact_cpu=supersparc 661 1.5 mrg break 662 1.5 mrg elif grep 'cpu0 is a .*TMS390Z5.' $dummy >/dev/null; then 663 1.5 mrg # TMS390Z50 and TMS390Z55 664 1.5 mrg exact_cpu=supersparc 665 1.5 mrg break 666 1.5 mrg fi 667 1.5 mrg fi 668 1.5 mrg done 669 1.5 mrg fi 670 1.5 mrg 671 1.5 mrg # Grep the output from prtconf on Solaris. 672 1.5 mrg # Use an explicit /usr/sbin, since that directory might not be in a normal 673 1.5 mrg # user's path. 674 1.5 mrg # 675 1.5 mrg # SUNW,UltraSPARC (driver not attached) 676 1.5 mrg # SUNW,UltraSPARC-II (driver not attached) 677 1.5 mrg # SUNW,UltraSPARC-IIi (driver not attached) 678 1.5 mrg # SUNW,UltraSPARC-III+ (driver not attached) 679 1.5 mrg # Ross,RT625 (driver not attached) 680 1.5 mrg # TI,TMS390Z50 (driver not attached) 681 1.5 mrg # 682 1.5 mrg # /usr/sbin/sysdef prints similar information, but includes all loadable 683 1.5 mrg # cpu modules, not just the real cpu. 684 1.5 mrg # 685 1.5 mrg # We first try a plain prtconf, since that is known to work on older systems. 686 1.5 mrg # But for newer T1 systems, that doesn't produce any useful output, we need 687 1.5 mrg # "prtconf -vp" there. 688 1.5 mrg # 689 1.5 mrg for prtconfopt in "" "-vp"; do 690 1.5 mrg if test -z "$exact_cpu"; then 691 1.5 mrg if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >$dummy; then 692 1.5 mrg if grep 'SUNW,UltraSPARC-T5' $dummy >/dev/null; then 693 1.5 mrg exact_cpu=ultrasparct5 694 1.5 mrg elif grep 'SUNW,UltraSPARC-T4' $dummy >/dev/null; then 695 1.5 mrg exact_cpu=ultrasparct4 696 1.5 mrg elif grep 'SUNW,UltraSPARC-T3' $dummy >/dev/null; then 697 1.5 mrg exact_cpu=ultrasparct3 698 1.5 mrg elif grep 'SUNW,UltraSPARC-T2' $dummy >/dev/null; then 699 1.5 mrg exact_cpu=ultrasparct2 700 1.5 mrg elif grep 'SUNW,UltraSPARC-T1' $dummy >/dev/null; then 701 1.5 mrg exact_cpu=ultrasparct1 702 1.5 mrg elif grep 'SUNW,UltraSPARC-III' $dummy >/dev/null; then 703 1.5 mrg exact_cpu=ultrasparc3 704 1.5 mrg elif grep 'SUNW,UltraSPARC-IIi' $dummy >/dev/null; then 705 1.5 mrg exact_cpu=ultrasparc2i 706 1.5 mrg elif grep 'SUNW,UltraSPARC-II' $dummy >/dev/null; then 707 1.5 mrg exact_cpu=ultrasparc2 708 1.8 palle elif egrep '(SUNW|ORCL),(Ultra)?SPARC' $dummy >/dev/null; then 709 1.5 mrg exact_cpu=ultrasparc 710 1.5 mrg elif grep 'Ross,RT62.' $dummy >/dev/null; then 711 1.5 mrg # RT620, RT625, RT626 hypersparcs (v8). 712 1.5 mrg exact_cpu=sparcv8 713 1.5 mrg elif grep 'TI,TMS390Z5.' $dummy >/dev/null; then 714 1.5 mrg # TMS390Z50 and TMS390Z55 715 1.5 mrg exact_cpu=supersparc 716 1.5 mrg elif grep 'TI,TMS390S10' $dummy >/dev/null; then 717 1.5 mrg exact_cpu=microsparc 718 1.5 mrg elif grep 'FMI,MB86904' $dummy >/dev/null; then 719 1.5 mrg # actually MicroSPARC-II 720 1.5 mrg exact_cpu=microsparc 721 1.5 mrg fi 722 1.5 mrg fi 723 1.5 mrg fi 724 1.5 mrg done 725 1.5 mrg 726 1.5 mrg # Grep the output from sysctl hw.model on sparc or sparc64 *BSD. 727 1.5 mrg # Use an explicit /sbin, since that directory might not be in a normal 728 1.5 mrg # user's path. Example outputs, 729 1.5 mrg # 730 1.5 mrg # hw.model: Sun Microsystems UltraSparc-IIi 731 1.5 mrg # 732 1.5 mrg if test -z "$exact_cpu"; then 733 1.5 mrg if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >$dummy; then 734 1.5 mrg if grep -i 'UltraSparc-T5' $dummy >/dev/null; then 735 1.5 mrg exact_cpu=ultrasparct5 736 1.5 mrg elif grep -i 'UltraSparc-T4' $dummy >/dev/null; then 737 1.5 mrg exact_cpu=ultrasparct4 738 1.5 mrg elif grep -i 'UltraSparc-T3' $dummy >/dev/null; then 739 1.5 mrg exact_cpu=ultrasparct3 740 1.5 mrg elif grep -i 'UltraSparc-T2' $dummy >/dev/null; then 741 1.5 mrg exact_cpu=ultrasparct2 742 1.5 mrg elif grep -i 'UltraSparc-T1' $dummy >/dev/null; then 743 1.5 mrg exact_cpu=ultrasparct1 744 1.5 mrg elif grep -i 'UltraSparc-III' $dummy >/dev/null; then 745 1.5 mrg exact_cpu=ultrasparc3 746 1.5 mrg elif grep -i 'UltraSparc-IIi' $dummy >/dev/null; then 747 1.5 mrg exact_cpu=ultrasparc2i 748 1.5 mrg elif grep -i 'UltraSparc-II' $dummy >/dev/null; then 749 1.5 mrg exact_cpu=ultrasparc2 750 1.5 mrg elif grep -i 'UltraSparc' $dummy >/dev/null; then 751 1.5 mrg exact_cpu=ultrasparc 752 1.5 mrg elif grep 'TMS390Z5.' $dummy >/dev/null; then 753 1.5 mrg # TMS390Z50 and TMS390Z55 754 1.5 mrg exact_cpu=supersparc 755 1.5 mrg elif grep 'TMS390S10' $dummy >/dev/null; then 756 1.5 mrg exact_cpu=microsparc 757 1.5 mrg elif grep 'MB86904' $dummy >/dev/null; then 758 1.5 mrg # actually MicroSPARC-II 759 1.5 mrg exact_cpu=microsparc 760 1.5 mrg elif grep 'MB86907' $dummy >/dev/null; then 761 1.5 mrg exact_cpu=turbosparc 762 1.5 mrg fi 763 1.5 mrg fi 764 1.5 mrg fi 765 1.5 mrg 766 1.5 mrg # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort 767 1.5 mrg # 768 1.5 mrg if test -z "$exact_cpu"; then 769 1.5 mrg case `uname -m` in 770 1.5 mrg sun4[md]) exact_cpu=sparcv8 ;; 771 1.5 mrg sun4u) exact_cpu=sparcv9 ;; 772 1.5 mrg esac 773 1.5 mrg fi 774 1.5 mrg ;; 775 1.5 mrg 776 1.5 mrg 777 1.5 mrg # Recognise x86 processors using a tricky cpuid with 4 arguments, repeating 778 1.5 mrg # arguments; for x86-64 we effectively pass the 1st in rdx and the 2nd in rcx. 779 1.5 mrg # This allows the same asm to work for both standard and Windoze calling 780 1.5 mrg # conventions. 781 1.5 mrg 782 1.5 mrg i?86-*-* | amd64-*-* | x86_64-*-*) 783 1.5 mrg eval $set_cc_for_build 784 1.5 mrg 785 1.5 mrg cat <<EOF >$dummy.c 786 1.5 mrg #include <string.h> 787 1.5 mrg #include <stdio.h> 788 1.5 mrg #define CPUID(a,b) cpuid(b,a,a,b) 789 1.5 mrg #if __cplusplus 790 1.5 mrg extern "C" 791 1.5 mrg #endif 792 1.5 mrg unsigned int cpuid (int, char *, char *, int); 793 1.5 mrg 794 1.5 mrg int 795 1.5 mrg gmp_workaround_skylake_cpuid_bug () 796 1.5 mrg { 797 1.5 mrg char feature_string[49]; 798 1.5 mrg char processor_name_string[49]; 799 1.5 mrg static const char *bad_cpus[] = {" G44", " G45", " G39" /* , "6600" */ }; 800 1.5 mrg int i; 801 1.5 mrg 802 1.5 mrg /* Example strings: */ 803 1.5 mrg /* "Intel(R) Pentium(R) CPU G4400 @ 3.30GHz" */ 804 1.5 mrg /* "Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz" */ 805 1.5 mrg /* ^ ^ ^ */ 806 1.5 mrg /* 0x80000002 0x80000003 0x80000004 */ 807 1.5 mrg /* We match out just the 0x80000003 part here. */ 808 1.5 mrg 809 1.5 mrg /* In their infinitive wisdom, Intel decided to use one register order for 810 1.5 mrg the vendor string, and another for the processor name string. We shuffle 811 1.5 mrg things about here, rather than write a new variant of our assembly cpuid. 812 1.5 mrg */ 813 1.5 mrg 814 1.5 mrg unsigned int eax, ebx, ecx, edx; 815 1.5 mrg eax = CPUID (feature_string, 0x80000003); 816 1.5 mrg ebx = ((unsigned int *)feature_string)[0]; 817 1.5 mrg edx = ((unsigned int *)feature_string)[1]; 818 1.5 mrg ecx = ((unsigned int *)feature_string)[2]; 819 1.5 mrg 820 1.5 mrg ((unsigned int *) (processor_name_string))[0] = eax; 821 1.5 mrg ((unsigned int *) (processor_name_string))[1] = ebx; 822 1.5 mrg ((unsigned int *) (processor_name_string))[2] = ecx; 823 1.5 mrg ((unsigned int *) (processor_name_string))[3] = edx; 824 1.5 mrg 825 1.5 mrg processor_name_string[16] = 0; 826 1.5 mrg 827 1.5 mrg for (i = 0; i < sizeof (bad_cpus) / sizeof (char *); i++) 828 1.5 mrg { 829 1.5 mrg if (strstr (processor_name_string, bad_cpus[i]) != 0) 830 1.5 mrg return 1; 831 1.5 mrg } 832 1.5 mrg return 0; 833 1.5 mrg } 834 1.5 mrg 835 1.5 mrg int 836 1.5 mrg main () 837 1.5 mrg { 838 1.5 mrg char vendor_string[13]; 839 1.5 mrg char feature_string[12]; 840 1.5 mrg long fms; 841 1.5 mrg int family, model; 842 1.5 mrg const char *modelstr, *suffix; 843 1.5 mrg int cpu_64bit = 0, cpu_avx = 0; 844 1.5 mrg int cpuid_64bit, cpuid_avx, cpuid_osxsave; 845 1.5 mrg 846 1.5 mrg CPUID (vendor_string, 0); 847 1.5 mrg vendor_string[12] = 0; 848 1.5 mrg 849 1.5 mrg fms = CPUID (feature_string, 1); 850 1.5 mrg 851 1.5 mrg family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff); 852 1.5 mrg model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0); 853 1.5 mrg 854 1.5 mrg cpuid_avx = (feature_string[11] >> 4) & 1; 855 1.5 mrg cpuid_osxsave = (feature_string[11] >> 3) & 1; 856 1.5 mrg 857 1.5 mrg modelstr = "$guess_cpu"; 858 1.5 mrg 859 1.5 mrg /**************************************************/ 860 1.5 mrg /*** WARNING: keep this list in sync with fat.c ***/ 861 1.5 mrg /**************************************************/ 862 1.5 mrg if (strcmp (vendor_string, "GenuineIntel") == 0) 863 1.5 mrg { 864 1.5 mrg switch (family) 865 1.1 mrg { 866 1.5 mrg case 5: 867 1.5 mrg if (model == 4 || model == 8) modelstr = "pentiummmx"; 868 1.5 mrg else modelstr = "pentium"; 869 1.5 mrg break; 870 1.5 mrg case 6: 871 1.5 mrg if (model <= 1) modelstr = "pentiumpro"; 872 1.5 mrg else if (model <= 6) modelstr = "pentium2"; 873 1.5 mrg else if (model <= 8) modelstr = "pentium3"; 874 1.5 mrg else if (model <= 9) modelstr = "pentiumm"; 875 1.5 mrg else if (model <= 0x0c) modelstr = "pentium3"; 876 1.5 mrg else if (model <= 0x0e) modelstr = "pentiumm"; 877 1.5 mrg else if (model <= 0x19) cpu_64bit = 1, modelstr = "core2"; 878 1.5 mrg else if (model == 0x1a) cpu_64bit = 1, modelstr = "nehalem"; /* NHM Gainestown */ 879 1.5 mrg else if (model == 0x1c) cpu_64bit = 1, modelstr = "atom"; /* Silverthorne */ 880 1.5 mrg else if (model == 0x1d) cpu_64bit = 1, modelstr = "core2"; /* PNR Dunnington */ 881 1.5 mrg else if (model == 0x1e) cpu_64bit = 1, modelstr = "nehalem"; /* NHM Lynnfield/Jasper */ 882 1.5 mrg else if (model == 0x25) cpu_64bit = 1, modelstr = "westmere"; /* WSM Clarkdale/Arrandale */ 883 1.5 mrg else if (model == 0x26) cpu_64bit = 1, modelstr = "atom"; /* Lincroft */ 884 1.5 mrg else if (model == 0x27) cpu_64bit = 1, modelstr = "atom"; /* Saltwell */ 885 1.5 mrg else if (model == 0x2a) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SB */ 886 1.5 mrg else if (model == 0x2c) cpu_64bit = 1, modelstr = "westmere"; /* WSM Gulftown */ 887 1.5 mrg else if (model == 0x2d) cpu_64bit = 1, cpu_avx=1, modelstr = "sandybridge";/* SBC-EP */ 888 1.5 mrg else if (model == 0x2e) cpu_64bit = 1, modelstr = "nehalem"; /* NHM Beckton */ 889 1.5 mrg else if (model == 0x2f) cpu_64bit = 1, modelstr = "westmere"; /* WSM Eagleton */ 890 1.5 mrg else if (model == 0x36) cpu_64bit = 1, modelstr = "atom"; /* Cedarview/Saltwell */ 891 1.5 mrg else if (model == 0x37) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont */ 892 1.5 mrg else if (model == 0x3a) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge"; /* IBR */ 893 1.5 mrg else if (model == 0x3c) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Haswell client */ 894 1.5 mrg else if (model == 0x3d) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell */ 895 1.5 mrg else if (model == 0x3e) cpu_64bit = 1, cpu_avx=1, modelstr = "ivybridge"; /* Ivytown */ 896 1.5 mrg else if (model == 0x3f) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Haswell server */ 897 1.5 mrg else if (model == 0x45) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Haswell ULT */ 898 1.5 mrg else if (model == 0x46) cpu_64bit = 1, cpu_avx=1, modelstr = "haswell"; /* Crystal Well */ 899 1.5 mrg else if (model == 0x47) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell */ 900 1.5 mrg else if (model == 0x4a) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont */ 901 1.5 mrg else if (model == 0x4c) cpu_64bit = 1, modelstr = "silvermont"; /* Airmont */ 902 1.5 mrg else if (model == 0x4d) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont/Avoton */ 903 1.5 mrg else if (model == 0x4e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake"; /* Skylake client */ 904 1.5 mrg else if (model == 0x4f) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell server */ 905 1.5 mrg else if (model == 0x55) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake"; /* Skylake server */ 906 1.5 mrg else if (model == 0x56) cpu_64bit = 1, cpu_avx=1, modelstr = "broadwell"; /* Broadwell microserver */ 907 1.5 mrg else if (model == 0x57) cpu_64bit = 1, modelstr = "knightslanding"; /* aka Xeon Phi */ 908 1.5 mrg else if (model == 0x5a) cpu_64bit = 1, modelstr = "silvermont"; /* Silvermont */ 909 1.5 mrg else if (model == 0x5c) cpu_64bit = 1, modelstr = "goldmont"; /* Goldmont */ 910 1.5 mrg else if (model == 0x5e) cpu_64bit = 1, cpu_avx=1, modelstr = "skylake"; /* Skylake */ 911 1.5 mrg else if (model == 0x5f) cpu_64bit = 1, modelstr = "goldmont"; /* Goldmont */ 912 1.5 mrg else if (model == 0x7a) cpu_64bit = 1, modelstr = "goldmont"; /* Goldmont Plus */ 913 1.5 mrg else if (model == 0x8e) cpu_64bit = 1, cpu_avx=1, modelstr = "kabylake"; /* Kabylake Y/U */ 914 1.5 mrg else if (model == 0x9e) cpu_64bit = 1, cpu_avx=1, modelstr = "kabylake"; /* Kabylake desktop */ 915 1.5 mrg else cpu_64bit = 1, modelstr = "nehalem"; /* default */ 916 1.5 mrg 917 1.5 mrg if (strcmp (modelstr, "haswell") == 0 || 918 1.5 mrg strcmp (modelstr, "broadwell") == 0 || 919 1.5 mrg strcmp (modelstr, "skylake") == 0) 920 1.4 sevan { 921 1.5 mrg /* Some haswell, broadwell, skylake lack BMI2. Let them appear 922 1.5 mrg as sandybridge for now. */ 923 1.5 mrg CPUID (feature_string, 7); 924 1.5 mrg if ((feature_string[0 + 8 / 8] & (1 << (8 % 8))) == 0 925 1.5 mrg || gmp_workaround_skylake_cpuid_bug ()) 926 1.5 mrg modelstr = "sandybridge"; 927 1.4 sevan } 928 1.5 mrg 929 1.5 mrg break; 930 1.5 mrg case 15: 931 1.5 mrg cpu_64bit = 1, modelstr = "pentium4"; 932 1.5 mrg break; 933 1.5 mrg } 934 1.5 mrg } 935 1.5 mrg else if (strcmp (vendor_string, "AuthenticAMD") == 0) 936 1.5 mrg { 937 1.5 mrg switch (family) 938 1.5 mrg { 939 1.5 mrg case 5: 940 1.5 mrg if (model <= 3) modelstr = "k5"; 941 1.5 mrg else if (model <= 7) modelstr = "k6"; 942 1.5 mrg else if (model == 8) modelstr = "k62"; 943 1.5 mrg else if (model == 9) modelstr = "k63"; 944 1.5 mrg else if (model == 10) modelstr = "geode"; 945 1.5 mrg else if (model == 13) modelstr = "k63"; 946 1.5 mrg break; 947 1.5 mrg case 6: 948 1.5 mrg modelstr = "athlon"; 949 1.5 mrg break; 950 1.5 mrg case 15: /* K8, K9 */ 951 1.5 mrg cpu_64bit = 1, modelstr = "k8"; 952 1.5 mrg break; 953 1.5 mrg case 16: /* K10 */ 954 1.5 mrg cpu_64bit = 1, modelstr = "k10"; 955 1.5 mrg break; 956 1.5 mrg case 17: /* Hybrid k8/k10, claim k8 */ 957 1.5 mrg cpu_64bit = 1, modelstr = "k8"; 958 1.5 mrg break; 959 1.5 mrg case 18: /* Llano, uses K10 core */ 960 1.5 mrg cpu_64bit = 1, modelstr = "k10"; 961 1.5 mrg break; 962 1.5 mrg case 19: /* AMD Internal, assume future K10 */ 963 1.5 mrg cpu_64bit = 1, modelstr = "k10"; 964 1.5 mrg break; 965 1.5 mrg case 20: /* Bobcat */ 966 1.5 mrg cpu_64bit = 1, modelstr = "bobcat"; 967 1.5 mrg break; 968 1.5 mrg case 21: /* Bulldozer */ 969 1.5 mrg cpu_64bit = 1, cpu_avx = 1; 970 1.5 mrg if (model <= 1) 971 1.5 mrg modelstr = "bulldozer"; 972 1.5 mrg else if (model < 0x20) /* really 2, [0x10-0x20) */ 973 1.5 mrg modelstr = "piledriver"; 974 1.5 mrg else if (model < 0x40) /* really [0x30-0x40) */ 975 1.5 mrg modelstr = "steamroller"; 976 1.5 mrg else /* really [0x60-0x70) */ 977 1.5 mrg modelstr = "excavator"; 978 1.5 mrg break; 979 1.5 mrg case 22: /* Jaguar, an improved bobcat */ 980 1.5 mrg cpu_64bit = 1, cpu_avx = 1, modelstr = "jaguar"; 981 1.5 mrg break; 982 1.5 mrg case 23: /* Zen */ 983 1.5 mrg cpu_64bit = 1, cpu_avx = 1; 984 1.5 mrg switch (model) 985 1.5 mrg { 986 1.5 mrg case 1: 987 1.5 mrg case 8: 988 1.5 mrg case 17: 989 1.5 mrg case 24: 990 1.5 mrg modelstr = "zen"; 991 1.5 mrg break; 992 1.5 mrg default: 993 1.5 mrg modelstr = "zen2"; 994 1.5 mrg break; 995 1.7 mrg } 996 1.7 mrg break; 997 1.7 mrg case 25: /* Zen 3 */ 998 1.7 mrg cpu_64bit = 1, cpu_avx = 1; 999 1.7 mrg modelstr = "zen3"; 1000 1.7 mrg break; 1001 1.1 mrg } 1002 1.5 mrg } 1003 1.7 mrg else if (strcmp (vendor_string, "HygonGenuine") == 0) 1004 1.7 mrg { 1005 1.7 mrg cpu_64bit = 1, cpu_avx = 1; 1006 1.7 mrg modelstr = "zen"; 1007 1.7 mrg } 1008 1.5 mrg else if (strcmp (vendor_string, "CyrixInstead") == 0) 1009 1.5 mrg { 1010 1.5 mrg /* Should recognize Cyrix' processors too. */ 1011 1.5 mrg } 1012 1.5 mrg else if (strcmp (vendor_string, "CentaurHauls") == 0) 1013 1.5 mrg { 1014 1.5 mrg switch (family) 1015 1.5 mrg { 1016 1.5 mrg case 6: 1017 1.5 mrg if (model < 9) modelstr = "viac3"; 1018 1.5 mrg else if (model < 15) modelstr = "viac32"; 1019 1.5 mrg else cpu_64bit = 1, modelstr = "nano"; 1020 1.5 mrg break; 1021 1.5 mrg } 1022 1.5 mrg } 1023 1.5 mrg 1024 1.5 mrg CPUID (feature_string, 0x80000001); 1025 1.5 mrg cpuid_64bit = (feature_string[7] >> 5) & 1; 1026 1.5 mrg 1027 1.5 mrg suffix = ""; 1028 1.5 mrg 1029 1.5 mrg if (cpuid_64bit && ! cpu_64bit) 1030 1.5 mrg /* If our cpuid-based CPU identification thinks this is a 32-bit CPU but 1031 1.5 mrg cpuid claims AMD64 capabilities, then revert to the generic "x86_64". 1032 1.5 mrg This is of course wrong, but it can happen in some virtualisers and 1033 1.5 mrg emulators, and this workaround allows for successful 64-bit builds. */ 1034 1.5 mrg modelstr = "x86_64"; 1035 1.5 mrg else if (cpu_avx && ! (cpuid_avx && cpuid_osxsave)) 1036 1.5 mrg /* For CPUs nominally capable of executing AVX, append "noavx" when not 1037 1.5 mrg both the AVX and OSXSAVE cpuid bits are set. We tolerate weirdness 1038 1.5 mrg here, as some virtualisers set a broken cpuid state, while other 1039 1.5 mrg virtualisers allow guests to set a broken state. */ 1040 1.5 mrg suffix = "noavx"; 1041 1.5 mrg 1042 1.5 mrg printf ("%s%s", modelstr, suffix); 1043 1.5 mrg return 0; 1044 1.5 mrg } 1045 1.5 mrg EOF 1046 1.5 mrg 1047 1.5 mrg # The rcx/ecx zeroing here and in the variant below is needed for the BMI2 1048 1.5 mrg # check. 1049 1.5 mrg 1050 1.5 mrg cat <<EOF >${dummy}0.s 1051 1.5 mrg .globl cpuid 1052 1.5 mrg .globl _cpuid 1053 1.5 mrg cpuid: 1054 1.5 mrg _cpuid: 1055 1.5 mrg push %rbx 1056 1.5 mrg mov %rdx, %r8 1057 1.5 mrg mov %ecx, %eax 1058 1.5 mrg xor %ecx, %ecx 1059 1.5 mrg .byte 0x0f 1060 1.5 mrg .byte 0xa2 1061 1.5 mrg mov %ebx, (%r8) 1062 1.5 mrg mov %edx, 4(%r8) 1063 1.5 mrg mov %ecx, 8(%r8) 1064 1.5 mrg pop %rbx 1065 1.5 mrg ret 1066 1.1 mrg EOF 1067 1.5 mrg 1068 1.5 mrg if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then 1069 1.5 mrg # On 80386 and early 80486 cpuid is not available and will result in a 1070 1.5 mrg # SIGILL message, hence 2>/dev/null. 1071 1.5 mrg # 1072 1.5 mrg # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an 1073 1.5 mrg # "Illegal instruction (core dumped)" message to stdout, so we test $? 1074 1.5 mrg # to check if the program run was successful. 1075 1.5 mrg # 1076 1.5 mrg x=`$SHELL -c $dummy 2>/dev/null` 1077 1.5 mrg if test $? = 0 && test -n "$x"; then 1078 1.5 mrg exact_cpu=$x 1079 1.5 mrg fi 1080 1.5 mrg fi 1081 1.5 mrg 1082 1.5 mrg cat <<EOF >${dummy}0.s 1083 1.5 mrg .globl cpuid 1084 1.5 mrg .globl _cpuid 1085 1.5 mrg cpuid: 1086 1.5 mrg _cpuid: 1087 1.5 mrg pushl %esi 1088 1.5 mrg pushl %ebx 1089 1.5 mrg movl 24(%esp),%eax 1090 1.5 mrg xor %ecx, %ecx 1091 1.5 mrg .byte 0x0f 1092 1.5 mrg .byte 0xa2 1093 1.5 mrg movl 20(%esp),%esi 1094 1.5 mrg movl %ebx,(%esi) 1095 1.5 mrg movl %edx,4(%esi) 1096 1.5 mrg movl %ecx,8(%esi) 1097 1.5 mrg popl %ebx 1098 1.5 mrg popl %esi 1099 1.5 mrg ret 1100 1.4 sevan EOF 1101 1.5 mrg 1102 1.5 mrg if test -z "$exact_cpu"; then 1103 1.5 mrg if ($CC_FOR_BUILD ${dummy}0.s $dummy.c -o $dummy) >/dev/null 2>&1; then 1104 1.5 mrg # On 80386 and early 80486 cpuid is not available and will result in a 1105 1.5 mrg # SIGILL message, hence 2>/dev/null. 1106 1.5 mrg # 1107 1.5 mrg # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an 1108 1.5 mrg # "Illegal instruction (core dumped)" message to stdout, so we test $? 1109 1.5 mrg # to check if the program run was successful. 1110 1.5 mrg # 1111 1.5 mrg x=`$SHELL -c $dummy 2>/dev/null` 1112 1.5 mrg if test $? = 0 && test -n "$x"; then 1113 1.5 mrg exact_cpu=$x 1114 1.5 mrg fi 1115 1.5 mrg fi 1116 1.5 mrg fi 1117 1.5 mrg 1118 1.5 mrg # We need to remove some .o files here since lame C compilers 1119 1.5 mrg # generate these even when not asked. 1120 1.5 mrg ;; 1121 1.5 mrg 1122 1.5 mrg s390*-*-*) 1123 1.5 mrg if test -f /proc/cpuinfo; then 1124 1.5 mrg model=`grep "^processor 0: version =" /proc/cpuinfo | sed -e 's/.*machine = //'` 1125 1.5 mrg case $model in 1126 1.5 mrg 2064 | 2066) zcpu="z900" ;; 1127 1.5 mrg 2084 | 2086) zcpu="z990" ;; 1128 1.5 mrg 2094 | 2096) zcpu="z9" ;; 1129 1.5 mrg 2097 | 2098) zcpu="z10" ;; 1130 1.5 mrg 2817 | 2818 | *) zcpu="z196" ;; 1131 1.5 mrg esac 1132 1.5 mrg case "$guess_full" in 1133 1.5 mrg s390x-*-*) exact_cpu=${zcpu} ;; 1134 1.5 mrg s390-*-*) exact_cpu=${zcpu}esa ;; 1135 1.5 mrg esac 1136 1.5 mrg fi 1137 1.5 mrg ;; 1138 1.5 mrg 1139 1.1 mrg esac 1140 1.1 mrg 1141 1.1 mrg 1142 1.1 mrg 1143 1.5 mrg # ------------------------------------------------------------------------- 1144 1.5 mrg # Use an exact cpu, if possible 1145 1.5 mrg 1146 1.5 mrg if test -n "$exact_cpu"; then 1147 1.5 mrg echo "$exact_cpu$guess_rest" 1148 1.5 mrg else 1149 1.5 mrg echo "$guess_full" 1150 1.5 mrg fi 1151 1.5 mrg exit 0 1152 1.5 mrg 1153 1.5 mrg 1154 1.1 mrg 1155 1.1 mrg # Local variables: 1156 1.5 mrg # fill-column: 76 1157 1.1 mrg # End: 1158