13a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers/* 23a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * Copyright (C) 2012 The Android Open Source Project 33a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * 43a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * Licensed under the Apache License, Version 2.0 (the "License"); 53a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * you may not use this file except in compliance with the License. 63a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * You may obtain a copy of the License at 73a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * 83a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * http://www.apache.org/licenses/LICENSE-2.0 93a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * 103a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * Unless required by applicable law or agreed to in writing, software 113a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * distributed under the License is distributed on an "AS IS" BASIS, 123a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * See the License for the specific language governing permissions and 143a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers * limitations under the License. 153a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers */ 163a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 173a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers#include "disassembler.h" 183a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 19cf7f19135f0e273f7b0136315633c2abfc715343Ian Rogers#include <ostream> 203a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 2107ed66b5ae659c452cbe1ab20c3dbf1d6f546461Elliott Hughes#include "base/logging.h" 222cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom#include "base/stringprintf.h" 233a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers#include "disassembler_arm.h" 24e6622be6c353c7178f34adf814c58370a51c5ed7Serban Constantinescu#include "disassembler_arm64.h" 2560454e8b48663e6e5cb4bb301cec5edf93f8ce54Elliott Hughes#include "disassembler_mips.h" 26706a10ea53a32455c6b3ffc5e5e0e1f6f191ec2aIan Rogers#include "disassembler_x86.h" 273a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 283a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogersnamespace art { 293a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 302cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian CarlstromDisassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) { 313a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers if (instruction_set == kArm || instruction_set == kThumb2) { 322cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return new arm::DisassemblerArm(options); 33e6622be6c353c7178f34adf814c58370a51c5ed7Serban Constantinescu } else if (instruction_set == kArm64) { 342cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return new arm64::DisassemblerArm64(options); 3560454e8b48663e6e5cb4bb301cec5edf93f8ce54Elliott Hughes } else if (instruction_set == kMips) { 36403e0d55a3e9c18d4228d0aab31dec0c908dc73dGoran Jakovljevic return new mips::DisassemblerMips(options, false); 3757b34294758e9c00993913ebe43c7ee4698a5cc6Andreas Gampe } else if (instruction_set == kMips64) { 38403e0d55a3e9c18d4228d0aab31dec0c908dc73dGoran Jakovljevic return new mips::DisassemblerMips(options, true); 39706a10ea53a32455c6b3ffc5e5e0e1f6f191ec2aIan Rogers } else if (instruction_set == kX86) { 402cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return new x86::DisassemblerX86(options, false); 4138e12034f1ef2b32e98b6e49cb36b7cc37a7f1beIan Rogers } else if (instruction_set == kX86_64) { 422cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return new x86::DisassemblerX86(options, true); 433a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } else { 44ed64e8d73d55e9b2b3e34439ee5747cdb8415c5eElliott Hughes UNIMPLEMENTED(FATAL) << "no disassembler for " << instruction_set; 452cebb24bfc3247d3e9be138a3350106737455918Mathieu Chartier return nullptr; 463a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers } 473a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers} 483a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers 492cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstromstd::string Disassembler::FormatInstructionPointer(const uint8_t* begin) { 502cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom if (disassembler_options_->absolute_addresses_) { 512cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return StringPrintf("%p", begin); 522cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } else { 532cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom size_t offset = begin - disassembler_options_->base_address_; 542cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom return StringPrintf("0x%08zx", offset); 552cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom } 562cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom} 572cbaccb67e22c0b313a9785bfc65bcb4b25d0676Brian Carlstrom 58eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre RamesDisassembler* create_disassembler(InstructionSet instruction_set, DisassemblerOptions* options) { 59eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames return Disassembler::Create(instruction_set, options); 60eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames} 61eb7b7399dbdb5e471b8ae00a567bf4f19edd3907Alexandre Rames 623a5c1ce3f11805a3382046f699c8fb1410a602b3Ian Rogers} // namespace art 63