one_byte_opcodes.isa revision 4725:441c280b5936
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: This_should_be_an_illegal_instruction();
66                default: push_ES();
67            }
68            0x7: decode MODE_SUBMODE {
69                0x0: This_should_be_an_illegal_instruction();
70                default: pop_ES();
71            }
72            default: MultiInst::ADD(OPCODE_OP_BOTTOM3,
73                                    [Eb,Gb], [Ev,Gv],
74                                    [Gb,Eb], [Gv,Ev],
75                                    [rAl,Ib], [rAx,Iz]);
76        }
77        0x01: decode OPCODE_OP_BOTTOM3 {
78            0x6: decode MODE_SUBMODE {
79                0x0: This_should_be_an_illegal_instruction();
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                                   [rAl,Ib], [rAx,Iz]);
89        }
90        0x02: decode OPCODE_OP_BOTTOM3 {
91            0x0: adc_Eb_Gb();
92            0x1: adc_Ev_Gv();
93            0x2: adc_Gb_Eb();
94            0x3: adc_Gv_Ev();
95            0x4: adc_Al_Ib();
96            0x5: adc_rAX_Iz();
97            0x6: decode MODE_SUBMODE {
98                0x0: This_should_be_an_illegal_instruction();
99                default: push_SS();
100            }
101            0x7: decode MODE_SUBMODE {
102                0x0: This_should_be_an_illegal_instruction();
103                default: pop_SS();
104            }
105        }
106        0x03: decode OPCODE_OP_BOTTOM3 {
107            0x0: sbb_Eb_Gb();
108            0x1: sbb_Ev_Gv();
109            0x2: sbb_Gb_Eb();
110            0x3: sbb_Gv_Ev();
111            0x4: sbb_Al_Ib();
112            0x5: sbb_rAX_Iz();
113            0x6: decode MODE_SUBMODE {
114                0x0: This_should_be_an_illegal_instruction();
115                default: push_DS();
116            }
117            0x7: decode MODE_SUBMODE {
118                0x0: This_should_be_an_illegal_instruction();
119                default: pop_DS();
120            }
121        }
122        0x04: decode OPCODE_OP_BOTTOM3 {
123            0x6: M5InternalError::error(
124                {{"Tried to execute the ES segment override prefix!"}});
125            0x7: decode MODE_SUBMODE {
126                0x0: This_should_be_an_illegal_instruction();
127                default: daa();
128            }
129            default: MultiInst::AND(OPCODE_OP_BOTTOM3,
130                                    [Eb,Gb], [Ev,Gv],
131                                    [Gb,Eb], [Gv,Ev],
132                                    [rAl,Ib], [rAx,Iz]);
133        }
134        0x05: decode OPCODE_OP_BOTTOM3 {
135            0x6: M5InternalError::error(
136                {{"Tried to execute the CS segment override prefix!"}});
137            0x7: das();
138            default: MultiInst::SUB(OPCODE_OP_BOTTOM3,
139                                    [Eb,Gb], [Ev,Gv],
140                                    [Gb,Eb], [Gv,Ev],
141                                    [rAl,Ib], [rAx,Iz]);
142        }
143        0x06: decode OPCODE_OP_BOTTOM3 {
144            0x6: M5InternalError::error(
145                {{"Tried to execute the SS segment override prefix!"}});
146            0x7: decode MODE_SUBMODE {
147                0x0: This_should_be_an_illegal_instruction();
148                default: aaa();
149            }
150            default: MultiInst::XOR(OPCODE_OP_BOTTOM3,
151                                    [Eb,Gb], [Ev,Gv],
152                                    [Gb,Eb], [Gv,Ev],
153                                    [rAl,Ib], [rAx,Iz]);
154        }
155        0x07: decode OPCODE_OP_BOTTOM3 {
156            0x6: M5InternalError::error(
157                {{"Tried to execute the DS segment override prefix!"}});
158            0x7: decode MODE_SUBMODE {
159                0x0: This_should_be_an_illegal_instruction();
160                default: aas();
161            }
162            default: MultiInst::CMP(OPCODE_OP_BOTTOM3,
163                                    [Eb,Gb], [Ev,Gv],
164                                    [Gb,Eb], [Gv,Ev],
165                                    [rAl,Ib], [rAx,Iz]);
166        }
167        0x08: decode MODE_SUBMODE {
168            0x0: M5InternalError::error (
169                {{"Tried to execute an REX prefix!"}});
170            default: decode OPCODE_OP_BOTTOM3 {
171                0x0: Inst::INC(rAx);
172                0x1: Inst::INC(rCx);
173                0x2: Inst::INC(rDx);
174                0x3: Inst::INC(rBx);
175                0x4: Inst::INC(rSP);
176                0x5: Inst::INC(rBP);
177                0x6: Inst::INC(rSI);
178                0x7: Inst::INC(rDI);
179            }
180        }
181        0x09: decode MODE_SUBMODE {
182            0x0: M5InternalError::error (
183                {{"Tried to execute an REX prefix!"}});
184            default: decode OPCODE_OP_BOTTOM3 {
185                0x0: Inst::DEC(rAx);
186                0x1: Inst::DEC(rCX);
187                0x2: Inst::DEC(rDx);
188                0x3: Inst::DEC(rBx);
189                0x4: Inst::DEC(rSP);
190                0x5: Inst::DEC(rBP);
191                0x6: Inst::DEC(rSI);
192                0x7: Inst::DEC(rDI);
193            }
194        }
195        format Inst {
196            0x0A: decode OPCODE_OP_BOTTOM3 {
197                0x0: PUSH(rAx);
198                0x1: PUSH(rCx);
199                0x2: PUSH(rDx);
200                0x3: PUSH(rBx);
201                0x4: PUSH(rSP);
202                0x5: PUSH(rBP);
203                0x6: PUSH(rSI);
204                0x7: PUSH(rDI);
205            }
206            0x0B: decode OPCODE_OP_BOTTOM3 {
207                0x0: POP(rAx);
208                0x1: POP(rCx);
209                0x2: POP(rDx);
210                0x3: POP(rBx);
211                0x4: POP(rSP);
212                0x5: POP(rBP);
213                0x6: POP(rSI);
214                0x7: POP(rDI);
215            }
216        }
217        0x0C: decode OPCODE_OP_BOTTOM3 {
218            0x0: decode MODE_SUBMODE {
219                0x0: This_should_be_an_illegal_instruction();
220                default: pusha();
221            }
222            0x1: decode MODE_SUBMODE {
223                0x0: This_should_be_an_illegal_instruction();
224                default: popa();
225            }
226            0x2: decode MODE_SUBMODE {
227                0x0: This_should_be_an_illegal_instruction();
228                default: bound_Gv_Ma();
229            }
230            0x3: decode MODE_SUBMODE {
231                0x0: Inst::MOVSXD(Gv,Ed);
232                default: arpl_Ew_Gw();
233            }
234            0x4: M5InternalError::error(
235                {{"Tried to execute the FS segment override prefix!"}});
236            0x5: M5InternalError::error(
237                {{"Tried to execute the GS segment override prefix!"}});
238            0x6: M5InternalError::error(
239                {{"Tried to execute the operand size override prefix!"}});
240            0x7: M5InternalError::error(
241                {{"Tried to execute the DS address size override prefix!"}});
242        }
243        0x0D: decode OPCODE_OP_BOTTOM3 {
244            0x0: push_Iz();
245            0x1: imul_Gv_Ev_Iz();
246            0x2: push_Ib();
247            0x3: imul_Gv_Ev_Ib();
248            0x4: ins_Yb_Dx();
249            0x5: ins_Yz_Dx();
250            0x6: outs_Dx_Xb();
251            0x7: outs_Dx_Xz();
252        }
253        0x0E: decode OPCODE_OP_BOTTOM3 {
254            0x0: jo_Jb();
255            0x1: jno_Jb();
256            0x2: jb_Jb();
257            0x3: Inst::JNB(Jb);
258            0x4: Inst::JZ(Jb);
259            0x5: Inst::JNZ(Jb);
260            0x6: Inst::JBE(Jb);
261            0x7: Inst::JNBE(Jb);
262        }
263        0x0F: decode OPCODE_OP_BOTTOM3 {
264            0x0: js_Jb();
265            0x1: jns_Jb();
266            0x2: jp_Jb();
267            0x3: jnp_Jb();
268            0x4: jl_Jb();
269            0x5: jnl_Jb();
270            0x6: jle_Jb();
271            0x7: Inst::JNLE(Jb);
272        }
273        0x10: decode OPCODE_OP_BOTTOM3 {
274            //0x0: group1_Eb_Ib();
275            0x0: decode MODRM_REG {
276                0x0: Inst::ADD(Eb,Ib);
277                0x1: Inst::OR(Eb,Ib);
278                0x2: adc_Eb_Ib();
279                0x3: sbb_Eb_Ib();
280                0x4: Inst::AND(Eb,Ib);
281                0x5: Inst::SUB(Eb,Ib);
282                0x6: Inst::XOR(Eb,Ib);
283                0x7: Inst::CMP(Eb,Ib);
284            }
285            //0x1: group1_Ev_Iz();
286            0x1: decode MODRM_REG {
287                0x0: add_Ev_Iz();
288                0x1: or_Ev_Ibz();
289                0x2: adc_Ev_Iz();
290                0x3: sbb_Ev_Iz();
291                0x4: Inst::AND(Ev,Iz);
292                0x5: Inst::SUB(Ev,Iz);
293                0x6: xor_Ev_Iz();
294                0x7: Inst::CMP(Ev,Iz);
295            }
296            0x2: decode MODE_SUBMODE {
297                0x0: This_should_be_an_illegal_instruction();
298                //default: group1_Eb_Ib();
299                default: decode MODRM_REG {
300                    0x0: Inst::ADD(Eb,Ib);
301                    0x1: Inst::OR(Eb,Ib);
302                    0x2: adc_Eb_Ib();
303                    0x3: sbb_Eb_Ib();
304                    0x4: Inst::AND(Eb,Ib);
305                    0x5: Inst::SUB(Eb,Ib);
306                    0x6: Inst::XOR(Eb,Ib);
307                    0x7: Inst::CMP(Eb,Ib);
308                }
309            }
310            //0x3: group1_Ev_Ib();
311            0x3: decode MODRM_REG {
312                0x0: Inst::ADD(Ev,Ib);
313                0x1: or_Ev_Ib();
314                0x2: adc_Ev_Ib();
315                0x3: sbb_Ev_Ib();
316                0x4: Inst::AND(Ev,Ib);
317                0x5: sub_Ev_Ib();
318                0x6: xor_Ev_Ib();
319                0x7: Inst::CMP(Ev,Ib);
320            }
321            0x4: Inst::TEST(Eb,Gb);
322            0x5: Inst::TEST(Ev,Gv);
323            0x6: xchg_Eb_Gb();
324            0x7: xchg_Ev_Gv();
325        }
326        0x11: decode OPCODE_OP_BOTTOM3 {
327            0x0: Inst::MOV(Eb,Gb);
328            0x1: Inst::MOV(Ev,Gv);
329            0x2: Inst::MOV(Gb,Eb);
330            0x3: Inst::MOV(Gv,Ev);
331            0x4: mov_MwRv_Sw(); //What to do with this one?
332            0x5: Inst::LEA(Gv,M);
333            0x6: mov_Sw_MwRv();
334            0x7: group10_Ev(); //Make sure this is Ev
335        }
336        0x12: decode OPCODE_OP_BOTTOM3 {
337            0x0: Inst::NOP(); //XXX repe makes this a "pause"
338            0x1: xchg_rCX_rAX();
339            0x2: xchg_rDX_rAX();
340            0x3: xchg_rBX_rAX();
341            0x4: xchg_rSP_rAX();
342            0x5: xchg_rBP_rAX();
343            0x6: xchg_rSI_rAX();
344            0x7: xchg_rDI_rAX();
345        }
346        0x13: decode OPCODE_OP_BOTTOM3 {
347            0x0: cbw_or_cwde_or_cdqe_rAX();
348            0x1: cwd_or_cdq_or_cqo_rAX_rDX();
349            0x2: decode MODE_SUBMODE {
350                0x0: This_should_be_an_illegal_instruction();
351                default: call_Ap();
352            }
353            0x3: fwait(); //aka wait
354            0x4: pushf_Fv();
355            0x5: popf_Fv();
356            //Both of these should be illegal only if CPUID.AHF64=0,
357            //according to sandpile.org
358            0x6: decode MODE_SUBMODE {
359                0x0: This_should_be_an_illegal_instruction();
360                default: sahf();
361            }
362            0x7: decode MODE_SUBMODE {
363                0x0: This_should_be_an_illegal_instruction();
364                default: lahf();
365            }
366        }
367        0x14: decode OPCODE_OP_BOTTOM3 {
368            0x0: mov_Al_Ob();
369            0x1: mov_rAX_Ov();
370            0x2: mov_Ob_Al();
371            0x3: mov_Ov_rAX();
372            0x4: movs_Yb_Xb();
373            0x5: movs_Yv_Xv();
374            0x6: cmps_Yb_Xb();
375            0x7: cmps_Yv_Xv();
376        }
377        0x15: decode OPCODE_OP_BOTTOM3 {
378            0x0: Inst::TEST(rAl,Ib);
379            0x1: Inst::TEST(rAX,Iz);
380            0x2: stos_Yb_Al();
381            0x3: stos_Yv_rAX();
382            0x4: lods_Al_Xb();
383            0x5: lods_rAX_Xv();
384            0x6: scas_Yb_Al();
385            0x7: scas_Yv_rAX();
386        }
387        0x16: decode OPCODE_OP_BOTTOM3 {
388            0x0: mov_Al_Ib();
389            0x1: mov_Cl_Ib();
390            0x2: mov_Dl_Ib();
391            0x3: mov_Bl_Ib();
392            0x4: mov_Ah_Ib();
393            0x5: mov_Ch_Ib();
394            0x6: mov_Dh_Ib();
395            0x7: mov_Bh_Ib();
396        }
397        format Inst {
398            0x17: decode OPCODE_OP_BOTTOM3 {
399                0x0: MOV(rAX,Iv);
400                0x1: MOV(rCX,Iv);
401                0x2: MOV(rDX,Iv);
402                0x3: MOV(rBX,Iv);
403                0x4: MOV(rSP,Iv);
404                0x5: MOV(rBP,Iv);
405                0x6: MOV(rSI,Iv);
406                0x7: MOV(rDI,Iv);
407            }
408        }
409        0x18: decode OPCODE_OP_BOTTOM3 {
410            //0x0: group2_Eb_Ib();
411            0x0: decode MODRM_REG {
412                0x0: rol_Eb_Ib();
413                0x1: ror_Eb_Ib();
414                0x2: rcl_Eb_Ib();
415                0x3: rcr_Eb_Ib();
416                0x4: Inst::SAL(Eb,Ib);
417                0x5: shr_Eb_Ib();
418                0x6: Inst::SAL(Eb,Ib);
419                0x7: sar_Eb_Ib();
420            }
421            //0x1: group2_Ev_Ib();
422            0x1: decode MODRM_REG {
423                0x0: rol_Ev_Ib();
424                0x1: ror_Ev_Ib();
425                0x2: rcl_Ev_Ib();
426                0x3: rcr_Ev_Ib();
427                0x4: Inst::SAL(Ev,Ib);
428                0x5: shr_Ev_Ib();
429                0x6: Inst::SAL(Ev,Ib);
430                0x7: sar_Ev_Ib();
431            }
432            0x2: ret_near_Iw();
433            0x3: Inst::RET_NEAR();
434            0x4: decode MODE_SUBMODE {
435                0x0: This_should_be_an_illegal_instruction();
436                default: les_Gz_Mp();
437            }
438            0x5: decode MODE_SUBMODE {
439                0x0: This_should_be_an_illegal_instruction();
440                default: lds_Gz_Mp();
441            }
442            //0x6: group12_Eb_Ib();
443            0x6: decode MODRM_REG {
444                0x0: Inst::MOV(Eb,Ib);
445            }
446            //0x7: group12_Ev_Iz();
447            0x7: decode MODRM_REG {
448                0x0: Inst::MOV(Ev,Iz);
449            }
450        }
451        0x19: decode OPCODE_OP_BOTTOM3 {
452            0x0: enter_Iw_Ib();
453            0x1: leave();
454            0x2: ret_far_Iw();
455            0x3: ret_far();
456            0x4: int3();
457            0x5: int_Ib();
458            0x6: decode MODE_SUBMODE {
459                0x0: This_should_be_an_illegal_instruction();
460                default: into();
461            }
462            0x7: iret();
463        }
464        0x1A: decode OPCODE_OP_BOTTOM3 {
465            0x0: group2_Eb_1();
466            0x1: group2_Ev_1();
467            0x2: group2_Eb_Cl();
468            0x3: group2_Ev_Cl();
469            0x4: decode MODE_SUBMODE {
470                0x0: This_should_be_an_illegal_instruction();
471                default: aam_Ib();
472            }
473            0x5: decode MODE_SUBMODE {
474                0x0: This_should_be_an_illegal_instruction();
475                default: aad_Ib();
476            }
477            0x6: decode MODE_SUBMODE {
478                0x0: This_should_be_an_illegal_instruction();
479                default: salc();
480            }
481            0x7: xlat();
482        }
483        0x1B: decode OPCODE_OP_BOTTOM3 {
484            0x0: esc0();
485            0x1: esc1();
486            0x2: esc2();
487            0x3: esc3();
488            0x4: esc4();
489            0x5: esc5();
490            0x6: esc6();
491            0x7: esc7();
492        }
493        0x1C: decode OPCODE_OP_BOTTOM3 {
494            0x0: loopne_Jb();
495            0x1: loope_Jb();
496            0x2: loop_Jb();
497            0x3: jcxz_or_jecx_or_jrcx();
498            0x4: in_Al_Ib();
499            0x5: in_eAX_Ib();
500            0x6: out_Ib_Al();
501            0x7: out_Ib_eAX();
502        }
503        0x1D: decode OPCODE_OP_BOTTOM3 {
504            0x0: Inst::CALL_NEAR(Jz);
505            0x1: jmp_Jz();
506            0x2: decode MODE_SUBMODE {
507                0x0: This_should_be_an_illegal_instruction();
508                default: jmp_Ap();
509            }
510            0x3: Inst::JMP(Jb);
511            0x4: in_Al_Dx();
512            0x5: in_eAX_Dx();
513            0x6: out_Dx_Al();
514            0x7: out_Dx_eAX();
515        }
516        0x1E: decode OPCODE_OP_BOTTOM3 {
517            0x0: M5InternalError::error(
518                {{"Tried to execute the lock prefix!"}});
519            0x1: int1();
520            0x2: M5InternalError::error(
521                {{"Tried to execute the repne prefix!"}});
522            0x3: M5InternalError::error(
523                {{"Tried to execute the rep/repe prefix!"}});
524            0x4: hlt();
525            0x5: cmc();
526            0x6: group3_Eb();
527            0x7: group3_Ev();
528        }
529        0x1F: decode OPCODE_OP_BOTTOM3 {
530            0x0: clc();
531            0x1: stc();
532            0x2: cli();
533            0x3: sti();
534            0x4: cld();
535            0x5: std();
536            0x6: group4();
537            //0x7: group5();
538            0x7: decode MODRM_REG {
539                0x0: Inst::INC(Ev);
540                0x1: dev_Ev();
541                0x2: call_Ev();
542                0x3: call_Mp();
543                0x4: jmp_Ev();
544                0x5: jmp_Mp();
545                0x6: push_Ev();
546                0x7: This_should_be_an_illegal_instruction();
547            }
548        }
549    }
550    default: FailUnimpl::oneByteOps();
551}
552