two_byte_opcodes.isa revision 12205:f29b67179a96
1// Copyright (c) 2007-2008 The Hewlett-Packard Development Company 2// Copyright (c) 2012-2013 AMD 3// All rights reserved. 4// 5// The license below extends only to copyright in the software and shall 6// not be construed as granting a license to any other intellectual 7// property including but not limited to intellectual property relating 8// to a hardware implementation of the functionality of the software 9// licensed hereunder. You may use the software subject to the license 10// terms below provided that you ensure that this notice is replicated 11// unmodified and in its entirety in all distributions of the software, 12// modified or unmodified, in source code or in binary form. 13// 14// Copyright (c) 2008 The Regents of The University of Michigan 15// All rights reserved. 16// 17// Redistribution and use in source and binary forms, with or without 18// modification, are permitted provided that the following conditions are 19// met: redistributions of source code must retain the above copyright 20// notice, this list of conditions and the following disclaimer; 21// redistributions in binary form must reproduce the above copyright 22// notice, this list of conditions and the following disclaimer in the 23// documentation and/or other materials provided with the distribution; 24// neither the name of the copyright holders nor the names of its 25// contributors may be used to endorse or promote products derived from 26// this software without specific prior written permission. 27// 28// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39// 40// Authors: Gabe Black 41 42//////////////////////////////////////////////////////////////////// 43// 44// Decode the two byte opcodes 45// 46'X86ISA::TwoByteOpcode': decode OPCODE_OP_TOP5 { 47 format WarnUnimpl { 48 0x00: decode OPCODE_OP_BOTTOM3 { 49 //0x00: group6(); 50 0x00: decode MODRM_REG { 51 0x0: sldt_Mw_or_Rv(); 52 0x1: str_Mw_or_Rv(); 53 0x2: Inst::LLDT(Ew); 54 0x3: Inst::LTR(Ew); 55 0x4: verr_Mw_or_Rv(); 56 0x5: verw_Mw_or_Rv(); 57 //0x6: jmpe_Ev(); // IA-64 58 default: Inst::UD2(); 59 } 60 //0x01: group7(); // Ugly, ugly, ugly... 61 0x01: decode MODRM_REG { 62 0x0: decode MODRM_MOD { 63 0x3: decode MODRM_RM { 64 0x1: vmcall(); 65 0x2: vmlaunch(); 66 0x3: vmresume(); 67 0x4: vmxoff(); 68 default: Inst::UD2(); 69 } 70 default: sgdt_Ms(); 71 } 72 0x1: decode MODRM_MOD { 73 0x3: decode MODRM_RM { 74 0x0: MonitorInst::monitor({{ 75 xc->armMonitor(Rax); 76 }}); 77 0x1: MwaitInst::mwait({{ 78 uint64_t m = 0; //mem 79 unsigned s = 0x8; //size 80 unsigned f = 0; //flags 81 readMemAtomic(xc, traceData, 82 xc->getAddrMonitor()->vAddr, 83 m, s, f); 84 xc->mwaitAtomic(xc->tcBase()); 85 MicroHalt hltObj(machInst, mnemonic, 0x0); 86 hltObj.execute(xc, traceData); 87 }}); 88 default: Inst::UD2(); 89 } 90 default: sidt_Ms(); 91 } 92 0x2: decode MODRM_MOD { 93 0x3: decode MODRM_RM { 94 0x0: xgetbv(); 95 0x1: xsetbv(); 96 } 97 default: decode MODE_SUBMODE { 98 0x0: Inst::LGDT(M); 99 default: decode OPSIZE { 100 // 16 bit operand sizes are special, but only 101 // in legacy and compatability modes. 102 0x2: Inst::LGDT_16(M); 103 default: Inst::LGDT(M); 104 } 105 } 106 } 107 0x3: decode MODRM_MOD { 108 0x3: decode MODRM_RM { 109 0x0: vmrun(); 110 0x1: vmmcall(); 111 0x2: vmload(); 112 0x3: vmsave(); 113 0x4: stgi(); 114 0x5: clgi(); 115 0x6: skinit(); 116 0x7: invlpga(); 117 } 118 default: decode MODE_SUBMODE { 119 0x0: Inst::LIDT(M); 120 default: decode OPSIZE { 121 // 16 bit operand sizes are special, but only 122 // in legacy and compatability modes. 123 0x2: Inst::LIDT_16(M); 124 default: Inst::LIDT(M); 125 } 126 } 127 } 128 0x4: decode MODRM_MOD { 129 0x3: Inst::SMSW(Rv); 130 default: Inst::SMSW(Mw); 131 } 132 0x6: Inst::LMSW(Ew); 133 0x7: decode MODRM_MOD { 134 0x3: decode MODRM_RM { 135 0x0: Inst::SWAPGS(); 136 0x1: rdtscp(); 137 default: Inst::UD2(); 138 } 139 default: Inst::INVLPG(M); 140 } 141 } 142 0x02: lar_Gv_Ew(); 143 0x03: lsl_Gv_Ew(); 144 // sandpile.org doesn't seem to know what this is...? We'll 145 // use it for pseudo instructions. We've got 16 bits of space 146 // to play with so there can be quite a few pseudo 147 // instructions. 148 //0x04: loadall_or_reset_or_hang(); 149 0x4: decode IMMEDIATE { 150 format BasicOperate { 151 0x00: m5arm({{ 152 PseudoInst::arm(xc->tcBase()); 153 }}, IsNonSpeculative); 154 0x01: m5quiesce({{ 155 PseudoInst::quiesce(xc->tcBase()); 156 }}, IsNonSpeculative, IsQuiesce); 157 0x02: m5quiesceNs({{ 158 PseudoInst::quiesceNs(xc->tcBase(), Rdi); 159 }}, IsNonSpeculative, IsQuiesce); 160 0x03: m5quiesceCycle({{ 161 PseudoInst::quiesceCycles(xc->tcBase(), Rdi); 162 }}, IsNonSpeculative, IsQuiesce); 163 0x04: m5quiesceTime({{ 164 Rax = PseudoInst::quiesceTime(xc->tcBase()); 165 }}, IsNonSpeculative); 166 0x07: m5rpns({{ 167 Rax = PseudoInst::rpns(xc->tcBase()); 168 }}, IsNonSpeculative); 169 0x21: m5exit({{ 170 PseudoInst::m5exit(xc->tcBase(), Rdi); 171 }}, IsNonSpeculative); 172 0x22: m5fail({{ 173 PseudoInst::m5fail(xc->tcBase(), Rdi, Rsi); 174 }}, IsNonSpeculative); 175 0x30: m5initparam({{ 176 Rax = PseudoInst::initParam(xc->tcBase(), Rdi, Rsi); 177 }}, IsNonSpeculative); 178 0x31: m5loadsymbol({{ 179 PseudoInst::loadsymbol(xc->tcBase()); 180 }}, IsNonSpeculative); 181 0x40: m5resetstats({{ 182 PseudoInst::resetstats(xc->tcBase(), Rdi, Rsi); 183 }}, IsNonSpeculative); 184 0x41: m5dumpstats({{ 185 PseudoInst::dumpstats(xc->tcBase(), Rdi, Rsi); 186 }}, IsNonSpeculative); 187 0x42: m5dumpresetstats({{ 188 PseudoInst::dumpresetstats(xc->tcBase(), Rdi, Rsi); 189 }}, IsNonSpeculative); 190 0x43: m5checkpoint({{ 191 PseudoInst::m5checkpoint(xc->tcBase(), Rdi, Rsi); 192 }}, IsNonSpeculative); 193 0x50: m5readfile({{ 194 Rax = PseudoInst::readfile( 195 xc->tcBase(), Rdi, Rsi, Rdx); 196 }}, IsNonSpeculative); 197 0x51: m5debugbreak({{ 198 PseudoInst::debugbreak(xc->tcBase()); 199 }}, IsNonSpeculative); 200 0x52: m5switchcpu({{ 201 PseudoInst::switchcpu(xc->tcBase()); 202 }}, IsNonSpeculative); 203 0x53: m5addsymbol({{ 204 PseudoInst::addsymbol(xc->tcBase(), Rdi, Rsi); 205 }}, IsNonSpeculative); 206 0x54: m5panic({{ 207 panic("M5 panic instruction called at pc = %#x.\n", 208 RIP); 209 }}, IsNonSpeculative); 210 0x55: m5reserved1({{ 211 warn("M5 reserved opcode 1 ignored.\n"); 212 }}, IsNonSpeculative); 213 0x56: m5reserved2({{ 214 warn("M5 reserved opcode 2 ignored.\n"); 215 }}, IsNonSpeculative); 216 0x57: m5reserved3({{ 217 warn("M5 reserved opcode 3 ignored.\n"); 218 }}, IsNonSpeculative); 219 0x58: m5reserved4({{ 220 warn("M5 reserved opcode 4 ignored.\n"); 221 }}, IsNonSpeculative); 222 0x59: m5reserved5({{ 223 warn("M5 reserved opcode 5 ignored.\n"); 224 }}, IsNonSpeculative); 225 0x5a: m5_work_begin({{ 226 PseudoInst::workbegin(xc->tcBase(), Rdi, Rsi); 227 }}, IsNonSpeculative); 228 0x5b: m5_work_end({{ 229 PseudoInst::workend(xc->tcBase(), Rdi, Rsi); 230 }}, IsNonSpeculative); 231 0x62: m5togglesync({{ 232 PseudoInst::togglesync(xc->tcBase()); 233 }}, IsNonSpeculative, IsQuiesce); 234 default: Inst::UD2(); 235 } 236 } 237 0x05: decode FullSystemInt { 238 0: SyscallInst::syscall('xc->syscall(Rax, &fault)', 239 IsSyscall, IsNonSpeculative, 240 IsSerializeAfter); 241 default: decode MODE_MODE { 242 0x0: decode MODE_SUBMODE { 243 0x0: Inst::SYSCALL_64(); 244 0x1: Inst::SYSCALL_COMPAT(); 245 } 246 0x1: Inst::SYSCALL_LEGACY(); 247 } 248 } 249 0x06: Inst::CLTS(); 250 0x07: decode MODE_SUBMODE { 251 0x0: decode OPSIZE { 252 // Return to 64 bit mode. 253 0x8: Inst::SYSRET_TO_64(); 254 // Return to compatibility mode. 255 default: Inst::SYSRET_TO_COMPAT(); 256 } 257 default: Inst::SYSRET_NON_64(); 258 } 259 } 260 0x01: decode OPCODE_OP_BOTTOM3 { 261 0x0: invd(); 262 0x1: wbinvd(); 263 0x2: Inst::UD2(); 264 0x3: Inst::UD2(); 265 0x4: Inst::UD2(); 266 0x5: Inst::PREFETCH(Mb); 267 0x6: FailUnimpl::femms(); 268 0x7: decode IMMEDIATE { 269 0x0C: pi2fw_Pq_Qq(); 270 0x0D: pi2fd_Pq_Qq(); 271 0x1C: pf2iw_Pq_Qq(); 272 0x1D: pf2id_Pq_Qq(); 273 0x8A: pfnacc_Pq_Qq(); 274 0x8E: pfpnacc_Pq_Qq(); 275 0x90: pfcmpge_Pq_Qq(); 276 0x94: pfmin_Pq_Qq(); 277 0x96: pfrcp_Pq_Qq(); 278 0x97: pfrsqrt_Pq_Qq(); 279 0x9A: Inst::PFSUB(Pq,Qq); 280 0x9E: pfadd_Pq_Qq(); 281 0xA0: pfcmpgt_Pq_Qq(); 282 0xA4: pfmax_Pq_Qq(); 283 0xA6: pfrcpit1_Pq_Qq(); 284 0xA7: pfrsqit1_Pq_Qq(); 285 0xAA: Inst::PFSUBR(Pq,Qq); 286 0xAE: pfacc_Pq_Qq(); 287 0xB0: pfcmpeq_Pq_Qq(); 288 0xB4: Inst::PFMUL(Pq,Qq); 289 0xB6: pfrcpit2_Pq_Qq(); 290 0xB7: Inst::PMULHRW(Pq,Qq); 291 0xBB: pswapd_Pq_Qq(); 292 0xBF: pavgusb_Pq_Qq(); 293 default: Inst::UD2(); 294 } 295 } 296 format Inst{ 297 0x02: decode LEGACY_DECODEVAL { 298 // no prefix 299 0x0: decode OPCODE_OP_BOTTOM3 { 300 0x0: MOVUPS(Vo,Wo); 301 0x1: MOVUPS(Wo,Vo); 302 0x2: decode MODRM_MOD { 303 0x3: MOVHLPS(Vps,VRq); 304 default: MOVLPS(Vps,Mq); 305 } 306 0x3: MOVLPS(Mq,Vps); 307 0x4: UNPCKLPS(Vps,Wq); 308 0x5: UNPCKHPS(Vps,Wq); 309 0x6: decode MODRM_MOD { 310 0x3: MOVLHPS(Vps,VRq); 311 default: MOVHPS(Vps,Mq); 312 } 313 0x7: MOVHPS(Mq,Vq); 314 } 315 // repe (0xF3) 316 0x4: decode OPCODE_OP_BOTTOM3 { 317 0x0: MOVSS(Vd,Wd); 318 0x1: MOVSS(Wd,Vd); 319 0x2: WarnUnimpl::movsldup_Vo_Wo(); 320 0x6: WarnUnimpl::movshdup_Vo_Wo(); 321 default: UD2(); 322 } 323 // operand size (0x66) 324 0x1: decode OPCODE_OP_BOTTOM3 { 325 0x0: MOVUPD(Vo,Wo); 326 0x1: MOVUPD(Wo,Vo); 327 0x2: MOVLPD(Vq,Mq); 328 0x3: MOVLPD(Mq,Vq); 329 0x4: UNPCKLPD(Vo,Wq); 330 0x5: UNPCKHPD(Vo,Wo); 331 0x6: MOVHPD(Vq,Mq); 332 0x7: MOVHPD(Mq,Vq); 333 } 334 // repne (0xF2) 335 0x8: decode OPCODE_OP_BOTTOM3 { 336 0x0: MOVSD(Vq,Wq); 337 0x1: MOVSD(Wq,Vq); 338 0x2: MOVDDUP(Vo,Wq); 339 default: UD2(); 340 } 341 default: UD2(); 342 } 343 0x03: decode OPCODE_OP_BOTTOM3 { 344 //group16(); 345 0x0: decode MODRM_REG { 346 0x0: WarnUnimpl::prefetch_nta(); 347 0x1: PREFETCH_T0(Mb); 348 0x2: WarnUnimpl::prefetch_t1(); 349 0x3: WarnUnimpl::prefetch_t2(); 350 default: HINT_NOP(); 351 } 352 0x1: HINT_NOP(); 353 0x2: HINT_NOP(); 354 0x3: HINT_NOP(); 355 0x4: HINT_NOP(); 356 0x5: HINT_NOP(); 357 0x6: HINT_NOP(); 358 0x7: HINT_NOP(); 359 } 360 0x04: decode LEGACY_DECODEVAL { 361 // no prefix 362 0x0: decode OPCODE_OP_BOTTOM3 { 363 0x0: CondInst::MOV( 364 {{isValidMiscReg(MISCREG_CR(MODRM_REG))}},Rd,Cd); 365 0x1: MOV(Rd,Dd); 366 0x2: CondInst::MOV( 367 {{isValidMiscReg(MISCREG_CR(MODRM_REG))}},Cd,Rd); 368 0x3: MOV(Dd,Rd); 369 default: UD2(); 370 } 371 // operand size (0x66) 372 0x1: decode OPCODE_OP_BOTTOM3 { 373 0x0: MOV(Rd,Cd); 374 0x2: MOV(Cd,Rd); 375 } 376 default: UD2(); 377 } 378 0x05: decode LEGACY_DECODEVAL { 379 // no prefix 380 0x0: decode OPCODE_OP_BOTTOM3 { 381 //These moves should really use size o (octword), but 382 //because they are split in two, they use q (quadword). 383 0x0: MOVAPS(Vq,Wq); 384 0x1: MOVAPS(Wq,Vq); 385 0x2: CVTPI2PS(Vq,Qq); 386 0x3: WarnUnimpl::movntps_Mo_Vo(); 387 0x4: CVTTPS2PI(Pq,Wq); 388 0x5: CVTPS2PI(Pq,Wq); 389 0x6: UCOMISS(Vd,Wd); 390 0x7: COMISS(Vd,Wd); 391 } 392 // repe (0xF3) 393 0x4: decode OPCODE_OP_BOTTOM3 { 394 0x2: CVTSI2SS(Vd,Ed); 395 0x4: CVTTSS2SI(Gd,Wd); 396 0x5: CVTSS2SI(Gd,Wd); 397 default: UD2(); 398 } 399 // operand size (0x66) 400 0x1: decode OPCODE_OP_BOTTOM3 { 401 0x0: MOVAPD(Vo,Wo); 402 0x1: MOVAPD(Wo,Vo); 403 0x2: CVTPI2PD(Vo,Qq); 404 0x3: WarnUnimpl::movntpd_Mo_Vo(); 405 0x4: CVTTPD2PI(Pq,Wo); 406 0x5: CVTPD2PI(Pq,Wo); 407 0x6: UCOMISD(Vq,Wq); 408 0x7: COMISD(Vq,Wq); 409 } 410 // repne (0xF2) 411 0x8: decode OPCODE_OP_BOTTOM3 { 412 // The size of the V operand should be q, not dp 413 0x2: CVTSI2SD(Vdp,Edp); 414 // The size of the W operand should be q, not dp 415 0x4: CVTTSD2SI(Gdp,Wdp); 416 0x5: CVTSD2SI(Gd,Wq); 417 default: UD2(); 418 } 419 default: UD2(); 420 } 421 } 422 0x06: decode OPCODE_OP_BOTTOM3 { 423 0x0: Inst::WRMSR(); 424 0x1: Inst::RDTSC(); 425 0x2: Inst::RDMSR(); 426 0x3: rdpmc(); 427 0x4: decode FullSystemInt { 428 0: SyscallInst::sysenter('xc->syscall(Rax, &fault)', 429 IsSyscall, IsNonSpeculative, 430 IsSerializeAfter); 431 default: sysenter(); 432 } 433 0x5: sysexit(); 434 0x6: Inst::UD2(); 435 0x7: getsec(); 436 } 437 0x07: decode OPCODE_OP_BOTTOM3 { 438 0x0: M5InternalError::error( 439 {{"Three byte opcode shouldn't be handled by " 440 "two_byte_opcodes.isa!"}}); 441 0x2: M5InternalError::error( 442 {{"Three byte opcode shouldn't be handled by " 443 "two_byte_opcodes.isa!"}}); 444 default: UD2(); 445 } 446 format Inst { 447 0x08: decode OPCODE_OP_BOTTOM3 { 448 0x0: CMOVO(Gv,Ev); 449 0x1: CMOVNO(Gv,Ev); 450 0x2: CMOVB(Gv,Ev); 451 0x3: CMOVNB(Gv,Ev); 452 0x4: CMOVZ(Gv,Ev); 453 0x5: CMOVNZ(Gv,Ev); 454 0x6: CMOVBE(Gv,Ev); 455 0x7: CMOVNBE(Gv,Ev); 456 } 457 0x09: decode OPCODE_OP_BOTTOM3 { 458 0x0: CMOVS(Gv,Ev); 459 0x1: CMOVNS(Gv,Ev); 460 0x2: CMOVP(Gv,Ev); 461 0x3: CMOVNP(Gv,Ev); 462 0x4: CMOVL(Gv,Ev); 463 0x5: CMOVNL(Gv,Ev); 464 0x6: CMOVLE(Gv,Ev); 465 0x7: CMOVNLE(Gv,Ev); 466 } 467 0x0A: decode LEGACY_DECODEVAL { 468 // no prefix 469 0x0: decode OPCODE_OP_BOTTOM3 { 470 0x0: MOVMSKPS(Gd,VRo); 471 0x1: SQRTPS(Vo,Wo); 472 0x2: WarnUnimpl::rqsrtps_Vo_Wo(); 473 0x3: RCPPS(Vo,Wo); 474 0x4: ANDPS(Vo,Wo); 475 0x5: ANDNPS(Vo,Wo); 476 0x6: ORPS(Vo,Wo); 477 0x7: XORPS(Vo,Wo); 478 } 479 // repe (0xF3) 480 0x4: decode OPCODE_OP_BOTTOM3 { 481 0x1: SQRTSS(Vd,Wd); 482 0x2: WarnUnimpl::rsqrtss_Vd_Wd(); 483 0x3: RCPSS(Vd,Wd); 484 default: UD2(); 485 } 486 // operand size (0x66) 487 0x1: decode OPCODE_OP_BOTTOM3 { 488 0x0: MOVMSKPD(Gd,VRo); 489 0x1: SQRTPD(Vo,Wo); 490 0x4: ANDPD(Vo,Wo); 491 0x5: ANDNPD(Vo,Wo); 492 0x6: ORPD(Vo,Wo); 493 0x7: XORPD(Vo,Wo); 494 default: UD2(); 495 } 496 // repne (0xF2) 497 0x8: decode OPCODE_OP_BOTTOM3 { 498 0x1: SQRTSD(Vq,Wq); 499 default: UD2(); 500 } 501 default: UD2(); 502 } 503 0x0B: decode LEGACY_DECODEVAL { 504 // no prefix 505 0x0: decode OPCODE_OP_BOTTOM3 { 506 0x0: ADDPS(Vo,Wo); 507 0x1: MULPS(Vo,Wo); 508 0x2: CVTPS2PD(Vo,Wq); 509 0x3: CVTDQ2PS(Vo,Wo); 510 0x4: SUBPS(Vo,Wo); 511 0x5: MINPS(Vo,Wo); 512 0x6: DIVPS(Vo,Wo); 513 0x7: MAXPS(Vo,Wo); 514 } 515 // repe (0xF3) 516 0x4: decode OPCODE_OP_BOTTOM3 { 517 0x0: ADDSS(Vd,Wd); 518 0x1: MULSS(Vd,Wd); 519 0x2: CVTSS2SD(Vq,Wd); 520 0x3: CVTTPS2DQ(Vo,Wo); 521 0x4: SUBSS(Vd,Wd); 522 0x5: MINSS(Vd,Wd); 523 0x6: DIVSS(Vd,Wd); 524 0x7: MAXSS(Vd,Wd); 525 } 526 // operand size (0x66) 527 0x1: decode OPCODE_OP_BOTTOM3 { 528 0x0: ADDPD(Vo,Wo); 529 0x1: MULPD(Vo,Wo); 530 0x2: CVTPD2PS(Vo,Wo); 531 0x3: CVTPS2DQ(Vo,Wo); 532 0x4: SUBPD(Vo,Wo); 533 0x5: MINPD(Vo,Wo); 534 0x6: DIVPD(Vo,Wo); 535 0x7: MAXPD(Vo,Wo); 536 } 537 // repne (0xF2) 538 0x8: decode OPCODE_OP_BOTTOM3 { 539 0x0: ADDSD(Vq,Wq); 540 0x1: MULSD(Vq,Wq); 541 0x2: CVTSD2SS(Vd,Wq); 542 0x4: SUBSD(Vq,Wq); 543 0x5: MINSD(Vq,Wq); 544 0x6: DIVSD(Vq,Wq); 545 0x7: MAXSD(Vq,Wq); 546 default: UD2(); 547 } 548 default: UD2(); 549 } 550 0x0C: decode LEGACY_DECODEVAL { 551 // no prefix 552 0x0: decode OPCODE_OP_BOTTOM3 { 553 0x0: PUNPCKLBW(Pq,Qd); 554 0x1: PUNPCKLWD(Pq,Qd); 555 0x2: PUNPCKLDQ(Pq,Qd); 556 0x3: PACKSSWB(Pq,Qq); 557 0x4: PCMPGTB(Pq,Qq); 558 0x5: PCMPGTW(Pq,Qq); 559 0x6: PCMPGTD(Pq,Qq); 560 0x7: PACKUSWB(Pq,Qq); 561 } 562 // operand size (0x66) 563 0x1: decode OPCODE_OP_BOTTOM3 { 564 0x0: PUNPCKLBW(Vo,Wq); 565 0x1: PUNPCKLWD(Vo,Wq); 566 0x2: PUNPCKLDQ(Vo,Wq); 567 0x3: PACKSSWB(Vo,Wo); 568 0x4: PCMPGTB(Vo,Wo); 569 0x5: PCMPGTW(Vo,Wo); 570 0x6: PCMPGTD(Vo,Wo); 571 0x7: PACKUSWB(Vo,Wo); 572 } 573 default: UD2(); 574 } 575 0x0D: decode LEGACY_DECODEVAL { 576 // no prefix 577 0x0: decode OPCODE_OP_BOTTOM3 { 578 0x0: PUNPCKHBW(Pq,Qq); 579 0x1: PUNPCKHWD(Pq,Qq); 580 0x2: PUNPCKHDQ(Pq,Qq); 581 0x3: PACKSSDW(Pq,Qq); 582 0x6: MOVD(Pq,Edp); 583 0x7: MOVQ(Pq,Qq); 584 default: UD2(); 585 } 586 // repe (0xF3) 587 0x4: decode OPCODE_OP_BOTTOM3 { 588 0x7: MOVDQU(Vo,Wo); 589 default: UD2(); 590 } 591 // operand size (0x66) 592 0x1: decode OPCODE_OP_BOTTOM3 { 593 0x0: PUNPCKHBW(Vo,Wo); 594 0x1: PUNPCKHWD(Vo,Wo); 595 0x2: PUNPCKHDQ(Vo,Wo); 596 0x3: PACKSSDW(Vo,Wo); 597 0x4: PUNPCKLQDQ(Vo,Wq); 598 0x5: PUNPCKHQDQ(Vo,Wq); 599 0x6: MOVD(Vo,Edp); 600 0x7: MOVDQA(Vo,Wo); 601 } 602 default: UD2(); 603 } 604 0x0E: decode LEGACY_DECODEVAL { 605 // no prefix 606 0x0: decode OPCODE_OP_BOTTOM3 { 607 0x0: PSHUFW(Pq,Qq,Ib); 608 //0x1: group12_pshimw(); 609 0x1: decode MODRM_REG { 610 0x2: PSRLW(PRq,Ib); 611 0x4: PSRAW(PRq,Ib); 612 0x6: PSLLW(PRq,Ib); 613 default: UD2(); 614 } 615 //0x2: group13_pshimd(); 616 0x2: decode MODRM_REG { 617 0x2: PSRLD(PRq,Ib); 618 0x4: PSRAD(PRq,Ib); 619 0x6: PSLLD(PRq,Ib); 620 default: UD2(); 621 } 622 //0x3: group14_pshimq(); 623 0x3: decode MODRM_REG { 624 0x2: PSRLQ(PRq,Ib); 625 0x6: PSLLQ(PRq,Ib); 626 default: Inst::UD2(); 627 } 628 0x4: Inst::PCMPEQB(Pq,Qq); 629 0x5: Inst::PCMPEQW(Pq,Qq); 630 0x6: Inst::PCMPEQD(Pq,Qq); 631 0x7: Inst::EMMS(); 632 } 633 // repe (0xF3) 634 0x4: decode OPCODE_OP_BOTTOM3 { 635 0x0: PSHUFHW(Vo,Wo,Ib); 636 default: UD2(); 637 } 638 // operand size (0x66) 639 0x1: decode OPCODE_OP_BOTTOM3 { 640 0x0: PSHUFD(Vo,Wo,Ib); 641 //0x1: group12_pshimw(); 642 0x1: decode MODRM_REG { 643 0x2: PSRLW(VRo,Ib); 644 0x4: PSRAW(VRo,Ib); 645 0x6: PSLLW(VRo,Ib); 646 } 647 //0x2: group13_pshimd(); 648 0x2: decode MODRM_REG { 649 0x2: PSRLD(VRo,Ib); 650 0x4: PSRAD(VRo,Ib); 651 0x6: PSLLD(VRo,Ib); 652 default: UD2(); 653 } 654 //0x3: group14_pshimq(); 655 0x3: decode MODRM_REG { 656 0x2: PSRLQ(VRo,Ib); 657 0x3: PSRLDQ(VRo,Ib); 658 0x6: PSLLQ(VRo,Ib); 659 0x7: PSLLDQ(VRo,Ib); 660 default: UD2(); 661 } 662 0x4: PCMPEQB(Vo,Wo); 663 0x5: PCMPEQW(Vo,Wo); 664 0x6: PCMPEQD(Vo,Wo); 665 default: UD2(); 666 } 667 // repne (0xF2) 668 0x8: decode OPCODE_OP_BOTTOM3 { 669 0x0: PSHUFLW(Vo,Wo,Ib); 670 default: UD2(); 671 } 672 default: UD2(); 673 } 674 0x0F: decode LEGACY_DECODEVAL { 675 // no prefix 676 0x0: decode OPCODE_OP_BOTTOM3 { 677 0x0: WarnUnimpl::vmread_Edp_Gdp(); 678 0x1: WarnUnimpl::vmwrite_Gdp_Edp(); 679 0x6: MOVD(Edp,Pdp); 680 0x7: MOVQ(Qq,Pq); 681 default: UD2(); 682 } 683 // repe (0xF3) 684 0x4: decode OPCODE_OP_BOTTOM3 { 685 0x6: MOVQ(Vq,Wq); 686 0x7: MOVDQU(Wo,Vo); 687 default: UD2(); 688 } 689 // operand size (0x66) 690 0x1: decode OPCODE_OP_BOTTOM3 { 691 0x4: HADDPD(Vo,Wo); 692 0x5: WarnUnimpl::hsubpd_Vo_Wo(); 693 0x6: MOVD(Edp,Vd); 694 0x7: MOVDQA(Wo,Vo); 695 default: UD2(); 696 } 697 // repne (0xF2) 698 0x8: decode OPCODE_OP_BOTTOM3 { 699 0x4: HADDPS(Vo,Wo); 700 0x5: WarnUnimpl::hsubps_Vo_Wo(); 701 default: UD2(); 702 } 703 default: UD2(); 704 } 705 0x10: decode OPCODE_OP_BOTTOM3 { 706 0x0: JO(Jz); 707 0x1: JNO(Jz); 708 0x2: JB(Jz); 709 0x3: JNB(Jz); 710 0x4: JZ(Jz); 711 0x5: JNZ(Jz); 712 0x6: JBE(Jz); 713 0x7: JNBE(Jz); 714 } 715 0x11: decode OPCODE_OP_BOTTOM3 { 716 0x0: JS(Jz); 717 0x1: JNS(Jz); 718 0x2: JP(Jz); 719 0x3: JNP(Jz); 720 0x4: JL(Jz); 721 0x5: JNL(Jz); 722 0x6: JLE(Jz); 723 0x7: JNLE(Jz); 724 } 725 0x12: decode OPCODE_OP_BOTTOM3 { 726 0x0: SETO(Eb); 727 0x1: SETNO(Eb); 728 0x2: SETB(Eb); 729 0x3: SETNB(Eb); 730 0x4: SETZ(Eb); 731 0x5: SETNZ(Eb); 732 0x6: SETBE(Eb); 733 0x7: SETNBE(Eb); 734 } 735 0x13: decode OPCODE_OP_BOTTOM3 { 736 0x0: SETS(Eb); 737 0x1: SETNS(Eb); 738 0x2: SETP(Eb); 739 0x3: SETNP(Eb); 740 0x4: SETL(Eb); 741 0x5: SETNL(Eb); 742 0x6: SETLE(Eb); 743 0x7: SETNLE(Eb); 744 } 745 } 746 0x14: decode OPCODE_OP_BOTTOM3 { 747 0x0: push_fs(); 748 0x1: pop_fs(); 749 0x2: CPUIDInst::CPUID({{ 750 CpuidResult result; 751 bool success = doCpuid(xc->tcBase(), bits(Rax, 31, 0), 752 bits(Rcx, 31, 0), result); 753 if (success) { 754 Rax = result.rax; 755 Rbx = result.rbx; 756 Rcx = result.rcx; 757 Rdx = result.rdx; 758 } else { 759 Rax = Rax; 760 Rbx = Rbx; 761 Rcx = Rcx; 762 Rdx = Rdx; 763 } 764 }}); 765 0x3: Inst::BT(Ev,Gv); 766 0x4: Inst::SHLD(Ev,Gv,Ib); 767 0x5: Inst::SHLD(Ev,Gv); 768 default: Inst::UD2(); 769 } 770 0x15: decode OPCODE_OP_BOTTOM3 { 771 0x0: push_gs(); 772 0x1: pop_gs(); 773 0x2: rsm_smm(); 774 0x3: Inst::BTS(Ev,Gv); 775 0x4: Inst::SHRD(Ev,Gv,Ib); 776 0x5: Inst::SHRD(Ev,Gv); 777 //0x6: group15(); 778 0x6: decode MODRM_MOD { 779 0x3: decode MODRM_REG { 780 0x5: BasicOperate::LFENCE( 781 {{/*Nothing*/}}, IsReadBarrier); 782 0x6: BasicOperate::MFENCE( 783 {{/*Nothing*/}}, IsMemBarrier); 784 0x7: BasicOperate::SFENCE( 785 {{/*Nothing*/}}, IsWriteBarrier); 786 default: Inst::UD2(); 787 } 788 default: decode MODRM_REG { 789 0x0: decode OPSIZE { 790 4: Inst::FXSAVE(M); 791 8: Inst::FXSAVE64(M); 792 default: fxsave(); 793 } 794 0x1: decode OPSIZE { 795 4: Inst::FXRSTOR(M); 796 8: Inst::FXRSTOR64(M); 797 default: fxrstor(); 798 } 799 0x2: Inst::LDMXCSR(Md); 800 0x3: Inst::STMXCSR(Md); 801 0x4: xsave(); 802 0x5: xrstor(); 803 0x6: Inst::UD2(); 804 0x7: clflush(); 805 } 806 } 807 0x7: Inst::IMUL(Gv,Ev); 808 } 809 format Inst { 810 0x16: decode OPCODE_OP_BOTTOM3 { 811 0x0: CMPXCHG(Eb,Gb); 812 0x1: CMPXCHG(Ev,Gv); 813 0x2: WarnUnimpl::lss_Gz_Mp(); 814 0x3: BTR(Ev,Gv); 815 0x4: WarnUnimpl::lfs_Gz_Mp(); 816 0x5: WarnUnimpl::lgs_Gz_Mp(); 817 //The size of the second operand in these instructions 818 //should really be "b" or "w", but it's set to v in order 819 //to have a consistent register size. This shouldn't 820 //affect behavior. 821 0x6: MOVZX_B(Gv,Ev); 822 0x7: MOVZX_W(Gv,Ev); 823 } 824 0x17: decode OPCODE_OP_BOTTOM3 { 825 0x0: decode LEGACY_REP { 826 0x0: WarnUnimpl::jmpe_Jz(); 827 0x1: WarnUnimpl::popcnt_Gv_Ev(); 828 } 829 //0x1: group10_UD2(); 830 0x1: UD2(); 831 //0x2: group8_Ev_Ib(); 832 0x2: decode MODRM_REG { 833 0x4: BT(Ev,Ib); 834 0x5: BTS(Ev,Ib); 835 0x6: BTR(Ev,Ib); 836 0x7: BTC(Ev,Ib); 837 default: UD2(); 838 } 839 0x3: BTC(Ev,Gv); 840 0x4: BSF(Gv,Ev); 841 0x5: BSR(Gv,Ev); 842 //The size of the second operand in these instructions 843 //should really be "b" or "w", but it's set to v in order 844 //to have a consistent register size. This shouldn't 845 //affect behavior. 846 0x6: MOVSX_B(Gv,Ev); 847 0x7: MOVSX_W(Gv,Ev); 848 } 849 0x18: decode OPCODE_OP_BOTTOM3 { 850 0x0: XADD(Eb,Gb); 851 0x1: XADD(Ev,Gv); 852 //0x7: group9(); 853 0x7: decode MODRM_REG { 854 //Also CMPXCHG16B 855 0x1: CMPXCHG8B(Mdp); 856 0x6: decode LEGACY_OP { 857 0x1: WarnUnimpl::vmclear_Mq(); 858 default: decode LEGACY_REP { 859 0x1: WarnUnimpl::vmxon_Mq(); 860 0x0: WarnUnimpl::vmptrld_Mq(); 861 } 862 } 863 0x7: WarnUnimpl::vmptrst_Mq(); 864 default: UD2(); 865 } 866 default: decode LEGACY_DECODEVAL { 867 // no prefix 868 0x0: decode OPCODE_OP_BOTTOM3 { 869 0x2: CMPPS(Vo,Wo,Ib); 870 0x3: MOVNTI(Mdp,Gdp); 871 0x4: PINSRW(Pq,Ew,Ib); 872 0x5: PEXTRW(Gd,PRq,Ib); 873 0x6: SHUFPS(Vps,Wps,Ib); 874 } 875 // repe (0xF3) 876 0x4: decode OPCODE_OP_BOTTOM3 { 877 0x2: CMPSS(Vd,Wd,Ib); 878 default: UD2(); 879 } 880 // operand size (0x66) 881 0x1: decode OPCODE_OP_BOTTOM3 { 882 0x2: CMPPD(Vo,Wo,Ib); 883 0x4: PINSRW(Vdw,Ew,Ib); 884 0x5: PEXTRW(Gd,VRdq,Ib); 885 0x6: SHUFPD(Vpd,Wpd,Ib); 886 default: UD2(); 887 } 888 // repne (0xF2) 889 0x8: decode OPCODE_OP_BOTTOM3 { 890 0x2: CMPSD(Vq,Wq,Ib); 891 default: UD2(); 892 } 893 default: UD2(); 894 } 895 } 896 0x19: decode OPSIZE { 897 4: BSWAP_D(Bd); 898 8: BSWAP_Q(Bq); 899 default: UD2(); 900 } 901 0x1A: decode LEGACY_DECODEVAL { 902 // no prefix 903 0x0: decode OPCODE_OP_BOTTOM3 { 904 0x1: PSRLW(Pq,Qq); 905 0x2: PSRLD(Pq,Qq); 906 0x3: PSRLQ(Pq,Qq); 907 0x4: PADDQ(Pq,Qq); 908 0x5: PMULLW(Pq,Qq); 909 0x7: PMOVMSKB(Gd,PRq); 910 default: UD2(); 911 } 912 // repe (0xF3) 913 0x4: decode OPCODE_OP_BOTTOM3 { 914 0x6: MOVQ2DQ(Vo,PRq); 915 default: UD2(); 916 } 917 // operand size (0x66) 918 0x1: decode OPCODE_OP_BOTTOM3 { 919 0x0: ADDSUBPD(Vo,Wo); 920 0x1: PSRLW(Vo,Wo); 921 0x2: PSRLD(Vo,Wo); 922 0x3: PSRLQ(Vo,Wo); 923 0x4: PADDQ(Vo,Wo); 924 0x5: PMULLW(Vo,Wo); 925 0x6: MOVQ(Wq,Vq); 926 0x7: PMOVMSKB(Gd,VRo); 927 } 928 // repne (0xF2) 929 0x8: decode OPCODE_OP_BOTTOM3 { 930 0x0: WarnUnimpl::addsubps_Vo_Wo(); 931 0x6: MOVDQ2Q(Pq,VRq); 932 default: UD2(); 933 } 934 default: UD2(); 935 } 936 0x1B: decode LEGACY_DECODEVAL { 937 // no prefix 938 0x0: decode OPCODE_OP_BOTTOM3 { 939 0x0: PSUBUSB(Pq,Qq); 940 0x1: PSUBUSW(Pq,Qq); 941 0x2: PMINUB(Pq,Qq); 942 0x3: PAND(Pq,Qq); 943 0x4: PADDUSB(Pq,Qq); 944 0x5: PADDUSW(Pq,Qq); 945 0x6: PMAXUB(Pq,Qq); 946 0x7: PANDN(Pq,Qq); 947 } 948 // operand size (0x66) 949 0x1: decode OPCODE_OP_BOTTOM3 { 950 0x0: PSUBUSB(Vo,Wo); 951 0x1: PSUBUSW(Vo,Wo); 952 0x2: PMINUB(Vo,Wo); 953 0x3: PAND(Vo,Wo); 954 0x4: PADDUSB(Vo,Wo); 955 0x5: PADDUSW(Vo,Wo); 956 0x6: PMAXUB(Vo,Wo); 957 0x7: PANDN(Vo,Wo); 958 } 959 default: UD2(); 960 } 961 0x1C: decode LEGACY_DECODEVAL { 962 // no prefix 963 0x0: decode OPCODE_OP_BOTTOM3 { 964 0x0: PAVGB(Pq,Qq); 965 0x1: PSRAW(Pq,Qq); 966 0x2: PSRAD(Pq,Qq); 967 0x3: PAVGW(Pq,Qq); 968 0x4: PMULHUW(Pq,Qq); 969 0x5: PMULHW(Pq,Qq); 970 0x7: WarnUnimpl::movntq_Mq_Pq(); 971 default: UD2(); 972 } 973 // repe (0xF3) 974 0x4: decode OPCODE_OP_BOTTOM3 { 975 0x6: CVTDQ2PD(Vo,Wq); 976 default: UD2(); 977 } 978 // operand size (0x66) 979 0x1: decode OPCODE_OP_BOTTOM3 { 980 0x0: PAVGB(Vo,Wo); 981 0x1: PSRAW(Vo,Wo); 982 0x2: PSRAD(Vo,Wo); 983 0x3: PAVGW(Vo,Wo); 984 0x4: PMULHUW(Vo,Wo); 985 0x5: PMULHW(Vo,Wo); 986 0x6: CVTTPD2DQ(Vo,Wo); 987 0x7: WarnUnimpl::movntdq_Mo_Vo(); 988 } 989 // repne (0xF2) 990 0x8: decode OPCODE_OP_BOTTOM3 { 991 0x6: CVTPD2DQ(Vo,Wo); 992 default: UD2(); 993 } 994 default: UD2(); 995 } 996 0x1D: decode LEGACY_DECODEVAL { 997 // no prefix 998 0x0: decode OPCODE_OP_BOTTOM3 { 999 0x0: PSUBSB(Pq,Qq); 1000 0x1: PSUBSW(Pq,Qq); 1001 0x2: PMINSW(Pq,Qq); 1002 0x3: POR(Pq,Qq); 1003 0x4: PADDSB(Pq,Qq); 1004 0x5: PADDSW(Pq,Qq); 1005 0x6: PMAXSW(Pq,Qq); 1006 0x7: PXOR(Pq,Qq); 1007 } 1008 // operand size (0x66) 1009 0x1: decode OPCODE_OP_BOTTOM3 { 1010 0x0: PSUBSB(Vo,Wo); 1011 0x1: PSUBSW(Vo,Wo); 1012 0x2: PMINSW(Vo,Wo); 1013 0x3: POR(Vo,Wo); 1014 0x4: PADDSB(Vo,Wo); 1015 0x5: PADDSW(Vo,Wo); 1016 0x6: PMAXSW(Vo,Wo); 1017 0x7: PXOR(Vo,Wo); 1018 } 1019 default: UD2(); 1020 } 1021 0x1E: decode LEGACY_DECODEVAL { 1022 // no prefix 1023 0x0: decode OPCODE_OP_BOTTOM3 { 1024 0x1: PSLLW(Pq,Qq); 1025 0x2: PSLLD(Pq,Qq); 1026 0x3: PSLLQ(Pq,Qq); 1027 0x4: PMULUDQ(Pq,Qq); 1028 0x5: PMADDWD(Pq,Qq); 1029 0x6: PSADBW(Pq,Qq); 1030 0x7: MASKMOVQ(Pq,PRq); 1031 default: UD2(); 1032 } 1033 // operand size (0x66) 1034 0x1: decode OPCODE_OP_BOTTOM3 { 1035 0x1: PSLLW(Vo,Wo); 1036 0x2: PSLLD(Vo,Wo); 1037 0x3: PSLLQ(Vo,Wo); 1038 0x4: PMULUDQ(Vo,Wo); 1039 0x5: PMADDWD(Vo,Wo); 1040 0x6: PSADBW(Vo,Wo); 1041 0x7: MASKMOVDQU(Vo,VRo); 1042 default: UD2(); 1043 } 1044 // repne (0xF2) 1045 0x8: decode OPCODE_OP_BOTTOM3 { 1046 0x0: WarnUnimpl::lddqu_Vo_Mo(); 1047 default: UD2(); 1048 } 1049 default: UD2(); 1050 } 1051 0x1F: decode LEGACY_DECODEVAL { 1052 // no prefix 1053 0x0: decode OPCODE_OP_BOTTOM3 { 1054 0x0: PSUBB(Pq,Qq); 1055 0x1: PSUBW(Pq,Qq); 1056 0x2: PSUBD(Pq,Qq); 1057 0x3: PSUBQ(Pq,Qq); 1058 0x4: PADDB(Pq,Qq); 1059 0x5: PADDW(Pq,Qq); 1060 0x6: PADDD(Pq,Qq); 1061 0x7: UD2(); 1062 } 1063 // operand size (0x66) 1064 0x1: decode OPCODE_OP_BOTTOM3 { 1065 0x0: PSUBB(Vo,Wo); 1066 0x1: PSUBW(Vo,Wo); 1067 0x2: PSUBD(Vo,Wo); 1068 0x3: PSUBQ(Vo,Wo); 1069 0x4: PADDB(Vo,Wo); 1070 0x5: PADDW(Vo,Wo); 1071 0x6: PADDD(Vo,Wo); 1072 0x7: UD2(); 1073 } 1074 default: UD2(); 1075 } 1076 } 1077 default: FailUnimpl::twoByteOps(); 1078 } 1079} 1080