one_byte_opcodes.isa revision 4771:d4b92447a598
1// Copyright (c) 2007 The Hewlett-Packard Development Company
2// All rights reserved.
3//
4// Redistribution and use of this software in source and binary forms,
5// with or without modification, are permitted provided that the
6// following conditions are met:
7//
8// The software must be used only for Non-Commercial Use which means any
9// use which is NOT directed to receiving any direct monetary
10// compensation for, or commercial advantage from such use.  Illustrative
11// examples of non-commercial use are academic research, personal study,
12// teaching, education and corporate research & development.
13// Illustrative examples of commercial use are distributing products for
14// commercial advantage and providing services using the software for
15// commercial advantage.
16//
17// If you wish to use this software or functionality therein that may be
18// covered by patents for commercial use, please contact:
19//     Director of Intellectual Property Licensing
20//     Office of Strategy and Technology
21//     Hewlett-Packard Company
22//     1501 Page Mill Road
23//     Palo Alto, California  94304
24//
25// Redistributions of source code must retain the above copyright notice,
26// this list of conditions and the following disclaimer.  Redistributions
27// in binary form must reproduce the above copyright notice, this list of
28// conditions and the following disclaimer in the documentation and/or
29// other materials provided with the distribution.  Neither the name of
30// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31// contributors may be used to endorse or promote products derived from
32// this software without specific prior written permission.  No right of
33// sublicense is granted herewith.  Derivatives of the software and
34// output created using the software may be prepared, but only for
35// Non-Commercial Uses.  Derivatives of the software may be shared with
36// others provided: (i) the others agree to abide by the list of
37// conditions herein which includes the Non-Commercial Use restrictions;
38// and (ii) such Derivatives of the software include the above copyright
39// notice to acknowledge the contribution from this software where
40// applicable, this list of conditions and the disclaimer below.
41//
42// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53//
54// Authors: Gabe Black
55
56////////////////////////////////////////////////////////////////////
57//
58// Decode the one byte opcodes
59//
60
610x1: decode OPCODE_OP_TOP5 {
62    format WarnUnimpl {
63        0x00: decode OPCODE_OP_BOTTOM3 {
64            0x6: decode MODE_SUBMODE {
65                0x0: Inst::UD2();
66                default: push_ES();
67            }
68            0x7: decode MODE_SUBMODE {
69                0x0: Inst::UD2();
70                default: pop_ES();
71            }
72            default: MultiInst::ADD(OPCODE_OP_BOTTOM3,
73                                    [Eb,Gb], [Ev,Gv],
74                                    [Gb,Eb], [Gv,Ev],
75                                    [rAb,Ib], [rAv,Iz]);
76        }
77        0x01: decode OPCODE_OP_BOTTOM3 {
78            0x6: decode MODE_SUBMODE {
79                0x0: Inst::UD2();
80                default: push_CS();
81            }
82            //Any time this is seen, it should generate a two byte opcode
83            0x7: M5InternalError::error(
84                {{"Saw a one byte opcode whose value was 0x0F!"}});
85            default: MultiInst::OR(OPCODE_OP_BOTTOM3,
86                                   [Eb,Gb], [Ev,Gv],
87                                   [Gb,Eb], [Gv,Ev],
88                                   [rAb,Ib], [rAv,Iz]);
89        }
90        0x02: decode OPCODE_OP_BOTTOM3 {
91            0x6: decode MODE_SUBMODE {
92                0x0: Inst::UD2();
93                default: push_SS();
94            }
95            0x7: decode MODE_SUBMODE {
96                0x0: Inst::UD2();
97                default: pop_SS();
98            }
99            default: MultiInst::ADC(OPCODE_OP_BOTTOM3,
100                                    [Eb,Gb], [Ev,Gv],
101                                    [Gb,Eb], [Gv,Ev],
102                                    [rAb,Ib], [rAv,Iz]);
103        }
104        0x03: decode OPCODE_OP_BOTTOM3 {
105            0x6: decode MODE_SUBMODE {
106                0x0: Inst::UD2();
107                default: push_DS();
108            }
109            0x7: decode MODE_SUBMODE {
110                0x0: Inst::UD2();
111                default: pop_DS();
112            }
113            default: MultiInst::SBB(OPCODE_OP_BOTTOM3,
114                                    [Eb,Gb], [Ev,Gv],
115                                    [Gb,Eb], [Gv,Ev],
116                                    [rAb,Ib], [rAv,Iz]);
117        }
118        0x04: decode OPCODE_OP_BOTTOM3 {
119            0x6: M5InternalError::error(
120                {{"Tried to execute the ES segment override prefix!"}});
121            0x7: decode MODE_SUBMODE {
122                0x0: Inst::UD2();
123                default: daa();
124            }
125            default: MultiInst::AND(OPCODE_OP_BOTTOM3,
126                                    [Eb,Gb], [Ev,Gv],
127                                    [Gb,Eb], [Gv,Ev],
128                                    [rAb,Ib], [rAv,Iz]);
129        }
130        0x05: decode OPCODE_OP_BOTTOM3 {
131            0x6: M5InternalError::error(
132                {{"Tried to execute the CS segment override prefix!"}});
133            0x7: das();
134            default: MultiInst::SUB(OPCODE_OP_BOTTOM3,
135                                    [Eb,Gb], [Ev,Gv],
136                                    [Gb,Eb], [Gv,Ev],
137                                    [rAb,Ib], [rAv,Iz]);
138        }
139        0x06: decode OPCODE_OP_BOTTOM3 {
140            0x6: M5InternalError::error(
141                {{"Tried to execute the SS segment override prefix!"}});
142            0x7: decode MODE_SUBMODE {
143                0x0: Inst::UD2();
144                default: aaa();
145            }
146            default: MultiInst::XOR(OPCODE_OP_BOTTOM3,
147                                    [Eb,Gb], [Ev,Gv],
148                                    [Gb,Eb], [Gv,Ev],
149                                    [rAb,Ib], [rAv,Iz]);
150        }
151        0x07: decode OPCODE_OP_BOTTOM3 {
152            0x6: M5InternalError::error(
153                {{"Tried to execute the DS segment override prefix!"}});
154            0x7: decode MODE_SUBMODE {
155                0x0: Inst::UD2();
156                default: aas();
157            }
158            default: MultiInst::CMP(OPCODE_OP_BOTTOM3,
159                                    [Eb,Gb], [Ev,Gv],
160                                    [Gb,Eb], [Gv,Ev],
161                                    [rAb,Ib], [rAv,Iz]);
162        }
163        format Inst {
164            0x08: decode MODE_SUBMODE {
165                0x0: M5InternalError::error (
166                    {{"Tried to execute an REX prefix!"}});
167                default: INC(Bv);
168            }
169            0x09: decode MODE_SUBMODE {
170                0x0: M5InternalError::error (
171                    {{"Tried to execute an REX prefix!"}});
172                default: DEC(Bv);
173            }
174            0x0A: PUSH(Bv);
175            0x0B: POP(Bv);
176        }
177        0x0C: decode OPCODE_OP_BOTTOM3 {
178            0x0: decode MODE_SUBMODE {
179                0x0: Inst::UD2();
180                default: Inst::PUSHA();
181            }
182            0x1: decode MODE_SUBMODE {
183                0x0: Inst::UD2();
184                default: Inst::POPA();
185            }
186            0x2: decode MODE_SUBMODE {
187                0x0: Inst::UD2();
188                default: bound_Gv_Ma();
189            }
190            0x3: decode MODE_SUBMODE {
191                //The second operand should really be of size "d", but it's
192                //set to "v" in order to have a consistent register size.
193                //This shouldn't affect behavior.
194                0x0: Inst::MOVSXD(Gv,Ev);
195                default: arpl_Ew_Gw();
196            }
197            0x4: M5InternalError::error(
198                {{"Tried to execute the FS segment override prefix!"}});
199            0x5: M5InternalError::error(
200                {{"Tried to execute the GS segment override prefix!"}});
201            0x6: M5InternalError::error(
202                {{"Tried to execute the operand size override prefix!"}});
203            0x7: M5InternalError::error(
204                {{"Tried to execute the DS address size override prefix!"}});
205        }
206        0x0D: decode OPCODE_OP_BOTTOM3 {
207            0x0: Inst::PUSH(Iz);
208            0x1: Inst::IMUL(Gv,Ev,Iz);
209            0x2: Inst::PUSH(Ib);
210            0x3: Inst::IMUL(Gv,Ev,Ib);
211            0x4: ins_Yb_Dx();
212            0x5: ins_Yz_Dx();
213            0x6: outs_Dx_Xb();
214            0x7: outs_Dx_Xz();
215        }
216        format Inst {
217            0x0E: decode OPCODE_OP_BOTTOM3 {
218                0x0: JO(Jb);
219                0x1: JNO(Jb);
220                0x2: JB(Jb);
221                0x3: JNB(Jb);
222                0x4: JZ(Jb);
223                0x5: JNZ(Jb);
224                0x6: JBE(Jb);
225                0x7: JNBE(Jb);
226            }
227            0x0F: decode OPCODE_OP_BOTTOM3 {
228                0x0: JS(Jb);
229                0x1: JNS(Jb);
230                0x2: JP(Jb);
231                0x3: JNP(Jb);
232                0x4: JL(Jb);
233                0x5: JNL(Jb);
234                0x6: JLE(Jb);
235                0x7: JNLE(Jb);
236            }
237        }
238        format Inst {
239            0x10: decode OPCODE_OP_BOTTOM3 {
240                //0x0: group1_Eb_Ib();
241                0x0: decode MODRM_REG {
242                    0x0: ADD(Eb,Ib);
243                    0x1: OR(Eb,Ib);
244                    0x2: ADC(Eb,Ib);
245                    0x3: SBB(Eb,Ib);
246                    0x4: AND(Eb,Ib);
247                    0x5: SUB(Eb,Ib);
248                    0x6: XOR(Eb,Ib);
249                    0x7: CMP(Eb,Ib);
250                }
251                //0x1: group1_Ev_Iz();
252                0x1: decode MODRM_REG {
253                    0x0: ADD(Ev,Iz);
254                    0x1: OR(Ev,Iz);
255                    0x2: ADC(Ev,Iz);
256                    0x3: SBB(Ev,Iz);
257                    0x4: AND(Ev,Iz);
258                    0x5: SUB(Ev,Iz);
259                    0x6: XOR(Ev,Iz);
260                    0x7: CMP(Ev,Iz);
261                }
262                0x2: decode MODE_SUBMODE {
263                    0x0: UD2();
264                    //default: group1_Eb_Ib();
265                    default: decode MODRM_REG {
266                        0x0: ADD(Eb,Ib);
267                        0x1: OR(Eb,Ib);
268                        0x2: ADC(Eb,Ib);
269                        0x3: SBB(Eb,Ib);
270                        0x4: AND(Eb,Ib);
271                        0x5: SUB(Eb,Ib);
272                        0x6: XOR(Eb,Ib);
273                        0x7: CMP(Eb,Ib);
274                    }
275                }
276                //0x3: group1_Ev_Ib();
277                0x3: decode MODRM_REG {
278                    0x0: ADD(Ev,Ib);
279                    0x1: OR(Ev,Ib);
280                    0x2: ADC(Ev,Ib);
281                    0x3: SBB(Ev,Ib);
282                    0x4: AND(Ev,Ib);
283                    0x5: SUB(Ev,Ib);
284                    0x6: XOR(Ev,Ib);
285                    0x7: CMP(Ev,Ib);
286                }
287                0x4: TEST(Eb,Gb);
288                0x5: TEST(Ev,Gv);
289                0x6: XCHG(Eb,Gb);
290                0x7: XCHG(Ev,Gv);
291            }
292        }
293        0x11: decode OPCODE_OP_BOTTOM3 {
294            0x0: Inst::MOV(Eb,Gb);
295            0x1: Inst::MOV(Ev,Gv);
296            0x2: Inst::MOV(Gb,Eb);
297            0x3: Inst::MOV(Gv,Ev);
298            0x4: mov_MwRv_Sw(); //What to do with this one?
299            0x5: Inst::LEA(Gv,M);
300            0x6: mov_Sw_MwRv();
301            0x7: group10_Ev(); //Make sure this is Ev
302        }
303        0x12: decode OPCODE_OP_BOTTOM3 {
304            0x0: Inst::NOP(); //XXX repe makes this a "pause"
305            default: xchg_B_rAX();
306        }
307        0x13: decode OPCODE_OP_BOTTOM3 {
308            0x0: Inst::CDQE(rAv);
309            0x1: Inst::CQO(rAv,rDv);
310            0x2: decode MODE_SUBMODE {
311                0x0: Inst::UD2();
312                default: call_far_Ap();
313            }
314            0x3: fwait(); //aka wait
315            0x4: pushf_Fv();
316            0x5: popf_Fv();
317            //Both of these should be illegal only if CPUID.AHF64=0,
318            //according to sandpile.org
319            0x6: decode MODE_SUBMODE {
320                0x0: Inst::UD2();
321                default: sahf();
322            }
323            0x7: decode MODE_SUBMODE {
324                0x0: Inst::UD2();
325                default: lahf();
326            }
327        }
328        0x14: decode OPCODE_OP_BOTTOM3 {
329            0x0: mov_Al_Ob();
330            0x1: mov_rAX_Ov();
331            0x2: mov_Ob_Al();
332            0x3: mov_Ov_rAX();
333            0x4: movs_Yb_Xb();
334            0x5: movs_Yv_Xv();
335            0x6: cmps_Yb_Xb();
336            0x7: cmps_Yv_Xv();
337        }
338        0x15: decode OPCODE_OP_BOTTOM3 {
339            0x0: Inst::TEST(rAb,Ib);
340            0x1: Inst::TEST(rAv,Iz);
341            0x2: stos_Yb_Al();
342            0x3: stos_Yv_rAX();
343            0x4: lods_Al_Xb();
344            0x5: lods_rAX_Xv();
345            0x6: scas_Yb_Al();
346            0x7: scas_Yv_rAX();
347        }
348        format Inst {
349            0x16: MOV(Bb,Ib);
350            0x17: MOV(Bv,Iv);
351            0x18: decode OPCODE_OP_BOTTOM3 {
352                //0x0: group2_Eb_Ib();
353                0x0: decode MODRM_REG {
354                    0x0: ROL(Eb,Ib);
355                    0x1: ROR(Eb,Ib);
356                    0x2: RCL(Eb,Ib);
357                    0x3: RCR(Eb,Ib);
358                    0x4: SAL(Eb,Ib);
359                    0x5: SHR(Eb,Ib);
360                    0x6: SAL(Eb,Ib);
361                    0x7: SAR(Eb,Ib);
362                }
363                //0x1: group2_Ev_Ib();
364                0x1: decode MODRM_REG {
365                    0x0: ROL(Ev,Ib);
366                    0x1: ROR(Ev,Ib);
367                    0x2: RCL(Ev,Ib);
368                    0x3: RCR(Ev,Ib);
369                    0x4: SAL(Ev,Ib);
370                    0x5: SHR(Ev,Ib);
371                    0x6: SAL(Ev,Ib);
372                    0x7: SAR(Ev,Ib);
373                }
374                0x2: RET_NEAR(Iw);
375                0x3: RET_NEAR();
376                0x4: decode MODE_SUBMODE {
377                    0x0: UD2();
378                    default: WarnUnimpl::les_Gz_Mp();
379                }
380                0x5: decode MODE_SUBMODE {
381                    0x0: UD2();
382                    default: WarnUnimpl::lds_Gz_Mp();
383                }
384                //0x6: group12_Eb_Ib();
385                0x6: decode MODRM_REG {
386                    0x0: MOV(Eb,Ib);
387                    default: UD2();
388                }
389                //0x7: group12_Ev_Iz();
390                0x7: decode MODRM_REG {
391                    0x0: MOV(Ev,Iz);
392                    default: UD2();
393                }
394            }
395        }
396        0x19: decode OPCODE_OP_BOTTOM3 {
397            0x0: enter_Iw_Ib();
398            0x1: leave();
399            0x2: ret_far_Iw();
400            0x3: ret_far();
401            0x4: int3();
402            0x5: int_Ib();
403            0x6: decode MODE_SUBMODE {
404                0x0: Inst::UD2();
405                default: into();
406            }
407            0x7: iret();
408        }
409        0x1A: decode OPCODE_OP_BOTTOM3 {
410            format Inst {
411                //0x0: group2_Eb_1();
412                0x0: decode MODRM_REG {
413                    0x0: ROL_1(Eb);
414                    0x1: ROR_1(Eb);
415                    0x2: RCL_1(Eb);
416                    0x3: RCR_1(Eb);
417                    0x4: SAL_1(Eb);
418                    0x5: SHR_1(Eb);
419                    0x6: SAL_1(Eb);
420                    0x7: SAR_1(Eb);
421                }
422                //0x1: group2_Ev_1();
423                0x1: decode MODRM_REG {
424                    0x0: ROL_1(Ev);
425                    0x1: ROR_1(Ev);
426                    0x2: RCL_1(Ev);
427                    0x3: RCR_1(Ev);
428                    0x4: SAL_1(Ev);
429                    0x5: SHR_1(Ev);
430                    0x6: SAL_1(Ev);
431                    0x7: SAR_1(Ev);
432                }
433                //0x2: group2_Eb_Cl();
434                0x2: decode MODRM_REG {
435                    0x0: ROL(Eb,rCb);
436                    0x1: ROR(Eb,rCb);
437                    0x2: RCL(Eb,rCb);
438                    0x3: RCR(Eb,rCb);
439                    0x4: SAL(Eb,rCb);
440                    0x5: SHR(Eb,rCb);
441                    0x6: SAL(Eb,rCb);
442                    0x7: SAR(Eb,rCb);
443                }
444                //The second operand should have size "b", but to have
445                //consistent register sizes it's "v". This shouldn't have
446                //any affect on functionality.
447                //0x3: group2_Ev_Cl();
448                0x3: decode MODRM_REG {
449                    0x0: ROL(Ev,rCv);
450                    0x1: ROR(Ev,rCv);
451                    0x2: RCL(Ev,rCv);
452                    0x3: RCR(Ev,rCv);
453                    0x4: SAL(Ev,rCv);
454                    0x5: SHR(Ev,rCv);
455                    0x6: SAL(Ev,rCv);
456                    0x7: SAR(Ev,rCv);
457                }
458            }
459            0x4: decode MODE_SUBMODE {
460                0x0: Inst::UD2();
461                default: aam_Ib();
462            }
463            0x5: decode MODE_SUBMODE {
464                0x0: Inst::UD2();
465                default: aad_Ib();
466            }
467            0x6: decode MODE_SUBMODE {
468                0x0: Inst::UD2();
469                default: salc();
470            }
471            0x7: xlat();
472        }
473        0x1B: decode OPCODE_OP_BOTTOM3 {
474            0x0: esc0();
475            0x1: esc1();
476            0x2: esc2();
477            0x3: esc3();
478            0x4: esc4();
479            0x5: esc5();
480            0x6: esc6();
481            0x7: esc7();
482        }
483        0x1C: decode OPCODE_OP_BOTTOM3 {
484            0x0: loopne_Jb();
485            0x1: loope_Jb();
486            0x2: loop_Jb();
487            0x3: jcxz_or_jecx_or_jrcx();
488            0x4: in_Al_Ib();
489            0x5: in_eAX_Ib();
490            0x6: out_Ib_Al();
491            0x7: out_Ib_eAX();
492        }
493        0x1D: decode OPCODE_OP_BOTTOM3 {
494            0x0: Inst::CALL_NEAR(Jz);
495            0x1: Inst::JMP(Jz);
496            0x2: decode MODE_SUBMODE {
497                0x0: Inst::UD2();
498                default: jmp_far_Ap();
499            }
500            0x3: Inst::JMP(Jb);
501            0x4: in_Al_Dx();
502            0x5: in_eAX_Dx();
503            0x6: out_Dx_Al();
504            0x7: out_Dx_eAX();
505        }
506        0x1E: decode OPCODE_OP_BOTTOM3 {
507            0x0: M5InternalError::error(
508                {{"Tried to execute the lock prefix!"}});
509            0x1: int1();
510            0x2: M5InternalError::error(
511                {{"Tried to execute the repne prefix!"}});
512            0x3: M5InternalError::error(
513                {{"Tried to execute the rep/repe prefix!"}});
514            0x4: hlt();
515            0x5: cmc();
516            //0x6: group3_Eb();
517            0x6: decode MODRM_REG {
518                0x0: Inst::TEST(Eb,Iz);
519                0x1: Inst::TEST(Eb,Iz);
520                0x2: Inst::NOT(Eb);
521                0x3: Inst::NEG(Eb);
522                0x4: mul_Eb();
523                0x5: imul_Eb();
524                0x6: div_Eb();
525                0x7: idiv_Eb();
526            }
527            //0x7: group3_Ev();
528            0x7: decode MODRM_REG {
529                0x0: Inst::TEST(Ev,Iz);
530                0x1: Inst::TEST(Ev,Iz);
531                0x2: Inst::NOT(Ev);
532                0x3: Inst::NEG(Ev);
533                0x4: mul_Ev();
534                0x5: imul_Ev();
535                0x6: div_Ev();
536                0x7: idiv_Ev();
537            }
538        }
539        0x1F: decode OPCODE_OP_BOTTOM3 {
540            0x0: clc();
541            0x1: stc();
542            0x2: cli();
543            0x3: sti();
544            0x4: cld();
545            0x5: std();
546            format Inst {
547                //0x6: group4();
548                0x6: decode MODRM_REG {
549                    0x0: INC(Eb);
550                    0x1: DEC(Eb);
551                    default: UD2();
552                }
553                //0x7: group5();
554                0x7: decode MODRM_REG {
555                    0x0: INC(Ev);
556                    0x1: DEC(Ev);
557                    0x2: CALL_NEAR(Ev);
558                    0x3: WarnUnimpl::call_far_Mp();
559                    0x4: JMP(Ev);
560                    0x5: WarnUnimpl::jmp_far_Mp();
561                    0x6: PUSH(Ev);
562                    0x7: UD2();
563                }
564            }
565        }
566    }
567    default: FailUnimpl::oneByteOps();
568}
569