- Fixed sys_ppu_thread_exit.

- Disabled some dbg tools.
This commit is contained in:
DH 2013-08-17 19:23:03 +03:00
parent 0aff049960
commit 2f5fa75bb4
16 changed files with 152 additions and 113 deletions

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "PPCInstrTable.h" #include "PPCInstrTable.h"
#pragma warning( disable : 4800 4554 ) #pragma warning( disable : 4800 )
template<typename TO> template<typename TO>
class InstrCaller class InstrCaller
@ -485,21 +485,21 @@ static InstrList<count2, TO>* connect_list(InstrList<count1, TO>* parent, InstrL
} }
template<typename TO, uint from, uint to> template<typename TO, uint from, uint to>
static InstrList<1 << (to - from + 1), TO>* new_list(const CodeField<from, to>& func, InstrCaller<TO>* error_func = nullptr) static InstrList<1 << CodeField<from, to>::size, TO>* new_list(const CodeField<from, to>& func, InstrCaller<TO>* error_func = nullptr)
{ {
return new InstrList<1 << (to - from + 1), TO>(func, error_func); return new InstrList<1 << CodeField<from, to>::size, TO>(func, error_func);
} }
template<int count, typename TO, uint from, uint to> template<int count, typename TO, uint from, uint to>
static InstrList<1 << (to - from + 1), TO>* new_list(InstrList<count, TO>* parent, int opcode, const CodeField<from, to>& func, InstrCaller<TO>* error_func = nullptr) static InstrList<1 << CodeField<from, to>::size, TO>* new_list(InstrList<count, TO>* parent, int opcode, const CodeField<from, to>& func, InstrCaller<TO>* error_func = nullptr)
{ {
return connect_list(parent, new InstrList<1 << (to - from + 1), TO>(func, error_func), opcode); return connect_list(parent, new InstrList<1 << CodeField<from, to>::size, TO>(func, error_func), opcode);
} }
template<int count, typename TO, uint from, uint to> template<int count, typename TO, uint from, uint to>
static InstrList<1 << (to - from + 1), TO>* new_list(InstrList<count, TO>* parent, const CodeField<from, to>& func, InstrCaller<TO>* error_func = nullptr) 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 << (to - from + 1), TO>(func, error_func)); return connect_list(parent, new InstrList<1 << CodeField<from, to>::size, TO>(func, error_func));
} }
template<typename TO, int opcode, int count> template<typename TO, int opcode, int count>

View file

@ -1,10 +1,12 @@
#pragma once #pragma once
template<int size, typename T> __forceinline static T sign(const T value) template<uint size, typename T> __forceinline static T sign(const T value)
{ {
if(value & (1 << (size - 1))) static_assert(size > 0 && size < sizeof(T) * 8, "Bad size");
static const T sub_value = T(1) << size;
if(value & (T(1) << (size - 1)))
{ {
return value - (1 << size); return value - sub_value;
} }
return value; return value;
@ -52,6 +54,7 @@ public:
{ {
} }
static const u32 size = to - from + 1;
static const u32 shift = 31 - to; static const u32 shift = 31 - to;
static const u32 mask = ((1ULL << ((to - from) + 1)) - 1) << shift; static const u32 mask = ((1ULL << ((to - from) + 1)) - 1) << shift;

View file

@ -10,8 +10,8 @@ PPCThread* GetCurrentPPCThread()
PPCThread::PPCThread(PPCThreadType type) PPCThread::PPCThread(PPCThreadType type)
: ThreadBase(true, "PPCThread") : ThreadBase(true, "PPCThread")
, m_type(type) , m_type(type)
, DisAsmFrame(NULL) , DisAsmFrame(nullptr)
, m_dec(NULL) , m_dec(nullptr)
, stack_size(0) , stack_size(0)
, stack_addr(0) , stack_addr(0)
, m_prio(0) , m_prio(0)
@ -28,12 +28,13 @@ PPCThread::~PPCThread()
void PPCThread::Close() void PPCThread::Close()
{ {
Stop();
if(DisAsmFrame) if(DisAsmFrame)
{ {
DisAsmFrame->Close(); DisAsmFrame->Close();
DisAsmFrame = nullptr; DisAsmFrame = nullptr;
} }
Stop();
} }
void PPCThread::Reset() void PPCThread::Reset()
@ -260,12 +261,11 @@ void PPCThread::Stop()
wxGetApp().SendDbgCommand(DID_STOP_THREAD, this); wxGetApp().SendDbgCommand(DID_STOP_THREAD, this);
m_status = Stopped; m_status = Stopped;
ThreadBase::Stop();
Reset(); Reset();
DoStop(); DoStop();
Emu.CheckStatus(); Emu.CheckStatus();
ThreadBase::Stop();
wxGetApp().SendDbgCommand(DID_STOPED_THREAD, this); wxGetApp().SendDbgCommand(DID_STOPED_THREAD, this);
} }

View file

@ -50,10 +50,11 @@ void PPCThreadManager::RemoveThread(const u32 id)
if(m_threads[i].GetId() != id) continue; if(m_threads[i].GetId() != id) continue;
wxGetApp().SendDbgCommand(DID_REMOVE_THREAD, &m_threads[i]); PPCThread* thr = &m_threads[i];
m_threads[i].Close();
delete &m_threads[i];
m_threads.RemoveFAt(i); m_threads.RemoveFAt(i);
wxGetApp().SendDbgCommand(DID_REMOVE_THREAD, thr);
thr->Close();
delete thr;
i--; i--;
} }

View file

@ -541,7 +541,9 @@ namespace PPU_instr
/*0x33a*/bind_instr(g1f_list, SRADI1, RA, RS, sh, RC); /*0x33a*/bind_instr(g1f_list, SRADI1, RA, RS, sh, RC);
/*0x33b*/bind_instr(g1f_list, SRADI2, RA, RS, sh, RC); /*0x33b*/bind_instr(g1f_list, SRADI2, RA, RS, sh, RC);
/*0x356*/bind_instr(g1f_list, EIEIO); /*0x356*/bind_instr(g1f_list, EIEIO);
/*0x387*/bind_instr(g1f_list, STVLXL, VS, RA, RB);
/*0x39a*/bind_instr(g1f_list, EXTSH, RA, RS, RC); /*0x39a*/bind_instr(g1f_list, EXTSH, RA, RS, RC);
/*0x387*/bind_instr(g1f_list, STVRXL, VS, RA, RB);
/*0x3ba*/bind_instr(g1f_list, EXTSB, RA, RS, RC); /*0x3ba*/bind_instr(g1f_list, EXTSB, RA, RS, RC);
/*0x3d7*/bind_instr(g1f_list, STFIWX, FRS, RA, RB); /*0x3d7*/bind_instr(g1f_list, STFIWX, FRS, RA, RB);
/*0x3da*/bind_instr(g1f_list, EXTSW, RA, RS, RC); /*0x3da*/bind_instr(g1f_list, EXTSW, RA, RS, RC);

View file

@ -739,7 +739,7 @@ public:
virtual void SRADI1(u32 ra, u32 rs, u32 sh, bool rc) = 0; virtual void SRADI1(u32 ra, u32 rs, u32 sh, bool rc) = 0;
virtual void SRADI2(u32 ra, u32 rs, u32 sh, bool rc) = 0; virtual void SRADI2(u32 ra, u32 rs, u32 sh, bool rc) = 0;
virtual void EIEIO() = 0; virtual void EIEIO() = 0;
virtual void STVLXL(u32 sd, u32 ra, u32 rb) = 0; virtual void STVLXL(u32 vs, u32 ra, u32 rb) = 0;
virtual void EXTSH(u32 ra, u32 rs, bool rc) = 0; virtual void EXTSH(u32 ra, u32 rs, bool rc) = 0;
virtual void STVRXL(u32 sd, u32 ra, u32 rb) = 0; virtual void STVRXL(u32 sd, u32 ra, u32 rb) = 0;
virtual void EXTSB(u32 ra, u32 rs, bool rc) = 0; virtual void EXTSB(u32 ra, u32 rs, bool rc) = 0;

View file

@ -178,6 +178,7 @@ bool dump_enable = false;
void PPUThread::DoCode(const s32 code) void PPUThread::DoCode(const s32 code)
{ {
#ifdef _DEBUG
static bool is_last_enabled = false; static bool is_last_enabled = false;
if(dump_enable) if(dump_enable)
@ -208,6 +209,7 @@ void PPUThread::DoCode(const s32 code)
cycle = 0; cycle = 0;
TB++; TB++;
} }
#endif
m_dec->Decode(code); m_dec->Decode(code);
} }

View file

@ -3,7 +3,7 @@
#include "Emu/Cell/PPCInstrTable.h" #include "Emu/Cell/PPCInstrTable.h"
#define CMD_DEBUG 0 #define CMD_DEBUG 0
#define DUMP_VERTEX_DATA 1 #define DUMP_VERTEX_DATA 0
#if CMD_DEBUG #if CMD_DEBUG
#define CMD_LOG ConLog.Write #define CMD_LOG ConLog.Write
@ -199,7 +199,6 @@ void GLRSXThread::Task()
{ {
u32 addr = cmd & ~(CELL_GCM_METHOD_FLAG_JUMP | CELL_GCM_METHOD_FLAG_NON_INCREMENT); u32 addr = cmd & ~(CELL_GCM_METHOD_FLAG_JUMP | CELL_GCM_METHOD_FLAG_NON_INCREMENT);
addr &= ~0x1000; addr &= ~0x1000;
//0x30101000 + 0x80bf000 = 0x80be000
ConLog.Warning("rsx jump(0x%x) #addr=0x%x, cmd=0x%x, get=0x%x, put=0x%x", addr, p.m_ioAddress + get, cmd, get, put); ConLog.Warning("rsx jump(0x%x) #addr=0x%x, cmd=0x%x, get=0x%x, put=0x%x", addr, p.m_ioAddress + get, cmd, get, put);
re(p.m_ctrl->get, addr); re(p.m_ctrl->get, addr);
continue; continue;
@ -1337,7 +1336,7 @@ void GLGSRender::ExecCMD()
m_program.SetTex(i); m_program.SetTex(i);
tex.Init(); tex.Init();
checkForGlError("tex.Init"); checkForGlError("tex.Init");
tex.Save(); //tex.Save();
} }
if(m_indexed_array.m_count) if(m_indexed_array.m_count)

View file

@ -140,19 +140,13 @@ bool IsLoadedFunc(u32 id)
return false; return false;
} }
bool CallFunc(u32 id) bool CallFunc(u32 num)
{ {
for(u32 i=0; i<g_modules_funcs_list.GetCount(); ++i) if(num - 1024 >= g_modules_funcs_list.GetCount())
{ return false;
if(g_modules_funcs_list[i].id == id)
{
(*g_modules_funcs_list[i].func)();
return true; (*g_modules_funcs_list[num - 1024].func)();
} return true;
}
return false;
} }
bool UnloadFunc(u32 id) bool UnloadFunc(u32 id)
@ -170,6 +164,19 @@ bool UnloadFunc(u32 id)
return false; return false;
} }
u32 GetFuncNumById(u32 id)
{
for(u32 i=0; i<g_modules_funcs_list.GetCount(); ++i)
{
if(g_modules_funcs_list[i].id == id)
{
return 1024 + i;
}
}
return id;
}
void UnloadModules() void UnloadModules()
{ {
for(u32 i=0; i<g_max_module_id; ++i) for(u32 i=0; i<g_max_module_id; ++i)

View file

@ -8,8 +8,6 @@ public:
virtual void operator()() = 0; virtual void operator()() = 0;
}; };
static func_caller *null_func = nullptr;
//TODO //TODO
struct ModuleFunc struct ModuleFunc
{ {
@ -74,8 +72,9 @@ public:
}; };
bool IsLoadedFunc(u32 id); bool IsLoadedFunc(u32 id);
bool CallFunc(u32 id); bool CallFunc(u32 num);
bool UnloadFunc(u32 id); bool UnloadFunc(u32 id);
void UnloadModules(); void UnloadModules();
u32 GetFuncNumById(u32 id);
Module* GetModuleByName(const wxString& name); Module* GetModuleByName(const wxString& name);
Module* GetModuleById(u16 id); Module* GetModuleById(u16 id);

View file

@ -3,6 +3,9 @@
#include "Modules.h" #include "Modules.h"
#include "SC_FUNC.h" #include "SC_FUNC.h"
void default_syscall();
static func_caller *null_func = bind_func(default_syscall);
static func_caller* sc_table[1024] = static func_caller* sc_table[1024] =
{ {
null_func, bind_func(sys_process_getpid), null_func, bind_func(sys_process_exit), null_func, //4 null_func, bind_func(sys_process_getpid), null_func, bind_func(sys_process_exit), null_func, //4
@ -212,6 +215,58 @@ static func_caller* sc_table[1024] =
null_func, null_func, null_func, bind_func(cellGcmCallback), //1024 null_func, null_func, null_func, bind_func(cellGcmCallback), //1024
}; };
bool enable_log = false;
void default_syscall()
{
declCPU();
u32 code = CPU.GPR[11];
//TODO: remove this
switch(code)
{
/*
//process
case 2: RESULT(lv2ProcessWaitForChild(CPU)); return;
case 4: RESULT(lv2ProcessGetStatus(CPU)); return;
case 5: RESULT(lv2ProcessDetachChild(CPU)); return;
case 12: RESULT(lv2ProcessGetNumberOfObject(CPU)); return;
case 13: RESULT(lv2ProcessGetId(CPU)); return;
case 18: RESULT(lv2ProcessGetPpid(CPU)); return;
case 19: RESULT(lv2ProcessKill(CPU)); return;
case 23: RESULT(lv2ProcessWaitForChild2(CPU)); return;
case 25: RESULT(lv2ProcessGetSdkVersion(CPU)); return;
*/
//timer
case 141:
case 142:
std::this_thread::sleep_for(std::chrono::nanoseconds(SC_ARGS_1));
RESULT(0);
return;
//tty
case 988:
ConLog.Warning("SysCall 988! r3: 0x%llx, r4: 0x%llx, pc: 0x%llx",
CPU.GPR[3], CPU.GPR[4], CPU.PC);
RESULT(0);
return;
case 999:
dump_enable = !dump_enable;
Emu.Pause();
ConLog.Warning("Dump %s", dump_enable ? "enabled" : "disabled");
return;
case 1000:
enable_log = !enable_log;
ConLog.Warning("Log %s", enable_log ? "enabled" : "disabled");
return;
}
ConLog.Error("Unknown syscall: %d - %08x", code, code);
RESULT(0);
return;
}
SysCalls::SysCalls(PPUThread& cpu) : CPU(cpu) SysCalls::SysCalls(PPUThread& cpu) : CPU(cpu)
{ {
} }
@ -220,58 +275,11 @@ SysCalls::~SysCalls()
{ {
} }
bool enable_log = false;
void SysCalls::DoSyscall(u32 code) void SysCalls::DoSyscall(u32 code)
{ {
if(code < 0x400) if(code < 1024)
{ {
if(sc_table[code]) (*sc_table[code])();
{
(*sc_table[code])();
return;
}
//TODO: remove this
switch(code)
{
//process
case 2: RESULT(lv2ProcessWaitForChild(CPU)); return;
case 4: RESULT(lv2ProcessGetStatus(CPU)); return;
case 5: RESULT(lv2ProcessDetachChild(CPU)); return;
case 12: RESULT(lv2ProcessGetNumberOfObject(CPU)); return;
case 13: RESULT(lv2ProcessGetId(CPU)); return;
case 18: RESULT(lv2ProcessGetPpid(CPU)); return;
case 19: RESULT(lv2ProcessKill(CPU)); return;
case 23: RESULT(lv2ProcessWaitForChild2(CPU)); return;
case 25: RESULT(lv2ProcessGetSdkVersion(CPU)); return;
//timer
case 141:
case 142:
std::this_thread::sleep_for(std::chrono::nanoseconds(SC_ARGS_1));
RESULT(0);
return;
//tty
case 988:
ConLog.Warning("SysCall 988! r3: 0x%llx, r4: 0x%llx, pc: 0x%llx",
CPU.GPR[3], CPU.GPR[4], CPU.PC);
RESULT(0);
return;
case 999:
dump_enable = !dump_enable;
Emu.Pause();
ConLog.Warning("Dump %s", dump_enable ? "enabled" : "disabled");
return;
case 1000:
enable_log = !enable_log;
ConLog.Warning("Log %s", enable_log ? "enabled" : "disabled");
return;
}
ConLog.Error("Unknown syscall: %d - %08x", code, code);
RESULT(0);
return; return;
} }

View file

@ -20,8 +20,10 @@ int sys_ppu_thread_exit(int errorcode)
{ {
sysPrxForUser.Warning("sys_ppu_thread_exit(errorcode=%d)", errorcode); sysPrxForUser.Warning("sys_ppu_thread_exit(errorcode=%d)", errorcode);
} }
Emu.GetCPU().RemoveThread(GetCurrentPPUThread().GetId()); PPUThread& thr = GetCurrentPPUThread();
thr.SetExitStatus(errorcode);
wxGetApp().SendDbgCommand(DID_EXIT_THR_SYSCALL, &thr);
return CELL_OK; return CELL_OK;
} }

View file

@ -74,6 +74,8 @@ public:
void HandleCommand(wxCommandEvent& event) void HandleCommand(wxCommandEvent& event)
{ {
event.Skip();
switch(event.GetId()) switch(event.GetId())
{ {
case DID_STOP_EMU: case DID_STOP_EMU:
@ -88,10 +90,13 @@ public:
case DID_RESUME_EMU: case DID_RESUME_EMU:
m_btn_run->SetLabel("Pause"); m_btn_run->SetLabel("Pause");
break; break;
case DID_EXIT_THR_SYSCALL:
Emu.GetCPU().RemoveThread(((PPCThread*)event.GetClientData())->GetId());
break;
} }
UpdateUI(); UpdateUI();
event.Skip();
} }
}; };

View file

@ -278,9 +278,17 @@ void InterpreterDisAsmFrame::ShowAddr(const u64 addr)
void InterpreterDisAsmFrame::WriteRegs() void InterpreterDisAsmFrame::WriteRegs()
{ {
if(!CPU)
{
m_regs->Clear();
return;
}
const wxString data = CPU->RegsToString();
m_regs->Freeze(); m_regs->Freeze();
m_regs->Clear(); m_regs->Clear();
if(CPU) m_regs->WriteText(CPU->RegsToString()); m_regs->WriteText(data);
m_regs->Thaw(); m_regs->Thaw();
} }
@ -293,9 +301,9 @@ void InterpreterDisAsmFrame::HandleCommand(wxCommandEvent& event)
{ {
switch(event.GetId()) switch(event.GetId())
{ {
case DID_STOP_EMU: case DID_STOPED_EMU:
case DID_PAUSE_EMU: case DID_PAUSED_EMU:
DoUpdate(); //DoUpdate();
break; break;
} }
} }
@ -304,12 +312,16 @@ void InterpreterDisAsmFrame::HandleCommand(wxCommandEvent& event)
switch(event.GetId()) switch(event.GetId())
{ {
case DID_PAUSE_THREAD: case DID_PAUSE_THREAD:
m_btn_run->Disable();
m_btn_step->Disable();
m_btn_pause->Disable();
break;
case DID_PAUSED_THREAD:
m_btn_run->Enable(); m_btn_run->Enable();
m_btn_step->Enable(); m_btn_step->Enable();
m_btn_pause->Disable(); m_btn_pause->Disable();
//DoUpdate();
case DID_CREATE_THREAD:
DoUpdate();
break; break;
case DID_START_THREAD: case DID_START_THREAD:
@ -318,11 +330,6 @@ void InterpreterDisAsmFrame::HandleCommand(wxCommandEvent& event)
m_btn_run->Disable(); m_btn_run->Disable();
m_btn_step->Disable(); m_btn_step->Disable();
m_btn_pause->Enable(); m_btn_pause->Enable();
if(event.GetId() == DID_START_THREAD)
{
DoUpdate();
}
break; break;
case DID_REMOVE_THREAD: case DID_REMOVE_THREAD:
@ -333,15 +340,14 @@ void InterpreterDisAsmFrame::HandleCommand(wxCommandEvent& event)
if(event.GetId() == DID_REMOVE_THREAD) if(event.GetId() == DID_REMOVE_THREAD)
{ {
m_choice_units->SetSelection(-1); //m_choice_units->SetSelection(-1);
wxCommandEvent event; //wxCommandEvent event;
event.SetInt(-1); //event.SetInt(-1);
//event.SetClientData(nullptr); //event.SetClientData(nullptr);
OnSelectUnit(event); //OnSelectUnit(event);
UpdateUnitList(); UpdateUnitList();
//DoUpdate();
} }
DoUpdate();
break; break;
} }
} }
@ -353,14 +359,17 @@ void InterpreterDisAsmFrame::HandleCommand(wxCommandEvent& event)
UpdateUnitList(); UpdateUnitList();
if(m_choice_units->GetSelection() == -1) if(m_choice_units->GetSelection() == -1)
{ {
m_choice_units->SetSelection(0); //m_choice_units->SetSelection(0);
wxCommandEvent event; //wxCommandEvent event;
event.SetInt(0); //event.SetInt(0);
event.SetClientData(&Emu.GetCPU().GetThreads()[0]); //event.SetClientData(&Emu.GetCPU().GetThreads()[0]);
OnSelectUnit(event); //OnSelectUnit(event);
DoUpdate();
} }
break; break;
case DID_REMOVED_THREAD:
UpdateUnitList();
break;
} }
} }
} }
@ -421,6 +430,7 @@ void InterpreterDisAsmFrame::DoRun(wxCommandEvent& WXUNUSED(event))
void InterpreterDisAsmFrame::DoPause(wxCommandEvent& WXUNUSED(event)) void InterpreterDisAsmFrame::DoPause(wxCommandEvent& WXUNUSED(event))
{ {
//DoUpdate();
if(CPU) CPU->Pause(); if(CPU) CPU->Pause();
} }

View file

@ -382,7 +382,7 @@ bool ELF64Loader::LoadPhdrData(u64 offset)
mem32_t out_tbl(tbl + i*8); mem32_t out_tbl(tbl + i*8);
out_tbl += dst + i*section; out_tbl += dst + i*section;
out_tbl += nid; out_tbl += GetFuncNumById(nid);
mem32_t out_dst(dst + i*section); mem32_t out_dst(dst + i*section);
out_dst += OR(11, 2, 2, 0); out_dst += OR(11, 2, 2, 0);

View file

@ -47,6 +47,7 @@ enum DbgCommand
DID_EXEC_THREAD, DID_EXEC_THREAD,
DID_REGISTRED_CALLBACK, DID_REGISTRED_CALLBACK,
DID_UNREGISTRED_CALLBACK, DID_UNREGISTRED_CALLBACK,
DID_EXIT_THR_SYSCALL,
DID_LAST_COMMAND, DID_LAST_COMMAND,
}; };