Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 74 additions & 3 deletions yabause/src/core/sh2/sh2_kronos/src/sh2_opcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
\brief SH2 interpreter interface
*/

#include <assert.h>
#include "sh2core.h"
#include "cs0.h"
#include "debug.h"
Expand All @@ -33,8 +34,65 @@
#include "sh2int_kronos.h"
#include "opcode_functions_define.h"

extern void SH2HandleInterrupts(SH2_struct *context);
extern void SH2ExecCb(SH2_struct *context);
extern void SH2HandleInterrupts(SH2_struct* context);
extern void SH2ExecCb(SH2_struct* context);

//////////////////////////////////////////////////////////////////////////////

static u8 FASTCALL SH2ProfilerTrackAddr(u32 addr, SH2_struct* sh)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the code here and executing it in the interpreter itself has a real performance impact on user lambda which never use the feature. Every simple function call presents an overhead. It should be better to handle it at a upper level, like breakpoints are done and only allow (and show) the option when a compatible cart is plugged. On upper level their might be a debug interpreter with its own set of function and norlmally, it already handle the subbroutine jump and return

{
return addr >= sh->profilerInfo.startMonitorAddress
&& addr < sh->profilerInfo.endMonitorAddress;
}

static void FASTCALL SH2ProfilerTrack(SH2_struct* sh)
{
if (!sh->profilerInfo.profilerEnabled) {
return;
}

const u32 pcAddr = sh->regs.PC;
SH2_ProfilerStackInfo* info = NULL;

if (SH2ProfilerTrackAddr(pcAddr, sh))
{
const u32 addr = pcAddr - sh->profilerInfo.startMonitorAddress;
assert(pcAddr >= PROFILE_START_ADDRESS);
assert(addr < PROFILE_NUM_INFOS);

if (sh->profilerInfo.stackPos < PROFILE_STACK_SIZE)
{
++sh->profilerInfo.stackPos;
assert(sh->profilerInfo.stackPos >= 0);
assert(sh->profilerInfo.stackPos < PROFILE_STACK_SIZE);

info = &sh->profilerInfo.stack[sh->profilerInfo.stackPos];
info->address = addr;
info->startTime = YabauseGetTicks();
}
}
}

static void FASTCALL SH2ProfilerStopTrack(SH2_struct* sh)
{
if (!sh->profilerInfo.profilerEnabled) {
return;
}

const s32 stackPos = sh->profilerInfo.stackPos;
if (stackPos >= 0)
{
SH2_ProfilerStackInfo* stackInfo = &sh->profilerInfo.stack[stackPos];
SH2_ProfilerInfo* info = &sh->profilerInfo.profile[stackInfo->address];

double elapsedTime = (YabauseGetTicks() - stackInfo->startTime) * 1000.0;
elapsedTime /= (double) yabsys.tickfreq;

info->time += elapsedTime;
++info->count;
--sh->profilerInfo.stackPos;
}
}

//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -295,6 +353,8 @@ static void SH2bsr(SH2_struct * sh, u32 disp)
sh->regs.PC = sh->regs.PC+(disp<<1);
sh->regs.PC += 2;

SH2ProfilerTrack(sh);

sh->cycles += 2;
SH2delay(sh, temp + 2);
}
Expand All @@ -308,6 +368,9 @@ static void SH2bsrf(SH2_struct * sh, u32 n)
sh->regs.PR = sh->regs.PC + 4;
sh->regs.PC += sh->regs.R[n];
sh->regs.PC += 2;

SH2ProfilerTrack(sh);

sh->cycles += 2;
SH2delay(sh, temp + 2);
}
Expand Down Expand Up @@ -753,6 +816,9 @@ static void SH2jsr(SH2_struct * sh, u32 m)
sh->regs.PR = sh->regs.PC + 4;
sh->regs.PC = sh->regs.R[m] - 4;
sh->regs.PC += 2;

SH2ProfilerTrack(sh);

sh->cycles += 2;
SH2delay(sh, temp + 2);
}
Expand Down Expand Up @@ -1658,6 +1724,9 @@ static void SH2rte(SH2_struct * sh)
{
u32 temp;
temp=sh->regs.PC;

SH2ProfilerStopTrack(sh);

sh->regs.PC = SH2MappedMemoryReadLong(sh, sh->regs.R[15]) - 4;
sh->regs.R[15] += 4;
sh->regs.SR.all = SH2MappedMemoryReadLong(sh, sh->regs.R[15]) & 0x000003F3;
Expand All @@ -1678,8 +1747,10 @@ static void SH2rte(SH2_struct * sh)
static void SH2rts(SH2_struct * sh)
{
u32 temp;

temp = sh->regs.PC;

SH2ProfilerStopTrack(sh);

sh->regs.PC = sh->regs.PR - 4;
sh->cycles += 2;
sh->regs.PC += 2;
Expand Down
109 changes: 56 additions & 53 deletions yabause/src/port/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ set( kronos_qt_FORMS
ui/UIPadSetting.ui
ui/UISTVSetting.ui
ui/UI3DControlPadSetting.ui
ui/UIWheelSetting.ui
ui/UIMissionStickSetting.ui
ui/UIDoubleMissionStickSetting.ui
ui/UIWheelSetting.ui
ui/UIMissionStickSetting.ui
ui/UIDoubleMissionStickSetting.ui
ui/UIGunSetting.ui
ui/UIMouseSetting.ui
ui/UIDebugCPU.ui
ui/UIDebugSCSP.ui
ui/UIDebugSCSPDSP.ui
ui/UIDebugVDP1.ui
ui/UIDebugVDP2.ui
ui/UIDebugVDP2Viewer.ui
ui/UIHexInput.ui
ui/UIMemoryTransfer.ui
ui/UIMemoryEditor.ui
ui/UIMemorySearch.ui )
ui/UIDebugCPU.ui
ui/UIDebugSCSP.ui
ui/UIDebugSCSPDSP.ui
ui/UIDebugVDP1.ui
ui/UIDebugVDP2.ui
ui/UIDebugVDP2Viewer.ui
ui/UIHexInput.ui
ui/UIProfiler.ui
ui/UIMemoryTransfer.ui
ui/UIMemoryEditor.ui
ui/UIMemorySearch.ui )

# pure C headers
set( kronos_qt_HEADERS
Expand All @@ -89,30 +90,31 @@ set( kronos_qt_MOC_HEADERS
ui/UIPortManager.h
ui/UIControllerSetting.h
ui/UIPadSetting.h
ui/UISTVSetting.h
ui/UISTVSetting.h
ui/UI3DControlPadSetting.h
ui/UIWheelSetting.h
ui/UIMissionStickSetting.h
ui/UIDoubleMissionStickSetting.h
ui/UIWheelSetting.h
ui/UIMissionStickSetting.h
ui/UIDoubleMissionStickSetting.h
ui/UIGunSetting.h
ui/UIMouseSetting.h
ui/UIShortcutManager.h
ui/UIDebugCPU.h
ui/UIDebugM68K.h
ui/UIDebugSCSP.h
ui/UIDebugSCSPChan.h
ui/UIDebugSCSPDSP.h
ui/UIDebugSCUDSP.h
ui/UIDebugSH2.h
ui/UIDebugVDP1.h
ui/UIDebugVDP2.h
ui/UIDebugVDP2Viewer.h
ui/UIDisasm.h
ui/UIHexInput.h
ui/UIMemoryTransfer.h
ui/UIHexEditor.h
ui/UIMemoryEditor.h
ui/UIMemorySearch.h
ui/UIDebugCPU.h
ui/UIDebugM68K.h
ui/UIDebugSCSP.h
ui/UIDebugSCSPChan.h
ui/UIDebugSCSPDSP.h
ui/UIDebugSCUDSP.h
ui/UIDebugSH2.h
ui/UIDebugVDP1.h
ui/UIDebugVDP2.h
ui/UIDebugVDP2Viewer.h
ui/UIDisasm.h
ui/UIHexInput.h
ui/UIProfiler.h
ui/UIMemoryTransfer.h
ui/UIHexEditor.h
ui/UIMemoryEditor.h
ui/UIMemorySearch.h
YabauseGL.h
VolatileSettings.h
Settings.h
Expand All @@ -135,30 +137,31 @@ set( kronos_qt_SOURCES
ui/UIPortManager.cpp
ui/UIControllerSetting.cpp
ui/UIPadSetting.cpp
ui/UISTVSetting.cpp
ui/UISTVSetting.cpp
ui/UI3DControlPadSetting.cpp
ui/UIWheelSetting.cpp
ui/UIMissionStickSetting.cpp
ui/UIDoubleMissionStickSetting.cpp
ui/UIWheelSetting.cpp
ui/UIMissionStickSetting.cpp
ui/UIDoubleMissionStickSetting.cpp
ui/UIGunSetting.cpp
ui/UIMouseSetting.cpp
ui/UIShortcutManager.cpp
ui/UIDebugCPU.cpp
ui/UIDebugM68K.cpp
ui/UIDebugSCSP.cpp
ui/UIDebugSCSPChan.cpp
ui/UIDebugSCSPDSP.cpp
ui/UIDebugSCUDSP.cpp
ui/UIDebugSH2.cpp
ui/UIDebugVDP1.cpp
ui/UIDebugVDP2.cpp
ui/UIDebugVDP2Viewer.cpp
ui/UIDisasm.cpp
ui/UIHexInput.cpp
ui/UIMemoryTransfer.cpp
ui/UIHexEditor.cpp
ui/UIMemoryEditor.cpp
ui/UIMemorySearch.cpp
ui/UIDebugCPU.cpp
ui/UIDebugM68K.cpp
ui/UIDebugSCSP.cpp
ui/UIDebugSCSPChan.cpp
ui/UIDebugSCSPDSP.cpp
ui/UIDebugSCUDSP.cpp
ui/UIDebugSH2.cpp
ui/UIDebugVDP1.cpp
ui/UIDebugVDP2.cpp
ui/UIDebugVDP2Viewer.cpp
ui/UIDisasm.cpp
ui/UIHexInput.cpp
ui/UIProfiler.cpp
ui/UIMemoryTransfer.cpp
ui/UIHexEditor.cpp
ui/UIMemoryEditor.cpp
ui/UIMemorySearch.cpp
Settings.cpp
VolatileSettings.cpp
YabauseThread.cpp
Expand Down
93 changes: 52 additions & 41 deletions yabause/src/port/qt/ui/UIDebugSH2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ UIDebugSH2::UIDebugSH2(UIDebugCPU::PROCTYPE proc, YabauseThread *mYabauseThread,
connect( pbLoadCode, SIGNAL( clicked() ), this, SLOT( loadCodeAddress() ) );

restoreAddr2line();
restoreCppFilt();
}

void UIDebugSH2::restoreAddr2line()
Expand All @@ -127,6 +128,12 @@ void UIDebugSH2::restoreAddr2line()
addr2line = settings->value( "Debug/Addr2Line" ).toString();
}

void UIDebugSH2::restoreCppFilt()
{
Settings* settings = QtYabause::settings();
cppfilt = settings->value( "Debug/CppFilt" ).toString();
}

void UIDebugSH2::updateRegList()
{
int i;
Expand Down Expand Up @@ -232,55 +239,59 @@ void UIDebugSH2::loadCodeAddress()
updateCodePage(static_cast<uint32_t>(std::stoull(newAddress, nullptr, 16)));
}

QString UIDebugSH2::findElfPath()
{
QString elfPath;
VolatileSettings *vs = QtYabause::volatileSettings();
if (vs->value("General/CdRom") != CDCORE_ISO)
{
return "";
}
else
{
const QString isoPathString{ vs->value( "Recents/ISOs" ).toString() };
const QFileInfo fileInfo(isoPathString);
QDir searchPath = fileInfo.dir();

const QString filename = fileInfo.completeBaseName() + ".elf";
YuiMsg("looking for %s\n", filename.toStdString().c_str());

if (searchPath.cd("build")) {
if (searchPath.exists(filename)) {
// Found in build folder
return QFileInfo(searchPath, filename).absoluteFilePath();
}
else {
searchPath.cdUp();
}
}

if (elfPath.isEmpty()) {
if (searchPath.exists(filename)) {
// Found in local folder
return QFileInfo(searchPath, filename).absoluteFilePath();
}
}
}

return "";
}

void UIDebugSH2::updateCodePage(u32 evaluateAddress)
{
YuiMsg("Address to inspect %x\n", evaluateAddress);
if (addr2line.isEmpty())
restoreAddr2line();

if (cppfilt.isEmpty())
restoreCppFilt();

QString elfPath = findElfPath();
if (elfPath.isEmpty())
return;

QString elfPath;
const QString program{ addr2line };

VolatileSettings *vs = QtYabause::volatileSettings();
if ( vs->value( "General/CdRom" ) != CDCORE_ISO )
{
YuiMsg("Not using ISO, ignoring code\n");
return;
}
else
{
const QString isoPathString{ vs->value( "Recents/ISOs" ).toString() };
const QFileInfo fileInfo(isoPathString);
QDir searchPath = fileInfo.dir();
const QString filename = fileInfo.completeBaseName() + ".elf";

YuiMsg("looking for %s\n", filename.toStdString().c_str());

if (searchPath.cd("build")) {
YuiMsg("looking for %s in %s\n", filename.toStdString().c_str(), searchPath.path().toStdString().c_str());
if (searchPath.exists(filename)) {
//Found in build folder
elfPath = QFileInfo(searchPath, filename).absoluteFilePath();
printf("Found %s !!\n", elfPath.toStdString().c_str());
}
else {
searchPath.cdUp();
}
}
if (elfPath.isEmpty()) {
YuiMsg("looking for %s in %s\n", filename.toStdString().c_str(), searchPath.path().toStdString().c_str());
if (searchPath.exists(filename)) {
//Found in local folder
YuiMsg("Found %s in %s\n", filename.toStdString().c_str(), searchPath.path().toStdString().c_str());
elfPath = QFileInfo(searchPath, filename).absoluteFilePath();
}
else {
// Not found at all
YuiMsg("Could not find elf file, ignoring code\n");
return;
}
}
}
std::stringstream hexAddress;
hexAddress << std::setfill('0') << std::setw(8) << std::hex
<< evaluateAddress;
Expand Down
Loading