Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 void Print(const char* str); | 29 void Print(const char* str); |
| 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 | 40 |
| 40 // Convenience functions. | 41 // Convenience functions. |
| 41 char* get_buffer() const { return buffer_; } | 42 char* get_buffer() const { return buffer_; } |
| 42 char* current_position_in_buffer() { return buffer_ + buffer_pos_; } | 43 char* current_position_in_buffer() { return buffer_ + buffer_pos_; } |
| 43 size_t remaining_size_in_buffer() { return buffer_size_ - buffer_pos_; } | 44 size_t remaining_size_in_buffer() { return buffer_size_ - buffer_pos_; } |
| 44 | 45 |
| 45 char* buffer_; // Decode instructions into this buffer. | 46 char* buffer_; // Decode instructions into this buffer. |
| 46 size_t buffer_size_; // The size of the character buffer. | 47 size_t buffer_size_; // The size of the character buffer. |
| 47 size_t buffer_pos_; // Current character position in buffer. | 48 size_t buffer_pos_; // Current character position in buffer. |
| 48 | 49 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 buffer_[buffer_pos_++] = cur; | 170 buffer_[buffer_pos_++] = cur; |
| 170 } | 171 } |
| 171 cur = *format++; | 172 cur = *format++; |
| 172 } | 173 } |
| 173 buffer_[buffer_pos_] = '\0'; | 174 buffer_[buffer_pos_] = '\0'; |
| 174 } | 175 } |
| 175 | 176 |
| 176 | 177 |
| 177 void MIPSDecoder::DecodeSpecial(Instr* instr) { | 178 void MIPSDecoder::DecodeSpecial(Instr* instr) { |
| 178 switch (instr->FunctionField()) { | 179 switch (instr->FunctionField()) { |
| 180 case ADDU: { | |
| 181 Format(instr, "addu 'rd, 'rs, 'rt"); | |
| 182 break; | |
| 183 } | |
| 184 case AND: { | |
| 185 Format(instr, "and 'rd, 'rs, 'rt"); | |
| 186 break; | |
| 187 } | |
| 188 case DIV: { | |
| 189 Format(instr, "div 'rs, 'rt"); | |
| 190 break; | |
| 191 } | |
| 192 case DIVU: { | |
| 193 Format(instr, "divu 'rs, 'rt"); | |
| 194 break; | |
| 195 } | |
| 196 case MFHI: { | |
| 197 Format(instr, "mfhi 'rd"); | |
| 198 break; | |
| 199 } | |
| 200 case MFLO: { | |
| 201 Format(instr, "mflo 'rd"); | |
| 202 break; | |
| 203 } | |
| 179 case SLL: { | 204 case SLL: { |
| 180 if ((instr->RdField() == R0) && | 205 if ((instr->RdField() == R0) && |
| 181 (instr->RtField() == R0) && | 206 (instr->RtField() == R0) && |
| 182 (instr->SaField() == 0)) { | 207 (instr->SaField() == 0)) { |
| 183 Format(instr, "nop"); | 208 Format(instr, "nop"); |
| 184 } else { | 209 } else { |
| 185 Format(instr, "sll 'rd, 'rt, 'sa"); | 210 Format(instr, "sll 'rd, 'rt, 'sa"); |
| 186 } | 211 } |
| 187 break; | 212 break; |
| 188 } | 213 } |
| 189 case JR: { | 214 case JR: { |
| 190 ASSERT(instr->RtField() == R0); | 215 ASSERT(instr->RtField() == R0); |
| 191 ASSERT(instr->RdField() == R0); | 216 ASSERT(instr->RdField() == R0); |
| 192 Format(instr, "jr'hint 'rs"); | 217 Format(instr, "jr'hint 'rs"); |
| 193 break; | 218 break; |
| 194 } | 219 } |
| 195 default: { | 220 default: { |
| 196 OS::PrintErr("DecodeSpecial: 0x%x\n", instr->InstructionBits()); | 221 OS::PrintErr("DecodeSpecial: 0x%x\n", instr->InstructionBits()); |
| 197 UNREACHABLE(); | 222 UNREACHABLE(); |
| 198 break; | 223 break; |
| 199 } | 224 } |
| 200 } | 225 } |
| 201 } | 226 } |
| 202 | 227 |
| 203 | 228 |
| 229 void MIPSDecoder::DecodeSpecial2(Instr* instr) { | |
| 230 switch (instr->FunctionField()) { | |
| 231 case CLO: { | |
| 232 Format(instr, "clo 'rd, 'rs"); | |
| 233 break; | |
| 234 } | |
| 235 case CLZ: { | |
| 236 Format(instr, "clz 'rd, 'rs"); | |
| 237 break; | |
| 238 } | |
| 239 default: { | |
| 240 OS::PrintErr("DecodeSpecial2: 0x%x\n", instr->InstructionBits()); | |
| 241 UNREACHABLE(); | |
| 242 break; | |
| 243 } | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 | |
| 204 void MIPSDecoder::InstructionDecode(Instr* instr) { | 248 void MIPSDecoder::InstructionDecode(Instr* instr) { |
| 205 switch (instr->OpcodeField()) { | 249 switch (instr->OpcodeField()) { |
| 206 case SPECIAL: { | 250 case SPECIAL: { |
| 207 DecodeSpecial(instr); | 251 DecodeSpecial(instr); |
| 208 break; | 252 break; |
| 209 } | 253 } |
| 254 case SPECIAL2: { | |
| 255 DecodeSpecial2(instr); | |
| 256 break; | |
| 257 } | |
| 258 case ADDI: { | |
| 259 Format(instr, "addi 'rt, 'rs, 'immu"); | |
|
Ivan Posva
2013/03/11 06:03:27
'imms as this immediate is sign-extended.
zra
2013/03/11 15:46:03
Done.
| |
| 260 break; | |
| 261 } | |
| 262 case ADDIU: { | |
| 263 Format(instr, "addiu 'rt, 'rs, 'immu"); | |
|
Ivan Posva
2013/03/11 06:03:27
ditto.
zra
2013/03/11 15:46:03
Done.
| |
| 264 break; | |
| 265 } | |
| 266 case ANDI: { | |
| 267 Format(instr, "andi 'rt, 'rs, 'immu"); | |
| 268 break; | |
| 269 } | |
| 270 case LUI: { | |
| 271 Format(instr, "lui 'rt, 'immu"); | |
| 272 break; | |
| 273 } | |
| 210 case ORI: { | 274 case ORI: { |
| 211 Format(instr, "ori 'rt, 'rs, 'immu"); | 275 Format(instr, "ori 'rt, 'rs, 'immu"); |
| 212 break; | 276 break; |
| 213 } | 277 } |
| 214 default: { | 278 default: { |
| 215 OS::PrintErr("Undecoded instruction: 0x%x\n", instr->InstructionBits()); | 279 OS::PrintErr("Undecoded instruction: 0x%x\n", instr->InstructionBits()); |
| 216 UNREACHABLE(); | 280 UNREACHABLE(); |
| 217 break; | 281 break; |
| 218 } | 282 } |
| 219 } | 283 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 human_buffer, | 323 human_buffer, |
| 260 sizeof(human_buffer), | 324 sizeof(human_buffer), |
| 261 pc); | 325 pc); |
| 262 pc += instruction_length; | 326 pc += instruction_length; |
| 263 } | 327 } |
| 264 } | 328 } |
| 265 | 329 |
| 266 } // namespace dart | 330 } // namespace dart |
| 267 | 331 |
| 268 #endif // defined TARGET_ARCH_MIPS | 332 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |