Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gopalsr83 committed Feb 18, 2015
2 parents 681fb1e + cae85c6 commit 85648da
Show file tree
Hide file tree
Showing 83 changed files with 4,611 additions and 4,127 deletions.
878 changes: 769 additions & 109 deletions Utilities/Thread.cpp

Large diffs are not rendered by default.

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);
}
};

4 changes: 4 additions & 0 deletions rpcs3/Emu/Cell/PPUDisAsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,10 @@ class PPUDisAsm

Write(fmt::Format("bc [%x:%x:%x:%x:%x], cr%d[%x], 0x%x, %d, %d", bo0, bo1, bo2, bo3, bo4, bi/4, bi%4, bd, aa, lk));
}
void HACK(u32 index)
{
Write(fmt::Format("hack %d", index));
}
void SC(u32 lev)
{
switch (lev)
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/Emu/Cell/PPUInstrTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ namespace PPU_instr
//This immediate field is used to specify a 16-bit unsigned integer
static CodeField<16, 31> uimm16;

static CodeField<6, 31> uimm26;

/*
Record bit.
0 Does not update the condition register (CR).
Expand Down Expand Up @@ -241,6 +243,7 @@ namespace PPU_instr
bind_instr(main_list, ADDI, RD, RA, simm16);
bind_instr(main_list, ADDIS, RD, RA, simm16);
bind_instr(main_list, BC, BO, BI, BD, AA, LK);
bind_instr(main_list, HACK, uimm26);
bind_instr(main_list, SC, LEV);
bind_instr(main_list, B, LI, AA, LK);
bind_instr(main_list, RLWIMI, RA, RS, SH, MB, ME, RC);
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/Emu/Cell/PPUInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,10 @@ class PPUInterpreter : public PPUOpcodes
if(lk) CPU.LR = nextLR;
}
}
void HACK(u32 index)
{
execute_ps3_func_by_index(CPU, index);
}
void SC(u32 lev)
{
switch (lev)
Expand Down
Loading

0 comments on commit 85648da

Please sign in to comment.