blob: c64d8eaf9d3d1d5fae52edd89055ea3a0f7483e9 [file] [log] [blame]
Serban Constantinescue6622be2014-02-27 15:36:47 +00001/*
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 Gampe277ccbd2014-11-03 21:36:10 -080022#pragma GCC diagnostic push
23#pragma GCC diagnostic ignored "-Wshadow"
Scott Wakeling97c72b72016-06-24 16:19:36 +010024#include "a64/decoder-a64.h"
25#include "a64/disasm-a64.h"
Andreas Gampe277ccbd2014-11-03 21:36:10 -080026#pragma GCC diagnostic pop
Serban Constantinescue6622be2014-02-27 15:36:47 +000027
28namespace art {
29namespace arm64 {
30
Scott Wakeling97c72b72016-06-24 16:19:36 +010031class CustomDisassembler FINAL : public vixl::aarch64::Disassembler {
Alexandre Ramesa37d9252014-10-27 11:28:14 +000032 public:
Aart Bikd3059e72016-05-11 10:30:47 -070033 explicit CustomDisassembler(DisassemblerOptions* options)
Scott Wakeling97c72b72016-06-24 16:19:36 +010034 : vixl::aarch64::Disassembler(),
Aart Bikd3059e72016-05-11 10:30:47 -070035 read_literals_(options->can_read_literals_),
36 base_address_(options->base_address_),
37 end_address_(options->end_address_) {
Alexandre Ramesd737ab32015-03-06 09:11:12 +000038 if (!options->absolute_addresses_) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010039 MapCodeAddress(0,
40 reinterpret_cast<const vixl::aarch64::Instruction*>(options->base_address_));
Alexandre Ramesd737ab32015-03-06 09:11:12 +000041 }
42 }
Alexandre Ramesa37d9252014-10-27 11:28:14 +000043
44 // Use register aliases in the disassembly.
Scott Wakeling97c72b72016-06-24 16:19:36 +010045 void AppendRegisterNameToOutput(const vixl::aarch64::Instruction* instr,
46 const vixl::aarch64::CPURegister& reg) OVERRIDE;
Alexandre Ramesa37d9252014-10-27 11:28:14 +000047
48 // Improve the disassembly of literal load instructions.
Scott Wakeling97c72b72016-06-24 16:19:36 +010049 void VisitLoadLiteral(const vixl::aarch64::Instruction* instr) OVERRIDE;
Zheng Xua34e7602015-02-03 12:03:15 +080050
51 // Improve the disassembly of thread offset.
Scott Wakeling97c72b72016-06-24 16:19:36 +010052 void VisitLoadStoreUnsignedOffset(const vixl::aarch64::Instruction* instr) OVERRIDE;
Alexandre Ramesa37d9252014-10-27 11:28:14 +000053
54 private:
55 // Indicate if the disassembler should read data loaded from literal pools.
56 // This should only be enabled if reading the target of literal loads is safe.
57 // Here are possible outputs when the option is on or off:
58 // read_literals_ | disassembly
59 // true | 0x72681558: 1c000acb ldr s11, pc+344 (addr 0x726816b0)
60 // false | 0x72681558: 1c000acb ldr s11, pc+344 (addr 0x726816b0) (3.40282e+38)
61 const bool read_literals_;
Aart Bikd3059e72016-05-11 10:30:47 -070062
63 // Valid address range: [base_address_, end_address_)
64 const void* const base_address_;
65 const void* const end_address_;
Alexandre Ramesa37d9252014-10-27 11:28:14 +000066};
67
Ian Rogers38e12032014-03-14 14:06:14 -070068class DisassemblerArm64 FINAL : public Disassembler {
Serban Constantinescue6622be2014-02-27 15:36:47 +000069 public:
Alexandre Ramesa37d9252014-10-27 11:28:14 +000070 explicit DisassemblerArm64(DisassemblerOptions* options) :
Alexandre Ramesd737ab32015-03-06 09:11:12 +000071 Disassembler(options), disasm(options) {
Serban Constantinescue6622be2014-02-27 15:36:47 +000072 decoder.AppendVisitor(&disasm);
73 }
74
Ian Rogers38e12032014-03-14 14:06:14 -070075 size_t Dump(std::ostream& os, const uint8_t* begin) OVERRIDE;
76 void Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) OVERRIDE;
Serban Constantinescue6622be2014-02-27 15:36:47 +000077
78 private:
Scott Wakeling97c72b72016-06-24 16:19:36 +010079 vixl::aarch64::Decoder decoder;
Alexandre Ramesa37d9252014-10-27 11:28:14 +000080 CustomDisassembler disasm;
Serban Constantinescue6622be2014-02-27 15:36:47 +000081
82 DISALLOW_COPY_AND_ASSIGN(DisassemblerArm64);
83};
84
85} // namespace arm64
86} // namespace art
87
88#endif // ART_DISASSEMBLER_DISASSEMBLER_ARM64_H_