1 // Copyright (c) 2007-2008 The Hewlett-Packard Development Company
2 // All rights reserved.
4 // The license below extends only to copyright in the software and shall
5 // not be construed as granting a license to any other intellectual
6 // property including but not limited to intellectual property relating
7 // to a hardware implementation of the functionality of the software
8 // licensed hereunder. You may use the software subject to the license
9 // terms below provided that you ensure that this notice is replicated
10 // unmodified and in its entirety in all distributions of the software,
11 // modified or unmodified, in source code or in binary form.
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted provided that the following conditions are
15 // met: redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer;
17 // redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution;
20 // neither the name of the copyright holders nor the names of its
21 // contributors may be used to endorse or promote products derived from
22 // this software without specific prior written permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Authors: Gabe Black
38 ////////////////////////////////////////////////////////////////////
40 // Decode the one byte opcodes
43 'X86ISA::OneByteOpcode': decode OPCODE_OP_TOP5 {
45 0x00: decode OPCODE_OP_BOTTOM3 {
46 0x6: decode MODE_SUBMODE {
48 default: WarnUnimpl::push_ES();
50 0x7: decode MODE_SUBMODE {
52 default: WarnUnimpl::pop_ES();
54 default: MultiInst::ADD(OPCODE_OP_BOTTOM3,
59 0x01: decode OPCODE_OP_BOTTOM3 {
60 0x6: decode MODE_SUBMODE {
62 default: WarnUnimpl::push_CS();
64 //Any time this is seen, it should generate a two byte opcode
65 0x7: M5InternalError::error(
66 {{"Saw a one byte opcode whose value was 0x0F!"}});
67 default: MultiInst::OR(OPCODE_OP_BOTTOM3,
72 0x02: decode OPCODE_OP_BOTTOM3 {
73 0x6: decode MODE_SUBMODE {
75 default: WarnUnimpl::push_SS();
77 0x7: decode MODE_SUBMODE {
79 default: WarnUnimpl::pop_SS();
81 default: MultiInst::ADC(OPCODE_OP_BOTTOM3,
86 0x03: decode OPCODE_OP_BOTTOM3 {
87 0x6: decode MODE_SUBMODE {
89 default: WarnUnimpl::push_DS();
91 0x7: decode MODE_SUBMODE {
93 default: WarnUnimpl::pop_DS();
95 default: MultiInst::SBB(OPCODE_OP_BOTTOM3,
100 0x04: decode OPCODE_OP_BOTTOM3 {
101 0x6: M5InternalError::error(
102 {{"Tried to execute the ES segment override prefix!"}});
103 0x7: decode MODE_SUBMODE {
105 default: WarnUnimpl::daa();
107 default: MultiInst::AND(OPCODE_OP_BOTTOM3,
112 0x05: decode OPCODE_OP_BOTTOM3 {
113 0x6: M5InternalError::error(
114 {{"Tried to execute the CS segment override prefix!"}});
115 0x7: decode MODE_SUBMODE {
117 default: WarnUnimpl::das();
119 default: MultiInst::SUB(OPCODE_OP_BOTTOM3,
124 0x06: decode OPCODE_OP_BOTTOM3 {
125 0x6: M5InternalError::error(
126 {{"Tried to execute the SS segment override prefix!"}});
127 0x7: decode MODE_SUBMODE {
129 default: WarnUnimpl::aaa();
131 default: MultiInst::XOR(OPCODE_OP_BOTTOM3,
136 0x07: decode OPCODE_OP_BOTTOM3 {
137 0x6: M5InternalError::error(
138 {{"Tried to execute the DS segment override prefix!"}});
139 0x7: decode MODE_SUBMODE {
141 default: WarnUnimpl::aas();
143 default: MultiInst::CMP(OPCODE_OP_BOTTOM3,
148 0x08: decode MODE_SUBMODE {
149 0x0: M5InternalError::error (
150 {{"Tried to execute an REX prefix!"}});
153 0x09: decode MODE_SUBMODE {
154 0x0: M5InternalError::error (
155 {{"Tried to execute an REX prefix!"}});
160 0x0C: decode OPCODE_OP_BOTTOM3 {
161 0x0: decode MODE_SUBMODE {
165 0x1: decode MODE_SUBMODE {
169 0x2: decode MODE_SUBMODE {
171 default: BOUND(Gv,Mv);
173 0x3: decode MODE_SUBMODE {
174 //The second operand should really be of size "d", but it's
175 //set to "v" in order to have a consistent register size.
176 //This shouldn't affect behavior.
178 default: WarnUnimpl::arpl_Ew_Gw();
180 0x4: M5InternalError::error(
181 {{"Tried to execute the FS segment override prefix!"}});
182 0x5: M5InternalError::error(
183 {{"Tried to execute the GS segment override prefix!"}});
184 0x6: M5InternalError::error(
185 {{"Tried to execute the operand size override prefix!"}});
186 0x7: M5InternalError::error(
187 {{"Tried to execute the DS address size override prefix!"}});
189 0x0D: decode OPCODE_OP_BOTTOM3 {
194 0x4: StringInst::INS(Yb,rD);
195 0x5: StringInst::INS(Yz,rD);
196 0x6: StringInst::OUTS(rD,Xb);
197 0x7: StringInst::OUTS(rD,Xz);
199 0x0E: decode OPCODE_OP_BOTTOM3 {
209 0x0F: decode OPCODE_OP_BOTTOM3 {
219 0x10: decode OPCODE_OP_BOTTOM3 {
220 //0x0: group1_Eb_Ib();
221 0x0: decode MODRM_REG {
231 //0x1: group1_Ev_Iz();
232 0x1: decode MODRM_REG {
242 0x2: decode MODE_SUBMODE {
244 //default: group1_Eb_Ib();
245 default: decode MODRM_REG {
256 //0x3: group1_Ev_Ib();
257 0x3: decode MODRM_REG {
272 0x11: decode OPCODE_OP_BOTTOM3 {
277 0x4: decode MODRM_REG {
279 0x3, 0x4, 0x5: MOV(Ev,Sv);
282 0x6: decode MODE_SUBMODE {
283 0x3, 0x4: MOV_REAL(Sv,Ev);
284 default: decode MODRM_REG {
285 0x1: UD2(); // Moving to the CS selector is illegal.
288 0x4, 0x5: MOV(Sv,Ev);
293 0x7: decode MODRM_REG {
298 0x12: decode OPCODE_OP_BOTTOM3 {
299 0x0: NopInst::NOP(); //XXX repe makes this a "pause"
300 default: XCHG(Bv,rAv);
302 0x13: decode OPCODE_OP_BOTTOM3 {
305 0x2: decode MODE_SUBMODE {
307 default: WarnUnimpl::call_far_Ap();
309 0x3: WarnUnimpl::fwait(); //aka wait
312 //The 64 bit versions of both of these should be illegal only
313 //if CPUID says it isn't supported. For now, we'll just assume
314 //that it's supported.
318 0x14: decode OPCODE_OP_BOTTOM3 {
323 0x4: StringInst::MOVS(Yb,Xb);
324 0x5: StringInst::MOVS(Yv,Xv);
325 0x6: StringTestInst::CMPS(Yb,Xb);
326 0x7: StringTestInst::CMPS(Yv,Xv);
328 0x15: decode OPCODE_OP_BOTTOM3 {
331 0x2: StringInst::STOS(Yb);
332 0x3: StringInst::STOS(Yv);
333 0x4: StringInst::LODS(Xb);
334 0x5: StringInst::LODS(Xv);
335 0x6: StringTestInst::SCAS(Yb);
336 0x7: StringTestInst::SCAS(Yv);
340 0x18: decode OPCODE_OP_BOTTOM3 {
341 //0x0: group2_Eb_Ib();
342 0x0: decode MODRM_REG {
352 //0x1: group2_Ev_Ib();
353 0x1: decode MODRM_REG {
365 0x4: decode MODE_SUBMODE {
367 default: WarnUnimpl::les_Gz_Mp();
369 0x5: decode MODE_SUBMODE {
371 default: WarnUnimpl::lds_Gz_Mp();
373 //0x6: group12_Eb_Ib();
374 0x6: decode MODRM_REG {
378 //0x7: group12_Ev_Iz();
379 0x7: decode MODRM_REG {
385 0x19: decode OPCODE_OP_BOTTOM3 {
386 // The second parameter here should be of size b, but
387 // immediate sizes are determined elsewhere and this would
388 // confuse the instruction type specialization code.
389 0x0: Inst::ENTER(Iw,Iw);
392 0x3: decode MODE_SUBMODE {
393 0x3, 0x4: ret_far_real();
394 default: Inst::RET_FAR();
397 0x5: decode FullSystemInt default inst_ib() {
398 0: decode IMMEDIATE {
399 // Really only the LSB matters, but the decoder
400 // will sign extend it, and there's no easy way to
401 // specify only checking the first byte.
403 SyscallInst::int80('xc->syscall(Rax)',
404 IsSyscall, IsNonSpeculative, IsSerializeAfter);
407 default: Inst::INT(Ib);
409 0x6: decode MODE_SUBMODE {
413 0x7: decode MODE_SUBMODE {
414 0x4: Inst::IRET_REAL();
415 0x3: Inst::IRET_VIRT();
416 default: Inst::IRET_PROT();
420 0x1A: decode OPCODE_OP_BOTTOM3 {
421 //0x0: group2_Eb_1();
422 0x0: decode MODRM_REG {
432 //0x1: group2_Ev_1();
433 0x1: decode MODRM_REG {
443 //0x2: group2_Eb_Cl();
444 0x2: decode MODRM_REG {
454 //The second operand should have size "b", but to have
455 //consistent register sizes it's "v". This shouldn't have
456 //any affect on functionality.
457 //0x3: group2_Ev_Cl();
458 0x3: decode MODRM_REG {
468 0x4: decode MODE_SUBMODE {
470 default: WarnUnimpl::aam_Ib();
472 0x5: decode MODE_SUBMODE {
474 default: WarnUnimpl::aad_Ib();
476 0x6: decode MODE_SUBMODE {
483 0x1C: decode OPCODE_OP_BOTTOM3 {
493 0x1D: decode OPCODE_OP_BOTTOM3 {
496 0x2: decode MODE_SUBMODE {
500 0x3: JMP_FAR_REAL(Iz);
501 0x4: JMP_FAR_REAL(Iz);
509 0x1E: decode OPCODE_OP_BOTTOM3 {
510 0x0: M5InternalError::error(
511 {{"Tried to execute the lock prefix!"}});
512 0x1: WarnUnimpl::int1();
513 0x2: M5InternalError::error(
514 {{"Tried to execute the repne prefix!"}});
515 0x3: M5InternalError::error(
516 {{"Tried to execute the rep/repe prefix!"}});
520 0x6: decode MODRM_REG {
527 //This should be Eb, but it access the entire word value ax.
532 0x7: decode MODRM_REG {
543 0x1F: decode OPCODE_OP_BOTTOM3 {
551 0x6: decode MODRM_REG {
557 0x7: decode MODRM_REG {
561 0x3: WarnUnimpl::call_far_Mp();
563 0x5: decode MODE_SUBMODE {
567 0x3: JMP_FAR_REAL(Mz);
568 0x4: JMP_FAR_REAL(Mz);
575 default: FailUnimpl::oneByteOps();