2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <disasm.h> // Bochs
|
2014-10-21 06:53:01 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/listctrl.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <wx/textctrl.h>
|
2009-02-23 20:29:55 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-07-18 01:33:51 +00:00
|
|
|
#include "Common/GekkoDisassembler.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/PowerPC/Gekko.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/PowerPC/PPCAnalyst.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "DolphinWX/Debugger/JitWindow.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Globals.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2015-05-31 21:21:47 +00:00
|
|
|
#include "UICommon/Disassembler.h"
|
2014-10-21 06:53:01 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
CJitWindow::CJitWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
|
|
|
|
long style, const wxString& name)
|
|
|
|
: wxPanel(parent, id, pos, size, style, name)
|
2010-07-26 03:46:14 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* sizerBig = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer* sizerSplit = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizerSplit->Add(ppc_box = new wxTextCtrl(this, wxID_ANY, "(ppc)", wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxTE_MULTILINE),
|
|
|
|
1, wxEXPAND);
|
|
|
|
sizerSplit->Add(x86_box = new wxTextCtrl(this, wxID_ANY, "(x86)", wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxTE_MULTILINE),
|
|
|
|
1, wxEXPAND);
|
2016-10-03 07:29:50 +00:00
|
|
|
sizerBig->Add(block_list = new JitBlockList(this, wxID_ANY, wxDefaultPosition,
|
|
|
|
wxDLG_UNIT(this, wxSize(80, 96)),
|
2016-06-24 08:43:46 +00:00
|
|
|
wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT |
|
|
|
|
wxLC_SINGLE_SEL | wxLC_SORT_ASCENDING),
|
|
|
|
0, wxEXPAND);
|
|
|
|
sizerBig->Add(sizerSplit, 2, wxEXPAND);
|
|
|
|
|
|
|
|
sizerBig->Add(button_refresh = new wxButton(this, wxID_ANY, _("&Refresh")));
|
|
|
|
button_refresh->Bind(wxEVT_BUTTON, &CJitWindow::OnRefresh, this);
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
SetSizerAndFit(sizerBig);
|
2014-10-21 06:53:01 +00:00
|
|
|
|
2015-05-31 21:21:47 +00:00
|
|
|
#if defined(_M_X86)
|
2016-06-24 08:43:46 +00:00
|
|
|
m_disassembler.reset(GetNewDisassembler("x86"));
|
2015-05-31 21:21:47 +00:00
|
|
|
#elif defined(_M_ARM_64)
|
2016-06-24 08:43:46 +00:00
|
|
|
m_disassembler.reset(GetNewDisassembler("aarch64"));
|
2014-10-21 06:53:01 +00:00
|
|
|
#else
|
2016-06-24 08:43:46 +00:00
|
|
|
m_disassembler.reset(GetNewDisassembler("UNK"));
|
2014-10-21 06:53:01 +00:00
|
|
|
#endif
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-08-30 21:01:19 +00:00
|
|
|
void CJitWindow::OnRefresh(wxCommandEvent& /*event*/)
|
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
block_list->Repopulate();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::ViewAddr(u32 em_address)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
Show(true);
|
|
|
|
Compare(em_address);
|
|
|
|
SetFocus();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::Compare(u32 em_address)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Get host side code disassembly
|
|
|
|
u32 host_instructions_count = 0;
|
|
|
|
u32 host_code_size = 0;
|
|
|
|
std::string host_instructions_disasm;
|
|
|
|
host_instructions_disasm = DisassembleBlock(m_disassembler.get(), &em_address,
|
|
|
|
&host_instructions_count, &host_code_size);
|
|
|
|
|
|
|
|
x86_box->SetValue(host_instructions_disasm);
|
|
|
|
|
|
|
|
// == Fill in ppc box
|
|
|
|
u32 ppc_addr = em_address;
|
|
|
|
PPCAnalyst::CodeBuffer code_buffer(32000);
|
|
|
|
PPCAnalyst::BlockStats st;
|
|
|
|
PPCAnalyst::BlockRegStats gpa;
|
|
|
|
PPCAnalyst::BlockRegStats fpa;
|
|
|
|
PPCAnalyst::CodeBlock code_block;
|
|
|
|
PPCAnalyst::PPCAnalyzer analyzer;
|
|
|
|
analyzer.SetOption(PPCAnalyst::PPCAnalyzer::OPTION_CONDITIONAL_CONTINUE);
|
|
|
|
|
|
|
|
code_block.m_stats = &st;
|
|
|
|
code_block.m_gpa = &gpa;
|
|
|
|
code_block.m_fpa = &fpa;
|
|
|
|
|
|
|
|
if (analyzer.Analyze(ppc_addr, &code_block, &code_buffer, 32000) != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
std::ostringstream ppc_disasm;
|
|
|
|
for (u32 i = 0; i < code_block.m_num_instructions; i++)
|
|
|
|
{
|
|
|
|
const PPCAnalyst::CodeOp& op = code_buffer.codebuffer[i];
|
|
|
|
std::string opcode = GekkoDisassembler::Disassemble(op.inst.hex, op.address);
|
|
|
|
ppc_disasm << std::setfill('0') << std::setw(8) << std::hex << op.address;
|
|
|
|
ppc_disasm << " " << opcode << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add stats to the end of the ppc box since it's generally the shortest.
|
|
|
|
ppc_disasm << std::dec << std::endl;
|
|
|
|
|
|
|
|
// Add some generic analysis
|
|
|
|
if (st.isFirstBlockOfFunction)
|
|
|
|
ppc_disasm << "(first block of function)" << std::endl;
|
|
|
|
if (st.isLastBlockOfFunction)
|
|
|
|
ppc_disasm << "(last block of function)" << std::endl;
|
|
|
|
|
|
|
|
ppc_disasm << st.numCycles << " estimated cycles" << std::endl;
|
|
|
|
|
|
|
|
ppc_disasm << "Num instr: PPC: " << code_block.m_num_instructions
|
|
|
|
<< " x86: " << host_instructions_count << " (blowup: "
|
|
|
|
<< 100 * host_instructions_count / code_block.m_num_instructions - 100 << "%)"
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
ppc_disasm << "Num bytes: PPC: " << code_block.m_num_instructions * 4
|
|
|
|
<< " x86: " << host_code_size
|
|
|
|
<< " (blowup: " << 100 * host_code_size / (4 * code_block.m_num_instructions) - 100
|
|
|
|
<< "%)" << std::endl;
|
|
|
|
|
|
|
|
ppc_box->SetValue(ppc_disasm.str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ppc_box->SetValue(StringFromFormat("(non-code address: %08x)", em_address));
|
|
|
|
x86_box->SetValue("---");
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void CJitWindow::Repopulate()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::OnHostMessage(wxCommandEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_NOTIFY_MAP_LOADED:
|
|
|
|
// NotifyMapLoaded();
|
|
|
|
break;
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// JitBlockList
|
|
|
|
//================
|
|
|
|
|
2014-08-30 21:01:19 +00:00
|
|
|
enum
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
COLUMN_ADDRESS,
|
|
|
|
COLUMN_PPCSIZE,
|
|
|
|
COLUMN_X86SIZE,
|
|
|
|
COLUMN_NAME,
|
|
|
|
COLUMN_FLAGS,
|
|
|
|
COLUMN_NUMEXEC,
|
|
|
|
COLUMN_COST, // (estimated as x86size * numexec)
|
2008-12-08 05:30:24 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JitBlockList::JitBlockList(wxWindow* parent, const wxWindowID id, const wxPoint& pos,
|
|
|
|
const wxSize& size, long style)
|
|
|
|
: wxListCtrl(parent, id, pos, size, style) // | wxLC_VIRTUAL)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
Init();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void JitBlockList::Init()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
InsertColumn(COLUMN_ADDRESS, _("Address"));
|
|
|
|
InsertColumn(COLUMN_PPCSIZE, _("PPC Size"));
|
|
|
|
InsertColumn(COLUMN_X86SIZE, _("x86 Size"));
|
|
|
|
InsertColumn(COLUMN_NAME, _("Symbol"));
|
|
|
|
InsertColumn(COLUMN_FLAGS, _("Flags"));
|
|
|
|
InsertColumn(COLUMN_NUMEXEC, _("NumExec"));
|
|
|
|
InsertColumn(COLUMN_COST, _("Cost"));
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void JitBlockList::Repopulate()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
}
|