Skip to content

Commit

Permalink
Loader improved, ModuleManager refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Feb 18, 2015
1 parent 1f2eafc commit af986d8
Show file tree
Hide file tree
Showing 72 changed files with 3,719 additions and 3,874 deletions.
14 changes: 10 additions & 4 deletions Utilities/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,11 +1182,15 @@ void ThreadBase::Start()
}
catch (const char* e)
{
LOG_ERROR(GENERAL, "%s: %s", GetThreadName().c_str(), e);
LOG_ERROR(GENERAL, "Exception: %s", e);
DumpInformation();
Emu.Pause();
}
catch (const std::string& e)
{
LOG_ERROR(GENERAL, "%s: %s", GetThreadName().c_str(), e.c_str());
LOG_ERROR(GENERAL, "Exception: %s", e);
DumpInformation();
Emu.Pause();
}

m_alive = false;
Expand Down Expand Up @@ -1325,11 +1329,13 @@ void thread_t::start(std::function<void()> func)
}
catch (const char* e)
{
LOG_ERROR(GENERAL, "%s: %s", name.c_str(), e);
LOG_ERROR(GENERAL, "Exception: %s", e);
Emu.Pause();
}
catch (const std::string& e)
{
LOG_ERROR(GENERAL, "%s: %s", name.c_str(), e.c_str());
LOG_ERROR(GENERAL, "Exception: %s", e.c_str());
Emu.Pause();
}

if (Emu.IsStopped())
Expand Down
3 changes: 2 additions & 1 deletion Utilities/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class NamedThreadBase
virtual void SetThreadName(const std::string& name);

void WaitForAnySignal(u64 time = 1);

void Notify();

virtual void DumpInformation() {}
};

NamedThreadBase* GetCurrentNamedThread();
Expand Down
47 changes: 39 additions & 8 deletions rpcs3/Emu/ARMv7/PSVFuncList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ std::vector<psv_log_base*> g_psv_modules;

void add_psv_func(psv_func& data)
{
for (auto& f : g_psv_func_list)
{
if (f.nid == data.nid && &f - g_psv_func_list.data() >= 2 /* special functions count */)
{
if (data.func)
{
f.func = data.func;
}

return;
}
}

g_psv_func_list.push_back(data);
}

Expand All @@ -27,28 +40,46 @@ u32 get_psv_func_index(const psv_func* func)
{
auto res = func - g_psv_func_list.data();

assert((size_t)res < g_psv_func_list.size());
if ((size_t)res >= g_psv_func_list.size())
{
throw __FUNCTION__;
}

return (u32)res;
}

const psv_func* get_psv_func_by_index(u32 index)
{
assert(index < g_psv_func_list.size());
if (index >= g_psv_func_list.size())
{
return nullptr;
}

return &g_psv_func_list[index];
}

void execute_psv_func_by_index(ARMv7Context& context, u32 index)
{
auto func = get_psv_func_by_index(index);

auto old_last_syscall = context.thread.m_last_syscall;
context.thread.m_last_syscall = func->nid;
if (auto func = get_psv_func_by_index(index))
{
auto old_last_syscall = context.thread.m_last_syscall;
context.thread.m_last_syscall = func->nid;

(*func->func)(context);
if (func->func)
{
(*func->func)(context);
}
else
{
throw "Unimplemented function";
}

context.thread.m_last_syscall = old_last_syscall;
context.thread.m_last_syscall = old_last_syscall;
}
else
{
throw "Invalid function index";
}
}

extern psv_log_base sceAppMgr;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/ARMv7/PSVFuncList.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ namespace psv_func_detail
// Basic information about the HLE function
struct psv_func
{
u32 nid; // Unique function ID only for old PSV executables (should be generated individually for each elf loaded)
u32 nid; // Unique function ID (should be generated individually for each elf loaded)
const char* name; // Function name for information
std::shared_ptr<psv_func_caller> func; // Function caller instance
psv_log_base* module; // Module for information
Expand Down
199 changes: 95 additions & 104 deletions rpcs3/Emu/CPU/CPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,76 @@ CPUThread::~CPUThread()
safe_delete(m_dec);
}

void CPUThread::DumpInformation()
{
auto get_syscall_name = [this](u64 syscall) -> std::string
{
switch (GetType())
{
case CPU_THREAD_ARMv7:
{
if ((u32)syscall == syscall)
{
if (syscall)
{
if (auto func = get_psv_func_by_nid((u32)syscall))
{
return func->name;
}
}
else
{
return{};
}
}

return "unknown function";
}

case CPU_THREAD_PPU:
{
if ((u32)syscall == syscall)
{
if (syscall)
{
if (syscall < 1024)
{
// TODO:
//return SysCalls::GetSyscallName((u32)syscall);
return "unknown syscall";
}
else
{
return SysCalls::GetHLEFuncName((u32)syscall);
}
}
else
{
return{};
}
}

return "unknown function";
}

case CPU_THREAD_SPU:
case CPU_THREAD_RAW_SPU:
default:
{
if (!syscall)
{
return{};
}

return "unknown function";
}
}
};

LOG_ERROR(GENERAL, "Information: is_alive=%d, m_last_syscall=0x%llx (%s)", IsAlive(), m_last_syscall, get_syscall_name(m_last_syscall));
LOG_WARNING(GENERAL, RegsToString());
}

bool CPUThread::IsRunning() const { return m_status == Running; }
bool CPUThread::IsPaused() const { return m_status == Paused; }
bool CPUThread::IsStopped() const { return m_status == Stopped; }
Expand Down Expand Up @@ -246,70 +316,6 @@ void CPUThread::ExecOnce()

void CPUThread::Task()
{
auto get_syscall_name = [this](u64 syscall) -> std::string
{
switch (GetType())
{
case CPU_THREAD_ARMv7:
{
if ((u32)syscall == syscall)
{
if (syscall)
{
if (auto func = get_psv_func_by_nid((u32)syscall))
{
return func->name;
}
}
else
{
return{};
}
}

return "unknown function";
}

case CPU_THREAD_PPU:
{
if ((u32)syscall == syscall)
{
if (syscall)
{
if (syscall < 1024)
{
// TODO:
//return SysCalls::GetSyscallName((u32)syscall);
return "unknown syscall";
}
else
{
return SysCalls::GetHLEFuncName((u32)syscall);
}
}
else
{
return{};
}
}

return "unknown function";
}

case CPU_THREAD_SPU:
case CPU_THREAD_RAW_SPU:
default:
{
if (!syscall)
{
return{};
}

return "unknown function";
}
}
};

if (Ini.HLELogging.GetValue()) LOG_NOTICE(GENERAL, "%s enter", CPUThread::GetFName().c_str());

const std::vector<u64>& bp = Emu.GetBreakPoints();
Expand All @@ -325,55 +331,41 @@ void CPUThread::Task()

std::vector<u32> trace;

try
while (true)
{
while (true)
int status = ThreadStatus();

if (status == CPUThread_Stopped || status == CPUThread_Break)
{
int status = ThreadStatus();
break;
}

if (status == CPUThread_Stopped || status == CPUThread_Break)
{
break;
}
if (status == CPUThread_Sleeping)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
continue;
}

if (status == CPUThread_Sleeping)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack
continue;
}
Step();
//if (m_trace_enabled)
//trace.push_back(PC);
NextPc(m_dec->DecodeMemory(PC + m_offset));

Step();
//if (m_trace_enabled) trace.push_back(PC);
NextPc(m_dec->DecodeMemory(PC + m_offset));
if (status == CPUThread_Step)
{
m_is_step = false;
break;
}

if (status == CPUThread_Step)
for (uint i = 0; i < bp.size(); ++i)
{
if (bp[i] == PC)
{
m_is_step = false;
Emu.Pause();
break;
}

for (uint i = 0; i < bp.size(); ++i)
{
if (bp[i] == PC)
{
Emu.Pause();
break;
}
}
}
}
catch (const std::string& e)
{
LOG_ERROR(GENERAL, "Exception: %s (is_alive=%d, m_last_syscall=0x%llx (%s))", e, IsAlive(), m_last_syscall, get_syscall_name(m_last_syscall));
LOG_NOTICE(GENERAL, RegsToString());
Emu.Pause();
}
catch (const char* e)
{
LOG_ERROR(GENERAL, "Exception: %s (is_alive=%d, m_last_syscall=0x%llx (%s))", e, IsAlive(), m_last_syscall, get_syscall_name(m_last_syscall));
LOG_NOTICE(GENERAL, RegsToString());
Emu.Pause();
}

if (trace.size())
{
Expand All @@ -383,7 +375,7 @@ void CPUThread::Task()

for (auto& v : trace) //LOG_NOTICE(GENERAL, "PC = 0x%x", v);
{
if (v - prev != 4)
if (v - prev != 4 && v - prev != 2)
{
LOG_NOTICE(GENERAL, "Trace: 0x%08x .. 0x%08x", start, prev);
start = v;
Expand All @@ -394,6 +386,5 @@ void CPUThread::Task()
LOG_NOTICE(GENERAL, "Trace end: 0x%08x .. 0x%08x", start, prev);
}


if (Ini.HLELogging.GetValue()) LOG_NOTICE(GENERAL, "%s leave", CPUThread::GetFName().c_str());
}
2 changes: 2 additions & 0 deletions rpcs3/Emu/CPU/CPUThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class CPUThread : public ThreadBase

bool m_trace_call_stack;

virtual void DumpInformation() override;

public:
virtual void InitRegs() = 0;

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPCDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ template<int count, typename TO, uint from, uint to>
static InstrList<(1 << (CodeField<from, to>::size)), TO>* new_list(InstrList<count, TO>* parent, const CodeField<from, to>& func, InstrCaller<TO>* error_func = nullptr)
{
return connect_list(parent, new InstrList<(1 << (CodeField<from, to>::size)), TO>(func, error_func));
}
}
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/PPCInstrTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,3 @@ class CodeFieldSignedOffset : public CodeFieldSigned<from, to, size>
return encode(data, value);
}
};

Loading

0 comments on commit af986d8

Please sign in to comment.