blob: e604c1f6291fbf08861a3d05fd9c2d00e7757a56 [file] [log] [blame]
Ian Rogers3a5c1ce2012-02-29 10:06:46 -08001/*
2 * Copyright (C) 2012 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#include "disassembler.h"
18
Ian Rogerscf7f1912014-10-22 22:06:39 -070019#include <ostream>
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080020
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include "base/logging.h"
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070022#include "base/stringprintf.h"
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080023#include "disassembler_arm.h"
Serban Constantinescue6622be2014-02-27 15:36:47 +000024#include "disassembler_arm64.h"
Elliott Hughes60454e82012-04-25 12:56:03 -070025#include "disassembler_mips.h"
Ian Rogers706a10e2012-03-23 17:00:55 -070026#include "disassembler_x86.h"
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080027
28namespace art {
29
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070030Disassembler* Disassembler::Create(InstructionSet instruction_set, DisassemblerOptions* options) {
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080031 if (instruction_set == kArm || instruction_set == kThumb2) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070032 return new arm::DisassemblerArm(options);
Serban Constantinescue6622be2014-02-27 15:36:47 +000033 } else if (instruction_set == kArm64) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070034 return new arm64::DisassemblerArm64(options);
Elliott Hughes60454e82012-04-25 12:56:03 -070035 } else if (instruction_set == kMips) {
Goran Jakovljevic403e0d52015-04-08 16:26:05 +020036 return new mips::DisassemblerMips(options, false);
Andreas Gampe57b34292015-01-14 15:45:59 -080037 } else if (instruction_set == kMips64) {
Goran Jakovljevic403e0d52015-04-08 16:26:05 +020038 return new mips::DisassemblerMips(options, true);
Ian Rogers706a10e2012-03-23 17:00:55 -070039 } else if (instruction_set == kX86) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070040 return new x86::DisassemblerX86(options, false);
Ian Rogers38e12032014-03-14 14:06:14 -070041 } else if (instruction_set == kX86_64) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070042 return new x86::DisassemblerX86(options, true);
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080043 } else {
Elliott Hughesed64e8d2012-03-02 20:37:45 -080044 UNIMPLEMENTED(FATAL) << "no disassembler for " << instruction_set;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070045 return nullptr;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080046 }
47}
48
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -070049std::string Disassembler::FormatInstructionPointer(const uint8_t* begin) {
50 if (disassembler_options_->absolute_addresses_) {
51 return StringPrintf("%p", begin);
52 } else {
53 size_t offset = begin - disassembler_options_->base_address_;
54 return StringPrintf("0x%08zx", offset);
55 }
56}
57
Alexandre Rameseb7b7392015-06-19 14:47:01 +010058Disassembler* create_disassembler(InstructionSet instruction_set, DisassemblerOptions* options) {
59 return Disassembler::Create(instruction_set, options);
60}
61
Ian Rogers3a5c1ce2012-02-29 10:06:46 -080062} // namespace art