Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // A Disassembler object is used to disassemble a block of code instruction by |
| 6 | // instruction. The default implementation of the NameConverter object can be |
| 7 | // overriden to modify register names or to do symbol lookup on addresses. |
| 8 | // |
| 9 | // The example below will disassemble a block of code and print it to stdout. |
| 10 | // |
| 11 | // NameConverter converter; |
| 12 | // Disassembler d(converter); |
| 13 | // for (byte* pc = begin; pc < end;) { |
| 14 | // v8::internal::EmbeddedVector<char, 256> buffer; |
| 15 | // byte* prev_pc = pc; |
| 16 | // pc += d.InstructionDecode(buffer, pc); |
| 17 | // printf("%p %08x %s\n", |
| 18 | // prev_pc, *reinterpret_cast<int32_t*>(prev_pc), buffer); |
| 19 | // } |
| 20 | // |
| 21 | // The Disassembler class also has a convenience method to disassemble a block |
| 22 | // of code into a FILE*, meaning that the above functionality could also be |
| 23 | // achieved by just calling Disassembler::Disassemble(stdout, begin, end); |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <stdarg.h> |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #if V8_TARGET_ARCH_S390 |
| 31 | |
| 32 | #include "src/base/platform/platform.h" |
| 33 | #include "src/disasm.h" |
| 34 | #include "src/macro-assembler.h" |
| 35 | #include "src/s390/constants-s390.h" |
| 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | //------------------------------------------------------------------------------ |
| 41 | |
| 42 | // Decoder decodes and disassembles instructions into an output buffer. |
| 43 | // It uses the converter to convert register names and call destinations into |
| 44 | // more informative description. |
| 45 | class Decoder { |
| 46 | public: |
| 47 | Decoder(const disasm::NameConverter& converter, Vector<char> out_buffer) |
| 48 | : converter_(converter), out_buffer_(out_buffer), out_buffer_pos_(0) { |
| 49 | out_buffer_[out_buffer_pos_] = '\0'; |
| 50 | } |
| 51 | |
| 52 | ~Decoder() {} |
| 53 | |
| 54 | // Writes one disassembled instruction into 'buffer' (0-terminated). |
| 55 | // Returns the length of the disassembled machine instruction in bytes. |
| 56 | int InstructionDecode(byte* instruction); |
| 57 | |
| 58 | private: |
| 59 | // Bottleneck functions to print into the out_buffer. |
| 60 | void PrintChar(const char ch); |
| 61 | void Print(const char* str); |
| 62 | |
| 63 | // Printing of common values. |
| 64 | void PrintRegister(int reg); |
| 65 | void PrintDRegister(int reg); |
| 66 | void PrintSoftwareInterrupt(SoftwareInterruptCodes svc); |
| 67 | |
| 68 | // Handle formatting of instructions and their options. |
| 69 | int FormatRegister(Instruction* instr, const char* option); |
| 70 | int FormatFloatingRegister(Instruction* instr, const char* option); |
| 71 | int FormatMask(Instruction* instr, const char* option); |
| 72 | int FormatDisplacement(Instruction* instr, const char* option); |
| 73 | int FormatImmediate(Instruction* instr, const char* option); |
| 74 | int FormatOption(Instruction* instr, const char* option); |
| 75 | void Format(Instruction* instr, const char* format); |
| 76 | void Unknown(Instruction* instr); |
| 77 | void UnknownFormat(Instruction* instr, const char* opcname); |
| 78 | |
| 79 | bool DecodeTwoByte(Instruction* instr); |
| 80 | bool DecodeFourByte(Instruction* instr); |
| 81 | bool DecodeSixByte(Instruction* instr); |
| 82 | |
| 83 | const disasm::NameConverter& converter_; |
| 84 | Vector<char> out_buffer_; |
| 85 | int out_buffer_pos_; |
| 86 | |
| 87 | DISALLOW_COPY_AND_ASSIGN(Decoder); |
| 88 | }; |
| 89 | |
| 90 | // Support for assertions in the Decoder formatting functions. |
| 91 | #define STRING_STARTS_WITH(string, compare_string) \ |
| 92 | (strncmp(string, compare_string, strlen(compare_string)) == 0) |
| 93 | |
| 94 | // Append the ch to the output buffer. |
| 95 | void Decoder::PrintChar(const char ch) { out_buffer_[out_buffer_pos_++] = ch; } |
| 96 | |
| 97 | // Append the str to the output buffer. |
| 98 | void Decoder::Print(const char* str) { |
| 99 | char cur = *str++; |
| 100 | while (cur != '\0' && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
| 101 | PrintChar(cur); |
| 102 | cur = *str++; |
| 103 | } |
| 104 | out_buffer_[out_buffer_pos_] = 0; |
| 105 | } |
| 106 | |
| 107 | // Print the register name according to the active name converter. |
| 108 | void Decoder::PrintRegister(int reg) { |
| 109 | Print(converter_.NameOfCPURegister(reg)); |
| 110 | } |
| 111 | |
| 112 | // Print the double FP register name according to the active name converter. |
| 113 | void Decoder::PrintDRegister(int reg) { |
| 114 | Print(DoubleRegister::from_code(reg).ToString()); |
| 115 | } |
| 116 | |
| 117 | // Print SoftwareInterrupt codes. Factoring this out reduces the complexity of |
| 118 | // the FormatOption method. |
| 119 | void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) { |
| 120 | switch (svc) { |
| 121 | case kCallRtRedirected: |
| 122 | Print("call rt redirected"); |
| 123 | return; |
| 124 | case kBreakpoint: |
| 125 | Print("breakpoint"); |
| 126 | return; |
| 127 | default: |
| 128 | if (svc >= kStopCode) { |
| 129 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d - 0x%x", |
| 130 | svc & kStopCodeMask, svc & kStopCodeMask); |
| 131 | } else { |
| 132 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", svc); |
| 133 | } |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Handle all register based formatting in this function to reduce the |
| 139 | // complexity of FormatOption. |
| 140 | int Decoder::FormatRegister(Instruction* instr, const char* format) { |
| 141 | DCHECK(format[0] == 'r'); |
| 142 | |
| 143 | if (format[1] == '1') { // 'r1: register resides in bit 8-11 |
| 144 | RRInstruction* rrinstr = reinterpret_cast<RRInstruction*>(instr); |
| 145 | int reg = rrinstr->R1Value(); |
| 146 | PrintRegister(reg); |
| 147 | return 2; |
| 148 | } else if (format[1] == '2') { // 'r2: register resides in bit 12-15 |
| 149 | RRInstruction* rrinstr = reinterpret_cast<RRInstruction*>(instr); |
| 150 | int reg = rrinstr->R2Value(); |
| 151 | // indicating it is a r0 for displacement, in which case the offset |
| 152 | // should be 0. |
| 153 | if (format[2] == 'd') { |
| 154 | if (reg == 0) return 4; |
| 155 | PrintRegister(reg); |
| 156 | return 3; |
| 157 | } else { |
| 158 | PrintRegister(reg); |
| 159 | return 2; |
| 160 | } |
| 161 | } else if (format[1] == '3') { // 'r3: register resides in bit 16-19 |
| 162 | RSInstruction* rsinstr = reinterpret_cast<RSInstruction*>(instr); |
| 163 | int reg = rsinstr->B2Value(); |
| 164 | PrintRegister(reg); |
| 165 | return 2; |
| 166 | } else if (format[1] == '4') { // 'r4: register resides in bit 20-23 |
| 167 | RSInstruction* rsinstr = reinterpret_cast<RSInstruction*>(instr); |
| 168 | int reg = rsinstr->B2Value(); |
| 169 | PrintRegister(reg); |
| 170 | return 2; |
| 171 | } else if (format[1] == '5') { // 'r5: register resides in bit 24-28 |
| 172 | RREInstruction* rreinstr = reinterpret_cast<RREInstruction*>(instr); |
| 173 | int reg = rreinstr->R1Value(); |
| 174 | PrintRegister(reg); |
| 175 | return 2; |
| 176 | } else if (format[1] == '6') { // 'r6: register resides in bit 29-32 |
| 177 | RREInstruction* rreinstr = reinterpret_cast<RREInstruction*>(instr); |
| 178 | int reg = rreinstr->R2Value(); |
| 179 | PrintRegister(reg); |
| 180 | return 2; |
| 181 | } else if (format[1] == '7') { // 'r6: register resides in bit 32-35 |
| 182 | SSInstruction* ssinstr = reinterpret_cast<SSInstruction*>(instr); |
| 183 | int reg = ssinstr->B2Value(); |
| 184 | PrintRegister(reg); |
| 185 | return 2; |
| 186 | } |
| 187 | |
| 188 | UNREACHABLE(); |
| 189 | return -1; |
| 190 | } |
| 191 | |
| 192 | int Decoder::FormatFloatingRegister(Instruction* instr, const char* format) { |
| 193 | DCHECK(format[0] == 'f'); |
| 194 | |
| 195 | // reuse 1, 5 and 6 because it is coresponding |
| 196 | if (format[1] == '1') { // 'r1: register resides in bit 8-11 |
| 197 | RRInstruction* rrinstr = reinterpret_cast<RRInstruction*>(instr); |
| 198 | int reg = rrinstr->R1Value(); |
| 199 | PrintDRegister(reg); |
| 200 | return 2; |
| 201 | } else if (format[1] == '2') { // 'f2: register resides in bit 12-15 |
| 202 | RRInstruction* rrinstr = reinterpret_cast<RRInstruction*>(instr); |
| 203 | int reg = rrinstr->R2Value(); |
| 204 | PrintDRegister(reg); |
| 205 | return 2; |
| 206 | } else if (format[1] == '3') { // 'f3: register resides in bit 16-19 |
| 207 | RRDInstruction* rrdinstr = reinterpret_cast<RRDInstruction*>(instr); |
| 208 | int reg = rrdinstr->R1Value(); |
| 209 | PrintDRegister(reg); |
| 210 | return 2; |
| 211 | } else if (format[1] == '5') { // 'f5: register resides in bit 24-28 |
| 212 | RREInstruction* rreinstr = reinterpret_cast<RREInstruction*>(instr); |
| 213 | int reg = rreinstr->R1Value(); |
| 214 | PrintDRegister(reg); |
| 215 | return 2; |
| 216 | } else if (format[1] == '6') { // 'f6: register resides in bit 29-32 |
| 217 | RREInstruction* rreinstr = reinterpret_cast<RREInstruction*>(instr); |
| 218 | int reg = rreinstr->R2Value(); |
| 219 | PrintDRegister(reg); |
| 220 | return 2; |
| 221 | } |
| 222 | UNREACHABLE(); |
| 223 | return -1; |
| 224 | } |
| 225 | |
| 226 | // FormatOption takes a formatting string and interprets it based on |
| 227 | // the current instructions. The format string points to the first |
| 228 | // character of the option string (the option escape has already been |
| 229 | // consumed by the caller.) FormatOption returns the number of |
| 230 | // characters that were consumed from the formatting string. |
| 231 | int Decoder::FormatOption(Instruction* instr, const char* format) { |
| 232 | switch (format[0]) { |
| 233 | case 'o': { |
| 234 | if (instr->Bit(10) == 1) { |
| 235 | Print("o"); |
| 236 | } |
| 237 | return 1; |
| 238 | } |
| 239 | case '.': { |
| 240 | if (instr->Bit(0) == 1) { |
| 241 | Print("."); |
| 242 | } else { |
| 243 | Print(" "); // ensure consistent spacing |
| 244 | } |
| 245 | return 1; |
| 246 | } |
| 247 | case 'r': { |
| 248 | return FormatRegister(instr, format); |
| 249 | } |
| 250 | case 'f': { |
| 251 | return FormatFloatingRegister(instr, format); |
| 252 | } |
| 253 | case 'i': { // int16 |
| 254 | return FormatImmediate(instr, format); |
| 255 | } |
| 256 | case 'u': { // uint16 |
| 257 | int32_t value = instr->Bits(15, 0); |
| 258 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 259 | return 6; |
| 260 | } |
| 261 | case 'l': { |
| 262 | // Link (LK) Bit 0 |
| 263 | if (instr->Bit(0) == 1) { |
| 264 | Print("l"); |
| 265 | } |
| 266 | return 1; |
| 267 | } |
| 268 | case 'a': { |
| 269 | // Absolute Address Bit 1 |
| 270 | if (instr->Bit(1) == 1) { |
| 271 | Print("a"); |
| 272 | } |
| 273 | return 1; |
| 274 | } |
| 275 | case 't': { // 'target: target of branch instructions |
| 276 | // target26 or target16 |
| 277 | DCHECK(STRING_STARTS_WITH(format, "target")); |
| 278 | if ((format[6] == '2') && (format[7] == '6')) { |
| 279 | int off = ((instr->Bits(25, 2)) << 8) >> 6; |
| 280 | out_buffer_pos_ += SNPrintF( |
| 281 | out_buffer_ + out_buffer_pos_, "%+d -> %s", off, |
| 282 | converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + off)); |
| 283 | return 8; |
| 284 | } else if ((format[6] == '1') && (format[7] == '6')) { |
| 285 | int off = ((instr->Bits(15, 2)) << 18) >> 16; |
| 286 | out_buffer_pos_ += SNPrintF( |
| 287 | out_buffer_ + out_buffer_pos_, "%+d -> %s", off, |
| 288 | converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + off)); |
| 289 | return 8; |
| 290 | } |
| 291 | case 'm': { |
| 292 | return FormatMask(instr, format); |
| 293 | } |
| 294 | } |
| 295 | case 'd': { // ds value for offset |
| 296 | return FormatDisplacement(instr, format); |
| 297 | } |
| 298 | default: { |
| 299 | UNREACHABLE(); |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | UNREACHABLE(); |
| 305 | return -1; |
| 306 | } |
| 307 | |
| 308 | int Decoder::FormatMask(Instruction* instr, const char* format) { |
| 309 | DCHECK(format[0] == 'm'); |
| 310 | int32_t value = 0; |
| 311 | if ((format[1] == '1')) { // prints the mask format in bits 8-12 |
| 312 | value = reinterpret_cast<RRInstruction*>(instr)->R1Value(); |
| 313 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", value); |
| 314 | return 2; |
| 315 | } else if (format[1] == '2') { // mask format in bits 16-19 |
| 316 | value = reinterpret_cast<RXInstruction*>(instr)->B2Value(); |
| 317 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", value); |
| 318 | return 2; |
| 319 | } else if (format[1] == '3') { // mask format in bits 20-23 |
| 320 | value = reinterpret_cast<RRFInstruction*>(instr)->M4Value(); |
| 321 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "0x%x", value); |
| 322 | return 2; |
| 323 | } |
| 324 | |
| 325 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 326 | return 2; |
| 327 | } |
| 328 | |
| 329 | int Decoder::FormatDisplacement(Instruction* instr, const char* format) { |
| 330 | DCHECK(format[0] == 'd'); |
| 331 | |
| 332 | if (format[1] == '1') { // displacement in 20-31 |
| 333 | RSInstruction* rsinstr = reinterpret_cast<RSInstruction*>(instr); |
| 334 | uint16_t value = rsinstr->D2Value(); |
| 335 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 336 | |
| 337 | return 2; |
| 338 | } else if (format[1] == '2') { // displacement in 20-39 |
| 339 | RXYInstruction* rxyinstr = reinterpret_cast<RXYInstruction*>(instr); |
| 340 | int32_t value = rxyinstr->D2Value(); |
| 341 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 342 | return 2; |
| 343 | } else if (format[1] == '4') { // SS displacement 2 36-47 |
| 344 | SSInstruction* ssInstr = reinterpret_cast<SSInstruction*>(instr); |
| 345 | uint16_t value = ssInstr->D2Value(); |
| 346 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 347 | return 2; |
| 348 | } else if (format[1] == '3') { // SS displacement 1 20 - 32 |
| 349 | SSInstruction* ssInstr = reinterpret_cast<SSInstruction*>(instr); |
| 350 | uint16_t value = ssInstr->D1Value(); |
| 351 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 352 | return 2; |
| 353 | } else { // s390 specific |
| 354 | int32_t value = SIGN_EXT_IMM16(instr->Bits(15, 0) & ~3); |
| 355 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 356 | return 1; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | int Decoder::FormatImmediate(Instruction* instr, const char* format) { |
| 361 | DCHECK(format[0] == 'i'); |
| 362 | |
| 363 | if (format[1] == '1') { // immediate in 16-31 |
| 364 | RIInstruction* riinstr = reinterpret_cast<RIInstruction*>(instr); |
| 365 | int16_t value = riinstr->I2Value(); |
| 366 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 367 | return 2; |
| 368 | } else if (format[1] == '2') { // immediate in 16-48 |
| 369 | RILInstruction* rilinstr = reinterpret_cast<RILInstruction*>(instr); |
| 370 | int32_t value = rilinstr->I2Value(); |
| 371 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 372 | return 2; |
| 373 | } else if (format[1] == '3') { // immediate in I format |
| 374 | IInstruction* iinstr = reinterpret_cast<IInstruction*>(instr); |
| 375 | int8_t value = iinstr->IValue(); |
| 376 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 377 | return 2; |
| 378 | } else if (format[1] == '4') { // immediate in 16-31, but outputs as offset |
| 379 | RIInstruction* riinstr = reinterpret_cast<RIInstruction*>(instr); |
| 380 | int16_t value = riinstr->I2Value() * 2; |
| 381 | if (value >= 0) |
| 382 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "*+"); |
| 383 | else |
| 384 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "*"); |
| 385 | |
| 386 | out_buffer_pos_ += SNPrintF( |
| 387 | out_buffer_ + out_buffer_pos_, "%d -> %s", value, |
| 388 | converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + value)); |
| 389 | return 2; |
| 390 | } else if (format[1] == '5') { // immediate in 16-31, but outputs as offset |
| 391 | RILInstruction* rilinstr = reinterpret_cast<RILInstruction*>(instr); |
| 392 | int32_t value = rilinstr->I2Value() * 2; |
| 393 | if (value >= 0) |
| 394 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "*+"); |
| 395 | else |
| 396 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "*"); |
| 397 | |
| 398 | out_buffer_pos_ += SNPrintF( |
| 399 | out_buffer_ + out_buffer_pos_, "%d -> %s", value, |
| 400 | converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + value)); |
| 401 | return 2; |
| 402 | } else if (format[1] == '6') { // unsigned immediate in 16-31 |
| 403 | RIInstruction* riinstr = reinterpret_cast<RIInstruction*>(instr); |
| 404 | uint16_t value = riinstr->I2UnsignedValue(); |
| 405 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 406 | return 2; |
| 407 | } else if (format[1] == '7') { // unsigned immediate in 16-47 |
| 408 | RILInstruction* rilinstr = reinterpret_cast<RILInstruction*>(instr); |
| 409 | uint32_t value = rilinstr->I2UnsignedValue(); |
| 410 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 411 | return 2; |
| 412 | } else if (format[1] == '8') { // unsigned immediate in 8-15 |
| 413 | SSInstruction* ssinstr = reinterpret_cast<SSInstruction*>(instr); |
| 414 | uint8_t value = ssinstr->Length(); |
| 415 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 416 | return 2; |
| 417 | } else if (format[1] == '9') { // unsigned immediate in 16-23 |
| 418 | RIEInstruction* rie_instr = reinterpret_cast<RIEInstruction*>(instr); |
| 419 | uint8_t value = rie_instr->I3Value(); |
| 420 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 421 | return 2; |
| 422 | } else if (format[1] == 'a') { // unsigned immediate in 24-31 |
| 423 | RIEInstruction* rie_instr = reinterpret_cast<RIEInstruction*>(instr); |
| 424 | uint8_t value = rie_instr->I4Value(); |
| 425 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 426 | return 2; |
| 427 | } else if (format[1] == 'b') { // unsigned immediate in 32-39 |
| 428 | RIEInstruction* rie_instr = reinterpret_cast<RIEInstruction*>(instr); |
| 429 | uint8_t value = rie_instr->I5Value(); |
| 430 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 431 | return 2; |
| 432 | } else if (format[1] == 'c') { // signed immediate in 8-15 |
| 433 | SSInstruction* ssinstr = reinterpret_cast<SSInstruction*>(instr); |
| 434 | int8_t value = ssinstr->Length(); |
| 435 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 436 | return 2; |
| 437 | } else if (format[1] == 'd') { // signed immediate in 32-47 |
| 438 | SILInstruction* silinstr = reinterpret_cast<SILInstruction*>(instr); |
| 439 | int16_t value = silinstr->I2Value(); |
| 440 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%d", value); |
| 441 | return 2; |
| 442 | } else if (format[1] == 'e') { // immediate in 16-47, but outputs as offset |
| 443 | RILInstruction* rilinstr = reinterpret_cast<RILInstruction*>(instr); |
| 444 | int32_t value = rilinstr->I2Value() * 2; |
| 445 | if (value >= 0) |
| 446 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "*+"); |
| 447 | else |
| 448 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "*"); |
| 449 | |
| 450 | out_buffer_pos_ += SNPrintF( |
| 451 | out_buffer_ + out_buffer_pos_, "%d -> %s", value, |
| 452 | converter_.NameOfAddress(reinterpret_cast<byte*>(instr) + value)); |
| 453 | return 2; |
| 454 | } |
| 455 | |
| 456 | UNREACHABLE(); |
| 457 | return -1; |
| 458 | } |
| 459 | |
| 460 | // Format takes a formatting string for a whole instruction and prints it into |
| 461 | // the output buffer. All escaped options are handed to FormatOption to be |
| 462 | // parsed further. |
| 463 | void Decoder::Format(Instruction* instr, const char* format) { |
| 464 | char cur = *format++; |
| 465 | while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) { |
| 466 | if (cur == '\'') { // Single quote is used as the formatting escape. |
| 467 | format += FormatOption(instr, format); |
| 468 | } else { |
| 469 | out_buffer_[out_buffer_pos_++] = cur; |
| 470 | } |
| 471 | cur = *format++; |
| 472 | } |
| 473 | out_buffer_[out_buffer_pos_] = '\0'; |
| 474 | } |
| 475 | |
| 476 | // The disassembler may end up decoding data inlined in the code. We do not want |
| 477 | // it to crash if the data does not ressemble any known instruction. |
| 478 | #define VERIFY(condition) \ |
| 479 | if (!(condition)) { \ |
| 480 | Unknown(instr); \ |
| 481 | return; \ |
| 482 | } |
| 483 | |
| 484 | // For currently unimplemented decodings the disassembler calls Unknown(instr) |
| 485 | // which will just print "unknown" of the instruction bits. |
| 486 | void Decoder::Unknown(Instruction* instr) { Format(instr, "unknown"); } |
| 487 | |
| 488 | // For currently unimplemented decodings the disassembler calls |
| 489 | // UnknownFormat(instr) which will just print opcode name of the |
| 490 | // instruction bits. |
| 491 | void Decoder::UnknownFormat(Instruction* instr, const char* name) { |
| 492 | char buffer[100]; |
| 493 | snprintf(buffer, sizeof(buffer), "%s (unknown-format)", name); |
| 494 | Format(instr, buffer); |
| 495 | } |
| 496 | |
| 497 | // Disassembles Two Byte S390 Instructions |
| 498 | // @return true if successfully decoded |
| 499 | bool Decoder::DecodeTwoByte(Instruction* instr) { |
| 500 | // Print the Instruction bits. |
| 501 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%04x ", |
| 502 | instr->InstructionBits<TwoByteInstr>()); |
| 503 | |
| 504 | Opcode opcode = instr->S390OpcodeValue(); |
| 505 | switch (opcode) { |
| 506 | case AR: |
| 507 | Format(instr, "ar\t'r1,'r2"); |
| 508 | break; |
| 509 | case SR: |
| 510 | Format(instr, "sr\t'r1,'r2"); |
| 511 | break; |
| 512 | case MR: |
| 513 | Format(instr, "mr\t'r1,'r2"); |
| 514 | break; |
| 515 | case DR: |
| 516 | Format(instr, "dr\t'r1,'r2"); |
| 517 | break; |
| 518 | case OR: |
| 519 | Format(instr, "or\t'r1,'r2"); |
| 520 | break; |
| 521 | case NR: |
| 522 | Format(instr, "nr\t'r1,'r2"); |
| 523 | break; |
| 524 | case XR: |
| 525 | Format(instr, "xr\t'r1,'r2"); |
| 526 | break; |
| 527 | case LR: |
| 528 | Format(instr, "lr\t'r1,'r2"); |
| 529 | break; |
| 530 | case CR: |
| 531 | Format(instr, "cr\t'r1,'r2"); |
| 532 | break; |
| 533 | case CLR: |
| 534 | Format(instr, "clr\t'r1,'r2"); |
| 535 | break; |
| 536 | case BCR: |
| 537 | Format(instr, "bcr\t'm1,'r2"); |
| 538 | break; |
| 539 | case LTR: |
| 540 | Format(instr, "ltr\t'r1,'r2"); |
| 541 | break; |
| 542 | case ALR: |
| 543 | Format(instr, "alr\t'r1,'r2"); |
| 544 | break; |
| 545 | case SLR: |
| 546 | Format(instr, "slr\t'r1,'r2"); |
| 547 | break; |
| 548 | case LNR: |
| 549 | Format(instr, "lnr\t'r1,'r2"); |
| 550 | break; |
| 551 | case LCR: |
| 552 | Format(instr, "lcr\t'r1,'r2"); |
| 553 | break; |
| 554 | case BASR: |
| 555 | Format(instr, "basr\t'r1,'r2"); |
| 556 | break; |
| 557 | case LDR: |
| 558 | Format(instr, "ldr\t'f1,'f2"); |
| 559 | break; |
| 560 | case BKPT: |
| 561 | Format(instr, "bkpt"); |
| 562 | break; |
| 563 | default: |
| 564 | return false; |
| 565 | } |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | // Disassembles Four Byte S390 Instructions |
| 570 | // @return true if successfully decoded |
| 571 | bool Decoder::DecodeFourByte(Instruction* instr) { |
| 572 | // Print the Instruction bits. |
| 573 | out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, "%08x ", |
| 574 | instr->InstructionBits<FourByteInstr>()); |
| 575 | |
| 576 | Opcode opcode = instr->S390OpcodeValue(); |
| 577 | switch (opcode) { |
| 578 | case AHI: |
| 579 | Format(instr, "ahi\t'r1,'i1"); |
| 580 | break; |
| 581 | case AGHI: |
| 582 | Format(instr, "aghi\t'r1,'i1"); |
| 583 | break; |
| 584 | case LHI: |
| 585 | Format(instr, "lhi\t'r1,'i1"); |
| 586 | break; |
| 587 | case LGHI: |
| 588 | Format(instr, "lghi\t'r1,'i1"); |
| 589 | break; |
| 590 | case MHI: |
| 591 | Format(instr, "mhi\t'r1,'i1"); |
| 592 | break; |
| 593 | case MGHI: |
| 594 | Format(instr, "mghi\t'r1,'i1"); |
| 595 | break; |
| 596 | case CHI: |
| 597 | Format(instr, "chi\t'r1,'i1"); |
| 598 | break; |
| 599 | case CGHI: |
| 600 | Format(instr, "cghi\t'r1,'i1"); |
| 601 | break; |
| 602 | case BRAS: |
| 603 | Format(instr, "bras\t'r1,'i1"); |
| 604 | break; |
| 605 | case BRC: |
| 606 | Format(instr, "brc\t'm1,'i4"); |
| 607 | break; |
| 608 | case BRCT: |
| 609 | Format(instr, "brct\t'r1,'i4"); |
| 610 | break; |
| 611 | case BRCTG: |
| 612 | Format(instr, "brctg\t'r1,'i4"); |
| 613 | break; |
| 614 | case IIHH: |
| 615 | Format(instr, "iihh\t'r1,'i1"); |
| 616 | break; |
| 617 | case IIHL: |
| 618 | Format(instr, "iihl\t'r1,'i1"); |
| 619 | break; |
| 620 | case IILH: |
| 621 | Format(instr, "iilh\t'r1,'i1"); |
| 622 | break; |
| 623 | case IILL: |
| 624 | Format(instr, "iill\t'r1,'i1"); |
| 625 | break; |
| 626 | case OILL: |
| 627 | Format(instr, "oill\t'r1,'i1"); |
| 628 | break; |
| 629 | case TMLL: |
| 630 | Format(instr, "tmll\t'r1,'i1"); |
| 631 | break; |
| 632 | case STM: |
| 633 | Format(instr, "stm\t'r1,'r2,'d1('r3)"); |
| 634 | break; |
| 635 | case LM: |
| 636 | Format(instr, "lm\t'r1,'r2,'d1('r3)"); |
| 637 | break; |
| 638 | case SLL: |
| 639 | Format(instr, "sll\t'r1,'d1('r3)"); |
| 640 | break; |
| 641 | case SRL: |
| 642 | Format(instr, "srl\t'r1,'d1('r3)"); |
| 643 | break; |
| 644 | case SLA: |
| 645 | Format(instr, "sla\t'r1,'d1('r3)"); |
| 646 | break; |
| 647 | case SRA: |
| 648 | Format(instr, "sra\t'r1,'d1('r3)"); |
| 649 | break; |
| 650 | case SLDL: |
| 651 | Format(instr, "sldl\t'r1,'d1('r3)"); |
| 652 | break; |
| 653 | case AGR: |
| 654 | Format(instr, "agr\t'r5,'r6"); |
| 655 | break; |
| 656 | case AGFR: |
| 657 | Format(instr, "agfr\t'r5,'r6"); |
| 658 | break; |
| 659 | case ARK: |
| 660 | Format(instr, "ark\t'r5,'r6,'r3"); |
| 661 | break; |
| 662 | case AGRK: |
| 663 | Format(instr, "agrk\t'r5,'r6,'r3"); |
| 664 | break; |
| 665 | case SGR: |
| 666 | Format(instr, "sgr\t'r5,'r6"); |
| 667 | break; |
| 668 | case SGFR: |
| 669 | Format(instr, "sgfr\t'r5,'r6"); |
| 670 | break; |
| 671 | case SRK: |
| 672 | Format(instr, "srk\t'r5,'r6,'r3"); |
| 673 | break; |
| 674 | case SGRK: |
| 675 | Format(instr, "sgrk\t'r5,'r6,'r3"); |
| 676 | break; |
| 677 | case NGR: |
| 678 | Format(instr, "ngr\t'r5,'r6"); |
| 679 | break; |
| 680 | case NRK: |
| 681 | Format(instr, "nrk\t'r5,'r6,'r3"); |
| 682 | break; |
| 683 | case NGRK: |
| 684 | Format(instr, "ngrk\t'r5,'r6,'r3"); |
| 685 | break; |
| 686 | case NILL: |
| 687 | Format(instr, "nill\t'r1,'i1"); |
| 688 | break; |
| 689 | case NILH: |
| 690 | Format(instr, "nilh\t'r1,'i1"); |
| 691 | break; |
| 692 | case OGR: |
| 693 | Format(instr, "ogr\t'r5,'r6"); |
| 694 | break; |
| 695 | case ORK: |
| 696 | Format(instr, "ork\t'r5,'r6,'r3"); |
| 697 | break; |
| 698 | case OGRK: |
| 699 | Format(instr, "ogrk\t'r5,'r6,'r3"); |
| 700 | break; |
| 701 | case XGR: |
| 702 | Format(instr, "xgr\t'r5,'r6"); |
| 703 | break; |
| 704 | case XRK: |
| 705 | Format(instr, "xrk\t'r5,'r6,'r3"); |
| 706 | break; |
| 707 | case XGRK: |
| 708 | Format(instr, "xgrk\t'r5,'r6,'r3"); |
| 709 | break; |
| 710 | case CGR: |
| 711 | Format(instr, "cgr\t'r5,'r6"); |
| 712 | break; |
| 713 | case CLGR: |
| 714 | Format(instr, "clgr\t'r5,'r6"); |
| 715 | break; |
| 716 | case LLGFR: |
| 717 | Format(instr, "llgfr\t'r5,'r6"); |
| 718 | break; |
| 719 | case LBR: |
| 720 | Format(instr, "lbr\t'r5,'r6"); |
| 721 | break; |
| 722 | case LEDBR: |
| 723 | Format(instr, "ledbr\t'f5,'f6"); |
| 724 | break; |
| 725 | case LDEBR: |
| 726 | Format(instr, "ldebr\t'f5,'f6"); |
| 727 | break; |
| 728 | case LTGR: |
| 729 | Format(instr, "ltgr\t'r5,'r6"); |
| 730 | break; |
| 731 | case LTDBR: |
| 732 | Format(instr, "ltdbr\t'f5,'f6"); |
| 733 | break; |
| 734 | case LTEBR: |
| 735 | Format(instr, "ltebr\t'f5,'f6"); |
| 736 | break; |
| 737 | case LGR: |
| 738 | Format(instr, "lgr\t'r5,'r6"); |
| 739 | break; |
| 740 | case LGDR: |
| 741 | Format(instr, "lgdr\t'r5,'f6"); |
| 742 | break; |
| 743 | case LGFR: |
| 744 | Format(instr, "lgfr\t'r5,'r6"); |
| 745 | break; |
| 746 | case LTGFR: |
| 747 | Format(instr, "ltgfr\t'r5,'r6"); |
| 748 | break; |
| 749 | case LCGR: |
| 750 | Format(instr, "lcgr\t'r5,'r6"); |
| 751 | break; |
| 752 | case MSR: |
| 753 | Format(instr, "msr\t'r5,'r6"); |
| 754 | break; |
| 755 | case LGBR: |
| 756 | Format(instr, "lgbr\t'r5,'r6"); |
| 757 | break; |
| 758 | case LGHR: |
| 759 | Format(instr, "lghr\t'r5,'r6"); |
| 760 | break; |
| 761 | case MSGR: |
| 762 | Format(instr, "msgr\t'r5,'r6"); |
| 763 | break; |
| 764 | case DSGR: |
| 765 | Format(instr, "dsgr\t'r5,'r6"); |
| 766 | break; |
| 767 | case LZDR: |
| 768 | Format(instr, "lzdr\t'f5"); |
| 769 | break; |
| 770 | case MLR: |
| 771 | Format(instr, "mlr\t'r5,'r6"); |
| 772 | break; |
| 773 | case MLGR: |
| 774 | Format(instr, "mlgr\t'r5,'r6"); |
| 775 | break; |
| 776 | case ALCR: |
| 777 | Format(instr, "alcr\t'r5,'r6"); |
| 778 | break; |
| 779 | case ALGR: |
| 780 | Format(instr, "algr\t'r5,'r6"); |
| 781 | break; |
| 782 | case ALRK: |
| 783 | Format(instr, "alrk\t'r5,'r6,'r3"); |
| 784 | break; |
| 785 | case ALGRK: |
| 786 | Format(instr, "algrk\t'r5,'r6,'r3"); |
| 787 | break; |
| 788 | case SLGR: |
| 789 | Format(instr, "slgr\t'r5,'r6"); |
| 790 | break; |
| 791 | case SLBR: |
| 792 | Format(instr, "slbr\t'r5,'r6"); |
| 793 | break; |
| 794 | case DLR: |
| 795 | Format(instr, "dlr\t'r5,'r6"); |
| 796 | break; |
| 797 | case DLGR: |
| 798 | Format(instr, "dlgr\t'r5,'r6"); |
| 799 | break; |
| 800 | case SLRK: |
| 801 | Format(instr, "slrk\t'r5,'r6,'r3"); |
| 802 | break; |
| 803 | case SLGRK: |
| 804 | Format(instr, "slgrk\t'r5,'r6,'r3"); |
| 805 | break; |
| 806 | case LHR: |
| 807 | Format(instr, "lhr\t'r5,'r6"); |
| 808 | break; |
| 809 | case LLHR: |
| 810 | Format(instr, "llhr\t'r5,'r6"); |
| 811 | break; |
| 812 | case LLGHR: |
| 813 | Format(instr, "llghr\t'r5,'r6"); |
| 814 | break; |
| 815 | case LNGR: |
| 816 | Format(instr, "lngr\t'r5,'r6"); |
| 817 | break; |
| 818 | case A: |
| 819 | Format(instr, "a\t'r1,'d1('r2d,'r3)"); |
| 820 | break; |
| 821 | case S: |
| 822 | Format(instr, "s\t'r1,'d1('r2d,'r3)"); |
| 823 | break; |
| 824 | case M: |
| 825 | Format(instr, "m\t'r1,'d1('r2d,'r3)"); |
| 826 | break; |
| 827 | case D: |
| 828 | Format(instr, "d\t'r1,'d1('r2d,'r3)"); |
| 829 | break; |
| 830 | case O: |
| 831 | Format(instr, "o\t'r1,'d1('r2d,'r3)"); |
| 832 | break; |
| 833 | case N: |
| 834 | Format(instr, "n\t'r1,'d1('r2d,'r3)"); |
| 835 | break; |
| 836 | case L: |
| 837 | Format(instr, "l\t'r1,'d1('r2d,'r3)"); |
| 838 | break; |
| 839 | case C: |
| 840 | Format(instr, "c\t'r1,'d1('r2d,'r3)"); |
| 841 | break; |
| 842 | case AH: |
| 843 | Format(instr, "ah\t'r1,'d1('r2d,'r3)"); |
| 844 | break; |
| 845 | case SH: |
| 846 | Format(instr, "sh\t'r1,'d1('r2d,'r3)"); |
| 847 | break; |
| 848 | case MH: |
| 849 | Format(instr, "mh\t'r1,'d1('r2d,'r3)"); |
| 850 | break; |
| 851 | case AL: |
| 852 | Format(instr, "al\t'r1,'d1('r2d,'r3)"); |
| 853 | break; |
| 854 | case SL: |
| 855 | Format(instr, "sl\t'r1,'d1('r2d,'r3)"); |
| 856 | break; |
| 857 | case LA: |
| 858 | Format(instr, "la\t'r1,'d1('r2d,'r3)"); |
| 859 | break; |
| 860 | case CH: |
| 861 | Format(instr, "ch\t'r1,'d1('r2d,'r3)"); |
| 862 | break; |
| 863 | case CL: |
| 864 | Format(instr, "cl\t'r1,'d1('r2d,'r3)"); |
| 865 | break; |
| 866 | case CLI: |
| 867 | Format(instr, "cli\t'd1('r3),'i8"); |
| 868 | break; |
| 869 | case TM: |
| 870 | Format(instr, "tm\t'd1('r3),'i8"); |
| 871 | break; |
| 872 | case BC: |
| 873 | Format(instr, "bc\t'm1,'d1('r2d,'r3)"); |
| 874 | break; |
| 875 | case BCT: |
| 876 | Format(instr, "bct\t'r1,'d1('r2d,'r3)"); |
| 877 | break; |
| 878 | case ST: |
| 879 | Format(instr, "st\t'r1,'d1('r2d,'r3)"); |
| 880 | break; |
| 881 | case STC: |
| 882 | Format(instr, "stc\t'r1,'d1('r2d,'r3)"); |
| 883 | break; |
| 884 | case IC_z: |
| 885 | Format(instr, "ic\t'r1,'d1('r2d,'r3)"); |
| 886 | break; |
| 887 | case LD: |
| 888 | Format(instr, "ld\t'f1,'d1('r2d,'r3)"); |
| 889 | break; |
| 890 | case LE: |
| 891 | Format(instr, "le\t'f1,'d1('r2d,'r3)"); |
| 892 | break; |
| 893 | case LDGR: |
| 894 | Format(instr, "ldgr\t'f5,'r6"); |
| 895 | break; |
| 896 | case STE: |
| 897 | Format(instr, "ste\t'f1,'d1('r2d,'r3)"); |
| 898 | break; |
| 899 | case STD: |
| 900 | Format(instr, "std\t'f1,'d1('r2d,'r3)"); |
| 901 | break; |
| 902 | case CFDBR: |
| 903 | Format(instr, "cfdbr\t'r5,'m2,'f6"); |
| 904 | break; |
| 905 | case CDFBR: |
| 906 | Format(instr, "cdfbr\t'f5,'m2,'r6"); |
| 907 | break; |
| 908 | case CFEBR: |
| 909 | Format(instr, "cfebr\t'r5,'m2,'f6"); |
| 910 | break; |
| 911 | case CEFBR: |
| 912 | Format(instr, "cefbr\t'f5,'m2,'r6"); |
| 913 | break; |
| 914 | case CGEBR: |
| 915 | Format(instr, "cgebr\t'r5,'m2,'f6"); |
| 916 | break; |
| 917 | case CGDBR: |
| 918 | Format(instr, "cgdbr\t'r5,'m2,'f6"); |
| 919 | break; |
| 920 | case CEGBR: |
| 921 | Format(instr, "cegbr\t'f5,'m2,'r6"); |
| 922 | break; |
| 923 | case CDGBR: |
| 924 | Format(instr, "cdgbr\t'f5,'m2,'r6"); |
| 925 | break; |
| 926 | case CDLFBR: |
| 927 | Format(instr, "cdlfbr\t'f5,'m2,'r6"); |
| 928 | break; |
| 929 | case CDLGBR: |
| 930 | Format(instr, "cdlgbr\t'f5,'m2,'r6"); |
| 931 | break; |
| 932 | case CELGBR: |
| 933 | Format(instr, "celgbr\t'f5,'m2,'r6"); |
| 934 | break; |
| 935 | case CLFDBR: |
| 936 | Format(instr, "clfdbr\t'r5,'m2,'f6"); |
| 937 | break; |
| 938 | case CLGDBR: |
| 939 | Format(instr, "clgdbr\t'r5,'m2,'f6"); |
| 940 | break; |
| 941 | case AEBR: |
| 942 | Format(instr, "aebr\t'f5,'f6"); |
| 943 | break; |
| 944 | case SEBR: |
| 945 | Format(instr, "sebr\t'f5,'f6"); |
| 946 | break; |
| 947 | case MEEBR: |
| 948 | Format(instr, "meebr\t'f5,'f6"); |
| 949 | break; |
| 950 | case DEBR: |
| 951 | Format(instr, "debr\t'f5,'f6"); |
| 952 | break; |
| 953 | case ADBR: |
| 954 | Format(instr, "adbr\t'f5,'f6"); |
| 955 | break; |
| 956 | case SDBR: |
| 957 | Format(instr, "sdbr\t'f5,'f6"); |
| 958 | break; |
| 959 | case MDBR: |
| 960 | Format(instr, "mdbr\t'f5,'f6"); |
| 961 | break; |
| 962 | case DDBR: |
| 963 | Format(instr, "ddbr\t'f5,'f6"); |
| 964 | break; |
| 965 | case CDBR: |
| 966 | Format(instr, "cdbr\t'f5,'f6"); |
| 967 | break; |
| 968 | case CEBR: |
| 969 | Format(instr, "cebr\t'f5,'f6"); |
| 970 | break; |
| 971 | case SQDBR: |
| 972 | Format(instr, "sqdbr\t'f5,'f6"); |
| 973 | break; |
| 974 | case SQEBR: |
| 975 | Format(instr, "sqebr\t'f5,'f6"); |
| 976 | break; |
| 977 | case LCDBR: |
| 978 | Format(instr, "lcdbr\t'f5,'f6"); |
| 979 | break; |
| 980 | case STH: |
| 981 | Format(instr, "sth\t'r1,'d1('r2d,'r3)"); |
| 982 | break; |
| 983 | case SRDA: |
| 984 | Format(instr, "srda\t'r1,'d1('r3)"); |
| 985 | break; |
| 986 | case SRDL: |
| 987 | Format(instr, "srdl\t'r1,'d1('r3)"); |
| 988 | break; |
| 989 | case MADBR: |
| 990 | Format(instr, "madbr\t'f3,'f5,'f6"); |
| 991 | break; |
| 992 | case MSDBR: |
| 993 | Format(instr, "msdbr\t'f3,'f5,'f6"); |
| 994 | break; |
| 995 | case FLOGR: |
| 996 | Format(instr, "flogr\t'r5,'r6"); |
| 997 | break; |
| 998 | case FIEBRA: |
| 999 | Format(instr, "fiebra\t'f5,'m2,'f6,'m3"); |
| 1000 | break; |
| 1001 | case FIDBRA: |
| 1002 | Format(instr, "fidbra\t'f5,'m2,'f6,'m3"); |
| 1003 | break; |
| 1004 | // TRAP4 is used in calling to native function. it will not be generated |
| 1005 | // in native code. |
| 1006 | case TRAP4: { |
| 1007 | Format(instr, "trap4"); |
| 1008 | break; |
| 1009 | } |
| 1010 | default: |
| 1011 | return false; |
| 1012 | } |
| 1013 | return true; |
| 1014 | } |
| 1015 | |
| 1016 | // Disassembles Six Byte S390 Instructions |
| 1017 | // @return true if successfully decoded |
| 1018 | bool Decoder::DecodeSixByte(Instruction* instr) { |
| 1019 | // Print the Instruction bits. |
| 1020 | out_buffer_pos_ += |
| 1021 | SNPrintF(out_buffer_ + out_buffer_pos_, "%012" PRIx64 " ", |
| 1022 | instr->InstructionBits<SixByteInstr>()); |
| 1023 | |
| 1024 | Opcode opcode = instr->S390OpcodeValue(); |
| 1025 | switch (opcode) { |
| 1026 | case LLILF: |
| 1027 | Format(instr, "llilf\t'r1,'i7"); |
| 1028 | break; |
| 1029 | case LLIHF: |
| 1030 | Format(instr, "llihf\t'r1,'i7"); |
| 1031 | break; |
| 1032 | case AFI: |
| 1033 | Format(instr, "afi\t'r1,'i7"); |
| 1034 | break; |
| 1035 | case ASI: |
| 1036 | Format(instr, "asi\t'd2('r3),'ic"); |
| 1037 | break; |
| 1038 | case AGSI: |
| 1039 | Format(instr, "agsi\t'd2('r3),'ic"); |
| 1040 | break; |
| 1041 | case ALFI: |
| 1042 | Format(instr, "alfi\t'r1,'i7"); |
| 1043 | break; |
| 1044 | case AHIK: |
| 1045 | Format(instr, "ahik\t'r1,'r2,'i1"); |
| 1046 | break; |
| 1047 | case AGHIK: |
| 1048 | Format(instr, "aghik\t'r1,'r2,'i1"); |
| 1049 | break; |
| 1050 | case CLGFI: |
| 1051 | Format(instr, "clgfi\t'r1,'i7"); |
| 1052 | break; |
| 1053 | case CLFI: |
| 1054 | Format(instr, "clfi\t'r1,'i7"); |
| 1055 | break; |
| 1056 | case CFI: |
| 1057 | Format(instr, "cfi\t'r1,'i2"); |
| 1058 | break; |
| 1059 | case CGFI: |
| 1060 | Format(instr, "cgfi\t'r1,'i2"); |
| 1061 | break; |
| 1062 | case BRASL: |
| 1063 | Format(instr, "brasl\t'r1,'ie"); |
| 1064 | break; |
| 1065 | case BRCL: |
| 1066 | Format(instr, "brcl\t'm1,'i5"); |
| 1067 | break; |
| 1068 | case IIHF: |
| 1069 | Format(instr, "iihf\t'r1,'i7"); |
| 1070 | break; |
| 1071 | case IILF: |
| 1072 | Format(instr, "iilf\t'r1,'i7"); |
| 1073 | break; |
| 1074 | case XIHF: |
| 1075 | Format(instr, "xihf\t'r1,'i7"); |
| 1076 | break; |
| 1077 | case XILF: |
| 1078 | Format(instr, "xilf\t'r1,'i7"); |
| 1079 | break; |
| 1080 | case SLLK: |
| 1081 | Format(instr, "sllk\t'r1,'r2,'d2('r3)"); |
| 1082 | break; |
| 1083 | case SLLG: |
| 1084 | Format(instr, "sllg\t'r1,'r2,'d2('r3)"); |
| 1085 | break; |
| 1086 | case RLL: |
| 1087 | Format(instr, "rll\t'r1,'r2,'d2('r3)"); |
| 1088 | break; |
| 1089 | case RLLG: |
| 1090 | Format(instr, "rllg\t'r1,'r2,'d2('r3)"); |
| 1091 | break; |
| 1092 | case SRLK: |
| 1093 | Format(instr, "srlk\t'r1,'r2,'d2('r3)"); |
| 1094 | break; |
| 1095 | case SRLG: |
| 1096 | Format(instr, "srlg\t'r1,'r2,'d2('r3)"); |
| 1097 | break; |
| 1098 | case SLAK: |
| 1099 | Format(instr, "slak\t'r1,'r2,'d2('r3)"); |
| 1100 | break; |
| 1101 | case SLAG: |
| 1102 | Format(instr, "slag\t'r1,'r2,'d2('r3)"); |
| 1103 | break; |
| 1104 | case SRAK: |
| 1105 | Format(instr, "srak\t'r1,'r2,'d2('r3)"); |
| 1106 | break; |
| 1107 | case SRAG: |
| 1108 | Format(instr, "srag\t'r1,'r2,'d2('r3)"); |
| 1109 | break; |
| 1110 | case RISBG: |
| 1111 | Format(instr, "risbg\t'r1,'r2,'i9,'ia,'ib"); |
| 1112 | break; |
| 1113 | case RISBGN: |
| 1114 | Format(instr, "risbgn\t'r1,'r2,'i9,'ia,'ib"); |
| 1115 | break; |
| 1116 | case LMY: |
| 1117 | Format(instr, "lmy\t'r1,'r2,'d2('r3)"); |
| 1118 | break; |
| 1119 | case LMG: |
| 1120 | Format(instr, "lmg\t'r1,'r2,'d2('r3)"); |
| 1121 | break; |
| 1122 | case STMY: |
| 1123 | Format(instr, "stmy\t'r1,'r2,'d2('r3)"); |
| 1124 | break; |
| 1125 | case STMG: |
| 1126 | Format(instr, "stmg\t'r1,'r2,'d2('r3)"); |
| 1127 | break; |
| 1128 | case LT: |
| 1129 | Format(instr, "lt\t'r1,'d2('r2d,'r3)"); |
| 1130 | break; |
| 1131 | case LTG: |
| 1132 | Format(instr, "ltg\t'r1,'d2('r2d,'r3)"); |
| 1133 | break; |
| 1134 | case ML: |
| 1135 | Format(instr, "ml\t'r1,'d2('r2d,'r3)"); |
| 1136 | break; |
| 1137 | case AY: |
| 1138 | Format(instr, "ay\t'r1,'d2('r2d,'r3)"); |
| 1139 | break; |
| 1140 | case SY: |
| 1141 | Format(instr, "sy\t'r1,'d2('r2d,'r3)"); |
| 1142 | break; |
| 1143 | case NY: |
| 1144 | Format(instr, "ny\t'r1,'d2('r2d,'r3)"); |
| 1145 | break; |
| 1146 | case OY: |
| 1147 | Format(instr, "oy\t'r1,'d2('r2d,'r3)"); |
| 1148 | break; |
| 1149 | case XY: |
| 1150 | Format(instr, "xy\t'r1,'d2('r2d,'r3)"); |
| 1151 | break; |
| 1152 | case CY: |
| 1153 | Format(instr, "cy\t'r1,'d2('r2d,'r3)"); |
| 1154 | break; |
| 1155 | case AHY: |
| 1156 | Format(instr, "ahy\t'r1,'d2('r2d,'r3)"); |
| 1157 | break; |
| 1158 | case SHY: |
| 1159 | Format(instr, "shy\t'r1,'d2('r2d,'r3)"); |
| 1160 | break; |
| 1161 | case LGH: |
| 1162 | Format(instr, "lgh\t'r1,'d2('r2d,'r3)"); |
| 1163 | break; |
| 1164 | case AG: |
| 1165 | Format(instr, "ag\t'r1,'d2('r2d,'r3)"); |
| 1166 | break; |
| 1167 | case AGF: |
| 1168 | Format(instr, "agf\t'r1,'d2('r2d,'r3)"); |
| 1169 | break; |
| 1170 | case SG: |
| 1171 | Format(instr, "sg\t'r1,'d2('r2d,'r3)"); |
| 1172 | break; |
| 1173 | case NG: |
| 1174 | Format(instr, "ng\t'r1,'d2('r2d,'r3)"); |
| 1175 | break; |
| 1176 | case OG: |
| 1177 | Format(instr, "og\t'r1,'d2('r2d,'r3)"); |
| 1178 | break; |
| 1179 | case XG: |
| 1180 | Format(instr, "xg\t'r1,'d2('r2d,'r3)"); |
| 1181 | break; |
| 1182 | case CG: |
| 1183 | Format(instr, "cg\t'r1,'d2('r2d,'r3)"); |
| 1184 | break; |
| 1185 | case LB: |
| 1186 | Format(instr, "lb\t'r1,'d2('r2d,'r3)"); |
| 1187 | break; |
| 1188 | case LG: |
| 1189 | Format(instr, "lg\t'r1,'d2('r2d,'r3)"); |
| 1190 | break; |
| 1191 | case LGF: |
| 1192 | Format(instr, "lgf\t'r1,'d2('r2d,'r3)"); |
| 1193 | break; |
| 1194 | case LLGF: |
| 1195 | Format(instr, "llgf\t'r1,'d2('r2d,'r3)"); |
| 1196 | break; |
| 1197 | case LY: |
| 1198 | Format(instr, "ly\t'r1,'d2('r2d,'r3)"); |
| 1199 | break; |
| 1200 | case ALY: |
| 1201 | Format(instr, "aly\t'r1,'d2('r2d,'r3)"); |
| 1202 | break; |
| 1203 | case ALG: |
| 1204 | Format(instr, "alg\t'r1,'d2('r2d,'r3)"); |
| 1205 | break; |
| 1206 | case SLG: |
| 1207 | Format(instr, "slg\t'r1,'d2('r2d,'r3)"); |
| 1208 | break; |
| 1209 | case SGF: |
| 1210 | Format(instr, "sgf\t'r1,'d2('r2d,'r3)"); |
| 1211 | break; |
| 1212 | case SLY: |
| 1213 | Format(instr, "sly\t'r1,'d2('r2d,'r3)"); |
| 1214 | break; |
| 1215 | case LLH: |
| 1216 | Format(instr, "llh\t'r1,'d2('r2d,'r3)"); |
| 1217 | break; |
| 1218 | case LLGH: |
| 1219 | Format(instr, "llgh\t'r1,'d2('r2d,'r3)"); |
| 1220 | break; |
| 1221 | case LLC: |
| 1222 | Format(instr, "llc\t'r1,'d2('r2d,'r3)"); |
| 1223 | break; |
| 1224 | case LLGC: |
| 1225 | Format(instr, "llgc\t'r1,'d2('r2d,'r3)"); |
| 1226 | break; |
| 1227 | case LDEB: |
| 1228 | Format(instr, "ldeb\t'f1,'d2('r2d,'r3)"); |
| 1229 | break; |
| 1230 | case LAY: |
| 1231 | Format(instr, "lay\t'r1,'d2('r2d,'r3)"); |
| 1232 | break; |
| 1233 | case LARL: |
| 1234 | Format(instr, "larl\t'r1,'i5"); |
| 1235 | break; |
| 1236 | case LGB: |
| 1237 | Format(instr, "lgb\t'r1,'d2('r2d,'r3)"); |
| 1238 | break; |
| 1239 | case CHY: |
| 1240 | Format(instr, "chy\t'r1,'d2('r2d,'r3)"); |
| 1241 | break; |
| 1242 | case CLY: |
| 1243 | Format(instr, "cly\t'r1,'d2('r2d,'r3)"); |
| 1244 | break; |
| 1245 | case CLIY: |
| 1246 | Format(instr, "cliy\t'd2('r3),'i8"); |
| 1247 | break; |
| 1248 | case TMY: |
| 1249 | Format(instr, "tmy\t'd2('r3),'i8"); |
| 1250 | break; |
| 1251 | case CLG: |
| 1252 | Format(instr, "clg\t'r1,'d2('r2d,'r3)"); |
| 1253 | break; |
| 1254 | case BCTG: |
| 1255 | Format(instr, "bctg\t'r1,'d2('r2d,'r3)"); |
| 1256 | break; |
| 1257 | case STY: |
| 1258 | Format(instr, "sty\t'r1,'d2('r2d,'r3)"); |
| 1259 | break; |
| 1260 | case STG: |
| 1261 | Format(instr, "stg\t'r1,'d2('r2d,'r3)"); |
| 1262 | break; |
| 1263 | case ICY: |
| 1264 | Format(instr, "icy\t'r1,'d2('r2d,'r3)"); |
| 1265 | break; |
| 1266 | case MVC: |
| 1267 | Format(instr, "mvc\t'd3('i8,'r3),'d4('r7)"); |
| 1268 | break; |
| 1269 | case MVHI: |
| 1270 | Format(instr, "mvhi\t'd3('r3),'id"); |
| 1271 | break; |
| 1272 | case MVGHI: |
| 1273 | Format(instr, "mvghi\t'd3('r3),'id"); |
| 1274 | break; |
| 1275 | case ALGFI: |
| 1276 | Format(instr, "algfi\t'r1,'i7"); |
| 1277 | break; |
| 1278 | case SLGFI: |
| 1279 | Format(instr, "slgfi\t'r1,'i7"); |
| 1280 | break; |
| 1281 | case SLFI: |
| 1282 | Format(instr, "slfi\t'r1,'i7"); |
| 1283 | break; |
| 1284 | case NIHF: |
| 1285 | Format(instr, "nihf\t'r1,'i7"); |
| 1286 | break; |
| 1287 | case NILF: |
| 1288 | Format(instr, "nilf\t'r1,'i7"); |
| 1289 | break; |
| 1290 | case OIHF: |
| 1291 | Format(instr, "oihf\t'r1,'i7"); |
| 1292 | break; |
| 1293 | case OILF: |
| 1294 | Format(instr, "oilf\t'r1,'i7"); |
| 1295 | break; |
| 1296 | case MSFI: |
| 1297 | Format(instr, "msfi\t'r1,'i7"); |
| 1298 | break; |
| 1299 | case MSGFI: |
| 1300 | Format(instr, "msgfi\t'r1,'i7"); |
| 1301 | break; |
| 1302 | case LDY: |
| 1303 | Format(instr, "ldy\t'f1,'d2('r2d,'r3)"); |
| 1304 | break; |
| 1305 | case LEY: |
| 1306 | Format(instr, "ley\t'f1,'d2('r2d,'r3)"); |
| 1307 | break; |
| 1308 | case STEY: |
| 1309 | Format(instr, "stey\t'f1,'d2('r2d,'r3)"); |
| 1310 | break; |
| 1311 | case STDY: |
| 1312 | Format(instr, "stdy\t'f1,'d2('r2d,'r3)"); |
| 1313 | break; |
| 1314 | case ADB: |
| 1315 | Format(instr, "adb\t'r1,'d1('r2d, 'r3)"); |
| 1316 | break; |
| 1317 | case SDB: |
| 1318 | Format(instr, "sdb\t'r1,'d1('r2d, 'r3)"); |
| 1319 | break; |
| 1320 | case MDB: |
| 1321 | Format(instr, "mdb\t'r1,'d1('r2d, 'r3)"); |
| 1322 | break; |
| 1323 | case DDB: |
| 1324 | Format(instr, "ddb\t'r1,'d1('r2d, 'r3)"); |
| 1325 | break; |
| 1326 | case SQDB: |
| 1327 | Format(instr, "sqdb\t'r1,'d1('r2d, 'r3)"); |
| 1328 | break; |
| 1329 | default: |
| 1330 | return false; |
| 1331 | } |
| 1332 | return true; |
| 1333 | } |
| 1334 | |
| 1335 | #undef VERIFIY |
| 1336 | |
| 1337 | // Disassemble the instruction at *instr_ptr into the output buffer. |
| 1338 | int Decoder::InstructionDecode(byte* instr_ptr) { |
| 1339 | Instruction* instr = Instruction::At(instr_ptr); |
| 1340 | int instrLength = instr->InstructionLength(); |
| 1341 | |
| 1342 | if (2 == instrLength) |
| 1343 | DecodeTwoByte(instr); |
| 1344 | else if (4 == instrLength) |
| 1345 | DecodeFourByte(instr); |
| 1346 | else |
| 1347 | DecodeSixByte(instr); |
| 1348 | |
| 1349 | return instrLength; |
| 1350 | } |
| 1351 | |
| 1352 | } // namespace internal |
| 1353 | } // namespace v8 |
| 1354 | |
| 1355 | //------------------------------------------------------------------------------ |
| 1356 | |
| 1357 | namespace disasm { |
| 1358 | |
| 1359 | const char* NameConverter::NameOfAddress(byte* addr) const { |
| 1360 | v8::internal::SNPrintF(tmp_buffer_, "%p", addr); |
| 1361 | return tmp_buffer_.start(); |
| 1362 | } |
| 1363 | |
| 1364 | const char* NameConverter::NameOfConstant(byte* addr) const { |
| 1365 | return NameOfAddress(addr); |
| 1366 | } |
| 1367 | |
| 1368 | const char* NameConverter::NameOfCPURegister(int reg) const { |
| 1369 | return v8::internal::Register::from_code(reg).ToString(); |
| 1370 | } |
| 1371 | |
| 1372 | const char* NameConverter::NameOfByteCPURegister(int reg) const { |
| 1373 | UNREACHABLE(); // S390 does not have the concept of a byte register |
| 1374 | return "nobytereg"; |
| 1375 | } |
| 1376 | |
| 1377 | const char* NameConverter::NameOfXMMRegister(int reg) const { |
| 1378 | // S390 does not have XMM register |
| 1379 | // TODO(joransiu): Consider update this for Vector Regs |
| 1380 | UNREACHABLE(); |
| 1381 | return "noxmmreg"; |
| 1382 | } |
| 1383 | |
| 1384 | const char* NameConverter::NameInCode(byte* addr) const { |
| 1385 | // The default name converter is called for unknown code. So we will not try |
| 1386 | // to access any memory. |
| 1387 | return ""; |
| 1388 | } |
| 1389 | |
| 1390 | //------------------------------------------------------------------------------ |
| 1391 | |
| 1392 | Disassembler::Disassembler(const NameConverter& converter) |
| 1393 | : converter_(converter) {} |
| 1394 | |
| 1395 | Disassembler::~Disassembler() {} |
| 1396 | |
| 1397 | int Disassembler::InstructionDecode(v8::internal::Vector<char> buffer, |
| 1398 | byte* instruction) { |
| 1399 | v8::internal::Decoder d(converter_, buffer); |
| 1400 | return d.InstructionDecode(instruction); |
| 1401 | } |
| 1402 | |
| 1403 | // The S390 assembler does not currently use constant pools. |
| 1404 | int Disassembler::ConstantPoolSizeAt(byte* instruction) { return -1; } |
| 1405 | |
| 1406 | void Disassembler::Disassemble(FILE* f, byte* begin, byte* end) { |
| 1407 | NameConverter converter; |
| 1408 | Disassembler d(converter); |
| 1409 | for (byte* pc = begin; pc < end;) { |
| 1410 | v8::internal::EmbeddedVector<char, 128> buffer; |
| 1411 | buffer[0] = '\0'; |
| 1412 | byte* prev_pc = pc; |
| 1413 | pc += d.InstructionDecode(buffer, pc); |
| 1414 | v8::internal::PrintF(f, "%p %08x %s\n", prev_pc, |
| 1415 | *reinterpret_cast<int32_t*>(prev_pc), buffer.start()); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | } // namespace disasm |
| 1420 | |
| 1421 | #endif // V8_TARGET_ARCH_S390 |