2013-04-17 21:43:35 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2014-02-18 18:56:29 -07:00
|
|
|
#include <disasm.h> // Bochs
|
|
|
|
#include <PowerPCDisasm.h> // Bochs
|
2008-12-07 22:30:24 -07:00
|
|
|
#include <wx/button.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/listbase.h>
|
2008-12-07 22:30:24 -07:00
|
|
|
#include <wx/listctrl.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/string.h>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include <wx/textctrl.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <wx/window.h>
|
|
|
|
#include <wx/windowid.h>
|
2009-02-23 13:29:55 -07:00
|
|
|
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/Common.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Core/PowerPC/Gekko.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/PowerPC/PPCAnalyst.h"
|
|
|
|
#include "Core/PowerPC/JitCommon/JitBase.h"
|
|
|
|
#include "Core/PowerPC/JitCommon/JitCache.h"
|
|
|
|
#include "DolphinWX/Globals.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
|
|
|
#include "DolphinWX/Debugger/JitWindow.h"
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDM_REFRESH_LIST = 23350,
|
|
|
|
IDM_PPC_BOX,
|
|
|
|
IDM_X86_BOX,
|
|
|
|
IDM_NEXT,
|
|
|
|
IDM_PREV,
|
|
|
|
IDM_BLOCKLIST,
|
|
|
|
};
|
|
|
|
|
2009-09-07 14:51:02 -06:00
|
|
|
BEGIN_EVENT_TABLE(CJitWindow, wxPanel)
|
2010-07-25 21:46:14 -06:00
|
|
|
//EVT_TEXT(IDM_ADDRBOX, CJitWindow::OnAddrBoxChange)
|
|
|
|
//EVT_LISTBOX(IDM_SYMBOLLIST, CJitWindow::OnSymbolListChange)
|
|
|
|
//EVT_HOST_COMMAND(wxID_ANY, CJitWindow::OnHostMessage)
|
2008-12-07 22:30:24 -07:00
|
|
|
EVT_BUTTON(IDM_REFRESH_LIST, CJitWindow::OnRefresh)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2010-07-21 20:05:28 -06:00
|
|
|
CJitWindow::CJitWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
2013-04-07 23:16:50 -06:00
|
|
|
const wxSize& size, long style, const wxString& name)
|
2010-07-21 20:05:28 -06:00
|
|
|
: wxPanel(parent, id, pos, size, style, name)
|
2010-07-25 21:46:14 -06:00
|
|
|
{
|
2008-12-07 22:30:24 -07:00
|
|
|
wxBoxSizer* sizerBig = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer* sizerSplit = new wxBoxSizer(wxHORIZONTAL);
|
2010-07-25 21:46:14 -06:00
|
|
|
sizerSplit->Add(ppc_box = new wxTextCtrl(this, IDM_PPC_BOX, _T("(ppc)"),
|
2013-04-07 23:16:50 -06:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE), 1, wxEXPAND);
|
2010-07-25 21:46:14 -06:00
|
|
|
sizerSplit->Add(x86_box = new wxTextCtrl(this, IDM_X86_BOX, _T("(x86)"),
|
2013-04-07 23:16:50 -06:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE), 1, wxEXPAND);
|
2008-12-07 22:30:24 -07:00
|
|
|
sizerBig->Add(block_list = new JitBlockList(this, IDM_BLOCKLIST,
|
|
|
|
wxDefaultPosition, wxSize(100, 140),
|
2010-07-25 21:46:14 -06:00
|
|
|
wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL | wxLC_SORT_ASCENDING),
|
|
|
|
0, wxEXPAND);
|
2008-12-07 22:30:24 -07:00
|
|
|
sizerBig->Add(sizerSplit, 2, wxEXPAND);
|
2014-02-16 21:51:41 -07:00
|
|
|
// sizerBig->Add(memview, 5, wxEXPAND);
|
|
|
|
// sizerBig->Add(sizerRight, 0, wxEXPAND | wxALL, 3);
|
2011-01-04 21:35:46 -07:00
|
|
|
sizerBig->Add(button_refresh = new wxButton(this, IDM_REFRESH_LIST, _("&Refresh")));
|
2014-02-16 21:51:41 -07:00
|
|
|
// sizerRight->Add(addrbox = new wxTextCtrl(this, IDM_ADDRBOX, _T("")));
|
|
|
|
// sizerRight->Add(new wxButton(this, IDM_SETPC, _("S&et PC")));
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
SetSizer(sizerBig);
|
|
|
|
|
|
|
|
sizerSplit->Fit(this);
|
|
|
|
sizerBig->Fit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::OnRefresh(wxCommandEvent& /*event*/) {
|
|
|
|
block_list->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::ViewAddr(u32 em_address)
|
|
|
|
{
|
2011-02-24 20:56:14 -07:00
|
|
|
Show(true);
|
|
|
|
Compare(em_address);
|
|
|
|
SetFocus();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::Compare(u32 em_address)
|
|
|
|
{
|
2008-12-28 19:02:35 -07:00
|
|
|
u8 *xDis = new u8[1<<18];
|
|
|
|
memset(xDis, 0, 1<<18);
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
disassembler x64disasm;
|
|
|
|
x64disasm.set_syntax_intel();
|
|
|
|
|
2010-01-19 12:28:27 -07:00
|
|
|
int block_num = jit->GetBlockCache()->GetBlockNumberFromStartAddress(em_address);
|
2008-12-07 22:30:24 -07:00
|
|
|
if (block_num < 0)
|
|
|
|
{
|
2013-04-07 23:16:50 -06:00
|
|
|
for (int i = 0; i < 500; i++)
|
|
|
|
{
|
2010-01-19 12:28:27 -07:00
|
|
|
block_num = jit->GetBlockCache()->GetBlockNumberFromStartAddress(em_address - 4 * i);
|
2008-12-19 15:21:29 -07:00
|
|
|
if (block_num >= 0)
|
|
|
|
break;
|
|
|
|
}
|
2013-04-07 23:16:50 -06:00
|
|
|
|
|
|
|
if (block_num >= 0)
|
|
|
|
{
|
2010-01-19 12:28:27 -07:00
|
|
|
JitBlock *block = jit->GetBlockCache()->GetBlock(block_num);
|
2010-07-25 21:46:14 -06:00
|
|
|
if (!(block->originalAddress <= em_address &&
|
2013-04-07 23:16:50 -06:00
|
|
|
block->originalSize + block->originalAddress >= em_address))
|
2008-12-19 15:21:29 -07:00
|
|
|
block_num = -1;
|
|
|
|
}
|
2013-04-07 23:16:50 -06:00
|
|
|
|
2008-12-19 15:21:29 -07:00
|
|
|
// Do not merge this "if" with the above - block_num changes inside it.
|
2013-04-07 23:16:50 -06:00
|
|
|
if (block_num < 0)
|
|
|
|
{
|
2013-02-28 01:39:06 -07:00
|
|
|
ppc_box->SetValue(StrToWxStr(StringFromFormat("(non-code address: %08x)",
|
2013-04-07 23:16:50 -06:00
|
|
|
em_address)));
|
2013-02-28 01:39:06 -07:00
|
|
|
x86_box->SetValue(StrToWxStr(StringFromFormat("(no translation)")));
|
2010-02-12 12:28:51 -07:00
|
|
|
delete[] xDis;
|
2008-12-19 15:21:29 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
2010-01-19 12:28:27 -07:00
|
|
|
JitBlock *block = jit->GetBlockCache()->GetBlock(block_num);
|
2010-07-25 21:46:14 -06:00
|
|
|
|
2008-12-19 15:21:29 -07:00
|
|
|
// 800031f0
|
2008-12-19 14:35:57 -07:00
|
|
|
// == Fill in x86 box
|
|
|
|
|
2010-01-19 12:28:27 -07:00
|
|
|
const u8 *code = (const u8 *)jit->GetBlockCache()->GetCompiledCodeFromBlock(block_num);
|
2008-12-19 14:35:57 -07:00
|
|
|
u64 disasmPtr = (u64)code;
|
2014-04-30 07:19:28 -06:00
|
|
|
const u8 *end = code + block->codeSize;
|
2008-12-19 14:35:57 -07:00
|
|
|
char *sptr = (char*)xDis;
|
|
|
|
|
|
|
|
int num_x86_instructions = 0;
|
|
|
|
while ((u8*)disasmPtr < end)
|
|
|
|
{
|
2014-03-02 04:21:50 -07:00
|
|
|
#if _M_X86_64
|
2008-12-19 14:35:57 -07:00
|
|
|
disasmPtr += x64disasm.disasm64(disasmPtr, disasmPtr, (u8*)disasmPtr, sptr);
|
2009-06-12 17:56:31 -06:00
|
|
|
#else
|
|
|
|
disasmPtr += x64disasm.disasm32(disasmPtr, disasmPtr, (u8*)disasmPtr, sptr);
|
|
|
|
#endif
|
2008-12-19 14:35:57 -07:00
|
|
|
sptr += strlen(sptr);
|
|
|
|
*sptr++ = 13;
|
|
|
|
*sptr++ = 10;
|
|
|
|
num_x86_instructions++;
|
|
|
|
}
|
2013-02-28 01:39:06 -07:00
|
|
|
x86_box->SetValue(StrToWxStr((char*)xDis));
|
2008-12-19 14:35:57 -07:00
|
|
|
|
2008-12-18 04:09:03 -07:00
|
|
|
// == Fill in ppc box
|
|
|
|
u32 ppc_addr = block->originalAddress;
|
|
|
|
PPCAnalyst::CodeBuffer code_buffer(32000);
|
|
|
|
PPCAnalyst::BlockStats st;
|
|
|
|
PPCAnalyst::BlockRegStats gpa;
|
|
|
|
PPCAnalyst::BlockRegStats fpa;
|
2014-04-30 07:19:28 -06:00
|
|
|
PPCAnalyst::CodeBlock code_block;
|
|
|
|
PPCAnalyst::PPCAnalyzer analyzer;
|
|
|
|
|
|
|
|
code_block.m_stats = &st;
|
|
|
|
code_block.m_gpa = &gpa;
|
|
|
|
code_block.m_fpa = &fpa;
|
|
|
|
|
|
|
|
if (analyzer.Analyze(ppc_addr, &code_block, &code_buffer, block->codeSize) != 0xFFFFFFFF)
|
2008-12-18 06:21:02 -07:00
|
|
|
{
|
2010-02-21 11:55:00 -07:00
|
|
|
sptr = (char*)xDis;
|
2014-04-30 07:19:28 -06:00
|
|
|
for (u32 i = 0; i < code_block.m_num_instructions; i++)
|
2008-12-18 04:09:03 -07:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2008-12-19 14:35:57 -07:00
|
|
|
|
|
|
|
// Add stats to the end of the ppc box since it's generally the shortest.
|
|
|
|
sptr += sprintf(sptr, "\n");
|
|
|
|
|
|
|
|
// Add some generic analysis
|
|
|
|
if (st.isFirstBlockOfFunction)
|
|
|
|
sptr += sprintf(sptr, "(first block of function)\n");
|
|
|
|
if (st.isLastBlockOfFunction)
|
|
|
|
sptr += sprintf(sptr, "(first block of function)\n");
|
|
|
|
|
|
|
|
sptr += sprintf(sptr, "%i estimated cycles\n", st.numCycles);
|
|
|
|
|
2010-07-25 21:46:14 -06:00
|
|
|
sptr += sprintf(sptr, "Num instr: PPC: %i x86: %i (blowup: %i%%)\n",
|
2014-04-30 07:19:28 -06:00
|
|
|
code_block.m_num_instructions, num_x86_instructions, 100 * (num_x86_instructions / code_block.m_num_instructions - 1));
|
2010-07-25 21:46:14 -06:00
|
|
|
sptr += sprintf(sptr, "Num bytes: PPC: %i x86: %i (blowup: %i%%)\n",
|
2014-04-30 07:19:28 -06:00
|
|
|
code_block.m_num_instructions * 4, block->codeSize, 100 * (block->codeSize / (4 * code_block.m_num_instructions) - 1));
|
2008-12-19 14:35:57 -07:00
|
|
|
|
2013-02-28 01:39:06 -07:00
|
|
|
ppc_box->SetValue(StrToWxStr((char*)xDis));
|
2013-04-07 23:16:50 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-28 01:39:06 -07:00
|
|
|
ppc_box->SetValue(StrToWxStr(StringFromFormat(
|
|
|
|
"(non-code address: %08x)", em_address)));
|
|
|
|
x86_box->SetValue("---");
|
2008-12-18 04:09:03 -07:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2010-02-12 12:28:51 -07:00
|
|
|
delete[] xDis;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJitWindow::OnHostMessage(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
2013-04-07 23:16:50 -06:00
|
|
|
case IDM_NOTIFYMAPLOADED:
|
|
|
|
//NotifyMapLoaded();
|
|
|
|
break;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// JitBlockList
|
|
|
|
//================
|
|
|
|
|
|
|
|
enum {
|
|
|
|
COLUMN_ADDRESS,
|
|
|
|
COLUMN_PPCSIZE,
|
|
|
|
COLUMN_X86SIZE,
|
|
|
|
COLUMN_NAME,
|
|
|
|
COLUMN_FLAGS,
|
|
|
|
COLUMN_NUMEXEC,
|
|
|
|
COLUMN_COST, // (estimated as x86size * numexec)
|
|
|
|
};
|
|
|
|
|
2010-07-25 21:46:14 -06:00
|
|
|
JitBlockList::JitBlockList(wxWindow* parent, const wxWindowID id,
|
2013-04-07 23:16:50 -06:00
|
|
|
const wxPoint& pos, const wxSize& size, long style)
|
2010-07-25 21:46:14 -06:00
|
|
|
: wxListCtrl(parent, id, pos, size, style) // | wxLC_VIRTUAL)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2010-07-25 21:46:14 -06:00
|
|
|
Init();
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void JitBlockList::Init()
|
|
|
|
{
|
2011-01-04 21:35:46 -07: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-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void JitBlockList::Update()
|
|
|
|
{
|
|
|
|
}
|