1 // Copyright (c) 2007 The Hewlett-Packard Development Company
2 // All rights reserved.
4 // Redistribution and use of this software in source and binary forms,
5 // with or without modification, are permitted provided that the
6 // following conditions are met:
8 // The software must be used only for Non-Commercial Use which means any
9 // use which is NOT directed to receiving any direct monetary
10 // compensation for, or commercial advantage from such use. Illustrative
11 // examples of non-commercial use are academic research, personal study,
12 // teaching, education and corporate research & development.
13 // Illustrative examples of commercial use are distributing products for
14 // commercial advantage and providing services using the software for
15 // commercial advantage.
17 // If you wish to use this software or functionality therein that may be
18 // covered by patents for commercial use, please contact:
19 // Director of Intellectual Property Licensing
20 // Office of Strategy and Technology
21 // Hewlett-Packard Company
22 // 1501 Page Mill Road
23 // Palo Alto, California 94304
25 // Redistributions of source code must retain the above copyright notice,
26 // this list of conditions and the following disclaimer. Redistributions
27 // in binary form must reproduce the above copyright notice, this list of
28 // conditions and the following disclaimer in the documentation and/or
29 // other materials provided with the distribution. Neither the name of
30 // the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31 // contributors may be used to endorse or promote products derived from
32 // this software without specific prior written permission. No right of
33 // sublicense is granted herewith. Derivatives of the software and
34 // output created using the software may be prepared, but only for
35 // Non-Commercial Uses. Derivatives of the software may be shared with
36 // others provided: (i) the others agree to abide by the list of
37 // conditions herein which includes the Non-Commercial Use restrictions;
38 // and (ii) such Derivatives of the software include the above copyright
39 // notice to acknowledge the contribution from this software where
40 // applicable, this list of conditions and the disclaimer below.
42 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 // Authors: Gabe Black
56 ////////////////////////////////////////////////////////////////////
58 // Decode the two byte opcodes
60 0x2: decode OPCODE_PREFIXA {
61 0x0F: decode OPCODE_OP_TOP5 {
63 0x00: decode OPCODE_OP_BOTTOM3 {
65 0x00: decode MODRM_REG {
72 //0x6: jmpe_Ev(); // IA-64
75 //0x01: group7(); // Ugly, ugly, ugly...
76 0x01: decode MODRM_MOD {
77 0x3: decode MODRM_REG {
78 0x0: decode MODRM_RM {
85 0x1: decode MODRM_RM {
90 0x3: decode MODRM_RM {
102 0x7: decode MODRM_RM {
105 default: Inst::UD2();
107 default: Inst::UD2();
109 default: decode MODRM_REG {
112 0x2: decode MODE_SUBMODE {
114 default: decode OPSIZE {
115 // 16 bit operand sizes are special, but only
116 // in legacy and compatability modes.
117 0x2: Inst::LGDT_16(M);
118 default: Inst::LGDT(M);
121 0x3: decode MODE_SUBMODE {
123 default: decode OPSIZE {
124 // 16 bit operand sizes are special, but only
125 // in legacy and compatability modes.
126 0x2: Inst::LIDT_16(M);
127 default: Inst::LIDT(M);
133 default: Inst::UD2();
138 //sandpile.org doesn't seem to know what this is... ?
139 0x04: loadall_or_reset_or_hang();
143 0x05: SyscallInst::syscall('xc->syscall(rax)', IsSyscall);
146 //sandpile.org says (AMD) after sysret, so I might want to check
147 //if that means amd64 or AMD machines
148 0x07: loadall_or_sysret();
150 0x01: decode OPCODE_OP_BOTTOM3 {
160 0x02: decode LEGACY_DECODEVAL {
162 0x0: decode OPCODE_OP_BOTTOM3 {
165 0x2: decode MODRM_MOD {
166 0x3: movhlps_Vq_VRq();
167 default: movlps_Vq_Mq();
172 0x6: decode MODRM_MOD {
173 0x3: movlhps_Vq_VRq();
174 default: movhps_Vq_Mq();
179 0x4: decode OPCODE_OP_BOTTOM3 {
182 0x2: movsldup_Vo_Wo();
183 0x6: movshdup_Vo_Wo();
184 default: Inst::UD2();
186 // operand size (0x66)
187 0x1: decode OPCODE_OP_BOTTOM3 {
190 0x2: Inst::MOVLPD(Vq,Mq);
191 0x3: Inst::MOVLPD(Mq,Vq);
192 0x4: unpcklpd_Vo_Wq();
193 0x5: unpckhpd_Vo_Wo();
198 0x8: decode OPCODE_OP_BOTTOM3 {
199 0x0: Inst::MOVSD(Vq,Wq);
200 0x1: Inst::MOVSD(Wq,Vq);
201 0x2: movddup_Vo_Wq();
202 default: Inst::UD2();
204 default: Inst::UD2();
206 0x03: decode OPCODE_OP_BOTTOM3 {
216 0x04: decode LEGACY_DECODEVAL {
218 0x0: decode OPCODE_OP_BOTTOM3 {
221 0x2: Inst::MOV(Cd,Rd);
225 default: Inst::UD2();
227 // lock prefix (0xF0)
228 0x2: decode OPCODE_OP_BOTTOM3 {
232 default: Inst::UD2();
234 0x05: decode LEGACY_DECODEVAL {
236 0x0: decode OPCODE_OP_BOTTOM3 {
237 //These moves should really use size o (octword), but
238 //because they are split in two, they use q (quadword).
239 0x0: Inst::MOVAPS(Vq,Wq);
240 0x1: Inst::MOVAPS(Wq,Vq);
241 0x2: decode MODRM_MOD {
242 0x3: cvtpi2pS_Vq_Pq();
243 default: cvtpi2ps_Vq_Mq();
245 0x3: movntps_Mo_Vo();
246 0x4: cvttps2pi_Pq_Wq();
247 0x5: cvtpS2pi_Pq_Wq();
248 0x6: ucomiss_Vd_Wd();
252 0x4: decode OPCODE_OP_BOTTOM3 {
253 0x2: cvtsi2ss_Vd_Ed();
254 0x4: cvttss2si_Gd_Wd();
255 0x5: cvtss2si_Gd_Wd();
256 default: Inst::UD2();
258 // operand size (0x66)
259 0x1: decode OPCODE_OP_BOTTOM3 {
262 0x2: decode MODRM_MOD {
263 0x3: cvtpi2pd_Vo_Pq();
264 default: cvtpi2pd_Vo_Mq();
266 0x3: movntpd_Mo_Vo();
267 0x4: cvttpd2pi_Pq_Wo();
268 0x5: cvtpd2pi_Pq_Wo();
269 0x6: Inst::UCOMISD(Vq,Wq);
273 0x8: decode OPCODE_OP_BOTTOM3 {
274 // The size of the V operand should be q, not dp
275 0x2: Inst::CVTSI2SD(Vdp,Edp);
276 // The size of the W operand should be q, not dp
277 0x4: Inst::CVTTSD2SI(Gdp,Wdp);
278 0x5: cvtsd2si_Gd_Wq();
279 default: Inst::UD2();
281 default: Inst::UD2();
283 0x06: decode OPCODE_OP_BOTTOM3 {
293 0x07: decode OPCODE_OP_BOTTOM3 {
294 0x0: three_byte_opcode();
295 0x1: three_byte_opcode();
296 0x2: three_byte_opcode();
297 0x3: three_byte_opcode();
298 0x4: three_byte_opcode();
299 0x5: three_byte_opcode();
300 0x6: three_byte_opcode();
301 0x7: three_byte_opcode();
304 0x08: decode OPCODE_OP_BOTTOM3 {
314 0x09: decode OPCODE_OP_BOTTOM3 {
325 0x0A: decode LEGACY_DECODEVAL {
327 0x0: decode OPCODE_OP_BOTTOM3 {
328 0x0: movmskps_Gd_VRo();
330 0x2: rqsrtps_Vo_Wo();
338 0x4: decode OPCODE_OP_BOTTOM3 {
340 0x2: rsqrtss_Vd_Wd();
342 default: Inst::UD2();
344 // operand size (0x66)
345 0x1: decode OPCODE_OP_BOTTOM3 {
346 0x0: movmskpd_Gd_VRo();
351 //This really should be type o, but it works on q sized
353 0x7: Inst::XORPD(Vq,Wq);
354 default: Inst::UD2();
358 0x8: decode OPCODE_OP_BOTTOM3 {
365 0x0B: decode LEGACY_DECODEVAL {
367 0x0: decode OPCODE_OP_BOTTOM3 {
370 0x2: cvtps2pd_Vo_Wq();
371 0x3: cvtdq2ps_Vo_Wo();
378 0x4: decode OPCODE_OP_BOTTOM3 {
381 0x2: cvtss2sd_Vq_Wd();
382 0x3: cvttps2dq_Vo_Wo();
388 // operand size (0x66)
389 0x1: decode OPCODE_OP_BOTTOM3 {
392 0x2: cvtpd2ps_Vo_Wo();
393 0x3: cvtps2dq_Vo_Wo();
400 0x8: decode OPCODE_OP_BOTTOM3 {
401 0x0: Inst::ADDSD(Vq,Wq);
402 0x1: Inst::MULSD(Vq,Wq);
403 0x2: cvtsd2ss_Vd_Wq();
404 0x4: Inst::SUBSD(Vq,Wq);
406 0x6: Inst::DIVSD(Vq,Wq);
408 default: Inst::UD2();
410 default: Inst::UD2();
412 0x0C: decode LEGACY_DECODEVAL {
414 0x0: decode OPCODE_OP_BOTTOM3 {
415 0x0: punpcklbw_Pq_Qd();
416 0x1: punpcklwd_Pq_Qd();
417 0x2: punpckldq_Pq_Qd();
418 0x3: packsswb_Pq_Qq();
419 0x4: pcmpgtb_Pq_Qq();
420 0x5: pcmpgtw_Pq_Qq();
421 0x6: pcmpgtd_Pq_Qq();
422 0x7: packuswb_Pq_Qq();
424 // operand size (0x66)
425 0x1: decode OPCODE_OP_BOTTOM3 {
426 0x0: punpcklbw_Vo_Wq();
427 0x1: punpcklwd_Vo_Wq();
428 0x2: punpckldq_Vo_Wq();
429 0x3: packsswb_Vo_Wo();
430 0x4: pcmpgtb_Vo_Wo();
431 0x5: pcmpgtw_Vo_Wo();
432 0x6: pcmpgtd_Vo_Wo();
433 0x7: packuswb_Vo_Wo();
435 default: Inst::UD2();
437 0x0D: decode LEGACY_DECODEVAL {
439 0x0: decode OPCODE_OP_BOTTOM3 {
440 0x0: punpckhbw_Pq_Qq();
441 0x1: punpckhwd_Pq_Qq();
442 0x2: punpckhdq_Pq_Qq();
443 0x3: packssdw_Pq_Qq();
446 default: Inst::UD2();
449 0x4: decode OPCODE_OP_BOTTOM3 {
451 default: Inst::UD2();
453 // operand size (0x66)
454 0x1: decode OPCODE_OP_BOTTOM3 {
455 0x0: punpckhbw_Vo_Wo();
456 0x1: punpckhwd_Vo_Wo();
457 0x2: punpckhdq_Vo_Wo();
458 0x3: packssdw_Vo_Wo();
459 0x4: punpcklqdq_Vo_Wq();
460 0x5: punpcklqdq_Vo_Wq();
464 default: Inst::UD2();
466 0x0E: decode LEGACY_DECODEVAL {
468 0x0: decode OPCODE_OP_BOTTOM3 {
469 0x0: pshufw_Pq_Qq_Ib();
470 //0x1: group13_pshimw();
471 0x1: decode MODRM_REG {
472 0x2: decode LEGACY_OP {
476 0x4: decode LEGACY_OP {
480 0x6: decode LEGACY_OP {
484 default: Inst::UD2();
486 //0x2: group14_pshimd();
487 0x2: decode MODRM_REG {
488 0x2: decode LEGACY_OP {
492 0x4: decode LEGACY_OP {
496 0x6: decode LEGACY_OP {
500 default: Inst::UD2();
502 //0x3: group15_pshimq();
503 0x3: decode MODRM_REG {
504 0x2: decode LEGACY_OP {
508 0x3: decode LEGACY_OP {
510 0x1: psrldq_VRo_Ib();
512 0x6: decode LEGACY_OP {
516 0x7: decode LEGACY_OP {
518 0x1: pslldq_VRo_Ib();
520 default: Inst::UD2();
522 0x4: pcmpeqb_Pq_Qq();
523 0x5: pcmpeqw_Pq_Qq();
524 0x6: pcmpeqd_Pq_Qq();
528 0x4: decode OPCODE_OP_BOTTOM3 {
529 0x0: pshufhw_Vo_Wo_Ib();
530 default: Inst::UD2();
532 // operand size (0x66)
533 0x1: decode OPCODE_OP_BOTTOM3 {
534 0x0: pshufd_Vo_Wo_Ib();
535 //0x1: group13_pshimw();
536 0x1: decode MODRM_REG {
537 0x2: decode LEGACY_OP {
541 0x4: decode LEGACY_OP {
545 0x6: decode LEGACY_OP {
549 default: Inst::UD2();
551 //0x2: group14_pshimd();
552 0x2: decode MODRM_REG {
553 0x2: decode LEGACY_OP {
557 0x4: decode LEGACY_OP {
561 0x6: decode LEGACY_OP {
565 default: Inst::UD2();
567 //0x3: group15_pshimq();
568 0x3: decode MODRM_REG {
569 0x2: decode LEGACY_OP {
573 0x3: decode LEGACY_OP {
575 0x1: psrldq_VRo_Ib();
577 0x6: decode LEGACY_OP {
581 0x7: decode LEGACY_OP {
583 0x1: pslldq_VRo_Ib();
585 default: Inst::UD2();
587 0x4: pcmpeqb_Vo_Wo();
588 0x5: pcmpeqw_Vo_Wo();
589 0x6: pcmpeqd_Vo_Wo();
590 default: Inst::UD2();
593 0x8: decode OPCODE_OP_BOTTOM3 {
594 0x0: pshuflw_Vo_Wo_Ib();
595 default: Inst::UD2();
597 default: Inst::UD2();
599 0x0F: decode LEGACY_DECODEVAL {
601 0x0: decode OPCODE_OP_BOTTOM3 {
602 0x0: vmread_Ed_or_Eq_Gd_or_Gq();
603 0x1: vmwrite_Gd_or_Gq_Ed_or_Eq();
606 default: Inst::UD2();
609 0x4: decode OPCODE_OP_BOTTOM3 {
610 0x6: movq_Vo_Mq_or_Vq_Vq();
612 default: Inst::UD2();
614 // operand size (0x66)
615 0x1: decode OPCODE_OP_BOTTOM3 {
620 default: Inst::UD2();
623 0x8: decode OPCODE_OP_BOTTOM3 {
626 default: Inst::UD2();
628 default: Inst::UD2();
631 0x10: decode OPCODE_OP_BOTTOM3 {
641 0x11: decode OPCODE_OP_BOTTOM3 {
651 0x12: decode OPCODE_OP_BOTTOM3 {
661 0x13: decode OPCODE_OP_BOTTOM3 {
672 0x14: decode OPCODE_OP_BOTTOM3 {
675 0x2: Inst::CPUID(rAd);
676 0x3: Inst::BT(Ev,Gv);
677 0x4: shld_Ev_Gv_Ib();
678 0x5: shld_Ev_Gv_rCl();
679 0x6: xbts_and_cmpxchg();
680 0x7: ibts_and_cmpxchg();
682 0x15: decode OPCODE_OP_BOTTOM3 {
686 0x3: Inst::BTS(Ev,Gv);
687 0x4: shrd_Ev_Gv_Ib();
688 0x5: shrd_Ev_Gv_rCl();
690 0x6: decode MODRM_MOD {
691 0x3: decode MODRM_REG {
695 default: Inst::UD2();
697 default: decode MODRM_REG {
701 default: Inst::UD2();
704 0x7: Inst::IMUL(Gv,Ev);
706 0x16: decode OPCODE_OP_BOTTOM3 {
707 0x0: Inst::CMPXCHG(Eb,Gb);
708 0x1: Inst::CMPXCHG(Ev,Gv);
710 0x3: Inst::BTR(Ev,Gv);
713 //The size of the second operand in these instructions should
714 //really be "b" or "w", but it's set to v in order to have a
715 //consistent register size. This shouldn't affect behavior.
716 0x6: Inst::MOVZX_B(Gv,Ev);
717 0x7: Inst::MOVZX_W(Gv,Ev);
719 0x17: decode OPCODE_OP_BOTTOM3 {
720 0x0: jmpe_Jz(); // IA-64?
722 //0x1: group11_UD2();
724 //0x2: group8_Ev_Ib();
725 0x2: decode MODRM_REG {
736 //The size of the second operand in these instructions should
737 //really be "b" or "w", but it's set to v in order to have a
738 //consistent register size. This shouldn't affect behavior.
739 0x6: Inst::MOVSX_B(Gv,Ev);
740 0x7: Inst::MOVSX_W(Gv,Ev);
742 0x18: decode OPCODE_OP_BOTTOM3 {
746 0x7: decode MODRM_REG {
748 0x6: decode LEGACY_OP {
750 default: decode LEGACY_REP {
756 default: Inst::UD2();
758 default: decode LEGACY_DECODEVAL {
760 0x0: decode OPCODE_OP_BOTTOM3 {
761 0x2: cmpccps_Vo_Wo_Ib();
762 0x3: cvtdq2ps_Vo_Wo();
768 0x4: decode OPCODE_OP_BOTTOM3 {
769 0x2: cmpccss_Vd_Wd_Ib();
770 default: Inst::UD2();
772 // operand size (0x66)
773 0x1: decode OPCODE_OP_BOTTOM3 {
774 0x2: cmpccpd_Vo_Wo_Ib();
778 default: Inst::UD2();
781 0x8: decode OPCODE_OP_BOTTOM3 {
782 0x2: cmpccsd_Vq_Wq_Ib();
783 default: Inst::UD2();
785 default: Inst::UD2();
789 0x1A: decode LEGACY_DECODEVAL {
791 0x0: decode OPCODE_OP_BOTTOM3 {
797 0x7: pmovmskb_Gd_PRq();
798 default: Inst::UD2();
801 0x4: decode OPCODE_OP_BOTTOM3 {
802 0x6: movq2dq_Vo_PRq();
803 default: Inst::UD2();
805 // operand size (0x66)
806 0x1: decode OPCODE_OP_BOTTOM3 {
807 0x0: addsubpd_Vo_Wo();
813 0x6: decode MODRM_MOD {
815 default: movq_Mq_Vq();
817 0x7: pmovmskb_Gd_VRo();
820 0x8: decode OPCODE_OP_BOTTOM3 {
821 0x0: addsubps_Vo_Wo();
822 0x6: movdq2q_Pq_VRq();
823 default: Inst::UD2();
825 default: Inst::UD2();
827 0x1B: decode LEGACY_DECODEVAL {
829 0x0: decode OPCODE_OP_BOTTOM3 {
830 0x0: psubusb_Pq_Qq();
831 0x1: psubusw_Pq_Qq();
834 0x4: paddusb_Pq_Qq();
835 0x5: paddusw_Pq_Qq();
839 // operand size (0x66)
840 0x1: decode OPCODE_OP_BOTTOM3 {
841 0x0: psubusb_Vo_Wo();
842 0x1: psubusw_Vo_Wo();
845 0x4: paddusb_Vo_Wo();
846 0x5: paddusw_Vo_Wo();
850 default: Inst::UD2();
852 0x1C: decode LEGACY_DECODEVAL {
854 0x0: decode OPCODE_OP_BOTTOM3 {
859 0x4: pmulhuw_Pq_Qq();
862 default: Inst::UD2();
865 0x4: decode OPCODE_OP_BOTTOM3 {
866 0x6: cvtdq2pd_Vo_Wq();
867 default: Inst::UD2();
869 // operand size (0x66)
870 0x1: decode OPCODE_OP_BOTTOM3 {
875 0x4: pmulhuw_Vo_Wo();
877 0x6: cvttpd2dq_Vo_Wo();
878 0x7: movntdq_Mo_Vo();
881 0x8: decode OPCODE_OP_BOTTOM3 {
882 0x6: cvtpd2dq_Vo_Wo();
883 default: Inst::UD2();
885 default: Inst::UD2();
887 0x1D: decode LEGACY_DECODEVAL {
889 0x0: decode OPCODE_OP_BOTTOM3 {
899 // operand size (0x66)
900 0x1: decode OPCODE_OP_BOTTOM3 {
910 default: Inst::UD2();
912 0x1E: decode OPCODE_OP_BOTTOM3 {
914 0x0: decode OPCODE_OP_BOTTOM3 {
918 0x4: pmuludq_Pq_Qq();
919 0x5: pmaddwd_Pq_Qq();
921 0x7: maskmovq_Pq_PRq();
922 default: Inst::UD2();
924 // operand size (0x66)
925 0x1: decode OPCODE_OP_BOTTOM3 {
929 0x4: pmuludq_Vo_Wo();
930 0x5: pmaddwd_Vo_Wo();
932 0x7: maskmovdqu_Vo_VRo();
933 default: Inst::UD2();
936 0x8: decode OPCODE_OP_BOTTOM3 {
938 default: Inst::UD2();
940 default: Inst::UD2();
942 0x1F: decode LEGACY_DECODEVAL {
944 0x0: decode OPCODE_OP_BOTTOM3 {
954 // operand size (0x66)
955 0x1: decode OPCODE_OP_BOTTOM3 {
965 default: Inst::UD2();
967 default: FailUnimpl::twoByteOps();
970 default: M5InternalError::error(
971 {{"Unexpected first opcode byte in two byte opcode!"}});