2013-11-24 10:55:18 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
2013-12-30 09:17:11 +00:00
|
|
|
|
2018-04-15 23:28:29 +00:00
|
|
|
#include <mutex>
|
2013-12-30 09:17:11 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2013-12-29 23:55:09 +00:00
|
|
|
#include "Core/Debugger/SymbolMap.h"
|
2013-11-24 10:55:18 +00:00
|
|
|
#include "Core/MIPS/MIPSAnalyst.h"
|
|
|
|
|
2014-10-27 00:49:24 +00:00
|
|
|
#ifdef _M_X64
|
|
|
|
typedef u64 HashType;
|
|
|
|
#else
|
|
|
|
typedef u32 HashType;
|
|
|
|
#endif
|
|
|
|
|
2013-11-29 16:21:48 +00:00
|
|
|
enum DisassemblyLineType { DISTYPE_OPCODE, DISTYPE_MACRO, DISTYPE_DATA, DISTYPE_OTHER };
|
2013-11-24 10:55:18 +00:00
|
|
|
|
|
|
|
struct DisassemblyLineInfo
|
|
|
|
{
|
|
|
|
DisassemblyLineType type;
|
|
|
|
MIPSAnalyst::MipsOpcodeInfo info;
|
|
|
|
std::string name;
|
|
|
|
std::string params;
|
|
|
|
u32 totalSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum LineType { LINE_UP, LINE_DOWN, LINE_RIGHT };
|
|
|
|
|
|
|
|
struct BranchLine
|
|
|
|
{
|
|
|
|
u32 first;
|
|
|
|
u32 second;
|
|
|
|
LineType type;
|
|
|
|
int laneIndex;
|
|
|
|
|
|
|
|
bool operator<(const BranchLine& other) const
|
|
|
|
{
|
|
|
|
return first < other.first;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DisassemblyEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~DisassemblyEntry() { };
|
|
|
|
virtual void recheck() = 0;
|
|
|
|
virtual int getNumLines() = 0;
|
|
|
|
virtual int getLineNum(u32 address, bool findStart) = 0;
|
|
|
|
virtual u32 getLineAddress(int line) = 0;
|
|
|
|
virtual u32 getTotalSize() = 0;
|
2018-05-10 00:51:27 +00:00
|
|
|
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) = 0;
|
2013-11-24 13:46:53 +00:00
|
|
|
virtual void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) { };
|
2013-11-24 10:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DisassemblyFunction: public DisassemblyEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DisassemblyFunction(u32 _address, u32 _size);
|
2017-04-28 03:02:49 +00:00
|
|
|
~DisassemblyFunction();
|
2014-12-08 20:14:35 +00:00
|
|
|
void recheck() override;
|
|
|
|
int getNumLines() override;
|
|
|
|
int getLineNum(u32 address, bool findStart) override;
|
|
|
|
u32 getLineAddress(int line) override;
|
|
|
|
u32 getTotalSize() override { return size; };
|
2018-05-10 00:51:27 +00:00
|
|
|
bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) override;
|
|
|
|
|
2013-11-24 10:55:18 +00:00
|
|
|
private:
|
|
|
|
void generateBranchLines();
|
|
|
|
void load();
|
|
|
|
void clear();
|
2013-11-26 21:20:12 +00:00
|
|
|
void addOpcodeSequence(u32 start, u32 end);
|
2013-11-24 10:55:18 +00:00
|
|
|
|
|
|
|
u32 address;
|
|
|
|
u32 size;
|
2014-10-27 00:49:24 +00:00
|
|
|
HashType hash;
|
2013-11-24 10:55:18 +00:00
|
|
|
std::vector<BranchLine> lines;
|
|
|
|
std::map<u32,DisassemblyEntry*> entries;
|
|
|
|
std::vector<u32> lineAddresses;
|
2018-04-15 23:28:29 +00:00
|
|
|
std::recursive_mutex lock_;
|
2013-11-24 10:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DisassemblyOpcode: public DisassemblyEntry
|
|
|
|
{
|
|
|
|
public:
|
2013-11-25 12:56:43 +00:00
|
|
|
DisassemblyOpcode(u32 _address, int _num): address(_address), num(_num) { };
|
2013-11-24 10:55:18 +00:00
|
|
|
virtual ~DisassemblyOpcode() { };
|
2014-12-08 20:14:35 +00:00
|
|
|
void recheck() override { };
|
|
|
|
int getNumLines() override { return num; };
|
|
|
|
int getLineNum(u32 address, bool findStart) override { return (address - this->address) / 4; };
|
|
|
|
u32 getLineAddress(int line) override { return address + line * 4; };
|
|
|
|
u32 getTotalSize() override { return num * 4; };
|
2018-05-10 00:51:27 +00:00
|
|
|
bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) override;
|
|
|
|
|
2013-11-24 10:55:18 +00:00
|
|
|
private:
|
|
|
|
u32 address;
|
2013-11-25 12:56:43 +00:00
|
|
|
int num;
|
2013-11-24 10:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DisassemblyMacro: public DisassemblyEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DisassemblyMacro(u32 _address): address(_address) { };
|
|
|
|
virtual ~DisassemblyMacro() { };
|
2014-12-08 20:14:35 +00:00
|
|
|
|
2013-11-24 10:55:18 +00:00
|
|
|
void setMacroLi(u32 _immediate, u8 _rt);
|
2013-11-24 12:50:35 +00:00
|
|
|
void setMacroMemory(std::string _name, u32 _immediate, u8 _rt, int _dataSize);
|
2014-12-08 20:14:35 +00:00
|
|
|
|
|
|
|
void recheck() override { };
|
|
|
|
int getNumLines() override { return 1; };
|
|
|
|
int getLineNum(u32 address, bool findStart) override { return 0; };
|
|
|
|
u32 getLineAddress(int line) override { return address; };
|
|
|
|
u32 getTotalSize() override { return numOpcodes * 4; };
|
2018-05-10 00:51:27 +00:00
|
|
|
bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;
|
2013-11-24 10:55:18 +00:00
|
|
|
private:
|
|
|
|
enum MacroType { MACRO_LI, MACRO_MEMORYIMM };
|
|
|
|
|
|
|
|
MacroType type;
|
|
|
|
std::string name;
|
|
|
|
u32 immediate;
|
|
|
|
u32 address;
|
|
|
|
u32 numOpcodes;
|
|
|
|
u8 rt;
|
2013-11-24 12:50:35 +00:00
|
|
|
int dataSize;
|
2013-11-24 10:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-11-27 23:33:21 +00:00
|
|
|
class DisassemblyData: public DisassemblyEntry
|
|
|
|
{
|
|
|
|
public:
|
2013-11-29 16:21:48 +00:00
|
|
|
DisassemblyData(u32 _address, u32 _size, DataType _type);
|
2013-11-27 23:33:21 +00:00
|
|
|
virtual ~DisassemblyData() { };
|
2014-12-08 20:14:35 +00:00
|
|
|
|
|
|
|
void recheck() override;
|
|
|
|
int getNumLines() override { return (int)lines.size(); };
|
|
|
|
int getLineNum(u32 address, bool findStart) override;
|
|
|
|
u32 getLineAddress(int line) override { return lineAddresses[line]; };
|
|
|
|
u32 getTotalSize() override { return size; };
|
2018-05-10 00:51:27 +00:00
|
|
|
bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
|
2013-11-27 23:33:21 +00:00
|
|
|
private:
|
|
|
|
void createLines();
|
|
|
|
|
|
|
|
struct DataEntry
|
|
|
|
{
|
|
|
|
std::string text;
|
|
|
|
u32 size;
|
|
|
|
int lineNum;
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 address;
|
|
|
|
u32 size;
|
2014-10-27 00:49:24 +00:00
|
|
|
HashType hash;
|
2013-11-27 23:33:21 +00:00
|
|
|
DataType type;
|
|
|
|
std::map<u32,DataEntry> lines;
|
|
|
|
std::vector<u32> lineAddresses;
|
2018-04-15 23:28:29 +00:00
|
|
|
std::recursive_mutex lock_;
|
2013-11-27 23:33:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DisassemblyComment: public DisassemblyEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DisassemblyComment(u32 _address, u32 _size, std::string name, std::string param);
|
|
|
|
virtual ~DisassemblyComment() { };
|
2014-12-08 20:14:35 +00:00
|
|
|
|
|
|
|
void recheck() override { };
|
|
|
|
int getNumLines() override { return 1; };
|
|
|
|
int getLineNum(u32 address, bool findStart) override { return 0; };
|
|
|
|
u32 getLineAddress(int line) override { return address; };
|
|
|
|
u32 getTotalSize() override { return size; };
|
2018-05-10 00:51:27 +00:00
|
|
|
bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
|
2013-11-27 23:33:21 +00:00
|
|
|
private:
|
|
|
|
u32 address;
|
|
|
|
u32 size;
|
|
|
|
std::string name;
|
|
|
|
std::string param;
|
|
|
|
};
|
|
|
|
|
2013-11-24 10:55:18 +00:00
|
|
|
class DebugInterface;
|
|
|
|
|
|
|
|
class DisassemblyManager
|
|
|
|
{
|
|
|
|
public:
|
2017-04-28 03:02:49 +00:00
|
|
|
~DisassemblyManager();
|
|
|
|
|
2013-11-25 15:18:29 +00:00
|
|
|
void clear();
|
2013-11-24 10:55:18 +00:00
|
|
|
|
|
|
|
void setCpu(DebugInterface* _cpu) { cpu = _cpu; };
|
2013-11-27 23:33:21 +00:00
|
|
|
void setMaxParamChars(int num) { maxParamChars = num; clear(); };
|
2018-05-10 00:51:27 +00:00
|
|
|
void getLine(u32 address, bool insertSymbols, DisassemblyLineInfo &dest, DebugInterface *cpuDebug = nullptr);
|
2013-11-24 10:55:18 +00:00
|
|
|
void analyze(u32 address, u32 size);
|
2013-11-24 13:46:53 +00:00
|
|
|
std::vector<BranchLine> getBranchLines(u32 start, u32 size);
|
2013-11-24 10:55:18 +00:00
|
|
|
|
|
|
|
u32 getStartAddress(u32 address);
|
|
|
|
u32 getNthPreviousAddress(u32 address, int n = 1);
|
|
|
|
u32 getNthNextAddress(u32 address, int n = 1);
|
|
|
|
|
|
|
|
static DebugInterface* getCpu() { return cpu; };
|
2013-11-27 23:33:21 +00:00
|
|
|
static int getMaxParamChars() { return maxParamChars; };
|
2013-11-24 10:55:18 +00:00
|
|
|
private:
|
|
|
|
static std::map<u32,DisassemblyEntry*> entries;
|
2018-04-15 23:28:29 +00:00
|
|
|
static std::recursive_mutex entriesLock_;
|
2013-11-24 10:55:18 +00:00
|
|
|
static DebugInterface* cpu;
|
2013-11-27 23:33:21 +00:00
|
|
|
static int maxParamChars;
|
2013-11-24 11:46:08 +00:00
|
|
|
};
|
|
|
|
|
2013-12-30 09:17:11 +00:00
|
|
|
bool isInInterval(u32 start, u32 size, u32 value);
|