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: Inst::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 //Non-temporal hint is ignored since we don't have 387 //proper support for it in the memory system. 388 0x3: MOVNTPS(Mq,Vq); 389 0x4: CVTTPS2PI(Pq,Wq); 390 0x5: CVTPS2PI(Pq,Wq); 391 0x6: UCOMISS(Vd,Wd); 392 0x7: COMISS(Vd,Wd); 393 } 394 // repe (0xF3) 395 0x4: decode OPCODE_OP_BOTTOM3 { 396 0x2: CVTSI2SS(Vd,Ed); 397 0x4: CVTTSS2SI(Gd,Wd); 398 0x5: CVTSS2SI(Gd,Wd); 399 default: UD2(); 400 } 401 // operand size (0x66) 402 0x1: decode OPCODE_OP_BOTTOM3 { 403 0x0: MOVAPD(Vo,Wo); 404 0x1: MOVAPD(Wo,Vo); 405 0x2: CVTPI2PD(Vo,Qq); 406 //Non-temporal hint is ignored since we don't have 407 //proper support for it in the memory system. 408 0x3: MOVNTPD(Mq,Vq); 409 0x4: CVTTPD2PI(Pq,Wo); 410 0x5: CVTPD2PI(Pq,Wo); 411 0x6: UCOMISD(Vq,Wq); 412 0x7: COMISD(Vq,Wq); 413 } 414 // repne (0xF2) 415 0x8: decode OPCODE_OP_BOTTOM3 { 416 // The size of the V operand should be q, not dp 417 0x2: CVTSI2SD(Vdp,Edp); 418 // The size of the W operand should be q, not dp 419 0x4: CVTTSD2SI(Gdp,Wdp); 420 0x5: CVTSD2SI(Gd,Wq); 421 default: UD2(); 422 } 423 default: UD2(); 424 } 425 } 426 0x06: decode OPCODE_OP_BOTTOM3 { 427 0x0: Inst::WRMSR(); 428 0x1: Inst::RDTSC(); 429 0x2: Inst::RDMSR(); 430 0x3: rdpmc(); 431 0x4: decode FullSystemInt { 432 0: SyscallInst::sysenter('xc->syscall(Rax, &fault)', 433 IsSyscall, IsNonSpeculative, 434 IsSerializeAfter); 435 default: sysenter(); 436 } 437 0x5: sysexit(); 438 0x6: Inst::UD2(); 439 0x7: getsec(); 440 } 441 0x07: decode OPCODE_OP_BOTTOM3 { 442 0x0: M5InternalError::error( 443 {{"Three byte opcode shouldn't be handled by " 444 "two_byte_opcodes.isa!"}}); 445 0x2: M5InternalError::error( 446 {{"Three byte opcode shouldn't be handled by " 447 "two_byte_opcodes.isa!"}}); 448 default: UD2(); 449 } 450 format Inst { 451 0x08: decode OPCODE_OP_BOTTOM3 { 452 0x0: CMOVO(Gv,Ev); 453 0x1: CMOVNO(Gv,Ev); 454 0x2: CMOVB(Gv,Ev); 455 0x3: CMOVNB(Gv,Ev); 456 0x4: CMOVZ(Gv,Ev); 457 0x5: CMOVNZ(Gv,Ev); 458 0x6: CMOVBE(Gv,Ev); 459 0x7: CMOVNBE(Gv,Ev); 460 } 461 0x09: decode OPCODE_OP_BOTTOM3 { 462 0x0: CMOVS(Gv,Ev); 463 0x1: CMOVNS(Gv,Ev); 464 0x2: CMOVP(Gv,Ev); 465 0x3: CMOVNP(Gv,Ev); 466 0x4: CMOVL(Gv,Ev); 467 0x5: CMOVNL(Gv,Ev); 468 0x6: CMOVLE(Gv,Ev); 469 0x7: CMOVNLE(Gv,Ev); 470 } 471 0x0A: decode LEGACY_DECODEVAL { 472 // no prefix 473 0x0: decode OPCODE_OP_BOTTOM3 { 474 0x0: MOVMSKPS(Gd,VRo); 475 0x1: SQRTPS(Vo,Wo); 476 0x2: WarnUnimpl::rqsrtps_Vo_Wo(); 477 0x3: RCPPS(Vo,Wo); 478 0x4: ANDPS(Vo,Wo); 479 0x5: ANDNPS(Vo,Wo); 480 0x6: ORPS(Vo,Wo); 481 0x7: XORPS(Vo,Wo); 482 } 483 // repe (0xF3) 484 0x4: decode OPCODE_OP_BOTTOM3 { 485 0x1: SQRTSS(Vd,Wd); 486 0x2: WarnUnimpl::rsqrtss_Vd_Wd(); 487 0x3: RCPSS(Vd,Wd); 488 default: UD2(); 489 } 490 // operand size (0x66) 491 0x1: decode OPCODE_OP_BOTTOM3 { 492 0x0: MOVMSKPD(Gd,VRo); 493 0x1: SQRTPD(Vo,Wo); 494 0x4: ANDPD(Vo,Wo); 495 0x5: ANDNPD(Vo,Wo); 496 0x6: ORPD(Vo,Wo); 497 0x7: XORPD(Vo,Wo); 498 default: UD2(); 499 } 500 // repne (0xF2) 501 0x8: decode OPCODE_OP_BOTTOM3 { 502 0x1: SQRTSD(Vq,Wq); 503 default: UD2(); 504 } 505 default: UD2(); 506 } 507 0x0B: decode LEGACY_DECODEVAL { 508 // no prefix 509 0x0: decode OPCODE_OP_BOTTOM3 { 510 0x0: ADDPS(Vo,Wo); 511 0x1: MULPS(Vo,Wo); 512 0x2: CVTPS2PD(Vo,Wq); 513 0x3: CVTDQ2PS(Vo,Wo); 514 0x4: SUBPS(Vo,Wo); 515 0x5: MINPS(Vo,Wo); 516 0x6: DIVPS(Vo,Wo); 517 0x7: MAXPS(Vo,Wo); 518 } 519 // repe (0xF3) 520 0x4: decode OPCODE_OP_BOTTOM3 { 521 0x0: ADDSS(Vd,Wd); 522 0x1: MULSS(Vd,Wd); 523 0x2: CVTSS2SD(Vq,Wd); 524 0x3: CVTTPS2DQ(Vo,Wo); 525 0x4: SUBSS(Vd,Wd); 526 0x5: MINSS(Vd,Wd); 527 0x6: DIVSS(Vd,Wd); 528 0x7: MAXSS(Vd,Wd); 529 } 530 // operand size (0x66) 531 0x1: decode OPCODE_OP_BOTTOM3 { 532 0x0: ADDPD(Vo,Wo); 533 0x1: MULPD(Vo,Wo); 534 0x2: CVTPD2PS(Vo,Wo); 535 0x3: CVTPS2DQ(Vo,Wo); 536 0x4: SUBPD(Vo,Wo); 537 0x5: MINPD(Vo,Wo); 538 0x6: DIVPD(Vo,Wo); 539 0x7: MAXPD(Vo,Wo); 540 } 541 // repne (0xF2) 542 0x8: decode OPCODE_OP_BOTTOM3 { 543 0x0: ADDSD(Vq,Wq); 544 0x1: MULSD(Vq,Wq); 545 0x2: CVTSD2SS(Vd,Wq); 546 0x4: SUBSD(Vq,Wq); 547 0x5: MINSD(Vq,Wq); 548 0x6: DIVSD(Vq,Wq); 549 0x7: MAXSD(Vq,Wq); 550 default: UD2(); 551 } 552 default: UD2(); 553 } 554 0x0C: decode LEGACY_DECODEVAL { 555 // no prefix 556 0x0: decode OPCODE_OP_BOTTOM3 { 557 0x0: PUNPCKLBW(Pq,Qd); 558 0x1: PUNPCKLWD(Pq,Qd); 559 0x2: PUNPCKLDQ(Pq,Qd); 560 0x3: PACKSSWB(Pq,Qq); 561 0x4: PCMPGTB(Pq,Qq); 562 0x5: PCMPGTW(Pq,Qq); 563 0x6: PCMPGTD(Pq,Qq); 564 0x7: PACKUSWB(Pq,Qq); 565 } 566 // operand size (0x66) 567 0x1: decode OPCODE_OP_BOTTOM3 { 568 0x0: PUNPCKLBW(Vo,Wq); 569 0x1: PUNPCKLWD(Vo,Wq); 570 0x2: PUNPCKLDQ(Vo,Wq); 571 0x3: PACKSSWB(Vo,Wo); 572 0x4: PCMPGTB(Vo,Wo); 573 0x5: PCMPGTW(Vo,Wo); 574 0x6: PCMPGTD(Vo,Wo); 575 0x7: PACKUSWB(Vo,Wo); 576 } 577 default: UD2(); 578 } 579 0x0D: decode LEGACY_DECODEVAL { 580 // no prefix 581 0x0: decode OPCODE_OP_BOTTOM3 { 582 0x0: PUNPCKHBW(Pq,Qq); 583 0x1: PUNPCKHWD(Pq,Qq); 584 0x2: PUNPCKHDQ(Pq,Qq); 585 0x3: PACKSSDW(Pq,Qq); 586 0x6: MOVD(Pq,Edp); 587 0x7: MOVQ(Pq,Qq); 588 default: UD2(); 589 } 590 // repe (0xF3) 591 0x4: decode OPCODE_OP_BOTTOM3 { 592 0x7: MOVDQU(Vo,Wo); 593 default: UD2(); 594 } 595 // operand size (0x66) 596 0x1: decode OPCODE_OP_BOTTOM3 { 597 0x0: PUNPCKHBW(Vo,Wo); 598 0x1: PUNPCKHWD(Vo,Wo); 599 0x2: PUNPCKHDQ(Vo,Wo); 600 0x3: PACKSSDW(Vo,Wo); 601 0x4: PUNPCKLQDQ(Vo,Wq); 602 0x5: PUNPCKHQDQ(Vo,Wq); 603 0x6: MOVD(Vo,Edp); 604 0x7: MOVDQA(Vo,Wo); 605 } 606 default: UD2(); 607 } 608 0x0E: decode LEGACY_DECODEVAL { 609 // no prefix 610 0x0: decode OPCODE_OP_BOTTOM3 { 611 0x0: PSHUFW(Pq,Qq,Ib); 612 //0x1: group12_pshimw(); 613 0x1: decode MODRM_REG { 614 0x2: PSRLW(PRq,Ib); 615 0x4: PSRAW(PRq,Ib); 616 0x6: PSLLW(PRq,Ib); 617 default: UD2(); 618 } 619 //0x2: group13_pshimd(); 620 0x2: decode MODRM_REG { 621 0x2: PSRLD(PRq,Ib); 622 0x4: PSRAD(PRq,Ib); 623 0x6: PSLLD(PRq,Ib); 624 default: UD2(); 625 } 626 //0x3: group14_pshimq(); 627 0x3: decode MODRM_REG { 628 0x2: PSRLQ(PRq,Ib); 629 0x6: PSLLQ(PRq,Ib); 630 default: Inst::UD2(); 631 } 632 0x4: Inst::PCMPEQB(Pq,Qq); 633 0x5: Inst::PCMPEQW(Pq,Qq); 634 0x6: Inst::PCMPEQD(Pq,Qq); 635 0x7: Inst::EMMS(); 636 } 637 // repe (0xF3) 638 0x4: decode OPCODE_OP_BOTTOM3 { 639 0x0: PSHUFHW(Vo,Wo,Ib); 640 default: UD2(); 641 } 642 // operand size (0x66) 643 0x1: decode OPCODE_OP_BOTTOM3 { 644 0x0: PSHUFD(Vo,Wo,Ib); 645 //0x1: group12_pshimw(); 646 0x1: decode MODRM_REG { 647 0x2: PSRLW(VRo,Ib); 648 0x4: PSRAW(VRo,Ib); 649 0x6: PSLLW(VRo,Ib); 650 } 651 //0x2: group13_pshimd(); 652 0x2: decode MODRM_REG { 653 0x2: PSRLD(VRo,Ib); 654 0x4: PSRAD(VRo,Ib); 655 0x6: PSLLD(VRo,Ib); 656 default: UD2(); 657 } 658 //0x3: group14_pshimq(); 659 0x3: decode MODRM_REG { 660 0x2: PSRLQ(VRo,Ib); 661 0x3: PSRLDQ(VRo,Ib); 662 0x6: PSLLQ(VRo,Ib); 663 0x7: PSLLDQ(VRo,Ib); 664 default: UD2(); 665 } 666 0x4: PCMPEQB(Vo,Wo); 667 0x5: PCMPEQW(Vo,Wo); 668 0x6: PCMPEQD(Vo,Wo); 669 default: UD2(); 670 } 671 // repne (0xF2) 672 0x8: decode OPCODE_OP_BOTTOM3 { 673 0x0: PSHUFLW(Vo,Wo,Ib); 674 default: UD2(); 675 } 676 default: UD2(); 677 } 678 0x0F: decode LEGACY_DECODEVAL { 679 // no prefix 680 0x0: decode OPCODE_OP_BOTTOM3 { 681 0x0: WarnUnimpl::vmread_Edp_Gdp(); 682 0x1: WarnUnimpl::vmwrite_Gdp_Edp(); 683 0x6: MOVD(Edp,Pdp); 684 0x7: MOVQ(Qq,Pq); 685 default: UD2(); 686 } 687 // repe (0xF3) 688 0x4: decode OPCODE_OP_BOTTOM3 { 689 0x6: MOVQ(Vq,Wq); 690 0x7: MOVDQU(Wo,Vo); 691 default: UD2(); 692 } 693 // operand size (0x66) 694 0x1: decode OPCODE_OP_BOTTOM3 { 695 0x4: HADDPD(Vo,Wo); 696 0x5: WarnUnimpl::hsubpd_Vo_Wo(); 697 0x6: MOVD(Edp,Vd); 698 0x7: MOVDQA(Wo,Vo); 699 default: UD2(); 700 } 701 // repne (0xF2) 702 0x8: decode OPCODE_OP_BOTTOM3 { 703 0x4: HADDPS(Vo,Wo); 704 0x5: WarnUnimpl::hsubps_Vo_Wo(); 705 default: UD2(); 706 } 707 default: UD2(); 708 } 709 0x10: decode OPCODE_OP_BOTTOM3 { 710 0x0: JO(Jz); 711 0x1: JNO(Jz); 712 0x2: JB(Jz); 713 0x3: JNB(Jz); 714 0x4: JZ(Jz); 715 0x5: JNZ(Jz); 716 0x6: JBE(Jz); 717 0x7: JNBE(Jz); 718 } 719 0x11: decode OPCODE_OP_BOTTOM3 { 720 0x0: JS(Jz); 721 0x1: JNS(Jz); 722 0x2: JP(Jz); 723 0x3: JNP(Jz); 724 0x4: JL(Jz); 725 0x5: JNL(Jz); 726 0x6: JLE(Jz); 727 0x7: JNLE(Jz); 728 } 729 0x12: decode OPCODE_OP_BOTTOM3 { 730 0x0: SETO(Eb); 731 0x1: SETNO(Eb); 732 0x2: SETB(Eb); 733 0x3: SETNB(Eb); 734 0x4: SETZ(Eb); 735 0x5: SETNZ(Eb); 736 0x6: SETBE(Eb); 737 0x7: SETNBE(Eb); 738 } 739 0x13: decode OPCODE_OP_BOTTOM3 { 740 0x0: SETS(Eb); 741 0x1: SETNS(Eb); 742 0x2: SETP(Eb); 743 0x3: SETNP(Eb); 744 0x4: SETL(Eb); 745 0x5: SETNL(Eb); 746 0x6: SETLE(Eb); 747 0x7: SETNLE(Eb); 748 } 749 } 750 0x14: decode OPCODE_OP_BOTTOM3 { 751 0x0: push_fs(); 752 0x1: pop_fs(); 753 0x2: CPUIDInst::CPUID({{ 754 CpuidResult result; 755 bool success = doCpuid(xc->tcBase(), bits(Rax, 31, 0), 756 bits(Rcx, 31, 0), result); 757 if (success) { 758 Rax = result.rax; 759 Rbx = result.rbx; 760 Rcx = result.rcx; 761 Rdx = result.rdx; 762 } else { 763 // It isn't defined what to do in this case. We used to 764 // leave R[abcd]x unmodified, but setting them all to 0 765 // seems a little safer and more predictable. 766 Rax = 0; 767 Rbx = 0; 768 Rcx = 0; 769 Rdx = 0; 770 } 771 }}); 772 0x3: Inst::BT(Ev,Gv); 773 0x4: Inst::SHLD(Ev,Gv,Ib); 774 0x5: Inst::SHLD(Ev,Gv); 775 default: Inst::UD2(); 776 } 777 0x15: decode OPCODE_OP_BOTTOM3 { 778 0x0: push_gs(); 779 0x1: pop_gs(); 780 0x2: rsm_smm(); 781 0x3: Inst::BTS(Ev,Gv); 782 0x4: Inst::SHRD(Ev,Gv,Ib); 783 0x5: Inst::SHRD(Ev,Gv); 784 //0x6: group15(); 785 0x6: decode MODRM_MOD { 786 0x3: decode MODRM_REG { 787 0x5: BasicOperate::LFENCE( 788 {{/*Nothing*/}}, IsReadBarrier); 789 0x6: BasicOperate::MFENCE( 790 {{/*Nothing*/}}, IsMemBarrier); 791 0x7: BasicOperate::SFENCE( 792 {{/*Nothing*/}}, IsWriteBarrier); 793 default: Inst::UD2(); 794 } 795 default: decode MODRM_REG { 796 0x0: decode OPSIZE { 797 4: Inst::FXSAVE(M); 798 8: Inst::FXSAVE64(M); 799 default: fxsave(); 800 } 801 0x1: decode OPSIZE { 802 4: Inst::FXRSTOR(M); 803 8: Inst::FXRSTOR64(M); 804 default: fxrstor(); 805 } 806 0x2: Inst::LDMXCSR(Md); 807 0x3: Inst::STMXCSR(Md); 808 0x4: xsave(); 809 0x5: xrstor(); 810 0x6: decode LEGACY_DECODEVAL { 811 0x0: Inst::UD2(); 812 0x1: Inst::CLWB(Mb); 813 default: Inst::UD2(); 814 } 815 0x7: decode LEGACY_DECODEVAL { 816 0x0: Inst::CLFLUSH(Mb); 817 0x1: Inst::CLFLUSHOPT(Mb); 818 default: Inst::CLFLUSH(Mb); 819 } 820 } 821 } 822 0x7: Inst::IMUL(Gv,Ev); 823 } 824 format Inst { 825 0x16: decode OPCODE_OP_BOTTOM3 { 826 0x0: CMPXCHG(Eb,Gb); 827 0x1: CMPXCHG(Ev,Gv); 828 0x2: WarnUnimpl::lss_Gz_Mp(); 829 0x3: BTR(Ev,Gv); 830 0x4: WarnUnimpl::lfs_Gz_Mp(); 831 0x5: WarnUnimpl::lgs_Gz_Mp(); 832 //The size of the second operand in these instructions 833 //should really be "b" or "w", but it's set to v in order 834 //to have a consistent register size. This shouldn't 835 //affect behavior. 836 0x6: MOVZX_B(Gv,Ev); 837 0x7: MOVZX_W(Gv,Ev); 838 } 839 0x17: decode OPCODE_OP_BOTTOM3 { 840 0x0: decode LEGACY_REP { 841 0x0: WarnUnimpl::jmpe_Jz(); 842 0x1: WarnUnimpl::popcnt_Gv_Ev(); 843 } 844 //0x1: group10_UD2(); 845 0x1: UD2(); 846 //0x2: group8_Ev_Ib(); 847 0x2: decode MODRM_REG { 848 0x4: BT(Ev,Ib); 849 0x5: BTS(Ev,Ib); 850 0x6: BTR(Ev,Ib); 851 0x7: BTC(Ev,Ib); 852 default: UD2(); 853 } 854 0x3: BTC(Ev,Gv); 855 0x4: BSF(Gv,Ev); 856 0x5: BSR(Gv,Ev); 857 //The size of the second operand in these instructions 858 //should really be "b" or "w", but it's set to v in order 859 //to have a consistent register size. This shouldn't 860 //affect behavior. 861 0x6: MOVSX_B(Gv,Ev); 862 0x7: MOVSX_W(Gv,Ev); 863 } 864 0x18: decode OPCODE_OP_BOTTOM3 { 865 0x0: XADD(Eb,Gb); 866 0x1: XADD(Ev,Gv); 867 //0x7: group9(); 868 0x7: decode MODRM_REG { 869 //Also CMPXCHG16B 870 0x1: CMPXCHG8B(Mdp); 871 0x6: decode LEGACY_OP { 872 0x1: WarnUnimpl::vmclear_Mq(); 873 default: decode LEGACY_REP { 874 0x1: WarnUnimpl::vmxon_Mq(); 875 0x0: WarnUnimpl::vmptrld_Mq(); 876 } 877 } 878 0x7: WarnUnimpl::vmptrst_Mq(); 879 default: UD2(); 880 } 881 default: decode LEGACY_DECODEVAL { 882 // no prefix 883 0x0: decode OPCODE_OP_BOTTOM3 { 884 0x2: CMPPS(Vo,Wo,Ib); 885 //Non-temporal hint is ignored since we don't have 886 //proper support for it in the memory system. 887 0x3: MOVNTI(Mdp,Gdp); 888 0x4: PINSRW(Pq,Ew,Ib); 889 0x5: PEXTRW(Gd,PRq,Ib); 890 0x6: SHUFPS(Vps,Wps,Ib); 891 } 892 // repe (0xF3) 893 0x4: decode OPCODE_OP_BOTTOM3 { 894 0x2: CMPSS(Vd,Wd,Ib); 895 default: UD2(); 896 } 897 // operand size (0x66) 898 0x1: decode OPCODE_OP_BOTTOM3 { 899 0x2: CMPPD(Vo,Wo,Ib); 900 0x4: PINSRW(Vdw,Ew,Ib); 901 0x5: PEXTRW(Gd,VRdq,Ib); 902 0x6: SHUFPD(Vpd,Wpd,Ib); 903 default: UD2(); 904 } 905 // repne (0xF2) 906 0x8: decode OPCODE_OP_BOTTOM3 { 907 0x2: CMPSD(Vq,Wq,Ib); 908 default: UD2(); 909 } 910 default: UD2(); 911 } 912 } 913 0x19: decode OPSIZE { 914 4: BSWAP_D(Bd); 915 8: BSWAP_Q(Bq); 916 default: UD2(); 917 } 918 0x1A: decode LEGACY_DECODEVAL { 919 // no prefix 920 0x0: decode OPCODE_OP_BOTTOM3 { 921 0x1: PSRLW(Pq,Qq); 922 0x2: PSRLD(Pq,Qq); 923 0x3: PSRLQ(Pq,Qq); 924 0x4: PADDQ(Pq,Qq); 925 0x5: PMULLW(Pq,Qq); 926 0x7: PMOVMSKB(Gd,PRq); 927 default: UD2(); 928 } 929 // repe (0xF3) 930 0x4: decode OPCODE_OP_BOTTOM3 { 931 0x6: MOVQ2DQ(Vo,PRq); 932 default: UD2(); 933 } 934 // operand size (0x66) 935 0x1: decode OPCODE_OP_BOTTOM3 { 936 0x0: ADDSUBPD(Vo,Wo); 937 0x1: PSRLW(Vo,Wo); 938 0x2: PSRLD(Vo,Wo); 939 0x3: PSRLQ(Vo,Wo); 940 0x4: PADDQ(Vo,Wo); 941 0x5: PMULLW(Vo,Wo); 942 0x6: MOVQ(Wq,Vq); 943 0x7: PMOVMSKB(Gd,VRo); 944 } 945 // repne (0xF2) 946 0x8: decode OPCODE_OP_BOTTOM3 { 947 0x0: WarnUnimpl::addsubps_Vo_Wo(); 948 0x6: MOVDQ2Q(Pq,VRq); 949 default: UD2(); 950 } 951 default: UD2(); 952 } 953 0x1B: decode LEGACY_DECODEVAL { 954 // no prefix 955 0x0: decode OPCODE_OP_BOTTOM3 { 956 0x0: PSUBUSB(Pq,Qq); 957 0x1: PSUBUSW(Pq,Qq); 958 0x2: PMINUB(Pq,Qq); 959 0x3: PAND(Pq,Qq); 960 0x4: PADDUSB(Pq,Qq); 961 0x5: PADDUSW(Pq,Qq); 962 0x6: PMAXUB(Pq,Qq); 963 0x7: PANDN(Pq,Qq); 964 } 965 // operand size (0x66) 966 0x1: decode OPCODE_OP_BOTTOM3 { 967 0x0: PSUBUSB(Vo,Wo); 968 0x1: PSUBUSW(Vo,Wo); 969 0x2: PMINUB(Vo,Wo); 970 0x3: PAND(Vo,Wo); 971 0x4: PADDUSB(Vo,Wo); 972 0x5: PADDUSW(Vo,Wo); 973 0x6: PMAXUB(Vo,Wo); 974 0x7: PANDN(Vo,Wo); 975 } 976 default: UD2(); 977 } 978 0x1C: decode LEGACY_DECODEVAL { 979 // no prefix 980 0x0: decode OPCODE_OP_BOTTOM3 { 981 0x0: PAVGB(Pq,Qq); 982 0x1: PSRAW(Pq,Qq); 983 0x2: PSRAD(Pq,Qq); 984 0x3: PAVGW(Pq,Qq); 985 0x4: PMULHUW(Pq,Qq); 986 0x5: PMULHW(Pq,Qq); 987 //Non-temporal hint is ignored since we don't have 988 //proper support for it in the memory system. 989 0x7: MOVNTQ(Mq,Pq); 990 default: UD2(); 991 } 992 // repe (0xF3) 993 0x4: decode OPCODE_OP_BOTTOM3 { 994 0x6: CVTDQ2PD(Vo,Wq); 995 default: UD2(); 996 } 997 // operand size (0x66) 998 0x1: decode OPCODE_OP_BOTTOM3 { 999 0x0: PAVGB(Vo,Wo); 1000 0x1: PSRAW(Vo,Wo); 1001 0x2: PSRAD(Vo,Wo); 1002 0x3: PAVGW(Vo,Wo); 1003 0x4: PMULHUW(Vo,Wo); 1004 0x5: PMULHW(Vo,Wo); 1005 0x6: CVTTPD2DQ(Vo,Wo); 1006 //MOVNTDQ should really use size o (octword), but 1007 //because it is split in two, we use q (quadword). 1008 //Non-temporal hint is ignored since we don't have 1009 //proper support for it in the memory system. 1010 0x7: MOVNTDQ(Mq,Vq); 1011 } 1012 // repne (0xF2) 1013 0x8: decode OPCODE_OP_BOTTOM3 { 1014 0x6: CVTPD2DQ(Vo,Wo); 1015 default: UD2(); 1016 } 1017 default: UD2(); 1018 } 1019 0x1D: decode LEGACY_DECODEVAL { 1020 // no prefix 1021 0x0: decode OPCODE_OP_BOTTOM3 { 1022 0x0: PSUBSB(Pq,Qq); 1023 0x1: PSUBSW(Pq,Qq); 1024 0x2: PMINSW(Pq,Qq); 1025 0x3: POR(Pq,Qq); 1026 0x4: PADDSB(Pq,Qq); 1027 0x5: PADDSW(Pq,Qq); 1028 0x6: PMAXSW(Pq,Qq); 1029 0x7: PXOR(Pq,Qq); 1030 } 1031 // operand size (0x66) 1032 0x1: decode OPCODE_OP_BOTTOM3 { 1033 0x0: PSUBSB(Vo,Wo); 1034 0x1: PSUBSW(Vo,Wo); 1035 0x2: PMINSW(Vo,Wo); 1036 0x3: POR(Vo,Wo); 1037 0x4: PADDSB(Vo,Wo); 1038 0x5: PADDSW(Vo,Wo); 1039 0x6: PMAXSW(Vo,Wo); 1040 0x7: PXOR(Vo,Wo); 1041 } 1042 default: UD2(); 1043 } 1044 0x1E: decode LEGACY_DECODEVAL { 1045 // no prefix 1046 0x0: decode OPCODE_OP_BOTTOM3 { 1047 0x1: PSLLW(Pq,Qq); 1048 0x2: PSLLD(Pq,Qq); 1049 0x3: PSLLQ(Pq,Qq); 1050 0x4: PMULUDQ(Pq,Qq); 1051 0x5: PMADDWD(Pq,Qq); 1052 0x6: PSADBW(Pq,Qq); 1053 0x7: MASKMOVQ(Pq,PRq); 1054 default: UD2(); 1055 } 1056 // operand size (0x66) 1057 0x1: decode OPCODE_OP_BOTTOM3 { 1058 0x1: PSLLW(Vo,Wo); 1059 0x2: PSLLD(Vo,Wo); 1060 0x3: PSLLQ(Vo,Wo); 1061 0x4: PMULUDQ(Vo,Wo); 1062 0x5: PMADDWD(Vo,Wo); 1063 0x6: PSADBW(Vo,Wo); 1064 0x7: MASKMOVDQU(Vo,VRo); 1065 default: UD2(); 1066 } 1067 // repne (0xF2) 1068 0x8: decode OPCODE_OP_BOTTOM3 { 1069 0x0: WarnUnimpl::lddqu_Vo_Mo(); 1070 default: UD2(); 1071 } 1072 default: UD2(); 1073 } 1074 0x1F: decode LEGACY_DECODEVAL { 1075 // no prefix 1076 0x0: decode OPCODE_OP_BOTTOM3 { 1077 0x0: PSUBB(Pq,Qq); 1078 0x1: PSUBW(Pq,Qq); 1079 0x2: PSUBD(Pq,Qq); 1080 0x3: PSUBQ(Pq,Qq); 1081 0x4: PADDB(Pq,Qq); 1082 0x5: PADDW(Pq,Qq); 1083 0x6: PADDD(Pq,Qq); 1084 0x7: UD2(); 1085 } 1086 // operand size (0x66) 1087 0x1: decode OPCODE_OP_BOTTOM3 { 1088 0x0: PSUBB(Vo,Wo); 1089 0x1: PSUBW(Vo,Wo); 1090 0x2: PSUBD(Vo,Wo); 1091 0x3: PSUBQ(Vo,Wo); 1092 0x4: PADDB(Vo,Wo); 1093 0x5: PADDW(Vo,Wo); 1094 0x6: PADDD(Vo,Wo); 1095 0x7: UD2(); 1096 } 1097 default: UD2(); 1098 } 1099 } 1100 default: FailUnimpl::twoByteOps(); 1101 } 1102} 1103