one_byte_opcodes.isa revision 4732:9fdd1a5ab692
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: Inst::UD2(); 66 default: push_ES(); 67 } 68 0x7: decode MODE_SUBMODE { 69 0x0: Inst::UD2(); 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: Inst::UD2(); 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 0x6: decode MODE_SUBMODE { 92 0x0: Inst::UD2(); 93 default: push_SS(); 94 } 95 0x7: decode MODE_SUBMODE { 96 0x0: Inst::UD2(); 97 default: pop_SS(); 98 } 99 default: MultiInst::ADC(OPCODE_OP_BOTTOM3, 100 [Eb,Gb], [Ev,Gv], 101 [Gb,Eb], [Gv,Ev], 102 [rAl,Ib], [rAx,Iz]); 103 } 104 0x03: decode OPCODE_OP_BOTTOM3 { 105 0x6: decode MODE_SUBMODE { 106 0x0: Inst::UD2(); 107 default: push_DS(); 108 } 109 0x7: decode MODE_SUBMODE { 110 0x0: Inst::UD2(); 111 default: pop_DS(); 112 } 113 default: MultiInst::SBB(OPCODE_OP_BOTTOM3, 114 [Eb,Gb], [Ev,Gv], 115 [Gb,Eb], [Gv,Ev], 116 [rAl,Ib], [rAx,Iz]); 117 } 118 0x04: decode OPCODE_OP_BOTTOM3 { 119 0x6: M5InternalError::error( 120 {{"Tried to execute the ES segment override prefix!"}}); 121 0x7: decode MODE_SUBMODE { 122 0x0: Inst::UD2(); 123 default: daa(); 124 } 125 default: MultiInst::AND(OPCODE_OP_BOTTOM3, 126 [Eb,Gb], [Ev,Gv], 127 [Gb,Eb], [Gv,Ev], 128 [rAl,Ib], [rAx,Iz]); 129 } 130 0x05: decode OPCODE_OP_BOTTOM3 { 131 0x6: M5InternalError::error( 132 {{"Tried to execute the CS segment override prefix!"}}); 133 0x7: das(); 134 default: MultiInst::SUB(OPCODE_OP_BOTTOM3, 135 [Eb,Gb], [Ev,Gv], 136 [Gb,Eb], [Gv,Ev], 137 [rAl,Ib], [rAx,Iz]); 138 } 139 0x06: decode OPCODE_OP_BOTTOM3 { 140 0x6: M5InternalError::error( 141 {{"Tried to execute the SS segment override prefix!"}}); 142 0x7: decode MODE_SUBMODE { 143 0x0: Inst::UD2(); 144 default: aaa(); 145 } 146 default: MultiInst::XOR(OPCODE_OP_BOTTOM3, 147 [Eb,Gb], [Ev,Gv], 148 [Gb,Eb], [Gv,Ev], 149 [rAl,Ib], [rAx,Iz]); 150 } 151 0x07: decode OPCODE_OP_BOTTOM3 { 152 0x6: M5InternalError::error( 153 {{"Tried to execute the DS segment override prefix!"}}); 154 0x7: decode MODE_SUBMODE { 155 0x0: Inst::UD2(); 156 default: aas(); 157 } 158 default: MultiInst::CMP(OPCODE_OP_BOTTOM3, 159 [Eb,Gb], [Ev,Gv], 160 [Gb,Eb], [Gv,Ev], 161 [rAl,Ib], [rAx,Iz]); 162 } 163 0x08: decode MODE_SUBMODE { 164 0x0: M5InternalError::error ( 165 {{"Tried to execute an REX prefix!"}}); 166 default: Inst::INC(B); 167 } 168 0x09: decode MODE_SUBMODE { 169 0x0: M5InternalError::error ( 170 {{"Tried to execute an REX prefix!"}}); 171 default: Inst::DEC(B); 172 } 173 format Inst { 174 0x0A: PUSH(B); 175 0x0B: POP(B); 176 } 177 0x0C: decode OPCODE_OP_BOTTOM3 { 178 0x0: decode MODE_SUBMODE { 179 0x0: Inst::UD2(); 180 default: pusha(); 181 } 182 0x1: decode MODE_SUBMODE { 183 0x0: Inst::UD2(); 184 default: popa(); 185 } 186 0x2: decode MODE_SUBMODE { 187 0x0: Inst::UD2(); 188 default: bound_Gv_Ma(); 189 } 190 0x3: decode MODE_SUBMODE { 191 0x0: Inst::MOVSXD(Gv,Ed); 192 default: arpl_Ew_Gw(); 193 } 194 0x4: M5InternalError::error( 195 {{"Tried to execute the FS segment override prefix!"}}); 196 0x5: M5InternalError::error( 197 {{"Tried to execute the GS segment override prefix!"}}); 198 0x6: M5InternalError::error( 199 {{"Tried to execute the operand size override prefix!"}}); 200 0x7: M5InternalError::error( 201 {{"Tried to execute the DS address size override prefix!"}}); 202 } 203 0x0D: decode OPCODE_OP_BOTTOM3 { 204 0x0: push_Iz(); 205 0x1: imul_Gv_Ev_Iz(); 206 0x2: push_Ib(); 207 0x3: imul_Gv_Ev_Ib(); 208 0x4: ins_Yb_Dx(); 209 0x5: ins_Yz_Dx(); 210 0x6: outs_Dx_Xb(); 211 0x7: outs_Dx_Xz(); 212 } 213 format Inst { 214 0x0E: decode OPCODE_OP_BOTTOM3 { 215 0x0: JO(Jb); 216 0x1: JNO(Jb); 217 0x2: JB(Jb); 218 0x3: JNB(Jb); 219 0x4: JZ(Jb); 220 0x5: JNZ(Jb); 221 0x6: JBE(Jb); 222 0x7: JNBE(Jb); 223 } 224 0x0F: decode OPCODE_OP_BOTTOM3 { 225 0x0: JS(Jb); 226 0x1: JNS(Jb); 227 0x2: JP(Jb); 228 0x3: JNP(Jb); 229 0x4: JL(Jb); 230 0x5: JNL(Jb); 231 0x6: JLE(Jb); 232 0x7: JNLE(Jb); 233 } 234 } 235 0x10: decode OPCODE_OP_BOTTOM3 { 236 format Inst { 237 //0x0: group1_Eb_Ib(); 238 0x0: decode MODRM_REG { 239 0x0: ADD(Eb,Ib); 240 0x1: OR(Eb,Ib); 241 0x2: ADC(Eb,Ib); 242 0x3: SBB(Eb,Ib); 243 0x4: AND(Eb,Ib); 244 0x5: SUB(Eb,Ib); 245 0x6: XOR(Eb,Ib); 246 0x7: CMP(Eb,Ib); 247 } 248 //0x1: group1_Ev_Iz(); 249 0x1: decode MODRM_REG { 250 0x0: ADD(Ev,Iz); 251 0x1: OR(Ev,Iz); 252 0x2: ADC(Ev,Iz); 253 0x3: SBB(Ev,Iz); 254 0x4: AND(Ev,Iz); 255 0x5: SUB(Ev,Iz); 256 0x6: XOR(Ev,Iz); 257 0x7: CMP(Ev,Iz); 258 } 259 0x2: decode MODE_SUBMODE { 260 0x0: UD2(); 261 //default: group1_Eb_Ib(); 262 default: decode MODRM_REG { 263 0x0: ADD(Eb,Ib); 264 0x1: OR(Eb,Ib); 265 0x2: ADC(Eb,Ib); 266 0x3: SBB(Eb,Ib); 267 0x4: AND(Eb,Ib); 268 0x5: SUB(Eb,Ib); 269 0x6: XOR(Eb,Ib); 270 0x7: CMP(Eb,Ib); 271 } 272 } 273 //0x3: group1_Ev_Ib(); 274 0x3: decode MODRM_REG { 275 0x0: ADD(Ev,Ib); 276 0x1: OR(Ev,Ib); 277 0x2: ADC(Ev,Ib); 278 0x3: SBB(Ev,Ib); 279 0x4: AND(Ev,Ib); 280 0x5: SUB(Ev,Ib); 281 0x6: XOR(Ev,Ib); 282 0x7: CMP(Ev,Ib); 283 } 284 0x4: Inst::TEST(Eb,Gb); 285 0x5: Inst::TEST(Ev,Gv); 286 } 287 0x6: xchg_Eb_Gb(); 288 0x7: xchg_Ev_Gv(); 289 } 290 0x11: decode OPCODE_OP_BOTTOM3 { 291 0x0: Inst::MOV(Eb,Gb); 292 0x1: Inst::MOV(Ev,Gv); 293 0x2: Inst::MOV(Gb,Eb); 294 0x3: Inst::MOV(Gv,Ev); 295 0x4: mov_MwRv_Sw(); //What to do with this one? 296 0x5: Inst::LEA(Gv,M); 297 0x6: mov_Sw_MwRv(); 298 0x7: group10_Ev(); //Make sure this is Ev 299 } 300 0x12: decode OPCODE_OP_BOTTOM3 { 301 0x0: Inst::NOP(); //XXX repe makes this a "pause" 302 default: xchg_B_rAX(); 303 } 304 0x13: decode OPCODE_OP_BOTTOM3 { 305 0x0: cbw_or_cwde_or_cdqe_rAX(); 306 0x1: cwd_or_cdq_or_cqo_rAX_rDX(); 307 0x2: decode MODE_SUBMODE { 308 0x0: Inst::UD2(); 309 default: call_far_Ap(); 310 } 311 0x3: fwait(); //aka wait 312 0x4: pushf_Fv(); 313 0x5: popf_Fv(); 314 //Both of these should be illegal only if CPUID.AHF64=0, 315 //according to sandpile.org 316 0x6: decode MODE_SUBMODE { 317 0x0: Inst::UD2(); 318 default: sahf(); 319 } 320 0x7: decode MODE_SUBMODE { 321 0x0: Inst::UD2(); 322 default: lahf(); 323 } 324 } 325 0x14: decode OPCODE_OP_BOTTOM3 { 326 0x0: mov_Al_Ob(); 327 0x1: mov_rAX_Ov(); 328 0x2: mov_Ob_Al(); 329 0x3: mov_Ov_rAX(); 330 0x4: movs_Yb_Xb(); 331 0x5: movs_Yv_Xv(); 332 0x6: cmps_Yb_Xb(); 333 0x7: cmps_Yv_Xv(); 334 } 335 0x15: decode OPCODE_OP_BOTTOM3 { 336 0x0: Inst::TEST(rAl,Ib); 337 0x1: Inst::TEST(rAX,Iz); 338 0x2: stos_Yb_Al(); 339 0x3: stos_Yv_rAX(); 340 0x4: lods_Al_Xb(); 341 0x5: lods_rAX_Xv(); 342 0x6: scas_Yb_Al(); 343 0x7: scas_Yv_rAX(); 344 } 345 0x16: decode OPCODE_OP_BOTTOM3 { 346 0x0: mov_Al_Ib(); 347 0x1: mov_Cl_Ib(); 348 0x2: mov_Dl_Ib(); 349 0x3: mov_Bl_Ib(); 350 0x4: mov_Ah_Ib(); 351 0x5: mov_Ch_Ib(); 352 0x6: mov_Dh_Ib(); 353 0x7: mov_Bh_Ib(); 354 } 355 0x17: Inst::MOV(B,Iv); 356 0x18: decode OPCODE_OP_BOTTOM3 { 357 //0x0: group2_Eb_Ib(); 358 0x0: decode MODRM_REG { 359 0x0: Inst::ROL(Eb,Ib); 360 0x1: Inst::ROR(Eb,Ib); 361 0x2: rcl_Eb_Ib(); 362 0x3: rcr_Eb_Ib(); 363 0x4: Inst::SAL(Eb,Ib); 364 0x5: Inst::SHR(Eb,Ib); 365 0x6: Inst::SAL(Eb,Ib); 366 0x7: Inst::SAR(Eb,Ib); 367 } 368 //0x1: group2_Ev_Ib(); 369 0x1: decode MODRM_REG { 370 0x0: Inst::ROL(Ev,Ib); 371 0x1: Inst::ROR(Ev,Ib); 372 0x2: rcl_Ev_Ib(); 373 0x3: rcr_Ev_Ib(); 374 0x4: Inst::SAL(Ev,Ib); 375 0x5: Inst::SHR(Ev,Ib); 376 0x6: Inst::SAL(Ev,Ib); 377 0x7: Inst::SAR(Ev,Ib); 378 } 379 0x2: ret_near_Iw(); 380 0x3: Inst::RET_NEAR(); 381 0x4: decode MODE_SUBMODE { 382 0x0: Inst::UD2(); 383 default: les_Gz_Mp(); 384 } 385 0x5: decode MODE_SUBMODE { 386 0x0: Inst::UD2(); 387 default: lds_Gz_Mp(); 388 } 389 //0x6: group12_Eb_Ib(); 390 0x6: decode MODRM_REG { 391 0x0: Inst::MOV(Eb,Ib); 392 } 393 //0x7: group12_Ev_Iz(); 394 0x7: decode MODRM_REG { 395 0x0: Inst::MOV(Ev,Iz); 396 } 397 } 398 0x19: decode OPCODE_OP_BOTTOM3 { 399 0x0: enter_Iw_Ib(); 400 0x1: leave(); 401 0x2: ret_far_Iw(); 402 0x3: ret_far(); 403 0x4: int3(); 404 0x5: int_Ib(); 405 0x6: decode MODE_SUBMODE { 406 0x0: Inst::UD2(); 407 default: into(); 408 } 409 0x7: iret(); 410 } 411 0x1A: decode OPCODE_OP_BOTTOM3 { 412 0x0: group2_Eb_1(); 413 0x1: group2_Ev_1(); 414 0x2: group2_Eb_Cl(); 415 0x3: group2_Ev_Cl(); 416 0x4: decode MODE_SUBMODE { 417 0x0: Inst::UD2(); 418 default: aam_Ib(); 419 } 420 0x5: decode MODE_SUBMODE { 421 0x0: Inst::UD2(); 422 default: aad_Ib(); 423 } 424 0x6: decode MODE_SUBMODE { 425 0x0: Inst::UD2(); 426 default: salc(); 427 } 428 0x7: xlat(); 429 } 430 0x1B: decode OPCODE_OP_BOTTOM3 { 431 0x0: esc0(); 432 0x1: esc1(); 433 0x2: esc2(); 434 0x3: esc3(); 435 0x4: esc4(); 436 0x5: esc5(); 437 0x6: esc6(); 438 0x7: esc7(); 439 } 440 0x1C: decode OPCODE_OP_BOTTOM3 { 441 0x0: loopne_Jb(); 442 0x1: loope_Jb(); 443 0x2: loop_Jb(); 444 0x3: jcxz_or_jecx_or_jrcx(); 445 0x4: in_Al_Ib(); 446 0x5: in_eAX_Ib(); 447 0x6: out_Ib_Al(); 448 0x7: out_Ib_eAX(); 449 } 450 0x1D: decode OPCODE_OP_BOTTOM3 { 451 0x0: Inst::CALL_NEAR(Jz); 452 0x1: Inst::JMP(Jz); 453 0x2: decode MODE_SUBMODE { 454 0x0: Inst::UD2(); 455 default: jmp_far_Ap(); 456 } 457 0x3: Inst::JMP(Jb); 458 0x4: in_Al_Dx(); 459 0x5: in_eAX_Dx(); 460 0x6: out_Dx_Al(); 461 0x7: out_Dx_eAX(); 462 } 463 0x1E: decode OPCODE_OP_BOTTOM3 { 464 0x0: M5InternalError::error( 465 {{"Tried to execute the lock prefix!"}}); 466 0x1: int1(); 467 0x2: M5InternalError::error( 468 {{"Tried to execute the repne prefix!"}}); 469 0x3: M5InternalError::error( 470 {{"Tried to execute the rep/repe prefix!"}}); 471 0x4: hlt(); 472 0x5: cmc(); 473 0x6: group3_Eb(); 474 0x7: group3_Ev(); 475 } 476 0x1F: decode OPCODE_OP_BOTTOM3 { 477 0x0: clc(); 478 0x1: stc(); 479 0x2: cli(); 480 0x3: sti(); 481 0x4: cld(); 482 0x5: std(); 483 format Inst { 484 //0x6: group4(); 485 0x6: decode MODRM_REG { 486 0x0: INC(Eb); 487 0x1: DEC(Eb); 488 default: UD2(); 489 } 490 //0x7: group5(); 491 0x7: decode MODRM_REG { 492 0x0: INC(Ev); 493 0x1: DEC(Ev); 494 0x2: CALL_NEAR(Ev); 495 0x3: WarnUnimpl::call_far_Mp(); 496 0x4: JMP(Ev); 497 0x5: WarnUnimpl::jmp_far_Mp(); 498 0x6: PUSH(Ev); 499 0x7: UD2(); 500 } 501 } 502 } 503 } 504 default: FailUnimpl::oneByteOps(); 505} 506