Deleted Added
sdiff udiff text old ( 11793:ef606668d247 ) new ( 12045:31d9a81ba286 )
full compact
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;

--- 82 unchanged lines hidden (view full) ---

91
92 //While there's still something to do...
93 while (!instDone && !outOfBytes) {
94 uint8_t nextByte = getNextByte();
95 switch (state) {
96 case PrefixState:
97 state = doPrefixState(nextByte);
98 break;
99
100 case TwoByteVexState:
101 state = doTwoByteVexState(nextByte);
102 break;
103
104 case ThreeByteVexFirstState:
105 state = doThreeByteVexFirstState(nextByte);
106 break;
107
108 case ThreeByteVexSecondState:
109 state = doThreeByteVexSecondState(nextByte);
110 break;
111
112 case OneByteOpcodeState:
113 state = doOneByteOpcodeState(nextByte);
114 break;
115 case TwoByteOpcodeState:
116 state = doTwoByteOpcodeState(nextByte);
117 break;
118 case ThreeByte0F38OpcodeState:
119 state = doThreeByte0F38OpcodeState(nextByte);

--- 97 unchanged lines hidden (view full) ---

217 case Repne:
218 DPRINTF(Decoder, "Found repne prefix.\n");
219 emi.legacy.repne = true;
220 break;
221 case RexPrefix:
222 DPRINTF(Decoder, "Found Rex prefix %#x.\n", nextByte);
223 emi.rex = nextByte;
224 break;
225
226 case Vex2Prefix:
227 DPRINTF(Decoder, "Found VEX two-byte prefix %#x.\n", nextByte);
228 emi.vex.zero = nextByte;
229 nextState = TwoByteVexState;
230 break;
231
232 case Vex3Prefix:
233 DPRINTF(Decoder, "Found VEX three-byte prefix %#x.\n", nextByte);
234 emi.vex.zero = nextByte;
235 nextState = ThreeByteVexFirstState;
236 break;
237
238 case 0:
239 nextState = OneByteOpcodeState;
240 break;
241
242 default:
243 panic("Unrecognized prefix %#x\n", nextByte);
244 }
245 return nextState;
246}
247
248Decoder::State
249Decoder::doTwoByteVexState(uint8_t nextByte)
250{
251 assert(emi.vex.zero == 0xc5);
252 consumeByte();
253 TwoByteVex tbe = 0;
254 tbe.first = nextByte;
255
256 emi.vex.first.r = tbe.first.r;
257 emi.vex.first.x = 1;
258 emi.vex.first.b = 1;
259 emi.vex.first.map_select = 1;
260
261 emi.vex.second.w = 0;
262 emi.vex.second.vvvv = tbe.first.vvvv;
263 emi.vex.second.l = tbe.first.l;
264 emi.vex.second.pp = tbe.first.pp;
265
266 emi.opcode.type = Vex;
267 return OneByteOpcodeState;
268}
269
270Decoder::State
271Decoder::doThreeByteVexFirstState(uint8_t nextByte)
272{
273 consumeByte();
274 emi.vex.first = nextByte;
275 return ThreeByteVexSecondState;
276}
277
278Decoder::State
279Decoder::doThreeByteVexSecondState(uint8_t nextByte)
280{
281 consumeByte();
282 emi.vex.second = nextByte;
283 emi.opcode.type = Vex;
284 return OneByteOpcodeState;
285}
286
287// Load the first opcode byte. Determine if there are more opcode bytes, and
288// if not, what immediate and/or ModRM is needed.
289Decoder::State
290Decoder::doOneByteOpcodeState(uint8_t nextByte)
291{
292 State nextState = ErrorState;
293 consumeByte();
294
295 if (emi.vex.zero != 0) {
296 DPRINTF(Decoder, "Found VEX opcode %#x.\n", nextByte);
297 emi.opcode.op = nextByte;
298 const uint8_t opcode_map = emi.vex.first.map_select;
299 nextState = processExtendedOpcode(ImmediateTypeVex[opcode_map]);
300 } else if (nextByte == 0x0f) {
301 nextState = TwoByteOpcodeState;
302 DPRINTF(Decoder, "Found opcode escape byte %#x.\n", nextByte);
303 } else {
304 DPRINTF(Decoder, "Found one byte opcode %#x.\n", nextByte);
305 emi.opcode.type = OneByteOpcode;
306 emi.opcode.op = nextByte;
307
308 nextState = processOpcode(ImmediateTypeOneByte, UsesModRMOneByte,
309 nextByte >= 0xA0 && nextByte <= 0xA3);
310 }

--- 105 unchanged lines hidden (view full) ---

416 } else {
417 instDone = true;
418 nextState = ResetState;
419 }
420 }
421 return nextState;
422}
423
424Decoder::State
425Decoder::processExtendedOpcode(ByteTable &immTable)
426{
427 //Figure out the effective operand size. This can be overriden to
428 //a fixed value at the decoder level.
429 int logOpSize;
430 if (emi.vex.second.w)
431 logOpSize = 3; // 64 bit operand size
432 else if (emi.vex.second.pp == 1)
433 logOpSize = altOp;
434 else
435 logOpSize = defOp;
436
437 //Set the actual op size
438 emi.opSize = 1 << logOpSize;
439
440 //Figure out the effective address size. This can be overriden to
441 //a fixed value at the decoder level.
442 int logAddrSize;
443 if (emi.legacy.addr)
444 logAddrSize = altAddr;
445 else
446 logAddrSize = defAddr;
447
448 //Set the actual address size
449 emi.addrSize = 1 << logAddrSize;
450
451 //Figure out the effective stack width. This can be overriden to
452 //a fixed value at the decoder level.
453 emi.stackSize = 1 << stack;
454
455 //Figure out how big of an immediate we'll retreive based
456 //on the opcode.
457 const uint8_t opcode = emi.opcode.op;
458
459 if (emi.vex.zero == 0xc5 || emi.vex.zero == 0xc4) {
460 int immType = immTable[opcode];
461 // Assume 64-bit mode;
462 immediateSize = SizeTypeToSize[2][immType];
463 }
464
465 if (opcode == 0x77) {
466 instDone = true;
467 return ResetState;
468 }
469 return ModRMState;
470}
471
472//Get the ModRM byte and determine what displacement, if any, there is.
473//Also determine whether or not to get the SIB byte, displacement, or
474//immediate next.
475Decoder::State
476Decoder::doModRMState(uint8_t nextByte)
477{
478 State nextState = ErrorState;
479 ModRM modRM = nextByte;

--- 224 unchanged lines hidden ---