Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_DISASSEMBLER_DISASSEMBLER_ARM64_H_ |
| 18 | #define ART_DISASSEMBLER_DISASSEMBLER_ARM64_H_ |
| 19 | |
| 20 | #include "disassembler.h" |
| 21 | |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 22 | #pragma GCC diagnostic push |
| 23 | #pragma GCC diagnostic ignored "-Wshadow" |
Serban Constantinescu | 82e52ce | 2015-03-26 16:50:57 +0000 | [diff] [blame] | 24 | #include "vixl/a64/decoder-a64.h" |
| 25 | #include "vixl/a64/disasm-a64.h" |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 26 | #pragma GCC diagnostic pop |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | namespace arm64 { |
| 30 | |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 31 | class CustomDisassembler FINAL : public vixl::Disassembler { |
| 32 | public: |
Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 33 | explicit CustomDisassembler(DisassemblerOptions* options) |
| 34 | : vixl::Disassembler(), |
| 35 | read_literals_(options->can_read_literals_), |
| 36 | base_address_(options->base_address_), |
| 37 | end_address_(options->end_address_) { |
Alexandre Rames | d737ab3 | 2015-03-06 09:11:12 +0000 | [diff] [blame] | 38 | if (!options->absolute_addresses_) { |
| 39 | MapCodeAddress(0, reinterpret_cast<const vixl::Instruction*>(options->base_address_)); |
| 40 | } |
| 41 | } |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 42 | |
| 43 | // Use register aliases in the disassembly. |
Zheng Xu | a34e760 | 2015-02-03 12:03:15 +0800 | [diff] [blame] | 44 | void AppendRegisterNameToOutput(const vixl::Instruction* instr, |
| 45 | const vixl::CPURegister& reg) OVERRIDE; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 46 | |
| 47 | // Improve the disassembly of literal load instructions. |
Zheng Xu | a34e760 | 2015-02-03 12:03:15 +0800 | [diff] [blame] | 48 | void VisitLoadLiteral(const vixl::Instruction* instr) OVERRIDE; |
| 49 | |
| 50 | // Improve the disassembly of thread offset. |
| 51 | void VisitLoadStoreUnsignedOffset(const vixl::Instruction* instr) OVERRIDE; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | // Indicate if the disassembler should read data loaded from literal pools. |
| 55 | // This should only be enabled if reading the target of literal loads is safe. |
| 56 | // Here are possible outputs when the option is on or off: |
| 57 | // read_literals_ | disassembly |
| 58 | // true | 0x72681558: 1c000acb ldr s11, pc+344 (addr 0x726816b0) |
| 59 | // false | 0x72681558: 1c000acb ldr s11, pc+344 (addr 0x726816b0) (3.40282e+38) |
| 60 | const bool read_literals_; |
Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 61 | |
| 62 | // Valid address range: [base_address_, end_address_) |
| 63 | const void* const base_address_; |
| 64 | const void* const end_address_; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 67 | class DisassemblerArm64 FINAL : public Disassembler { |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 68 | public: |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 69 | explicit DisassemblerArm64(DisassemblerOptions* options) : |
Alexandre Rames | d737ab3 | 2015-03-06 09:11:12 +0000 | [diff] [blame] | 70 | Disassembler(options), disasm(options) { |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 71 | decoder.AppendVisitor(&disasm); |
| 72 | } |
| 73 | |
Ian Rogers | 38e1203 | 2014-03-14 14:06:14 -0700 | [diff] [blame] | 74 | size_t Dump(std::ostream& os, const uint8_t* begin) OVERRIDE; |
| 75 | void Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) OVERRIDE; |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | vixl::Decoder decoder; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 79 | CustomDisassembler disasm; |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 80 | |
| 81 | DISALLOW_COPY_AND_ASSIGN(DisassemblerArm64); |
| 82 | }; |
| 83 | |
| 84 | } // namespace arm64 |
| 85 | } // namespace art |
| 86 | |
| 87 | #endif // ART_DISASSEMBLER_DISASSEMBLER_ARM64_H_ |