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