OLD | NEW |
1 /* Copyright (c) 2007, Google Inc. | 1 /* Copyright (c) 2007, Google Inc. |
2 * All rights reserved. | 2 * All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // the instruction gives us the full length of the instruction in bytes. | 93 // the instruction gives us the full length of the instruction in bytes. |
94 instruction_bytes += operand_bytes_ + (current_byte - start_byte); | 94 instruction_bytes += operand_bytes_ + (current_byte - start_byte); |
95 | 95 |
96 // Return the instruction type, which was set by ProcessOpcode(). | 96 // Return the instruction type, which was set by ProcessOpcode(). |
97 return instruction_type_; | 97 return instruction_type_; |
98 } | 98 } |
99 | 99 |
100 void MiniDisassembler::Initialize() { | 100 void MiniDisassembler::Initialize() { |
101 operand_is_32_bits_ = operand_default_is_32_bits_; | 101 operand_is_32_bits_ = operand_default_is_32_bits_; |
102 address_is_32_bits_ = address_default_is_32_bits_; | 102 address_is_32_bits_ = address_default_is_32_bits_; |
| 103 #ifdef _M_X64 |
| 104 operand_default_support_64_bits_ = true; |
| 105 #else |
| 106 operand_default_support_64_bits_ = false; |
| 107 #endif |
| 108 operand_is_64_bits_ = false; |
103 operand_bytes_ = 0; | 109 operand_bytes_ = 0; |
104 have_modrm_ = false; | 110 have_modrm_ = false; |
105 should_decode_modrm_ = false; | 111 should_decode_modrm_ = false; |
106 instruction_type_ = IT_UNKNOWN; | 112 instruction_type_ = IT_UNKNOWN; |
107 got_f2_prefix_ = false; | 113 got_f2_prefix_ = false; |
108 got_f3_prefix_ = false; | 114 got_f3_prefix_ = false; |
109 got_66_prefix_ = false; | 115 got_66_prefix_ = false; |
110 } | 116 } |
111 | 117 |
112 InstructionType MiniDisassembler::ProcessPrefixes(unsigned char* start_byte, | 118 InstructionType MiniDisassembler::ProcessPrefixes(unsigned char* start_byte, |
113 unsigned int& size) { | 119 unsigned int& size) { |
114 InstructionType instruction_type = IT_GENERIC; | 120 InstructionType instruction_type = IT_GENERIC; |
115 const Opcode& opcode = s_ia32_opcode_map_[0].table_[*start_byte]; | 121 const Opcode& opcode = s_ia32_opcode_map_[0].table_[*start_byte]; |
116 | 122 |
117 switch (opcode.type_) { | 123 switch (opcode.type_) { |
118 case IT_PREFIX_ADDRESS: | 124 case IT_PREFIX_ADDRESS: |
119 address_is_32_bits_ = !address_default_is_32_bits_; | 125 address_is_32_bits_ = !address_default_is_32_bits_; |
120 goto nochangeoperand; | 126 goto nochangeoperand; |
121 case IT_PREFIX_OPERAND: | 127 case IT_PREFIX_OPERAND: |
122 operand_is_32_bits_ = !operand_default_is_32_bits_; | 128 operand_is_32_bits_ = !operand_default_is_32_bits_; |
123 nochangeoperand: | 129 nochangeoperand: |
124 case IT_PREFIX: | 130 case IT_PREFIX: |
125 | 131 |
126 if (0xF2 == (*start_byte)) | 132 if (0xF2 == (*start_byte)) |
127 got_f2_prefix_ = true; | 133 got_f2_prefix_ = true; |
128 else if (0xF3 == (*start_byte)) | 134 else if (0xF3 == (*start_byte)) |
129 got_f3_prefix_ = true; | 135 got_f3_prefix_ = true; |
130 else if (0x66 == (*start_byte)) | 136 else if (0x66 == (*start_byte)) |
131 got_66_prefix_ = true; | 137 got_66_prefix_ = true; |
| 138 else if (operand_default_support_64_bits_ && (*start_byte) & 0x48) |
| 139 operand_is_64_bits_ = true; |
132 | 140 |
133 instruction_type = opcode.type_; | 141 instruction_type = opcode.type_; |
134 size ++; | 142 size ++; |
135 // we got a prefix, so add one and check next byte | 143 // we got a prefix, so add one and check next byte |
136 ProcessPrefixes(start_byte + 1, size); | 144 ProcessPrefixes(start_byte + 1, size); |
137 default: | 145 default: |
138 break; // not a prefix byte | 146 break; // not a prefix byte |
139 } | 147 } |
140 | 148 |
141 return instruction_type; | 149 return instruction_type; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 case OT_PD: // Unaligned packed double-precision floating point value | 315 case OT_PD: // Unaligned packed double-precision floating point value |
308 operand_bytes_ += OS_DOUBLE_PRECISION_FLOATING; | 316 operand_bytes_ += OS_DOUBLE_PRECISION_FLOATING; |
309 break; | 317 break; |
310 case OT_SS: | 318 case OT_SS: |
311 // Scalar element of a 128-bit packed single-precision | 319 // Scalar element of a 128-bit packed single-precision |
312 // floating data. | 320 // floating data. |
313 // We simply return enItUnknown since we don't have to support | 321 // We simply return enItUnknown since we don't have to support |
314 // floating point | 322 // floating point |
315 succeeded = false; | 323 succeeded = false; |
316 break; | 324 break; |
317 case OT_V: // Word or doubleword, depending on operand-size attribute. | 325 case OT_V: // Word, doubleword or quadword, depending on operand-size |
318 if (operand_is_32_bits_) | 326 // attribute. |
| 327 if (operand_is_64_bits_ && flag_operand & AM_I && |
| 328 flag_operand & IOS_64) |
| 329 operand_bytes_ += OS_QUAD_WORD; |
| 330 else if (operand_is_32_bits_) |
319 operand_bytes_ += OS_DOUBLE_WORD; | 331 operand_bytes_ += OS_DOUBLE_WORD; |
320 else | 332 else |
321 operand_bytes_ += OS_WORD; | 333 operand_bytes_ += OS_WORD; |
322 break; | 334 break; |
323 case OT_W: // Word, regardless of operand-size attribute. | 335 case OT_W: // Word, regardless of operand-size attribute. |
324 operand_bytes_ += OS_WORD; | 336 operand_bytes_ += OS_WORD; |
325 break; | 337 break; |
326 | 338 |
327 // Can safely ignore these. | 339 // Can safely ignore these. |
328 case OT_A: // Two one-word operands in memory or two double-word | 340 case OT_A: // Two one-word operands in memory or two double-word |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 default: | 422 default: |
411 break; | 423 break; |
412 } | 424 } |
413 } | 425 } |
414 | 426 |
415 size++; | 427 size++; |
416 return true; | 428 return true; |
417 } | 429 } |
418 | 430 |
419 }; // namespace sidestep | 431 }; // namespace sidestep |
OLD | NEW |