Merge pull request #647 from lioncash/disasm

Common: Introduce the new Gekko disassembler to Common.
This commit is contained in:
Pierre Bourdon
2014-08-03 21:52:08 -07:00
21 changed files with 2553 additions and 2434 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
@ -189,15 +190,15 @@ void CCodeView::OnMouseUpL(wxMouseEvent& event)
u32 CCodeView::AddrToBranch(u32 addr)
{
char disasm[256];
m_debugger->Disassemble(addr, disasm, 256);
const char *mojs = strstr(disasm, "->0x");
if (mojs)
std::string disasm = m_debugger->Disassemble(addr);
size_t pos = disasm.find("->0x");
if (pos != std::string::npos)
{
u32 dest;
sscanf(mojs+4,"%08x", &dest);
return dest;
std::string hex = disasm.substr(pos + 2);
return std::stoul(hex, nullptr, 16);
}
return 0;
}
@ -253,16 +254,14 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event)
case IDM_COPYCODE:
{
char disasm[256];
m_debugger->Disassemble(m_selection, disasm, 256);
std::string disasm = m_debugger->Disassemble(m_selection);
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(disasm)));
}
break;
case IDM_COPYHEX:
{
char temp[24];
sprintf(temp, "%08x", m_debugger->ReadInstruction(m_selection));
std::string temp = StringFromFormat("%08x", m_debugger->ReadInstruction(m_selection));
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp)));
}
break;
@ -280,9 +279,8 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event)
u32 end = start + symbol->size;
for (u32 addr = start; addr != end; addr += 4)
{
char disasm[256];
m_debugger->Disassemble(addr, disasm, 256);
text = text + StringFromFormat("%08x: ", addr) + disasm + "\r\n";
std::string disasm = m_debugger->Disassemble(addr);
text += StringFromFormat("%08x: ", addr) + disasm + "\r\n";
}
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(text)));
}
@ -478,65 +476,51 @@ void CCodeView::OnPaint(wxPaintEvent& event)
// If running
if (m_debugger->IsAlive())
{
char dis[256];
m_debugger->Disassemble(address, dis, 256);
char* dis2 = strchr(dis, '\t');
char desc[256] = "";
std::vector<std::string> dis;
SplitString(m_debugger->Disassemble(address), '\t', dis);
// If we have a code
if (dis2)
static const size_t VALID_BRANCH_LENGTH = 10;
const std::string& opcode = dis[0];
const std::string& operands = dis[1];
std::string desc;
// look for hex strings to decode branches
std::string hex_str;
size_t pos = operands.find("0x8");
if (pos != std::string::npos)
{
*dis2 = 0;
dis2++;
// look for hex strings to decode branches
const char* mojs = strstr(dis2, "0x8");
if (mojs)
{
for (int k = 0; k < 8; k++)
{
bool found = false;
for (int j = 0; j < 22; j++)
{
if (mojs[k + 2] == "0123456789ABCDEFabcdef"[j])
found = true;
}
if (!found)
{
mojs = nullptr;
break;
}
}
}
if (mojs)
{
int offs;
sscanf(mojs + 2, "%08x", &offs);
branches[numBranches].src = rowY1 + m_rowHeight / 2;
branches[numBranches].srcAddr = address / m_align;
branches[numBranches++].dst = (int)(rowY1 + ((s64)(u32)offs - (s64)(u32)address) * m_rowHeight / m_align + m_rowHeight / 2);
sprintf(desc, "-->%s", m_debugger->GetDescription(offs).c_str());
dc.SetTextForeground(wxTheColourDatabase->Find("PURPLE")); // the -> arrow illustrations are purple
}
else
{
dc.SetTextForeground(*wxBLACK);
}
dc.DrawText(StrToWxStr(dis2), 17 + 17*charWidth, rowY1);
// ------------
hex_str = operands.substr(pos);
}
if (hex_str.length() == VALID_BRANCH_LENGTH)
{
u32 offs = std::stoul(hex_str, nullptr, 16);
branches[numBranches].src = rowY1 + m_rowHeight / 2;
branches[numBranches].srcAddr = address / m_align;
branches[numBranches++].dst = (int)(rowY1 + ((s64)(u32)offs - (s64)(u32)address) * m_rowHeight / m_align + m_rowHeight / 2);
desc = StringFromFormat("-->%s", m_debugger->GetDescription(offs).c_str());
dc.SetTextForeground(wxTheColourDatabase->Find("PURPLE")); // the -> arrow illustrations are purple
}
else
{
dc.SetTextForeground(*wxBLACK);
}
dc.DrawText(StrToWxStr(operands), 17 + 17*charWidth, rowY1);
// ------------
// Show blr as its' own color
if (strcmp(dis, "blr"))
if (opcode == "blr")
dc.SetTextForeground(wxTheColourDatabase->Find("DARK GREEN"));
else
dc.SetTextForeground(wxTheColourDatabase->Find("VIOLET"));
dc.DrawText(StrToWxStr(dis), 17 + (m_plain ? 1*charWidth : 9*charWidth), rowY1);
dc.DrawText(StrToWxStr(opcode), 17 + (m_plain ? 1*charWidth : 9*charWidth), rowY1);
if (desc[0] == 0)
if (desc.empty())
{
strcpy(desc, m_debugger->GetDescription(address).c_str());
desc = m_debugger->GetDescription(address);
}
if (!m_plain)
@ -545,7 +529,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
//char temp[256];
//UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE);
if (strlen(desc))
if (!desc.empty())
{
dc.DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1);
}

View File

@ -5,7 +5,6 @@
#include <cstdio>
#include <cstring>
#include <disasm.h> // Bochs
#include <PowerPCDisasm.h> // Bochs
#include <wx/button.h>
#include <wx/chartype.h>
#include <wx/defs.h>
@ -22,6 +21,7 @@
#include <wx/windowid.h>
#include "Common/Common.h"
#include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h"
#include "Core/PowerPC/Gekko.h"
#include "Core/PowerPC/PPCAnalyst.h"
@ -161,9 +161,8 @@ void CJitWindow::Compare(u32 em_address)
for (u32 i = 0; i < code_block.m_num_instructions; i++)
{
const PPCAnalyst::CodeOp &op = code_buffer.codebuffer[i];
char temp[256];
DisassembleGekko(op.inst.hex, op.address, temp, 256);
sptr += sprintf(sptr, "%08x %s\n", op.address, temp);
std::string temp = GekkoDisassembler::Disassemble(op.inst.hex, op.address);
sptr += sprintf(sptr, "%08x %s\n", op.address, temp.c_str());
}
// Add stats to the end of the ppc box since it's generally the shortest.

View File

@ -10,6 +10,7 @@
#include <wx/windowid.h>
#include "Common/CommonTypes.h"
#include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h"
#include "Core/HW/ProcessorInterface.h"
#include "Core/PowerPC/Gekko.h"
@ -22,9 +23,6 @@ class wxWindow;
// F-zero 80005e60 wtf??
extern const char* GetGPRName(unsigned int index);
extern const char* GetFPRName(unsigned int index);
static const char *special_reg_names[] = {
"PC", "LR", "CTR", "CR", "FPSCR", "MSR", "SRR0", "SRR1", "Exceptions", "Int Mask", "Int Cause",
};
@ -54,9 +52,9 @@ wxString CRegTable::GetValue(int row, int col)
{
switch (col)
{
case 0: return StrToWxStr(GetGPRName(row));
case 0: return StrToWxStr(GekkoDisassembler::GetGPRName(row));
case 1: return wxString::Format("%08x", GPR(row));
case 2: return StrToWxStr(GetFPRName(row));
case 2: return StrToWxStr(GekkoDisassembler::GetFPRName(row));
case 3: return wxString::Format("%016llx", riPS0(row));
case 4: return wxString::Format("%016llx", riPS1(row));
default: return wxEmptyString;