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