| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package x86asm |
| 6 |
|
| 7 |
import ( |
| 8 |
"bytes" |
| 9 |
"strings" |
| 10 |
"testing" |
| 11 |
) |
| 12 |
|
| 13 |
func TestObjdump32Manual(t *testing.T) { testObjdump32(t, hexCases(t, objdumpManualTests)) } |
| 14 |
func TestObjdump32Testdata(t *testing.T) { testObjdump32(t, concat(basicPrefixes, testdataCases(t))) } |
| 15 |
func TestObjdump32ModRM(t *testing.T) { testObjdump32(t, concat(basicPrefixes, enumModRM)) } |
| 16 |
func TestObjdump32OneByte(t *testing.T) { testBasic(t, testObjdump32) } |
| 17 |
func TestObjdump320F(t *testing.T) { testBasic(t, testObjdump32, 0x0F) } |
| 18 |
func TestObjdump320F38(t *testing.T) { testBasic(t, testObjdump32, 0x0F, 0x38) } |
| 19 |
func TestObjdump320F3A(t *testing.T) { testBasic(t, testObjdump32, 0x0F, 0x3A) } |
| 20 |
func TestObjdump32Prefix(t *testing.T) { testPrefix(t, testObjdump32) } |
| 21 |
|
| 22 |
func TestObjdump64Manual(t *testing.T) { testObjdump64(t, hexCases(t, objdumpManualTests)) } |
| 23 |
func TestObjdump64Testdata(t *testing.T) { testObjdump64(t, concat(basicPrefixes, testdataCases(t))) } |
| 24 |
func TestObjdump64ModRM(t *testing.T) { testObjdump64(t, concat(basicPrefixes, enumModRM)) } |
| 25 |
func TestObjdump64OneByte(t *testing.T) { testBasic(t, testObjdump64) } |
| 26 |
func TestObjdump640F(t *testing.T) { testBasic(t, testObjdump64, 0x0F) } |
| 27 |
func TestObjdump640F38(t *testing.T) { testBasic(t, testObjdump64, 0x0F, 0x38) } |
| 28 |
func TestObjdump640F3A(t *testing.T) { testBasic(t, testObjdump64, 0x0F, 0x3A) } |
| 29 |
func TestObjdump64Prefix(t *testing.T) { testPrefix(t, testObjdump64) } |
| 30 |
|
| 31 |
func TestObjdump64REXTestdata(t *testing.T) { |
| 32 |
testObjdump64(t, filter(concat3(basicPrefixes, rexPrefixes, testdataCases(t)), isValidREX)) |
| 33 |
} |
| 34 |
func TestObjdump64REXModRM(t *testing.T) { |
| 35 |
testObjdump64(t, concat3(basicPrefixes, rexPrefixes, enumModRM)) |
| 36 |
} |
| 37 |
func TestObjdump64REXOneByte(t *testing.T) { testBasicREX(t, testObjdump64) } |
| 38 |
func TestObjdump64REX0F(t *testing.T) { testBasicREX(t, testObjdump64, 0x0F) } |
| 39 |
func TestObjdump64REX0F38(t *testing.T) { testBasicREX(t, testObjdump64, 0x0F, 0x38) } |
| 40 |
func TestObjdump64REX0F3A(t *testing.T) { testBasicREX(t, testObjdump64, 0x0F, 0x3A) } |
| 41 |
func TestObjdump64REXPrefix(t *testing.T) { testPrefixREX(t, testObjdump64) } |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
var objdumpManualTests = ` |
| 47 |
4883FE017413 |
| 48 |
488DFC2500000000 |
| 49 |
488D3D00000000 |
| 50 |
` |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
func allowedMismatchObjdump(text string, size int, inst *Inst, dec ExtInst) bool { |
| 55 |
if size == 15 && dec.nenc == 15 && contains(text, "truncated") && contains(dec.text, "(bad)") { |
| 56 |
return true |
| 57 |
} |
| 58 |
|
| 59 |
if i := strings.LastIndex(dec.text, " "); isPrefix(dec.text[i+1:]) && size == 1 && isPrefix(text) { |
| 60 |
return true |
| 61 |
} |
| 62 |
|
| 63 |
if size == dec.nenc && contains(dec.text, "movupd") && contains(dec.text, "data32") { |
| 64 |
s := strings.Replace(dec.text, "data32 ", "", -1) |
| 65 |
if text == s { |
| 66 |
return true |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
if text == "error: unrecognized instruction" { |
| 72 |
text = "BAD" |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
if contains(dec.text, "%?", "<internal disassembler error>", "(8087 only)", "(287 only)") { |
| 81 |
dec.text = "(bad)" |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
i := bytes.IndexByte(dec.enc[:], 0x0F) |
| 88 |
if contains(dec.text, "nop") && i >= 0 && i+2 < len(dec.enc) && dec.enc[i+1]&^7 == 0x18 && (dec.enc[i+1] != 0x1F || (dec.enc[i+2]>>3)&7 != 0) { |
| 89 |
dec.text = "(bad)" |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
if text == "BAD" && contains(dec.text, "(bad)") { |
| 94 |
return true |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
if (text == "BAD" || size == 1 && isPrefix(text)) && hasPrefix(dec.text, unsupported...) { |
| 99 |
return true |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
if (contains(dec.text, "(bad)") || dec.nenc == 1 && isPrefix(dec.text)) && hasPrefix(text, libopcodesUnsupported...) { |
| 104 |
return true |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
if (contains(dec.text, "(bad)") || dec.nenc == 1 && isPrefix(dec.text)) && inst.Opcode>>24 == 0x90 && countPrefix(inst, 0xF2) > 0 { |
| 109 |
return true |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
if (contains(dec.text, "(bad)") || dec.nenc == 1 && isPrefix(dec.text)) && contains(text, "%cr", "%db", "%tr") { |
| 116 |
return true |
| 117 |
} |
| 118 |
|
| 119 |
if contains(dec.text, "fwait") && dec.nenc == 1 && dec.enc[0] != 0x9B { |
| 120 |
return true |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
if (text == "fwait" || strings.HasSuffix(text, " fwait")) && dec.nenc >= len(strings.Fields(text)) && dec.enc[len(strings.Fields(text))-1] == 0x9B { |
| 128 |
return true |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
if text == "BAD" && contains(dec.text, "nop/reserved") { |
| 135 |
return true |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
if contains(text, "rdrand") && contains(dec.text, "vmptrld", "vmxon", "vmclear") { |
| 141 |
return true |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
if text == "BAD" && contains(dec.text, "fnop") && (dec.enc[0] != 0xD9 || dec.enc[1] != 0xD0) { |
| 147 |
return true |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
if contains(text, "nop") && contains(dec.text, "xchg %ax,%ax") { |
| 154 |
return true |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
if size == 1 && dec.nenc == 1 && prefixByte[text] > 0 && prefixByte[text] == prefixByte[dec.text] { |
| 159 |
return true |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
if size == 1 && dec.nenc >= 1 && prefixByte[text] == dec.enc[0] && contains(dec.text, "(bad)", "fwait", "fnop") { |
| 166 |
return true |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
if contains(text, ".+0x2211", ".+0x11") && contains(dec.text, " .-") { |
| 172 |
return true |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
if countPrefix(inst, 0x66) > 0 && contains(dec.text, "movdq2q", "movq2dq") && !contains(dec.text, "%mm") { |
| 178 |
return true |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
if (text == "BAD" || size == 1 && isPrefix(text)) && contains(dec.text, "swapgs", "syscall", "sysret", "rdfsbase", "rdgsbase", "wrfsbase", "wrgsbase") { |
| 183 |
return true |
| 184 |
} |
| 185 |
|
| 186 |
return false |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
var unsupported = strings.Fields(` |
| 192 |
bndc |
| 193 |
bndl |
| 194 |
bndm |
| 195 |
bnds |
| 196 |
clac |
| 197 |
clgi |
| 198 |
femms |
| 199 |
fldln |
| 200 |
getsec |
| 201 |
invlpga |
| 202 |
kmov |
| 203 |
montmul |
| 204 |
pavg |
| 205 |
pf2i |
| 206 |
pfacc |
| 207 |
pfadd |
| 208 |
pfcmp |
| 209 |
pfmax |
| 210 |
pfmin |
| 211 |
pfmul |
| 212 |
pfna |
| 213 |
pfpnac |
| 214 |
pfrc |
| 215 |
pfrs |
| 216 |
pfsub |
| 217 |
phadd |
| 218 |
phsub |
| 219 |
pi2f |
| 220 |
pmulhr |
| 221 |
prefetch |
| 222 |
pswap |
| 223 |
ptest |
| 224 |
rdseed |
| 225 |
skinit |
| 226 |
stac |
| 227 |
stgi |
| 228 |
vadd |
| 229 |
vand |
| 230 |
vcmp |
| 231 |
vcomis |
| 232 |
vcvt |
| 233 |
vcvt |
| 234 |
vdiv |
| 235 |
vhadd |
| 236 |
vhsub |
| 237 |
vld |
| 238 |
vmax |
| 239 |
vmcall |
| 240 |
vmfunc |
| 241 |
vmin |
| 242 |
vmlaunch |
| 243 |
vmload |
| 244 |
vmmcall |
| 245 |
vmov |
| 246 |
vmov |
| 247 |
vmov |
| 248 |
vmptrld |
| 249 |
vmptrst |
| 250 |
vmread |
| 251 |
vmresume |
| 252 |
vmrun |
| 253 |
vmsave |
| 254 |
vmul |
| 255 |
vmwrite |
| 256 |
vmxoff |
| 257 |
vor |
| 258 |
vpack |
| 259 |
vpadd |
| 260 |
vpand |
| 261 |
vpavg |
| 262 |
vpcmp |
| 263 |
vpcmp |
| 264 |
vpins |
| 265 |
vpmadd |
| 266 |
vpmax |
| 267 |
vpmin |
| 268 |
vpmul |
| 269 |
vpmul |
| 270 |
vpor |
| 271 |
vpsad |
| 272 |
vpshuf |
| 273 |
vpsll |
| 274 |
vpsra |
| 275 |
vpsrad |
| 276 |
vpsrl |
| 277 |
vpsub |
| 278 |
vpunp |
| 279 |
vpxor |
| 280 |
vrcp |
| 281 |
vrsqrt |
| 282 |
vshuf |
| 283 |
vsqrt |
| 284 |
vsub |
| 285 |
vucomis |
| 286 |
vunp |
| 287 |
vxor |
| 288 |
vzero |
| 289 |
xcrypt |
| 290 |
xsha1 |
| 291 |
xsha256 |
| 292 |
xstore-rng |
| 293 |
insertq |
| 294 |
extrq |
| 295 |
vmclear |
| 296 |
invvpid |
| 297 |
adox |
| 298 |
vmxon |
| 299 |
invept |
| 300 |
adcx |
| 301 |
vmclear |
| 302 |
prefetchwt1 |
| 303 |
enclu |
| 304 |
encls |
| 305 |
salc |
| 306 |
fstpnce |
| 307 |
fdisi8087_nop |
| 308 |
fsetpm287_nop |
| 309 |
feni8087_nop |
| 310 |
syscall |
| 311 |
sysret |
| 312 |
`) |
| 313 |
|
| 314 |
|
| 315 |
var libopcodesUnsupported = strings.Fields(` |
| 316 |
addsubps |
| 317 |
aes |
| 318 |
blend |
| 319 |
cvttpd2dq |
| 320 |
dpp |
| 321 |
extract |
| 322 |
haddps |
| 323 |
hsubps |
| 324 |
insert |
| 325 |
invpcid |
| 326 |
lddqu |
| 327 |
movmsk |
| 328 |
movnt |
| 329 |
movq2dq |
| 330 |
mps |
| 331 |
pack |
| 332 |
pblend |
| 333 |
pclmul |
| 334 |
pcmp |
| 335 |
pext |
| 336 |
phmin |
| 337 |
pins |
| 338 |
pmax |
| 339 |
pmin |
| 340 |
pmov |
| 341 |
pmovmsk |
| 342 |
pmul |
| 343 |
popcnt |
| 344 |
pslld |
| 345 |
psllq |
| 346 |
psllw |
| 347 |
psrad |
| 348 |
psraw |
| 349 |
psrl |
| 350 |
ptest |
| 351 |
punpck |
| 352 |
round |
| 353 |
xrstor |
| 354 |
xsavec |
| 355 |
xsaves |
| 356 |
comis |
| 357 |
ucomis |
| 358 |
movhps |
| 359 |
movntps |
| 360 |
rsqrt |
| 361 |
rcpp |
| 362 |
puncpck |
| 363 |
bsf |
| 364 |
movq2dq |
| 365 |
cvttpd2dq |
| 366 |
movq |
| 367 |
hsubpd |
| 368 |
movdqa |
| 369 |
movhpd |
| 370 |
addsubpd |
| 371 |
movd |
| 372 |
haddpd |
| 373 |
cvtps2dq |
| 374 |
bsr |
| 375 |
cvtdq2ps |
| 376 |
rdrand |
| 377 |
maskmov |
| 378 |
movq2dq |
| 379 |
movlhps |
| 380 |
movbe |
| 381 |
movlpd |
| 382 |
`) |