Annotation of /trunk/depend-tools/analyse-x86
Parent Directory | Revision Log
Revision 414 -
(hide annotations)
(download)
Sun Jan 21 19:33:19 2007 UTC (17 years, 8 months ago) by niro
File size: 7706 byte(s)
Sun Jan 21 19:33:19 2007 UTC (17 years, 8 months ago) by niro
File size: 7706 byte(s)
new script: gets the minimal architecture of a binary to run with
1 | niro | 414 | #!/bin/sh |
2 | # | ||
3 | # Tavis Ormandy <taviso@gentoo.org> 2003 | ||
4 | # Improvments by Will Woods <wwoods@gentoo.org> | ||
5 | # | ||
6 | # Identify instruction set used in binary. | ||
7 | # | ||
8 | ################## | ||
9 | |||
10 | # ksh massively out performs bash. | ||
11 | if test -x /bin/ksh -a "$BASH_VERSION"; then | ||
12 | exec /bin/ksh "$0" "$@" | ||
13 | fi | ||
14 | |||
15 | # initialize everything to zero. | ||
16 | eval {i486,i586,ppro,mmx,sse,sse2,amd,amd2,cpuid}=0 | ||
17 | |||
18 | # unfortunately there are mnemonic collissions between vendor sets | ||
19 | # so check vendor_id string, and enable relevant sets. | ||
20 | printf "Checking vendor_id string..." | ||
21 | if ! test "${1%=*}" == "--vendor"; then | ||
22 | case "`grep -Em1 '^vendor_id.*: ' /proc/cpuinfo | cut -d\" \" -f2`" in | ||
23 | *GenuineIntel*) vendor=intel; printf "GenuineIntel\n";; | ||
24 | *AuthenticAMD*) vendor=amd; printf "AuthenticAMD\n";; | ||
25 | *CyrixInstead*) vendor=cyrix; printf "CyrixInstead\n";; | ||
26 | *GenuineTMx86*) vendor=transmeta; printf "GenuineTMx86\n";; | ||
27 | *) vendor=other; printf "other\n";; | ||
28 | esac | ||
29 | else | ||
30 | # allow vendor to be overridden | ||
31 | vendor=${1#*=}; shift | ||
32 | printf "%s\n" $vendor | ||
33 | fi | ||
34 | |||
35 | # quick sanity tests. | ||
36 | if ! test "$1"; then | ||
37 | printf "usage: %s [--vendor=intel|amd|cyrix|transmeta] /path/to/binary\n" $0 1>&2 | ||
38 | exit 1 | ||
39 | elif ! test -e "$1"; then | ||
40 | printf "error: %s does not exist.\n" "$1" 1>&2 | ||
41 | exit 1 | ||
42 | elif ! test -r "$1"; then | ||
43 | printf "error: cant read %s.\n" "$1" 1>&2 | ||
44 | exit 1 | ||
45 | fi | ||
46 | |||
47 | printf "Disassembling %s, please wait...\n" $1 | ||
48 | |||
49 | # initialize screen output | ||
50 | case "$vendor" in | ||
51 | *intel*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ | ||
52 | $i486 $i586 $ppro $mmx $sse $sse2;; | ||
53 | *amd*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u 3dnow: %4u\r" \ | ||
54 | $i486 $i586 $ppro $mmx $sse $(($amd+$amd2));; | ||
55 | *cyrix*) printf "i486: %4u i586: %4u mmx: %4u\r" \ | ||
56 | $i486 $i586 $mmx;; | ||
57 | *transmeta*) printf "i486: %4u i586: %4u mmx: %4u\r" \ | ||
58 | $i486 $i586 $mmx;; | ||
59 | *) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ | ||
60 | $i486 $i586 $ppro $mmx $sse $sse2;; | ||
61 | esac | ||
62 | |||
63 | # do the disassembling. | ||
64 | |||
65 | # %cr{0,2,3,4} version | ||
66 | # objdump -d $1 | cut -f3 | | ||
67 | objdump -d $1 | cut -f3 | cut -d" " -f1 | ( | ||
68 | # %cr{0,2,3,4} version | ||
69 | # while read instruction operands; do | ||
70 | while read instruction; do | ||
71 | case "$instruction" in | ||
72 | "cmpxchg"|"xadd"|"bswap"|"invd"|"wbinvd"|"invlpg") let ++i486; print=1;; | ||
73 | "rdmsr"|"wrmsr"|"rdtsc"|"cmpxch8B"|"rsm") let ++i586; print=1;; | ||
74 | "cmovcc"|"fcmovcc"|"fcomi"|"fcomip"|"fucomi"|"fucomip"|"rdpmc"|"ud2") let ++ppro; print=1;; | ||
75 | "emms"|"movd"|"movq"|"packsswb"|"packssdw"|"packuswb"|"paddb"|"paddw"|"paddd"|"paddsb"|"paddsw"|"paddusb"|"paddusw"|"pand"|"pandn"|"pcmpeqb"|"pcmpeqw"|"pcmpeqd"|"pcmpgtb"|"pcmpgtw"|"pcmpgtd"|"pmaddwd"|"pmulhw"|"pmullw"|"por"|"psllw"|"pslld"|"psllq"|"psraw"|"psrad"|"psrlw"|"psrld"|"psrlq"|"psubb"|"psubw"|"psubd"|"psubsb"|"psubsw"|"psubusb"|"psubusw"|"punpckhbw"|"punpckhwd"|"punpckhdq"|"punpcklbw"|"punpcklwd"|"punpckldq"|"pxor") let ++mmx; print=1;; | ||
76 | "addps"|"addss"|"andnps"|"andps"|"cmpps"|"cmpss"|"comiss"|"cvtpi2ps"|"cvtps2pi"|"cvtsi2ss"|"cvtss2si"|"cvttps2pi"|"cvttss2si"|"divps"|"divss"|"fxrstor"|"fxsave"|"ldmxcsr"|"maxps"|"maxss"|"minps"|"minss"|"movaps"|"movhlps"|"movhps"|"movlhps"|"movlps"|"movmskps"|"movss"|"movups"|"mulps"|"mulss"|"orps"|"pavgb"|"pavgw"|"psadbw"|"rcpps"|"rcpss"|"rsqrtps"|"rsqrtss"|"shufps"|"sqrtps"|"sqrtss"|"stmxcsr"|"subps"|"subss"|"ucomiss"|"unpckhps"|"unpcklps"|"xorps"|"pextrw"|"pinsrw"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhuw"|"pshufw"|"maskmovq"|"movntps"|"movntq"|"prefetch"|"sfence") let ++sse; print=1;; | ||
77 | "addpd"|"addsd"|"andnpd"|"andpd"|"clflush"|"cmppd"|"cmpsd"|"comisd"|"cvtdq2pd"|"cvtdq2ps"|"cvtpd2pi"|"cvtpd2pq"|"cvtpd2ps"|"cvtpi2pd"|"cvtps2dq"|"cvtps2pd"|"cvtsd2si"|"cvtsd2ss"|"cvtsi2sd"|"cvtss2sd"|"cvttpd2pi"|"cvttpd2dq"|"cvttps2dq"|"cvttsd2si"|"divpd"|"divsd"|"lfence"|"maskmovdqu"|"maxpd"|"maxsd"|"mfence"|"minpd"|"minsd"|"movapd"|"movd"|"movdq2q"|"movdqa"|"movdqu"|"movhpd"|"movlpd"|"movmskpd"|"movntdq"|"movnti"|"movntpd"|"movq"|"movq2dq"|"movsd"|"movupd"|"mulpd"|"mulsd"|"orpd"|"packsswb"|"packssdw"|"packuswb"|"paddb"|"paddw"|"paddd"|"paddq"|"paddq"|"paddsb"|"paddsw"|"paddusb"|"paddusw"|"pand"|"pandn"|"pause"|"pavgb"|"pavgw"|"pcmpeqb"|"pcmpeqw"|"pcmpeqd"|"pcmpgtb"|"pcmpgtw"|"pcmpgtd"|"pextrw"|"pinsrw"|"pmaddwd"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhw"|"pmulhuw"|"pmullw"|"pmuludq"|"pmuludq"|"por"|"psadbw"|"pshufd"|"pshufhw"|"pshuflw"|"pslldq"|"psllw"|"pslld"|"psllq"|"psraw"|"psrad"|"psrldq"|"psrlw"|"psrld"|"psrlq"|"psubb"|"psubw"|"psubd"|"psubq"|"psubq"|"psubsb"|"psubsw"|"psubusb"|"psubusw"|"psubsb"|"punpckhbw"|"punpckhwd"|"punpckhdq"|"punpckhqdq"|"punpcklbw"|"punpcklwd"|"punpckldq"|"punpcklqdq"|"pxor"|"shufpd"|"sqrtpd"|"sqrtsd"|"subpd"|"subsd"|"ucomisd"|"unpckhpd"|"unpcklpd"|"xorpd") let ++sse2; print=1;; | ||
78 | "pavgusb"|"pfadd"|"pfsub"|"pfsubr"|"pfacc"|"pfcmpge"|"pfcmpgt"|"pfcmpeq"|"pfmin"|"pfmax"|"pi2fw"|"pi2fd"|"pf2iw"|"pf2id"|"pfrcp"|"pfrsqrt"|"pfmul"|"pfrcpit1"|"pfrsqit1"|"pfrcpit2"|"pmulhrw"|"pswapw"|"femms"|"prefetch") let ++amd; print=1;; | ||
79 | "pf2iw"|"pfnacc"|"pfpnacc"|"pi2fw"|"pswapd"|"maskmovq"|"movntq"|"pavgb"|"pavgw"|"pextrw"|"pinsrw"|"pmaxsw"|"pmaxub"|"pminsw"|"pminub"|"pmovmskb"|"pmulhuw"|"prefetchnta"|"prefetcht0"|"prefetcht1"|"prefetcht2"|"psadbw"|"pshufw"|"sfence") let ++amd2; print=1;; | ||
80 | "cpuid") let ++cpuid ++i586; print=1;; | ||
81 | # %cr{0,2,3,4} version | ||
82 | # "mov") [[ "$operands" == *%cr[0234]* ]] && let ++i586; print=1;; | ||
83 | esac | ||
84 | # check if screen needs updating. | ||
85 | if test "$print"; then | ||
86 | case "$vendor" in | ||
87 | *intel*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ | ||
88 | $i486 $i586 $ppro $mmx $sse $sse2;; | ||
89 | *amd*) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u 3dnow: %4u\r" \ | ||
90 | $i486 $i586 $ppro $mmx $sse $(($amd+$amd2));; | ||
91 | *cyrix*) printf "i486: %4u i586: %4u mmx: %4u\r" \ | ||
92 | $i486 $i586 $mmx;; | ||
93 | *transmeta*) printf "i486: %4u i586: %4u mmx: %4u\r" \ | ||
94 | $i486 $i586 $mmx;; | ||
95 | *) printf "i486: %4u i586: %4u ppro: %4u mmx: %4u sse: %4u sse2: %4u\r" \ | ||
96 | $i486 $i586 $ppro $mmx $sse $sse2;; | ||
97 | esac | ||
98 | unset print | ||
99 | fi | ||
100 | done | ||
101 | |||
102 | # print a newline | ||
103 | echo | ||
104 | |||
105 | # cpuid instruction could mean the application checks to see | ||
106 | # if an instruction is supported before executing it. This might | ||
107 | # mean it will work on anything over a pentium. | ||
108 | if test $cpuid -gt 0; then | ||
109 | printf "\nThis binary was found to contain the cpuid instruction.\n" | ||
110 | printf "It may be able to conditionally execute instructions if\n" | ||
111 | printf "they are supported on the host (i586+).\n\n" | ||
112 | fi | ||
113 | |||
114 | # print minimum required processor, if there are collissions | ||
115 | # use the vendor to decide what to print. | ||
116 | if test $sse2 -gt 0; then | ||
117 | subarch="Pentium IV (pentium4)" | ||
118 | elif test $sse -gt 0; then | ||
119 | if test "$vendor" == "intel"; then | ||
120 | subarch="Pentium III (pentium3)" | ||
121 | elif test "$vendor" == "amd"; then | ||
122 | subarch="AMD Athlon 4 (athlon-4)" | ||
123 | else | ||
124 | subarch="Pentium III (pentium3)" | ||
125 | fi | ||
126 | elif test "$vendor" == "amd" -a $amd2 -gt 0; then | ||
127 | subarch="AMD Athlon (athlon)" | ||
128 | elif test "$vendor" == "amd" -a $amd -gt 0; then | ||
129 | subarch="AMD K6 III (k6-3)" | ||
130 | elif test $mmx -gt 0; then | ||
131 | if test "$vendor" == "intel"; then | ||
132 | if test $ppro -gt 0; then | ||
133 | subarch="Pentium II (pentium2)" | ||
134 | else | ||
135 | subarch="Intel Pentium MMX [P55C] (pentium-mmx)" | ||
136 | fi | ||
137 | elif test "$vendor" == "amd"; then | ||
138 | subarch="AMD K6 (k6)" | ||
139 | elif test "$vendor" == "cyrix"; then | ||
140 | subarch="Cyrix 6x86MX / MII (pentium-mmx)" | ||
141 | else | ||
142 | subarch="Intel Pentium MMX [P55C] (pentium-mmx)" | ||
143 | fi | ||
144 | elif test $ppro -gt 0; then | ||
145 | subarch="Pentium Pro (i686 or pentiumpro)" | ||
146 | elif test $i586 -gt 0; then | ||
147 | subarch="Pentium or compatible (i586) (i586 or pentium)" | ||
148 | elif test $i486 -gt 0; then | ||
149 | subarch="80486 or comaptible (i486)" | ||
150 | else | ||
151 | subarch="80386 or compatible (i386)" | ||
152 | fi | ||
153 | |||
154 | # print message and exit. | ||
155 | printf "%s will run on %s or higher processor.\n" "$1" "$subarch"; ) |
Properties
Name | Value |
---|---|
svn:executable | * |