1 // Copyright (c) 2007 The Hewlett-Packard Development Company
2 // All rights reserved.
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:
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.
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
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.
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.
54 // Authors: Gabe Black
56 ////////////////////////////////////////////////////////////////////
58 // Decode the one byte opcodes
61 0x1: decode OPCODE_OP_TOP5 {
63 0x00: decode OPCODE_OP_BOTTOM3 {
64 0x6: decode MODE_SUBMODE {
68 0x7: decode MODE_SUBMODE {
72 default: MultiInst::ADD(OPCODE_OP_BOTTOM3,
77 0x01: decode OPCODE_OP_BOTTOM3 {
78 0x6: decode MODE_SUBMODE {
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,
90 0x02: decode OPCODE_OP_BOTTOM3 {
91 0x6: decode MODE_SUBMODE {
95 0x7: decode MODE_SUBMODE {
99 default: MultiInst::ADC(OPCODE_OP_BOTTOM3,
104 0x03: decode OPCODE_OP_BOTTOM3 {
105 0x6: decode MODE_SUBMODE {
109 0x7: decode MODE_SUBMODE {
113 default: MultiInst::SBB(OPCODE_OP_BOTTOM3,
118 0x04: decode OPCODE_OP_BOTTOM3 {
119 0x6: M5InternalError::error(
120 {{"Tried to execute the ES segment override prefix!"}});
121 0x7: decode MODE_SUBMODE {
125 default: MultiInst::AND(OPCODE_OP_BOTTOM3,
130 0x05: decode OPCODE_OP_BOTTOM3 {
131 0x6: M5InternalError::error(
132 {{"Tried to execute the CS segment override prefix!"}});
134 default: MultiInst::SUB(OPCODE_OP_BOTTOM3,
139 0x06: decode OPCODE_OP_BOTTOM3 {
140 0x6: M5InternalError::error(
141 {{"Tried to execute the SS segment override prefix!"}});
142 0x7: decode MODE_SUBMODE {
146 default: MultiInst::XOR(OPCODE_OP_BOTTOM3,
151 0x07: decode OPCODE_OP_BOTTOM3 {
152 0x6: M5InternalError::error(
153 {{"Tried to execute the DS segment override prefix!"}});
154 0x7: decode MODE_SUBMODE {
158 default: MultiInst::CMP(OPCODE_OP_BOTTOM3,
164 0x08: decode MODE_SUBMODE {
165 0x0: M5InternalError::error (
166 {{"Tried to execute an REX prefix!"}});
169 0x09: decode MODE_SUBMODE {
170 0x0: M5InternalError::error (
171 {{"Tried to execute an REX prefix!"}});
177 0x0C: decode OPCODE_OP_BOTTOM3 {
178 0x0: decode MODE_SUBMODE {
180 default: Inst::PUSHA();
182 0x1: decode MODE_SUBMODE {
184 default: Inst::POPA();
186 0x2: decode MODE_SUBMODE {
188 default: bound_Gv_Ma();
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();
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!"}});
206 0x0D: decode OPCODE_OP_BOTTOM3 {
208 0x1: Inst::IMUL(Gv,Ev,Iz);
210 0x3: Inst::IMUL(Gv,Ev,Ib);
217 0x0E: decode OPCODE_OP_BOTTOM3 {
227 0x0F: decode OPCODE_OP_BOTTOM3 {
239 0x10: decode OPCODE_OP_BOTTOM3 {
240 //0x0: group1_Eb_Ib();
241 0x0: decode MODRM_REG {
251 //0x1: group1_Ev_Iz();
252 0x1: decode MODRM_REG {
262 0x2: decode MODE_SUBMODE {
264 //default: group1_Eb_Ib();
265 default: decode MODRM_REG {
276 //0x3: group1_Ev_Ib();
277 0x3: decode MODRM_REG {
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);
301 0x7: group10_Ev(); //Make sure this is Ev
303 0x12: decode OPCODE_OP_BOTTOM3 {
304 0x0: Inst::NOP(); //XXX repe makes this a "pause"
305 default: xchg_B_rAX();
307 0x13: decode OPCODE_OP_BOTTOM3 {
308 0x0: Inst::CDQE(rAv);
309 0x1: Inst::CQO(rAv,rDv);
310 0x2: decode MODE_SUBMODE {
312 default: call_far_Ap();
314 0x3: fwait(); //aka wait
317 //Both of these should be illegal only if CPUID.AHF64=0,
318 //according to sandpile.org
319 0x6: decode MODE_SUBMODE {
323 0x7: decode MODE_SUBMODE {
328 0x14: decode OPCODE_OP_BOTTOM3 {
335 0x6: StringInst::CMPS(Yb,Xb);
336 0x7: StringInst::CMPS(Yv,Xv);
338 0x15: decode OPCODE_OP_BOTTOM3 {
339 0x0: Inst::TEST(rAb,Ib);
340 0x1: Inst::TEST(rAv,Iz);
345 0x6: StringInst::SCAS(Yb);
346 0x7: StringInst::SCAS(Yv);
351 0x18: decode OPCODE_OP_BOTTOM3 {
352 //0x0: group2_Eb_Ib();
353 0x0: decode MODRM_REG {
363 //0x1: group2_Ev_Ib();
364 0x1: decode MODRM_REG {
376 0x4: decode MODE_SUBMODE {
378 default: WarnUnimpl::les_Gz_Mp();
380 0x5: decode MODE_SUBMODE {
382 default: WarnUnimpl::lds_Gz_Mp();
384 //0x6: group12_Eb_Ib();
385 0x6: decode MODRM_REG {
389 //0x7: group12_Ev_Iz();
390 0x7: decode MODRM_REG {
396 0x19: decode OPCODE_OP_BOTTOM3 {
403 0x6: decode MODE_SUBMODE {
409 0x1A: decode OPCODE_OP_BOTTOM3 {
411 //0x0: group2_Eb_1();
412 0x0: decode MODRM_REG {
422 //0x1: group2_Ev_1();
423 0x1: decode MODRM_REG {
433 //0x2: group2_Eb_Cl();
434 0x2: decode MODRM_REG {
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 {
459 0x4: decode MODE_SUBMODE {
463 0x5: decode MODE_SUBMODE {
467 0x6: decode MODE_SUBMODE {
474 0x1C: decode OPCODE_OP_BOTTOM3 {
478 0x3: jcxz_or_jecx_or_jrcx();
484 0x1D: decode OPCODE_OP_BOTTOM3 {
485 0x0: Inst::CALL_NEAR(Jz);
487 0x2: decode MODE_SUBMODE {
489 default: jmp_far_Ap();
497 0x1E: decode OPCODE_OP_BOTTOM3 {
498 0x0: M5InternalError::error(
499 {{"Tried to execute the lock prefix!"}});
501 0x2: M5InternalError::error(
502 {{"Tried to execute the repne prefix!"}});
503 0x3: M5InternalError::error(
504 {{"Tried to execute the rep/repe prefix!"}});
509 0x6: decode MODRM_REG {
516 //This should be Eb, but it access the entire word value ax.
521 0x7: decode MODRM_REG {
533 0x1F: decode OPCODE_OP_BOTTOM3 {
537 0x2: WarnUnimpl::cli();
538 0x3: WarnUnimpl::sti();
542 0x6: decode MODRM_REG {
548 0x7: decode MODRM_REG {
552 0x3: WarnUnimpl::call_far_Mp();
554 0x5: WarnUnimpl::jmp_far_Mp();
561 default: FailUnimpl::oneByteOps();