1 // Copyright (c) 2007-2008 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 {
66 default: WarnUnimpl::push_ES();
68 0x7: decode MODE_SUBMODE {
70 default: WarnUnimpl::pop_ES();
72 default: MultiInst::ADD(OPCODE_OP_BOTTOM3,
77 0x01: decode OPCODE_OP_BOTTOM3 {
78 0x6: decode MODE_SUBMODE {
80 default: WarnUnimpl::push_CS();
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 {
93 default: WarnUnimpl::push_SS();
95 0x7: decode MODE_SUBMODE {
97 default: WarnUnimpl::pop_SS();
99 default: MultiInst::ADC(OPCODE_OP_BOTTOM3,
104 0x03: decode OPCODE_OP_BOTTOM3 {
105 0x6: decode MODE_SUBMODE {
107 default: WarnUnimpl::push_DS();
109 0x7: decode MODE_SUBMODE {
111 default: WarnUnimpl::pop_DS();
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 {
123 default: WarnUnimpl::daa();
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!"}});
133 0x7: decode MODE_SUBMODE {
135 default: WarnUnimpl::das();
137 default: MultiInst::SUB(OPCODE_OP_BOTTOM3,
142 0x06: decode OPCODE_OP_BOTTOM3 {
143 0x6: M5InternalError::error(
144 {{"Tried to execute the SS segment override prefix!"}});
145 0x7: decode MODE_SUBMODE {
147 default: WarnUnimpl::aaa();
149 default: MultiInst::XOR(OPCODE_OP_BOTTOM3,
154 0x07: decode OPCODE_OP_BOTTOM3 {
155 0x6: M5InternalError::error(
156 {{"Tried to execute the DS segment override prefix!"}});
157 0x7: decode MODE_SUBMODE {
159 default: WarnUnimpl::aas();
161 default: MultiInst::CMP(OPCODE_OP_BOTTOM3,
166 0x08: decode MODE_SUBMODE {
167 0x0: M5InternalError::error (
168 {{"Tried to execute an REX prefix!"}});
171 0x09: decode MODE_SUBMODE {
172 0x0: M5InternalError::error (
173 {{"Tried to execute an REX prefix!"}});
178 0x0C: decode OPCODE_OP_BOTTOM3 {
179 0x0: decode MODE_SUBMODE {
183 0x1: decode MODE_SUBMODE {
187 0x2: decode MODE_SUBMODE {
189 default: BOUND(Gv,Mv);
191 0x3: decode MODE_SUBMODE {
192 //The second operand should really be of size "d", but it's
193 //set to "v" in order to have a consistent register size.
194 //This shouldn't affect behavior.
196 default: WarnUnimpl::arpl_Ew_Gw();
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!"}});
207 0x0D: decode OPCODE_OP_BOTTOM3 {
212 0x4: StringInst::INS(Yb,rD);
213 0x5: StringInst::INS(Yz,rD);
214 0x6: StringInst::OUTS(rD,Xb);
215 0x7: StringInst::OUTS(rD,Xz);
217 0x0E: decode OPCODE_OP_BOTTOM3 {
227 0x0F: decode OPCODE_OP_BOTTOM3 {
237 0x10: decode OPCODE_OP_BOTTOM3 {
238 //0x0: group1_Eb_Ib();
239 0x0: decode MODRM_REG {
249 //0x1: group1_Ev_Iz();
250 0x1: decode MODRM_REG {
260 0x2: decode MODE_SUBMODE {
262 //default: group1_Eb_Ib();
263 default: decode MODRM_REG {
274 //0x3: group1_Ev_Ib();
275 0x3: decode MODRM_REG {
290 0x11: decode OPCODE_OP_BOTTOM3 {
295 0x4: decode MODRM_REG {
297 0x3, 0x4, 0x5: MOV(Ev,Sv);
300 0x6: decode MODE_SUBMODE {
301 0x3, 0x4: MOV_REAL(Sv,Ev);
302 default: decode MODRM_REG {
303 0x1: UD2(); // Moving to the CS selector is illegal.
306 0x4, 0x5: MOV(Sv,Ev);
311 0x7: decode MODRM_REG {
316 0x12: decode OPCODE_OP_BOTTOM3 {
317 0x0: NOP(); //XXX repe makes this a "pause"
318 default: XCHG(Bv,rAv);
320 0x13: decode OPCODE_OP_BOTTOM3 {
323 0x2: decode MODE_SUBMODE {
325 default: WarnUnimpl::call_far_Ap();
327 0x3: WarnUnimpl::fwait(); //aka wait
330 //The 64 bit versions of both of these should be illegal only
331 //if CPUID says it isn't supported. For now, we'll just assume
332 //that it's supported.
336 0x14: decode OPCODE_OP_BOTTOM3 {
341 0x4: StringInst::MOVS(Yb,Xb);
342 0x5: StringInst::MOVS(Yv,Xv);
343 0x6: StringTestInst::CMPS(Yb,Xb);
344 0x7: StringTestInst::CMPS(Yv,Xv);
346 0x15: decode OPCODE_OP_BOTTOM3 {
349 0x2: StringInst::STOS(Yb);
350 0x3: StringInst::STOS(Yv);
351 0x4: StringInst::LODS(Xb);
352 0x5: StringInst::LODS(Xv);
353 0x6: StringTestInst::SCAS(Yb);
354 0x7: StringTestInst::SCAS(Yv);
358 0x18: decode OPCODE_OP_BOTTOM3 {
359 //0x0: group2_Eb_Ib();
360 0x0: decode MODRM_REG {
370 //0x1: group2_Ev_Ib();
371 0x1: decode MODRM_REG {
383 0x4: decode MODE_SUBMODE {
385 default: WarnUnimpl::les_Gz_Mp();
387 0x5: decode MODE_SUBMODE {
389 default: WarnUnimpl::lds_Gz_Mp();
391 //0x6: group12_Eb_Ib();
392 0x6: decode MODRM_REG {
396 //0x7: group12_Ev_Iz();
397 0x7: decode MODRM_REG {
403 0x19: decode OPCODE_OP_BOTTOM3 {
404 // The second parameter here should be of size b, but
405 // immediate sizes are determined elsewhere and this would
406 // confuse the instruction type specialization code.
407 0x0: Inst::ENTER(Iw,Iw);
410 0x3: decode MODE_SUBMODE {
411 0x3, 0x4: ret_far_real();
412 default: Inst::RET_FAR();
418 // Really only the LSB matters, but the predecoder will sign
419 // extend it, and there's no easy way to specify only checking
421 0x5: decode IMMEDIATE {
423 SyscallInst::int80('xc->syscall(Rax)', IsSyscall);
427 0x6: decode MODE_SUBMODE {
431 0x7: decode MODE_SUBMODE {
432 0x4: Inst::IRET_REAL();
433 0x3: Inst::IRET_VIRT();
434 default: Inst::IRET_PROT();
438 0x1A: decode OPCODE_OP_BOTTOM3 {
439 //0x0: group2_Eb_1();
440 0x0: decode MODRM_REG {
450 //0x1: group2_Ev_1();
451 0x1: decode MODRM_REG {
461 //0x2: group2_Eb_Cl();
462 0x2: decode MODRM_REG {
472 //The second operand should have size "b", but to have
473 //consistent register sizes it's "v". This shouldn't have
474 //any affect on functionality.
475 //0x3: group2_Ev_Cl();
476 0x3: decode MODRM_REG {
486 0x4: decode MODE_SUBMODE {
488 default: WarnUnimpl::aam_Ib();
490 0x5: decode MODE_SUBMODE {
492 default: WarnUnimpl::aad_Ib();
494 0x6: decode MODE_SUBMODE {
501 0x1C: decode OPCODE_OP_BOTTOM3 {
511 0x1D: decode OPCODE_OP_BOTTOM3 {
514 0x2: decode MODE_SUBMODE {
518 0x3: JMP_FAR_REAL(Iz);
519 0x4: JMP_FAR_REAL(Iz);
527 0x1E: decode OPCODE_OP_BOTTOM3 {
528 0x0: M5InternalError::error(
529 {{"Tried to execute the lock prefix!"}});
530 0x1: WarnUnimpl::int1();
531 0x2: M5InternalError::error(
532 {{"Tried to execute the repne prefix!"}});
533 0x3: M5InternalError::error(
534 {{"Tried to execute the rep/repe prefix!"}});
538 0x6: decode MODRM_REG {
545 //This should be Eb, but it access the entire word value ax.
550 0x7: decode MODRM_REG {
561 0x1F: decode OPCODE_OP_BOTTOM3 {
569 0x6: decode MODRM_REG {
575 0x7: decode MODRM_REG {
579 0x3: WarnUnimpl::call_far_Mp();
581 0x5: decode MODE_SUBMODE {
585 0x3: JMP_FAR_REAL(Mz);
586 0x4: JMP_FAR_REAL(Mz);
593 default: FailUnimpl::oneByteOps();