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 | |
Artem Serov | af4e42a | 2016-08-08 15:11:24 +0100 | [diff] [blame] | 22 | // TODO(VIXL): Make VIXL compile with -Wshadow. |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 23 | #pragma GCC diagnostic push |
| 24 | #pragma GCC diagnostic ignored "-Wshadow" |
Artem Serov | af4e42a | 2016-08-08 15:11:24 +0100 | [diff] [blame] | 25 | #include "aarch64/decoder-aarch64.h" |
| 26 | #include "aarch64/disasm-aarch64.h" |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 27 | #pragma GCC diagnostic pop |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | namespace arm64 { |
| 31 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 32 | class CustomDisassembler final : public vixl::aarch64::Disassembler { |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 33 | public: |
Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 34 | explicit CustomDisassembler(DisassemblerOptions* options) |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 35 | : vixl::aarch64::Disassembler(), |
Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 36 | read_literals_(options->can_read_literals_), |
| 37 | base_address_(options->base_address_), |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 38 | end_address_(options->end_address_), |
| 39 | options_(options) { |
Alexandre Rames | d737ab3 | 2015-03-06 09:11:12 +0000 | [diff] [blame] | 40 | if (!options->absolute_addresses_) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 41 | MapCodeAddress(0, |
| 42 | reinterpret_cast<const vixl::aarch64::Instruction*>(options->base_address_)); |
Alexandre Rames | d737ab3 | 2015-03-06 09:11:12 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 45 | |
| 46 | // Use register aliases in the disassembly. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 47 | void AppendRegisterNameToOutput(const vixl::aarch64::Instruction* instr, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 48 | const vixl::aarch64::CPURegister& reg) override; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 49 | |
| 50 | // Improve the disassembly of literal load instructions. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 51 | void VisitLoadLiteral(const vixl::aarch64::Instruction* instr) override; |
Zheng Xu | a34e760 | 2015-02-03 12:03:15 +0800 | [diff] [blame] | 52 | |
| 53 | // Improve the disassembly of thread offset. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 54 | void VisitLoadStoreUnsignedOffset(const vixl::aarch64::Instruction* instr) override; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | // Indicate if the disassembler should read data loaded from literal pools. |
| 58 | // This should only be enabled if reading the target of literal loads is safe. |
| 59 | // Here are possible outputs when the option is on or off: |
| 60 | // read_literals_ | disassembly |
| 61 | // true | 0x72681558: 1c000acb ldr s11, pc+344 (addr 0x726816b0) |
| 62 | // false | 0x72681558: 1c000acb ldr s11, pc+344 (addr 0x726816b0) (3.40282e+38) |
| 63 | const bool read_literals_; |
Aart Bik | d3059e7 | 2016-05-11 10:30:47 -0700 | [diff] [blame] | 64 | |
| 65 | // Valid address range: [base_address_, end_address_) |
| 66 | const void* const base_address_; |
| 67 | const void* const end_address_; |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 68 | |
| 69 | DisassemblerOptions* options_; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 72 | class DisassemblerArm64 final : public Disassembler { |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 73 | public: |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 74 | explicit DisassemblerArm64(DisassemblerOptions* options) : |
Alexandre Rames | d737ab3 | 2015-03-06 09:11:12 +0000 | [diff] [blame] | 75 | Disassembler(options), disasm(options) { |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 76 | decoder.AppendVisitor(&disasm); |
| 77 | } |
| 78 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 79 | size_t Dump(std::ostream& os, const uint8_t* begin) override; |
| 80 | 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] | 81 | |
| 82 | private: |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 83 | vixl::aarch64::Decoder decoder; |
Alexandre Rames | a37d925 | 2014-10-27 11:28:14 +0000 | [diff] [blame] | 84 | CustomDisassembler disasm; |
Serban Constantinescu | e6622be | 2014-02-27 15:36:47 +0000 | [diff] [blame] | 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(DisassemblerArm64); |
| 87 | }; |
| 88 | |
| 89 | } // namespace arm64 |
| 90 | } // namespace art |
| 91 | |
| 92 | #endif // ART_DISASSEMBLER_DISASSEMBLER_ARM64_H_ |