decoder.cc (10593:a39de7b8d2c9) | decoder.cc (10924:d02e9c239892) |
---|---|
1/* 2 * Copyright (c) 2011 Google 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 34 unchanged lines hidden (view full) --- 43{ 44 origPC = basePC + offset; 45 DPRINTF(Decoder, "Setting origPC to %#x\n", origPC); 46 instBytes = &decodePages->lookup(origPC); 47 chunkIdx = 0; 48 49 emi.rex = 0; 50 emi.legacy = 0; | 1/* 2 * Copyright (c) 2011 Google 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 34 unchanged lines hidden (view full) --- 43{ 44 origPC = basePC + offset; 45 DPRINTF(Decoder, "Setting origPC to %#x\n", origPC); 46 instBytes = &decodePages->lookup(origPC); 47 chunkIdx = 0; 48 49 emi.rex = 0; 50 emi.legacy = 0; |
51 emi.vex = 0; 52 |
|
51 emi.opcode.type = BadOpcode; 52 emi.opcode.op = 0; 53 54 immediateCollected = 0; 55 emi.immediate = 0; 56 emi.displacement = 0; 57 emi.dispSize = 0; 58 --- 29 unchanged lines hidden (view full) --- 88 89 //While there's still something to do... 90 while (!instDone && !outOfBytes) { 91 uint8_t nextByte = getNextByte(); 92 switch (state) { 93 case PrefixState: 94 state = doPrefixState(nextByte); 95 break; | 53 emi.opcode.type = BadOpcode; 54 emi.opcode.op = 0; 55 56 immediateCollected = 0; 57 emi.immediate = 0; 58 emi.displacement = 0; 59 emi.dispSize = 0; 60 --- 29 unchanged lines hidden (view full) --- 90 91 //While there's still something to do... 92 while (!instDone && !outOfBytes) { 93 uint8_t nextByte = getNextByte(); 94 switch (state) { 95 case PrefixState: 96 state = doPrefixState(nextByte); 97 break; |
98 99 case TwoByteVexState: 100 state = doTwoByteVexState(nextByte); 101 break; 102 103 case ThreeByteVexFirstState: 104 state = doThreeByteVexFirstState(nextByte); 105 break; 106 107 case ThreeByteVexSecondState: 108 state = doThreeByteVexSecondState(nextByte); 109 break; 110 |
|
96 case OneByteOpcodeState: 97 state = doOneByteOpcodeState(nextByte); 98 break; 99 case TwoByteOpcodeState: 100 state = doTwoByteOpcodeState(nextByte); 101 break; 102 case ThreeByte0F38OpcodeState: 103 state = doThreeByte0F38OpcodeState(nextByte); --- 97 unchanged lines hidden (view full) --- 201 case Repne: 202 DPRINTF(Decoder, "Found repne prefix.\n"); 203 emi.legacy.repne = true; 204 break; 205 case RexPrefix: 206 DPRINTF(Decoder, "Found Rex prefix %#x.\n", nextByte); 207 emi.rex = nextByte; 208 break; | 111 case OneByteOpcodeState: 112 state = doOneByteOpcodeState(nextByte); 113 break; 114 case TwoByteOpcodeState: 115 state = doTwoByteOpcodeState(nextByte); 116 break; 117 case ThreeByte0F38OpcodeState: 118 state = doThreeByte0F38OpcodeState(nextByte); --- 97 unchanged lines hidden (view full) --- 216 case Repne: 217 DPRINTF(Decoder, "Found repne prefix.\n"); 218 emi.legacy.repne = true; 219 break; 220 case RexPrefix: 221 DPRINTF(Decoder, "Found Rex prefix %#x.\n", nextByte); 222 emi.rex = nextByte; 223 break; |
224 225 case Vex2Prefix: 226 DPRINTF(Decoder, "Found VEX two-byte prefix %#x.\n", nextByte); 227 emi.vex.zero = nextByte; 228 nextState = TwoByteVexState; 229 break; 230 231 case Vex3Prefix: 232 DPRINTF(Decoder, "Found VEX three-byte prefix %#x.\n", nextByte); 233 emi.vex.zero = nextByte; 234 nextState = ThreeByteVexFirstState; 235 break; 236 |
|
209 case 0: 210 nextState = OneByteOpcodeState; 211 break; | 237 case 0: 238 nextState = OneByteOpcodeState; 239 break; |
240 |
|
212 default: 213 panic("Unrecognized prefix %#x\n", nextByte); 214 } 215 return nextState; 216} 217 | 241 default: 242 panic("Unrecognized prefix %#x\n", nextByte); 243 } 244 return nextState; 245} 246 |
247Decoder::State 248Decoder::doTwoByteVexState(uint8_t nextByte) 249{ 250 assert(emi.vex.zero == 0xc5); 251 consumeByte(); 252 TwoByteVex tbe = 0; 253 tbe.first = nextByte; 254 255 emi.vex.first.r = tbe.first.r; 256 emi.vex.first.x = 1; 257 emi.vex.first.b = 1; 258 emi.vex.first.map_select = 1; 259 260 emi.vex.second.w = 0; 261 emi.vex.second.vvvv = tbe.first.vvvv; 262 emi.vex.second.l = tbe.first.l; 263 emi.vex.second.pp = tbe.first.pp; 264 265 emi.opcode.type = Vex; 266 return OneByteOpcodeState; 267} 268 269Decoder::State 270Decoder::doThreeByteVexFirstState(uint8_t nextByte) 271{ 272 consumeByte(); 273 emi.vex.first = nextByte; 274 return ThreeByteVexSecondState; 275} 276 277Decoder::State 278Decoder::doThreeByteVexSecondState(uint8_t nextByte) 279{ 280 consumeByte(); 281 emi.vex.second = nextByte; 282 emi.opcode.type = Vex; 283 return OneByteOpcodeState; 284} 285 |
|
218// Load the first opcode byte. Determine if there are more opcode bytes, and 219// if not, what immediate and/or ModRM is needed. 220Decoder::State 221Decoder::doOneByteOpcodeState(uint8_t nextByte) 222{ 223 State nextState = ErrorState; 224 consumeByte(); | 286// Load the first opcode byte. Determine if there are more opcode bytes, and 287// if not, what immediate and/or ModRM is needed. 288Decoder::State 289Decoder::doOneByteOpcodeState(uint8_t nextByte) 290{ 291 State nextState = ErrorState; 292 consumeByte(); |
225 if (nextByte == 0x0f) { | 293 294 if (emi.vex.zero != 0) { 295 DPRINTF(Decoder, "Found VEX opcode %#x.\n", nextByte); 296 emi.opcode.op = nextByte; 297 const uint8_t opcode_map = emi.vex.first.map_select; 298 nextState = processExtendedOpcode(ImmediateTypeVex[opcode_map]); 299 } else if (nextByte == 0x0f) { |
226 nextState = TwoByteOpcodeState; 227 DPRINTF(Decoder, "Found opcode escape byte %#x.\n", nextByte); 228 } else { 229 DPRINTF(Decoder, "Found one byte opcode %#x.\n", nextByte); 230 emi.opcode.type = OneByteOpcode; 231 emi.opcode.op = nextByte; 232 233 nextState = processOpcode(ImmediateTypeOneByte, UsesModRMOneByte, --- 107 unchanged lines hidden (view full) --- 341 } else { 342 instDone = true; 343 nextState = ResetState; 344 } 345 } 346 return nextState; 347} 348 | 300 nextState = TwoByteOpcodeState; 301 DPRINTF(Decoder, "Found opcode escape byte %#x.\n", nextByte); 302 } else { 303 DPRINTF(Decoder, "Found one byte opcode %#x.\n", nextByte); 304 emi.opcode.type = OneByteOpcode; 305 emi.opcode.op = nextByte; 306 307 nextState = processOpcode(ImmediateTypeOneByte, UsesModRMOneByte, --- 107 unchanged lines hidden (view full) --- 415 } else { 416 instDone = true; 417 nextState = ResetState; 418 } 419 } 420 return nextState; 421} 422 |
423Decoder::State 424Decoder::processExtendedOpcode(ByteTable &immTable) 425{ 426 //Figure out the effective operand size. This can be overriden to 427 //a fixed value at the decoder level. 428 int logOpSize; 429 if (emi.vex.second.w) 430 logOpSize = 3; // 64 bit operand size 431 else if (emi.vex.second.pp == 1) 432 logOpSize = altOp; 433 else 434 logOpSize = defOp; 435 436 //Set the actual op size 437 emi.opSize = 1 << logOpSize; 438 439 //Figure out the effective address size. This can be overriden to 440 //a fixed value at the decoder level. 441 int logAddrSize; 442 if(emi.legacy.addr) 443 logAddrSize = altAddr; 444 else 445 logAddrSize = defAddr; 446 447 //Set the actual address size 448 emi.addrSize = 1 << logAddrSize; 449 450 //Figure out the effective stack width. This can be overriden to 451 //a fixed value at the decoder level. 452 emi.stackSize = 1 << stack; 453 454 //Figure out how big of an immediate we'll retreive based 455 //on the opcode. 456 const uint8_t opcode = emi.opcode.op; 457 458 if (emi.vex.zero == 0xc5 || emi.vex.zero == 0xc4) { 459 int immType = immTable[opcode]; 460 // Assume 64-bit mode; 461 immediateSize = SizeTypeToSize[2][immType]; 462 } 463 464 if (opcode == 0x77) { 465 instDone = true; 466 return ResetState; 467 } 468 return ModRMState; 469} 470 |
|
349//Get the ModRM byte and determine what displacement, if any, there is. 350//Also determine whether or not to get the SIB byte, displacement, or 351//immediate next. 352Decoder::State 353Decoder::doModRMState(uint8_t nextByte) 354{ 355 State nextState = ErrorState; | 471//Get the ModRM byte and determine what displacement, if any, there is. 472//Also determine whether or not to get the SIB byte, displacement, or 473//immediate next. 474Decoder::State 475Decoder::doModRMState(uint8_t nextByte) 476{ 477 State nextState = ErrorState; |
356 ModRM modRM; 357 modRM = nextByte; | 478 ModRM modRM = nextByte; |
358 DPRINTF(Decoder, "Found modrm byte %#x.\n", nextByte); 359 if (defOp == 1) { 360 //figure out 16 bit displacement size 361 if ((modRM.mod == 0 && modRM.rm == 6) || modRM.mod == 2) 362 displacementSize = 2; 363 else if (modRM.mod == 1) 364 displacementSize = 1; 365 else --- 216 unchanged lines hidden --- | 479 DPRINTF(Decoder, "Found modrm byte %#x.\n", nextByte); 480 if (defOp == 1) { 481 //figure out 16 bit displacement size 482 if ((modRM.mod == 0 && modRM.rm == 6) || modRM.mod == 2) 483 displacementSize = 2; 484 else if (modRM.mod == 1) 485 displacementSize = 1; 486 else --- 216 unchanged lines hidden --- |