one_byte_opcodes.isa revision 4595:5162e9a7728c
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            0x4: ADD();
65            0x5: ADD();
66            0x6: decode MODE_SUBMODE {
67                0x0: This_should_be_an_illegal_instruction();
68                default: push_ES();
69            }
70            0x7: decode MODE_SUBMODE {
71                0x0: This_should_be_an_illegal_instruction();
72                default: pop_ES();
73            }
74            default: ADD();
75        }
76        0x01: decode OPCODE_OP_BOTTOM3 {
77            0x0: or_Eb_Gb();
78            0x1: or_Ev_Gv();
79            0x2: or_Gb_Eb();
80            0x3: or_Gv_Ev();
81            0x4: or_Al_Ib();
82            0x5: or_rAX_Iz();
83            0x6: decode MODE_SUBMODE {
84                0x0: This_should_be_an_illegal_instruction();
85                default: push_CS();
86            }
87            //Any time this is seen, it should generate a two byte opcode
88            0x7: M5InternalError::error(
89                {{"Saw a one byte opcode whose value was 0x0F!"}});
90        }
91        0x02: decode OPCODE_OP_BOTTOM3 {
92            0x0: adc_Eb_Gb();
93            0x1: adc_Ev_Gv();
94            0x2: adc_Gb_Eb();
95            0x3: adc_Gv_Ev();
96            0x4: adc_Al_Ib();
97            0x5: adc_rAX_Iz();
98            0x6: decode MODE_SUBMODE {
99                0x0: This_should_be_an_illegal_instruction();
100                default: push_SS();
101            }
102            0x7: decode MODE_SUBMODE {
103                0x0: This_should_be_an_illegal_instruction();
104                default: pop_SS();
105            }
106        }
107        0x03: decode OPCODE_OP_BOTTOM3 {
108            0x0: sbb_Eb_Gb();
109            0x1: sbb_Ev_Gv();
110            0x2: sbb_Gb_Eb();
111            0x3: sbb_Gv_Ev();
112            0x4: sbb_Al_Ib();
113            0x5: sbb_rAX_Iz();
114            0x6: decode MODE_SUBMODE {
115                0x0: This_should_be_an_illegal_instruction();
116                default: push_DS();
117            }
118            0x7: decode MODE_SUBMODE {
119                0x0: This_should_be_an_illegal_instruction();
120                default: pop_DS();
121            }
122        }
123        0x04: decode OPCODE_OP_BOTTOM3 {
124            0x0: and_Eb_Gb();
125            0x1: and_Ev_Gv();
126            0x2: and_Gb_Eb();
127            0x3: and_Gv_Ev();
128            0x4: and_Al_Ib();
129            0x5: and_rAX_Iz();
130            0x6: M5InternalError::error(
131                {{"Tried to execute the ES segment override prefix!"}});
132            0x7: decode MODE_SUBMODE {
133                0x0: This_should_be_an_illegal_instruction();
134                default: daa();
135            }
136        }
137        0x05: decode OPCODE_OP_BOTTOM3 {
138            0x0: sub_Eb_Gb();
139            0x1: sub_Ev_Gv();
140            0x2: sub_Gb_Eb();
141            0x3: sub_Gv_Ev();
142            0x4: sub_Al_Ib();
143            0x5: sub_rAX_Iz();
144            0x6: M5InternalError::error(
145                {{"Tried to execute the CS segment override prefix!"}});
146            0x7: das();
147        }
148        0x06: decode OPCODE_OP_BOTTOM3 {
149            0x4: Inst::XOR(rAl,Ib);
150            0x5: Inst::XOR(rAx,Iz);
151            0x6: M5InternalError::error(
152                {{"Tried to execute the SS segment override prefix!"}});
153            0x7: decode MODE_SUBMODE {
154                0x0: This_should_be_an_illegal_instruction();
155                default: aaa();
156            }
157            default: MultiInst::XOR(OPCODE_OP_BOTTOM3,
158                                    [Eb,Gb], [Ev,Gv],
159                                    [Gb,Eb], [Gv,Ev]);
160        }
161        0x07: decode OPCODE_OP_BOTTOM3 {
162            0x0: cmp_Eb_Gb();
163            0x1: cmp_Ev_Gv();
164            0x2: cmp_Gb_Eb();
165            0x3: cmp_Gv_Ev();
166            0x4: cmp_Al_Ib();
167            0x5: cmp_rAX_Iz();
168            0x6: M5InternalError::error(
169                {{"Tried to execute the DS segment override prefix!"}});
170            0x7: decode MODE_SUBMODE {
171                0x0: This_should_be_an_illegal_instruction();
172                default: aas();
173            }
174        }
175        0x08: decode MODE_SUBMODE {
176            0x0: M5InternalError::error (
177                {{"Tried to execute an REX prefix!"}});
178            default: decode OPCODE_OP_BOTTOM3 {
179                0x0: inc_eAX();
180                0x1: inc_eCX();
181                0x2: inc_eDX();
182                0x3: inc_eBX();
183                0x4: inc_eSP();
184                0x5: inc_eBP();
185                0x6: inc_eSI();
186                0x7: inc_eDI();
187            }
188        }
189        0x09: decode MODE_SUBMODE {
190            0x0: M5InternalError::error (
191                {{"Tried to execute an REX prefix!"}});
192            default: decode OPCODE_OP_BOTTOM3 {
193                0x0: dec_eAX();
194                0x1: dec_eCX();
195                0x2: dec_eDX();
196                0x3: dec_eBX();
197                0x4: dec_eSP();
198                0x5: dec_eBP();
199                0x6: dec_eSI();
200                0x7: dec_eDI();
201            }
202        }
203        format Inst {
204            0x0A: decode OPCODE_OP_BOTTOM3 {
205                0x0: PUSH(rAx);
206                0x1: PUSH(rCx);
207                0x2: PUSH(rDx);
208                0x3: PUSH(rBx);
209                0x4: PUSH(rSP);
210                0x5: PUSH(rBP);
211                0x6: PUSH(rSI);
212                0x7: PUSH(rDI);
213            }
214            0x0B: decode OPCODE_OP_BOTTOM3 {
215                0x0: POP(rAx);
216                0x1: POP(rCx);
217                0x2: POP(rDx);
218                0x3: POP(rBx);
219                0x4: POP(rSP);
220                0x5: POP(rBP);
221                0x6: POP(rSI);
222                0x7: POP(rDI);
223            }
224        }
225        0x0C: decode OPCODE_OP_BOTTOM3 {
226            0x0: decode MODE_SUBMODE {
227                0x0: This_should_be_an_illegal_instruction();
228                default: pusha();
229            }
230            0x1: decode MODE_SUBMODE {
231                0x0: This_should_be_an_illegal_instruction();
232                default: popa();
233            }
234            0x2: decode MODE_SUBMODE {
235                0x0: This_should_be_an_illegal_instruction();
236                default: bound_Gv_Ma();
237            }
238            0x3: decode MODE_SUBMODE {
239                0x0: Inst::MOVSXD(Gv,Ed);
240                default: arpl_Ew_Gw();
241            }
242            0x4: M5InternalError::error(
243                {{"Tried to execute the FS segment override prefix!"}});
244            0x5: M5InternalError::error(
245                {{"Tried to execute the GS segment override prefix!"}});
246            0x6: M5InternalError::error(
247                {{"Tried to execute the operand size override prefix!"}});
248            0x7: M5InternalError::error(
249                {{"Tried to execute the DS address size override prefix!"}});
250        }
251        0x0D: decode OPCODE_OP_BOTTOM3 {
252            0x0: push_Iz();
253            0x1: imul_Gv_Ev_Iz();
254            0x2: push_Ib();
255            0x3: imul_Gv_Ev_Ib();
256            0x4: ins_Yb_Dx();
257            0x5: ins_Yz_Dx();
258            0x6: outs_Dx_Xb();
259            0x7: outs_Dx_Xz();
260        }
261        0x0E: decode OPCODE_OP_BOTTOM3 {
262            0x0: jo_Jb();
263            0x1: jno_Jb();
264            0x2: jb_Jb();
265            0x3: jnb_Jb();
266            0x4: jz_Jb();
267            0x5: jnz_Jb();
268            0x6: jbe_Jb();
269            0x7: jnbe_Jb();
270        }
271        0x0F: decode OPCODE_OP_BOTTOM3 {
272            0x0: js_Jb();
273            0x1: jns_Jb();
274            0x2: jp_Jb();
275            0x3: jnp_Jb();
276            0x4: jl_Jb();
277            0x5: jnl_Jb();
278            0x6: jle_Jb();
279            0x7: jnke_Jb();
280        }
281        0x10: decode OPCODE_OP_BOTTOM3 {
282            0x0: group1_Eb_Ib();
283            0x1: group1_Ev_Iz();
284            0x2: decode MODE_SUBMODE {
285                0x0: This_should_be_an_illegal_instruction();
286                default: group1_Eb_Ib();
287            }
288            //0x3: group1_Ev_Ib();
289            0x3: decode MODRM_REG {
290                0x0: add_Eb_Ib();
291                0x1: or_Eb_Ib();
292                0x2: adc_Eb_Ib();
293                0x3: sbb_Eb_Ib();
294                0x4: Inst::AND(Eb,Ib);
295                0x5: sub_Eb_Ib();
296                0x6: xor_Eb_Ib();
297                0x7: cmp_Eb_Ib();
298            }
299            0x4: test_Eb_Gb();
300            0x5: test_Ev_Gv();
301            0x6: xchg_Eb_Gb();
302            0x7: xchg_Ev_Gv();
303        }
304        0x11: decode OPCODE_OP_BOTTOM3 {
305            0x0: Inst::MOV(Eb,Gb);
306            0x1: Inst::MOV(Ev,Gv);
307            0x2: Inst::MOV(Gb,Eb);
308            0x3: Inst::MOV(Gv,Eb);
309            0x4: mov_MwRv_Sw(); //What to do with this one?
310            0x5: lea_Gv_M();
311            0x6: mov_Sw_MwRv();
312            0x7: group10_Ev(); //Make sure this is Ev
313        }
314        0x12: decode OPCODE_OP_BOTTOM3 {
315            default: nop_or_pause(); //Check for repe prefix
316            0x1: xchg_rCX_rAX();
317            0x2: xchg_rDX_rAX();
318            0x3: xchg_rVX_rAX();
319            0x4: xchg_rSP_rAX();
320            0x5: xchg_rBP_rAX();
321            0x6: xchg_rSI_rAX();
322            0x7: xchg_rDI_rAX();
323        }
324        0x13: decode OPCODE_OP_BOTTOM3 {
325            0x0: cbw_or_cwde_or_cdqe_rAX();
326            0x1: cwd_or_cdq_or_cqo_rAX_rDX();
327            0x2: decode MODE_SUBMODE {
328                0x0: This_should_be_an_illegal_instruction();
329                default: call_Ap();
330            }
331            0x3: fwait(); //aka wait
332            0x4: pushf_Fv();
333            0x5: popf_Fv();
334            //Both of these should be illegal only if CPUID.AHF64=0,
335            //according to sandpile.org
336            0x6: decode MODE_SUBMODE {
337                0x0: This_should_be_an_illegal_instruction();
338                default: sahf();
339            }
340            0x7: decode MODE_SUBMODE {
341                0x0: This_should_be_an_illegal_instruction();
342                default: lahf();
343            }
344        }
345        0x14: decode OPCODE_OP_BOTTOM3 {
346            0x0: mov_Al_Ob();
347            0x1: mov_rAX_Ov();
348            0x2: mov_Ob_Al();
349            0x3: mov_Ov_rAX();
350            0x4: movs_Yb_Xb();
351            0x5: movs_Yv_Xv();
352            0x6: cmps_Yb_Xb();
353            0x7: cmps_Yv_Xv();
354        }
355        0x15: decode OPCODE_OP_BOTTOM3 {
356            0x0: test_Al_Ib();
357            0x1: test_rAX_Iz();
358            0x2: stos_Yb_Al();
359            0x3: stos_Yv_rAX();
360            0x4: lods_Al_Xb();
361            0x5: lods_rAX_Xv();
362            0x6: scas_Yb_Al();
363            0x7: scas_Yv_rAX();
364        }
365        0x16: decode OPCODE_OP_BOTTOM3 {
366            0x0: mov_Al_Ib();
367            0x1: mov_Cl_Ib();
368            0x2: mov_Dl_Ib();
369            0x3: mov_Bl_Ib();
370            0x4: mov_Ah_Ib();
371            0x5: mov_Ch_Ib();
372            0x6: mov_Dh_Ib();
373            0x7: mov_Bh_Ib();
374        }
375        0x17: decode OPCODE_OP_BOTTOM3 {
376            0x0: mov_rAX_Iv();
377            0x1: mov_rCX_Iv();
378            0x2: mov_rDX_Iv();
379            0x3: mov_rBX_Iv();
380            0x4: mov_rSP_Iv();
381            0x5: mov_rBP_Iv();
382            0x6: mov_rSI_Iv();
383            0x7: mov_rDI_Iv();
384        }
385        0x18: decode OPCODE_OP_BOTTOM3 {
386            0x0: group2_Eb_Ib();
387            0x1: group2_Ev_Ib();
388            0x2: ret_near_Iw();
389            0x3: ret_near();
390            0x4: decode MODE_SUBMODE {
391                0x0: This_should_be_an_illegal_instruction();
392                default: les_Gz_Mp();
393            }
394            0x5: decode MODE_SUBMODE {
395                0x0: This_should_be_an_illegal_instruction();
396                default: lds_Gz_Mp();
397            }
398            //0x6: group12_Eb_Ib();
399            0x6: decode MODRM_REG {
400                0x0: Inst::MOV(Eb,Ib);
401            }
402            //0x7: group12_Ev_Iz();
403            0x7: decode MODRM_REG {
404                0x0: Inst::MOV(Ev,Iz);
405            }
406        }
407        0x19: decode OPCODE_OP_BOTTOM3 {
408            0x0: enter_Iw_Ib();
409            0x1: leave();
410            0x2: ret_far_Iw();
411            0x3: ret_far();
412            0x4: int3();
413            0x5: int_Ib();
414            0x6: decode MODE_SUBMODE {
415                0x0: This_should_be_an_illegal_instruction();
416                default: into();
417            }
418            0x7: iret();
419        }
420        0x1A: decode OPCODE_OP_BOTTOM3 {
421            0x0: group2_Eb_1();
422            0x1: group2_Ev_1();
423            0x2: group2_Eb_Cl();
424            0x3: group2_Ev_Cl();
425            0x4: decode MODE_SUBMODE {
426                0x0: This_should_be_an_illegal_instruction();
427                default: aam_Ib();
428            }
429            0x5: decode MODE_SUBMODE {
430                0x0: This_should_be_an_illegal_instruction();
431                default: aad_Ib();
432            }
433            0x6: decode MODE_SUBMODE {
434                0x0: This_should_be_an_illegal_instruction();
435                default: salc();
436            }
437            0x7: xlat();
438        }
439        0x1B: decode OPCODE_OP_BOTTOM3 {
440            0x0: esc0();
441            0x1: esc1();
442            0x2: esc2();
443            0x3: esc3();
444            0x4: esc4();
445            0x5: esc5();
446            0x6: esc6();
447            0x7: esc7();
448        }
449        0x1C: decode OPCODE_OP_BOTTOM3 {
450            0x0: loopne_Jb();
451            0x1: loope_Jb();
452            0x2: loop_Jb();
453            0x3: jcxz_or_jecx_or_jrcx();
454            0x4: in_Al_Ib();
455            0x5: in_eAX_Ib();
456            0x6: out_Ib_Al();
457            0x7: out_Ib_eAX();
458        }
459        0x1D: decode OPCODE_OP_BOTTOM3 {
460            0x0: Inst::CALL(Jz);
461            0x1: jmp_Jz();
462            0x2: decode MODE_SUBMODE {
463                0x0: This_should_be_an_illegal_instruction();
464                default: jmp_Ap();
465            }
466            0x3: jmp_Jb();
467            0x4: in_Al_Dx();
468            0x5: in_eAX_Dx();
469            0x6: out_Dx_Al();
470            0x7: out_Dx_eAX();
471        }
472        0x1E: decode OPCODE_OP_BOTTOM3 {
473            0x0: M5InternalError::error(
474                {{"Tried to execute the lock prefix!"}});
475            0x1: int1();
476            0x2: M5InternalError::error(
477                {{"Tried to execute the repne prefix!"}});
478            0x3: M5InternalError::error(
479                {{"Tried to execute the rep/repe prefix!"}});
480            0x4: hlt();
481            0x5: cmc();
482            0x6: group3_Eb();
483            0x7: group3_Ev();
484        }
485        0x1F: decode OPCODE_OP_BOTTOM3 {
486            0x0: clc();
487            0x1: stc();
488            0x2: cli();
489            0x3: sti();
490            0x4: cld();
491            0x5: std();
492            0x6: group4();
493            0x7: group5();
494        }
495    }
496    default: FailUnimpl::oneByteOps();
497}
498