| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/disassembler.h" | 5 #include "vm/disassembler.h" |
| 6 | 6 |
| 7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS. | 7 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS. |
| 8 #if defined(TARGET_ARCH_MIPS) | 8 #if defined(TARGET_ARCH_MIPS) |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // Printing of common values. | 31 // Printing of common values. |
| 32 void PrintRegister(Register reg); | 32 void PrintRegister(Register reg); |
| 33 | 33 |
| 34 int FormatRegister(Instr* instr, const char* format); | 34 int FormatRegister(Instr* instr, const char* format); |
| 35 int FormatOption(Instr* instr, const char* format); | 35 int FormatOption(Instr* instr, const char* format); |
| 36 void Format(Instr* instr, const char* format); | 36 void Format(Instr* instr, const char* format); |
| 37 | 37 |
| 38 void DecodeSpecial(Instr* instr); | 38 void DecodeSpecial(Instr* instr); |
| 39 void DecodeSpecial2(Instr* instr); | 39 void DecodeSpecial2(Instr* instr); |
| 40 void DecodeSpecial3(Instr* instr); |
| 40 | 41 |
| 41 // Convenience functions. | 42 // Convenience functions. |
| 42 char* get_buffer() const { return buffer_; } | 43 char* get_buffer() const { return buffer_; } |
| 43 char* current_position_in_buffer() { return buffer_ + buffer_pos_; } | 44 char* current_position_in_buffer() { return buffer_ + buffer_pos_; } |
| 44 size_t remaining_size_in_buffer() { return buffer_size_ - buffer_pos_; } | 45 size_t remaining_size_in_buffer() { return buffer_size_ - buffer_pos_; } |
| 45 | 46 |
| 46 char* buffer_; // Decode instructions into this buffer. | 47 char* buffer_; // Decode instructions into this buffer. |
| 47 size_t buffer_size_; // The size of the character buffer. | 48 size_t buffer_size_; // The size of the character buffer. |
| 48 size_t buffer_pos_; // Current character position in buffer. | 49 size_t buffer_pos_; // Current character position in buffer. |
| 49 | 50 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } else { | 170 } else { |
| 170 buffer_[buffer_pos_++] = cur; | 171 buffer_[buffer_pos_++] = cur; |
| 171 } | 172 } |
| 172 cur = *format++; | 173 cur = *format++; |
| 173 } | 174 } |
| 174 buffer_[buffer_pos_] = '\0'; | 175 buffer_[buffer_pos_] = '\0'; |
| 175 } | 176 } |
| 176 | 177 |
| 177 | 178 |
| 178 void MIPSDecoder::DecodeSpecial(Instr* instr) { | 179 void MIPSDecoder::DecodeSpecial(Instr* instr) { |
| 180 ASSERT(instr->OpcodeField() == SPECIAL); |
| 179 switch (instr->FunctionField()) { | 181 switch (instr->FunctionField()) { |
| 180 case ADDU: { | 182 case ADDU: { |
| 181 Format(instr, "addu 'rd, 'rs, 'rt"); | 183 Format(instr, "addu 'rd, 'rs, 'rt"); |
| 182 break; | 184 break; |
| 183 } | 185 } |
| 184 case AND: { | 186 case AND: { |
| 185 Format(instr, "and 'rd, 'rs, 'rt"); | 187 Format(instr, "and 'rd, 'rs, 'rt"); |
| 186 break; | 188 break; |
| 187 } | 189 } |
| 188 case DIV: { | 190 case DIV: { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 default: { | 222 default: { |
| 221 OS::PrintErr("DecodeSpecial: 0x%x\n", instr->InstructionBits()); | 223 OS::PrintErr("DecodeSpecial: 0x%x\n", instr->InstructionBits()); |
| 222 UNREACHABLE(); | 224 UNREACHABLE(); |
| 223 break; | 225 break; |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 | 229 |
| 228 | 230 |
| 229 void MIPSDecoder::DecodeSpecial2(Instr* instr) { | 231 void MIPSDecoder::DecodeSpecial2(Instr* instr) { |
| 232 ASSERT(instr->OpcodeField() == SPECIAL2); |
| 230 switch (instr->FunctionField()) { | 233 switch (instr->FunctionField()) { |
| 231 case CLO: { | 234 case CLO: { |
| 232 Format(instr, "clo 'rd, 'rs"); | 235 Format(instr, "clo 'rd, 'rs"); |
| 233 break; | 236 break; |
| 234 } | 237 } |
| 235 case CLZ: { | 238 case CLZ: { |
| 236 Format(instr, "clz 'rd, 'rs"); | 239 Format(instr, "clz 'rd, 'rs"); |
| 237 break; | 240 break; |
| 238 } | 241 } |
| 239 default: { | 242 default: { |
| 240 OS::PrintErr("DecodeSpecial2: 0x%x\n", instr->InstructionBits()); | 243 OS::PrintErr("DecodeSpecial2: 0x%x\n", instr->InstructionBits()); |
| 241 UNREACHABLE(); | 244 UNREACHABLE(); |
| 242 break; | 245 break; |
| 243 } | 246 } |
| 244 } | 247 } |
| 245 } | 248 } |
| 246 | 249 |
| 247 | 250 |
| 251 void MIPSDecoder::DecodeSpecial3(Instr* instr) { |
| 252 ASSERT(instr->OpcodeField() == SPECIAL3); |
| 253 switch (instr->FunctionField()) { |
| 254 default: { |
| 255 OS::PrintErr("DecodeSpecial3: 0x%x\n", instr->InstructionBits()); |
| 256 UNREACHABLE(); |
| 257 break; |
| 258 } |
| 259 } |
| 260 } |
| 261 |
| 262 |
| 248 void MIPSDecoder::InstructionDecode(Instr* instr) { | 263 void MIPSDecoder::InstructionDecode(Instr* instr) { |
| 249 switch (instr->OpcodeField()) { | 264 switch (instr->OpcodeField()) { |
| 250 case SPECIAL: { | 265 case SPECIAL: { |
| 251 DecodeSpecial(instr); | 266 DecodeSpecial(instr); |
| 252 break; | 267 break; |
| 253 } | 268 } |
| 254 case SPECIAL2: { | 269 case SPECIAL2: { |
| 255 DecodeSpecial2(instr); | 270 DecodeSpecial2(instr); |
| 256 break; | 271 break; |
| 257 } | 272 } |
| 258 case ADDI: { | 273 case SPECIAL3: { |
| 259 Format(instr, "addi 'rt, 'rs, 'immu"); | 274 DecodeSpecial3(instr); |
| 260 break; | 275 break; |
| 261 } | 276 } |
| 262 case ADDIU: { | 277 case ADDIU: { |
| 263 Format(instr, "addiu 'rt, 'rs, 'immu"); | 278 Format(instr, "addiu 'rt, 'rs, 'imms"); |
| 264 break; | 279 break; |
| 265 } | 280 } |
| 266 case ANDI: { | 281 case ANDI: { |
| 267 Format(instr, "andi 'rt, 'rs, 'immu"); | 282 Format(instr, "andi 'rt, 'rs, 'immu"); |
| 268 break; | 283 break; |
| 269 } | 284 } |
| 285 case LB: { |
| 286 Format(instr, "lb 'rt, 'imms('rs)"); |
| 287 break; |
| 288 } |
| 289 case LBU: { |
| 290 Format(instr, "lbu 'rt, 'imms('rs)"); |
| 291 break; |
| 292 } |
| 293 case LH: { |
| 294 Format(instr, "lh 'rt, 'imms('rs)"); |
| 295 break; |
| 296 } |
| 270 case LUI: { | 297 case LUI: { |
| 271 Format(instr, "lui 'rt, 'immu"); | 298 Format(instr, "lui 'rt, 'immu"); |
| 272 break; | 299 break; |
| 273 } | 300 } |
| 301 case LW: { |
| 302 Format(instr, "lw 'rt, 'imms('rs)"); |
| 303 break; |
| 304 } |
| 274 case ORI: { | 305 case ORI: { |
| 275 Format(instr, "ori 'rt, 'rs, 'immu"); | 306 Format(instr, "ori 'rt, 'rs, 'immu"); |
| 276 break; | 307 break; |
| 277 } | 308 } |
| 309 case SB: { |
| 310 Format(instr, "sb 'rt, 'imms('rs)"); |
| 311 break; |
| 312 } |
| 313 case SH: { |
| 314 Format(instr, "sh 'rt, 'imms('rs)"); |
| 315 break; |
| 316 } |
| 317 case SW: { |
| 318 Format(instr, "sw 'rt, 'imms('rs)"); |
| 319 break; |
| 320 } |
| 278 default: { | 321 default: { |
| 279 OS::PrintErr("Undecoded instruction: 0x%x\n", instr->InstructionBits()); | 322 OS::PrintErr("Undecoded instruction: 0x%x\n", instr->InstructionBits()); |
| 280 UNREACHABLE(); | 323 UNREACHABLE(); |
| 281 break; | 324 break; |
| 282 } | 325 } |
| 283 } | 326 } |
| 284 } | 327 } |
| 285 | 328 |
| 286 | 329 |
| 287 int Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, | 330 int Disassembler::DecodeInstruction(char* hex_buffer, intptr_t hex_size, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 human_buffer, | 366 human_buffer, |
| 324 sizeof(human_buffer), | 367 sizeof(human_buffer), |
| 325 pc); | 368 pc); |
| 326 pc += instruction_length; | 369 pc += instruction_length; |
| 327 } | 370 } |
| 328 } | 371 } |
| 329 | 372 |
| 330 } // namespace dart | 373 } // namespace dart |
| 331 | 374 |
| 332 #endif // defined TARGET_ARCH_MIPS | 375 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |