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 {
68 //sandpile.org doesn't seem to know what this is... ?
69 0x04: loadall_or_reset_or_hang();
73 0x05: SyscallInst::syscall('xc->syscall(rax)', IsSyscall);
76 //sandpile.org says (AMD) after sysret, so I might want to check
77 //if that means amd64 or AMD machines
78 0x07: loadall_or_sysret();
80 0x01: decode OPCODE_OP_BOTTOM3 {
90 0x02: decode LEGACY_DECODEVAL {
92 0x0: decode OPCODE_OP_BOTTOM3 {
95 0x2: decode MODRM_MOD {
96 0x3: movhlps_Vq_VRq();
97 default: movlps_Vq_Mq();
102 0x6: decode MODRM_MOD {
103 0x3: movlhps_Vq_VRq();
104 default: movhps_Vq_Mq();
109 0x4: decode OPCODE_OP_BOTTOM3 {
112 0x2: movsldup_Vo_Wo();
113 0x6: movshdup_Vo_Wo();
114 default: Inst::UD2();
116 // operand size (0x66)
117 0x1: decode OPCODE_OP_BOTTOM3 {
120 0x2: Inst::MOVLPD(Vq,Mq);
121 0x3: Inst::MOVLPD(Mq,Vq);
122 0x4: unpcklpd_Vo_Wq();
123 0x5: unpckhpd_Vo_Wo();
128 0x8: decode OPCODE_OP_BOTTOM3 {
129 0x0: Inst::MOVSD(Vq,Wq);
130 0x1: Inst::MOVSD(Wq,Vq);
131 0x2: movddup_Vo_Wq();
132 default: Inst::UD2();
134 default: Inst::UD2();
136 0x03: decode OPCODE_OP_BOTTOM3 {
146 0x04: decode LEGACY_DECODEVAL {
148 0x0: decode OPCODE_OP_BOTTOM3 {
155 default: Inst::UD2();
157 // lock prefix (0xF0)
158 0x2: decode OPCODE_OP_BOTTOM3 {
162 default: Inst::UD2();
164 0x05: decode LEGACY_DECODEVAL {
166 0x0: decode OPCODE_OP_BOTTOM3 {
167 //These moves should really use size o (octword), but
168 //because they are split in two, they use q (quadword).
169 0x0: Inst::MOVAPS(Vq,Wq);
170 0x1: Inst::MOVAPS(Wq,Vq);
171 0x2: decode MODRM_MOD {
172 0x3: cvtpi2pS_Vq_Pq();
173 default: cvtpi2ps_Vq_Mq();
175 0x3: movntps_Mo_Vo();
176 0x4: cvttps2pi_Pq_Wq();
177 0x5: cvtpS2pi_Pq_Wq();
178 0x6: ucomiss_Vd_Wd();
182 0x4: decode OPCODE_OP_BOTTOM3 {
183 0x2: cvtsi2ss_Vd_Ed();
184 0x4: cvttss2si_Gd_Wd();
185 0x5: cvtss2si_Gd_Wd();
186 default: Inst::UD2();
188 // operand size (0x66)
189 0x1: decode OPCODE_OP_BOTTOM3 {
192 0x2: decode MODRM_MOD {
193 0x3: cvtpi2pd_Vo_Pq();
194 default: cvtpi2pd_Vo_Mq();
196 0x3: movntpd_Mo_Vo();
197 0x4: cvttpd2pi_Pq_Wo();
198 0x5: cvtpd2pi_Pq_Wo();
199 0x6: ucomisd_Vq_Wq();
203 0x8: decode OPCODE_OP_BOTTOM3 {
204 // The size of the V operand should be q, not dp
205 0x2: Inst::CVTSI2SD(Vdp,Edp);
206 // The size of the W operand should be q, not dp
207 0x4: Inst::CVTTSD2SI(Gdp,Wdp);
208 0x5: cvtsd2si_Gd_Wq();
209 default: Inst::UD2();
211 default: Inst::UD2();
213 0x06: decode OPCODE_OP_BOTTOM3 {
223 0x07: decode OPCODE_OP_BOTTOM3 {
224 0x0: three_byte_opcode();
225 0x1: three_byte_opcode();
226 0x2: three_byte_opcode();
227 0x3: three_byte_opcode();
228 0x4: three_byte_opcode();
229 0x5: three_byte_opcode();
230 0x6: three_byte_opcode();
231 0x7: three_byte_opcode();
234 0x08: decode OPCODE_OP_BOTTOM3 {
244 0x09: decode OPCODE_OP_BOTTOM3 {
255 0x0A: decode LEGACY_DECODEVAL {
257 0x0: decode OPCODE_OP_BOTTOM3 {
258 0x0: movmskps_Gd_VRo();
260 0x2: rqsrtps_Vo_Wo();
268 0x4: decode OPCODE_OP_BOTTOM3 {
270 0x2: rsqrtss_Vd_Wd();
272 default: Inst::UD2();
274 // operand size (0x66)
275 0x1: decode OPCODE_OP_BOTTOM3 {
276 0x0: movmskpd_Gd_VRo();
282 default: Inst::UD2();
285 0x8: decode OPCODE_OP_BOTTOM3 {
287 default: Inst::UD2();
289 default: Inst::UD2();
291 0x0B: decode LEGACY_DECODEVAL {
293 0x0: decode OPCODE_OP_BOTTOM3 {
296 0x2: cvtps2pd_Vo_Wq();
297 0x3: cvtdq2ps_Vo_Wo();
304 0x4: decode OPCODE_OP_BOTTOM3 {
307 0x2: cvtss2sd_Vq_Wd();
308 0x3: cvttps2dq_Vo_Wo();
314 // operand size (0x66)
315 0x1: decode OPCODE_OP_BOTTOM3 {
318 0x2: cvtpd2ps_Vo_Wo();
319 0x3: cvtps2dq_Vo_Wo();
326 0x8: decode OPCODE_OP_BOTTOM3 {
327 0x0: Inst::ADDSD(Vq,Wq);
328 0x1: Inst::MULSD(Vq,Wq);
329 0x2: cvtsd2ss_Vd_Wq();
330 0x4: Inst::SUBSD(Vq,Wq);
332 0x6: Inst::DIVSD(Vq,Wq);
334 default: Inst::UD2();
336 default: Inst::UD2();
338 0x0C: decode LEGACY_DECODEVAL {
340 0x0: decode OPCODE_OP_BOTTOM3 {
341 0x0: punpcklbw_Pq_Qd();
342 0x1: punpcklwd_Pq_Qd();
343 0x2: punpckldq_Pq_Qd();
344 0x3: packsswb_Pq_Qq();
345 0x4: pcmpgtb_Pq_Qq();
346 0x5: pcmpgtw_Pq_Qq();
347 0x6: pcmpgtd_Pq_Qq();
348 0x7: packuswb_Pq_Qq();
350 // operand size (0x66)
351 0x1: decode OPCODE_OP_BOTTOM3 {
352 0x0: punpcklbw_Vo_Wq();
353 0x1: punpcklwd_Vo_Wq();
354 0x2: punpckldq_Vo_Wq();
355 0x3: packsswb_Vo_Wo();
356 0x4: pcmpgtb_Vo_Wo();
357 0x5: pcmpgtw_Vo_Wo();
358 0x6: pcmpgtd_Vo_Wo();
359 0x7: packuswb_Vo_Wo();
361 default: Inst::UD2();
363 0x0D: decode LEGACY_DECODEVAL {
365 0x0: decode OPCODE_OP_BOTTOM3 {
366 0x0: punpckhbw_Pq_Qq();
367 0x1: punpckhwd_Pq_Qq();
368 0x2: punpckhdq_Pq_Qq();
369 0x3: packssdw_Pq_Qq();
372 default: Inst::UD2();
375 0x4: decode OPCODE_OP_BOTTOM3 {
377 default: Inst::UD2();
379 // operand size (0x66)
380 0x1: decode OPCODE_OP_BOTTOM3 {
381 0x0: punpckhbw_Vo_Wo();
382 0x1: punpckhwd_Vo_Wo();
383 0x2: punpckhdq_Vo_Wo();
384 0x3: packssdw_Vo_Wo();
385 0x4: punpcklqdq_Vo_Wq();
386 0x5: punpcklqdq_Vo_Wq();
390 default: Inst::UD2();
392 0x0E: decode LEGACY_DECODEVAL {
394 0x0: decode OPCODE_OP_BOTTOM3 {
395 0x0: pshufw_Pq_Qq_Ib();
396 0x1: group13_pshimw();
397 0x2: group14_pshimd();
398 0x3: group15_pshimq();
399 0x4: pcmpeqb_Pq_Qq();
400 0x5: pcmpeqw_Pq_Qq();
401 0x6: pcmpeqd_Pq_Qq();
405 0x4: decode OPCODE_OP_BOTTOM3 {
406 0x0: pshufhw_Vo_Wo_Ib();
407 default: Inst::UD2();
409 // operand size (0x66)
410 0x1: decode OPCODE_OP_BOTTOM3 {
411 0x0: pshufd_Vo_Wo_Ib();
412 0x1: group13_pshimw();
413 0x2: group14_pshimd();
414 0x3: group15_pshimq_dq();
415 0x4: pcmpeqb_Vo_Wo();
416 0x5: pcmpeqw_Vo_Wo();
417 0x6: pcmpeqd_Vo_Wo();
418 default: Inst::UD2();
421 0x8: decode OPCODE_OP_BOTTOM3 {
422 0x0: pshuflw_Vo_Wo_Ib();
423 default: Inst::UD2();
425 default: Inst::UD2();
427 0x0F: decode LEGACY_DECODEVAL {
429 0x0: decode OPCODE_OP_BOTTOM3 {
430 0x0: vmread_Ed_or_Eq_Gd_or_Gq();
431 0x1: vmwrite_Gd_or_Gq_Ed_or_Eq();
434 default: Inst::UD2();
437 0x4: decode OPCODE_OP_BOTTOM3 {
438 0x6: movq_Vo_Mq_or_Vq_Vq();
440 default: Inst::UD2();
442 // operand size (0x66)
443 0x1: decode OPCODE_OP_BOTTOM3 {
448 default: Inst::UD2();
451 0x8: decode OPCODE_OP_BOTTOM3 {
454 default: Inst::UD2();
456 default: Inst::UD2();
459 0x10: decode OPCODE_OP_BOTTOM3 {
469 0x11: decode OPCODE_OP_BOTTOM3 {
479 0x12: decode OPCODE_OP_BOTTOM3 {
489 0x13: decode OPCODE_OP_BOTTOM3 {
500 0x14: decode OPCODE_OP_BOTTOM3 {
503 0x2: Inst::CPUID(rAd);
505 0x4: shld_Ev_Gv_Ib();
506 0x5: shld_Ev_Gv_rCl();
507 0x6: xbts_and_cmpxchg();
508 0x7: ibts_and_cmpxchg();
510 0x15: decode OPCODE_OP_BOTTOM3 {
515 0x4: shrd_Ev_Gv_Ib();
516 0x5: shrd_Ev_Gv_rCl();
518 0x7: Inst::IMUL(Gv,Ev);
520 0x16: decode OPCODE_OP_BOTTOM3 {
521 0x0: Inst::CMPXCHG(Eb,Gb);
522 0x1: Inst::CMPXCHG(Ev,Gv);
527 //The size of the second operand in these instructions should
528 //really be "b" or "w", but it's set to v in order to have a
529 //consistent register size. This shouldn't affect behavior.
530 0x6: Inst::MOVZX_B(Gv,Ev);
531 0x7: Inst::MOVZX_W(Gv,Ev);
533 0x17: decode OPCODE_OP_BOTTOM3 {
534 0x0: jmpe_Jz(); // IA-64?
540 //The size of the second operand in these instructions should
541 //really be "b" or "w", but it's set to v in order to have a
542 //consistent register size. This shouldn't affect behavior.
543 0x6: Inst::MOVSX_B(Gv,Ev);
544 0x7: Inst::MOVSX_W(Gv,Ev);
546 0x18: decode OPCODE_OP_BOTTOM3 {
550 default: decode LEGACY_DECODEVAL {
552 0x0: decode OPCODE_OP_BOTTOM3 {
553 0x2: cmpccps_Vo_Wo_Ib();
554 0x3: cvtdq2ps_Vo_Wo();
560 0x4: decode OPCODE_OP_BOTTOM3 {
561 0x2: cmpccss_Vd_Wd_Ib();
562 default: Inst::UD2();
564 // operand size (0x66)
565 0x1: decode OPCODE_OP_BOTTOM3 {
566 0x2: cmpccpd_Vo_Wo_Ib();
570 default: Inst::UD2();
573 0x8: decode OPCODE_OP_BOTTOM3 {
574 0x2: cmpccsd_Vq_Wq_Ib();
575 default: Inst::UD2();
577 default: Inst::UD2();
581 0x1A: decode LEGACY_DECODEVAL {
583 0x0: decode OPCODE_OP_BOTTOM3 {
589 0x7: pmovmskb_Gd_PRq();
590 default: Inst::UD2();
593 0x4: decode OPCODE_OP_BOTTOM3 {
594 0x6: movq2dq_Vo_PRq();
595 default: Inst::UD2();
597 // operand size (0x66)
598 0x1: decode OPCODE_OP_BOTTOM3 {
599 0x0: addsubpd_Vo_Wo();
605 0x6: decode MODRM_MOD {
607 default: movq_Mq_Vq();
609 0x7: pmovmskb_Gd_VRo();
612 0x8: decode OPCODE_OP_BOTTOM3 {
613 0x0: addsubps_Vo_Wo();
614 0x6: movdq2q_Pq_VRq();
615 default: Inst::UD2();
617 default: Inst::UD2();
619 0x1B: decode LEGACY_DECODEVAL {
621 0x0: decode OPCODE_OP_BOTTOM3 {
622 0x0: psubusb_Pq_Qq();
623 0x1: psubusw_Pq_Qq();
626 0x4: paddusb_Pq_Qq();
627 0x5: paddusw_Pq_Qq();
631 // operand size (0x66)
632 0x1: decode OPCODE_OP_BOTTOM3 {
633 0x0: psubusb_Vo_Wo();
634 0x1: psubusw_Vo_Wo();
637 0x4: paddusb_Vo_Wo();
638 0x5: paddusw_Vo_Wo();
642 default: Inst::UD2();
644 0x1C: decode LEGACY_DECODEVAL {
646 0x0: decode OPCODE_OP_BOTTOM3 {
651 0x4: pmulhuw_Pq_Qq();
654 default: Inst::UD2();
657 0x4: decode OPCODE_OP_BOTTOM3 {
658 0x6: cvtdq2pd_Vo_Wq();
659 default: Inst::UD2();
661 // operand size (0x66)
662 0x1: decode OPCODE_OP_BOTTOM3 {
667 0x4: pmulhuw_Vo_Wo();
669 0x6: cvttpd2dq_Vo_Wo();
670 0x7: movntdq_Mo_Vo();
673 0x8: decode OPCODE_OP_BOTTOM3 {
674 0x6: cvtpd2dq_Vo_Wo();
675 default: Inst::UD2();
677 default: Inst::UD2();
679 0x1D: decode LEGACY_DECODEVAL {
681 0x0: decode OPCODE_OP_BOTTOM3 {
691 // operand size (0x66)
692 0x1: decode OPCODE_OP_BOTTOM3 {
702 default: Inst::UD2();
704 0x1E: decode OPCODE_OP_BOTTOM3 {
706 0x0: decode OPCODE_OP_BOTTOM3 {
710 0x4: pmuludq_Pq_Qq();
711 0x5: pmaddwd_Pq_Qq();
713 0x7: maskmovq_Pq_PRq();
714 default: Inst::UD2();
716 // operand size (0x66)
717 0x1: decode OPCODE_OP_BOTTOM3 {
721 0x4: pmuludq_Vo_Wo();
722 0x5: pmaddwd_Vo_Wo();
724 0x7: maskmovdqu_Vo_VRo();
725 default: Inst::UD2();
728 0x8: decode OPCODE_OP_BOTTOM3 {
730 default: Inst::UD2();
732 default: Inst::UD2();
734 0x1F: decode LEGACY_DECODEVAL {
736 0x0: decode OPCODE_OP_BOTTOM3 {
746 // operand size (0x66)
747 0x1: decode OPCODE_OP_BOTTOM3 {
757 default: Inst::UD2();
759 default: FailUnimpl::twoByteOps();
762 default: M5InternalError::error(
763 {{"Unexpected first opcode byte in two byte opcode!"}});