one_byte_opcodes.isa revision 4727:8a6b7746df57
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: Inst::INC(B);
171        }
172        0x09: decode MODE_SUBMODE {
173            0x0: M5InternalError::error (
174                {{"Tried to execute an REX prefix!"}});
175            default: Inst::DEC(B);
176        }
177        format Inst {
178            0x0A: PUSH(B);
179            0x0B: POP(B);
180        }
181        0x0C: decode OPCODE_OP_BOTTOM3 {
182            0x0: decode MODE_SUBMODE {
183                0x0: This_should_be_an_illegal_instruction();
184                default: pusha();
185            }
186            0x1: decode MODE_SUBMODE {
187                0x0: This_should_be_an_illegal_instruction();
188                default: popa();
189            }
190            0x2: decode MODE_SUBMODE {
191                0x0: This_should_be_an_illegal_instruction();
192                default: bound_Gv_Ma();
193            }
194            0x3: decode MODE_SUBMODE {
195                0x0: Inst::MOVSXD(Gv,Ed);
196                default: arpl_Ew_Gw();
197            }
198            0x4: M5InternalError::error(
199                {{"Tried to execute the FS segment override prefix!"}});
200            0x5: M5InternalError::error(
201                {{"Tried to execute the GS segment override prefix!"}});
202            0x6: M5InternalError::error(
203                {{"Tried to execute the operand size override prefix!"}});
204            0x7: M5InternalError::error(
205                {{"Tried to execute the DS address size override prefix!"}});
206        }
207        0x0D: decode OPCODE_OP_BOTTOM3 {
208            0x0: push_Iz();
209            0x1: imul_Gv_Ev_Iz();
210            0x2: push_Ib();
211            0x3: imul_Gv_Ev_Ib();
212            0x4: ins_Yb_Dx();
213            0x5: ins_Yz_Dx();
214            0x6: outs_Dx_Xb();
215            0x7: outs_Dx_Xz();
216        }
217        format Inst {
218            0x0E: decode OPCODE_OP_BOTTOM3 {
219                0x0: JO(Jb);
220                0x1: JNO(Jb);
221                0x2: JB(Jb);
222                0x3: JNB(Jb);
223                0x4: JZ(Jb);
224                0x5: JNZ(Jb);
225                0x6: JBE(Jb);
226                0x7: JNBE(Jb);
227            }
228            0x0F: decode OPCODE_OP_BOTTOM3 {
229                0x0: JS(Jb);
230                0x1: JNS(Jb);
231                0x2: JP(Jb);
232                0x3: JNP(Jb);
233                0x4: JL(Jb);
234                0x5: JNL(Jb);
235                0x6: JLE(Jb);
236                0x7: JNLE(Jb);
237            }
238        }
239        0x10: decode OPCODE_OP_BOTTOM3 {
240            //0x0: group1_Eb_Ib();
241            0x0: decode MODRM_REG {
242                0x0: Inst::ADD(Eb,Ib);
243                0x1: Inst::OR(Eb,Ib);
244                0x2: adc_Eb_Ib();
245                0x3: sbb_Eb_Ib();
246                0x4: Inst::AND(Eb,Ib);
247                0x5: Inst::SUB(Eb,Ib);
248                0x6: Inst::XOR(Eb,Ib);
249                0x7: Inst::CMP(Eb,Ib);
250            }
251            //0x1: group1_Ev_Iz();
252            0x1: decode MODRM_REG {
253                0x0: Inst::ADD(Ev,Iz);
254                0x1: Inst::OR(Ev,Iz);
255                0x2: adc_Ev_Iz();
256                0x3: sbb_Ev_Iz();
257                0x4: Inst::AND(Ev,Iz);
258                0x5: Inst::SUB(Ev,Iz);
259                0x6: Inst::XOR(Ev,Iz);
260                0x7: Inst::CMP(Ev,Iz);
261            }
262            0x2: decode MODE_SUBMODE {
263                0x0: This_should_be_an_illegal_instruction();
264                //default: group1_Eb_Ib();
265                default: decode MODRM_REG {
266                    0x0: Inst::ADD(Eb,Ib);
267                    0x1: Inst::OR(Eb,Ib);
268                    0x2: adc_Eb_Ib();
269                    0x3: sbb_Eb_Ib();
270                    0x4: Inst::AND(Eb,Ib);
271                    0x5: Inst::SUB(Eb,Ib);
272                    0x6: Inst::XOR(Eb,Ib);
273                    0x7: Inst::CMP(Eb,Ib);
274                }
275            }
276            //0x3: group1_Ev_Ib();
277            0x3: decode MODRM_REG {
278                0x0: Inst::ADD(Ev,Ib);
279                0x1: Inst::OR(Ev,Ib);
280                0x2: adc_Ev_Ib();
281                0x3: sbb_Ev_Ib();
282                0x4: Inst::AND(Ev,Ib);
283                0x5: Inst::SUB(Ev,Ib);
284                0x6: Inst::XOR(Ev,Ib);
285                0x7: Inst::CMP(Ev,Ib);
286            }
287            0x4: Inst::TEST(Eb,Gb);
288            0x5: Inst::TEST(Ev,Gv);
289            0x6: xchg_Eb_Gb();
290            0x7: xchg_Ev_Gv();
291        }
292        0x11: decode OPCODE_OP_BOTTOM3 {
293            0x0: Inst::MOV(Eb,Gb);
294            0x1: Inst::MOV(Ev,Gv);
295            0x2: Inst::MOV(Gb,Eb);
296            0x3: Inst::MOV(Gv,Ev);
297            0x4: mov_MwRv_Sw(); //What to do with this one?
298            0x5: Inst::LEA(Gv,M);
299            0x6: mov_Sw_MwRv();
300            0x7: group10_Ev(); //Make sure this is Ev
301        }
302        0x12: decode OPCODE_OP_BOTTOM3 {
303            0x0: Inst::NOP(); //XXX repe makes this a "pause"
304            default: xchg_B_rAX();
305        }
306        0x13: decode OPCODE_OP_BOTTOM3 {
307            0x0: cbw_or_cwde_or_cdqe_rAX();
308            0x1: cwd_or_cdq_or_cqo_rAX_rDX();
309            0x2: decode MODE_SUBMODE {
310                0x0: This_should_be_an_illegal_instruction();
311                default: call_Ap();
312            }
313            0x3: fwait(); //aka wait
314            0x4: pushf_Fv();
315            0x5: popf_Fv();
316            //Both of these should be illegal only if CPUID.AHF64=0,
317            //according to sandpile.org
318            0x6: decode MODE_SUBMODE {
319                0x0: This_should_be_an_illegal_instruction();
320                default: sahf();
321            }
322            0x7: decode MODE_SUBMODE {
323                0x0: This_should_be_an_illegal_instruction();
324                default: lahf();
325            }
326        }
327        0x14: decode OPCODE_OP_BOTTOM3 {
328            0x0: mov_Al_Ob();
329            0x1: mov_rAX_Ov();
330            0x2: mov_Ob_Al();
331            0x3: mov_Ov_rAX();
332            0x4: movs_Yb_Xb();
333            0x5: movs_Yv_Xv();
334            0x6: cmps_Yb_Xb();
335            0x7: cmps_Yv_Xv();
336        }
337        0x15: decode OPCODE_OP_BOTTOM3 {
338            0x0: Inst::TEST(rAl,Ib);
339            0x1: Inst::TEST(rAX,Iz);
340            0x2: stos_Yb_Al();
341            0x3: stos_Yv_rAX();
342            0x4: lods_Al_Xb();
343            0x5: lods_rAX_Xv();
344            0x6: scas_Yb_Al();
345            0x7: scas_Yv_rAX();
346        }
347        0x16: decode OPCODE_OP_BOTTOM3 {
348            0x0: mov_Al_Ib();
349            0x1: mov_Cl_Ib();
350            0x2: mov_Dl_Ib();
351            0x3: mov_Bl_Ib();
352            0x4: mov_Ah_Ib();
353            0x5: mov_Ch_Ib();
354            0x6: mov_Dh_Ib();
355            0x7: mov_Bh_Ib();
356        }
357        0x17: Inst::MOV(B,Iv);
358        0x18: decode OPCODE_OP_BOTTOM3 {
359            //0x0: group2_Eb_Ib();
360            0x0: decode MODRM_REG {
361                0x0: rol_Eb_Ib();
362                0x1: ror_Eb_Ib();
363                0x2: rcl_Eb_Ib();
364                0x3: rcr_Eb_Ib();
365                0x4: Inst::SAL(Eb,Ib);
366                0x5: shr_Eb_Ib();
367                0x6: Inst::SAL(Eb,Ib);
368                0x7: sar_Eb_Ib();
369            }
370            //0x1: group2_Ev_Ib();
371            0x1: decode MODRM_REG {
372                0x0: rol_Ev_Ib();
373                0x1: ror_Ev_Ib();
374                0x2: rcl_Ev_Ib();
375                0x3: rcr_Ev_Ib();
376                0x4: Inst::SAL(Ev,Ib);
377                0x5: shr_Ev_Ib();
378                0x6: Inst::SAL(Ev,Ib);
379                0x7: sar_Ev_Ib();
380            }
381            0x2: ret_near_Iw();
382            0x3: Inst::RET_NEAR();
383            0x4: decode MODE_SUBMODE {
384                0x0: This_should_be_an_illegal_instruction();
385                default: les_Gz_Mp();
386            }
387            0x5: decode MODE_SUBMODE {
388                0x0: This_should_be_an_illegal_instruction();
389                default: lds_Gz_Mp();
390            }
391            //0x6: group12_Eb_Ib();
392            0x6: decode MODRM_REG {
393                0x0: Inst::MOV(Eb,Ib);
394            }
395            //0x7: group12_Ev_Iz();
396            0x7: decode MODRM_REG {
397                0x0: Inst::MOV(Ev,Iz);
398            }
399        }
400        0x19: decode OPCODE_OP_BOTTOM3 {
401            0x0: enter_Iw_Ib();
402            0x1: leave();
403            0x2: ret_far_Iw();
404            0x3: ret_far();
405            0x4: int3();
406            0x5: int_Ib();
407            0x6: decode MODE_SUBMODE {
408                0x0: This_should_be_an_illegal_instruction();
409                default: into();
410            }
411            0x7: iret();
412        }
413        0x1A: decode OPCODE_OP_BOTTOM3 {
414            0x0: group2_Eb_1();
415            0x1: group2_Ev_1();
416            0x2: group2_Eb_Cl();
417            0x3: group2_Ev_Cl();
418            0x4: decode MODE_SUBMODE {
419                0x0: This_should_be_an_illegal_instruction();
420                default: aam_Ib();
421            }
422            0x5: decode MODE_SUBMODE {
423                0x0: This_should_be_an_illegal_instruction();
424                default: aad_Ib();
425            }
426            0x6: decode MODE_SUBMODE {
427                0x0: This_should_be_an_illegal_instruction();
428                default: salc();
429            }
430            0x7: xlat();
431        }
432        0x1B: decode OPCODE_OP_BOTTOM3 {
433            0x0: esc0();
434            0x1: esc1();
435            0x2: esc2();
436            0x3: esc3();
437            0x4: esc4();
438            0x5: esc5();
439            0x6: esc6();
440            0x7: esc7();
441        }
442        0x1C: decode OPCODE_OP_BOTTOM3 {
443            0x0: loopne_Jb();
444            0x1: loope_Jb();
445            0x2: loop_Jb();
446            0x3: jcxz_or_jecx_or_jrcx();
447            0x4: in_Al_Ib();
448            0x5: in_eAX_Ib();
449            0x6: out_Ib_Al();
450            0x7: out_Ib_eAX();
451        }
452        0x1D: decode OPCODE_OP_BOTTOM3 {
453            0x0: Inst::CALL_NEAR(Jz);
454            0x1: jmp_Jz();
455            0x2: decode MODE_SUBMODE {
456                0x0: This_should_be_an_illegal_instruction();
457                default: jmp_Ap();
458            }
459            0x3: Inst::JMP(Jb);
460            0x4: in_Al_Dx();
461            0x5: in_eAX_Dx();
462            0x6: out_Dx_Al();
463            0x7: out_Dx_eAX();
464        }
465        0x1E: decode OPCODE_OP_BOTTOM3 {
466            0x0: M5InternalError::error(
467                {{"Tried to execute the lock prefix!"}});
468            0x1: int1();
469            0x2: M5InternalError::error(
470                {{"Tried to execute the repne prefix!"}});
471            0x3: M5InternalError::error(
472                {{"Tried to execute the rep/repe prefix!"}});
473            0x4: hlt();
474            0x5: cmc();
475            0x6: group3_Eb();
476            0x7: group3_Ev();
477        }
478        0x1F: decode OPCODE_OP_BOTTOM3 {
479            0x0: clc();
480            0x1: stc();
481            0x2: cli();
482            0x3: sti();
483            0x4: cld();
484            0x5: std();
485            0x6: group4();
486            //0x7: group5();
487            0x7: decode MODRM_REG {
488                0x0: Inst::INC(Ev);
489                0x1: dev_Ev();
490                0x2: call_Ev();
491                0x3: call_Mp();
492                0x4: jmp_Ev();
493                0x5: jmp_Mp();
494                0x6: push_Ev();
495                0x7: This_should_be_an_illegal_instruction();
496            }
497        }
498    }
499    default: FailUnimpl::oneByteOps();
500}
501