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