cpu_type removed, system_type added

cpu_state -> cpu_flag
vm::stack_allocator template improved
ppu_cmd type changed to enum, cmd64 type added
This commit is contained in:
Nekotekina 2016-08-09 17:14:41 +03:00
parent 009ac37a7d
commit bdeccd889f
39 changed files with 449 additions and 492 deletions

View file

@ -39,22 +39,19 @@ s32 arm_error_code::report(s32 error, const char* text)
{
if (auto thread = get_current_cpu_thread())
{
if (thread->type == cpu_type::arm)
if (auto func = static_cast<ARMv7Thread*>(thread)->last_function)
{
if (auto func = static_cast<ARMv7Thread*>(thread)->last_function)
{
LOG_ERROR(ARMv7, "Function '%s' failed with 0x%08x : %s", func, error, text);
}
else
{
LOG_ERROR(ARMv7, "Unknown function failed with 0x%08x : %s", error, text);
}
return error;
LOG_ERROR(ARMv7, "Function '%s' failed with 0x%08x : %s", func, error, text);
}
else
{
LOG_ERROR(ARMv7, "Unknown function failed with 0x%08x : %s", error, text);
}
return error;
}
LOG_ERROR(ARMv7, "Illegal call to ppu_report_error(0x%x, '%s')!");
LOG_ERROR(ARMv7, "Illegal call to arm_report_error(0x%x, '%s')!");
return error;
}
@ -63,7 +60,7 @@ std::vector<arm_function_t>& arm_function_manager::access()
static std::vector<arm_function_t> list
{
nullptr,
[](ARMv7Thread& cpu) { cpu.state += cpu_state::ret; },
[](ARMv7Thread& cpu) { cpu.state += cpu_flag::ret; },
};
return list;

View file

@ -120,7 +120,7 @@ ARMv7Thread::~ARMv7Thread()
}
ARMv7Thread::ARMv7Thread(const std::string& name)
: cpu_thread(cpu_type::arm)
: cpu_thread()
, m_name(name)
{
}
@ -142,15 +142,15 @@ void ARMv7Thread::fast_call(u32 addr)
{
cpu_task_main();
if (SP != old_SP && !test(state, cpu_state::ret + cpu_state::exit)) // SP shouldn't change
if (SP != old_SP && !test(state, cpu_flag::ret + cpu_flag::exit)) // SP shouldn't change
{
fmt::throw_exception("Stack inconsistency (addr=0x%x, SP=0x%x, old=0x%x)", addr, SP, old_SP);
}
}
catch (cpu_state _s)
catch (cpu_flag _s)
{
state += _s;
if (_s != cpu_state::ret) throw;
if (_s != cpu_flag::ret) throw;
}
catch (EmulationStopped)
{
@ -165,7 +165,7 @@ void ARMv7Thread::fast_call(u32 addr)
throw;
}
state -= cpu_state::ret;
state -= cpu_flag::ret;
PC = old_PC;
SP = old_SP;
@ -173,3 +173,46 @@ void ARMv7Thread::fast_call(u32 addr)
custom_task = std::move(old_task);
last_function = old_func;
}
u32 ARMv7Thread::stack_push(u32 size, u32 align_v)
{
if (auto cpu = get_current_cpu_thread())
{
ARMv7Thread& context = static_cast<ARMv7Thread&>(*cpu);
const u32 old_pos = context.SP;
context.SP -= align(size + 4, 4); // room minimal possible size
context.SP &= ~(align_v - 1); // fix stack alignment
if (context.SP < context.stack_addr)
{
fmt::throw_exception("Stack overflow (size=0x%x, align=0x%x, SP=0x%x, stack=*0x%x)" HERE, size, align_v, context.SP, context.stack_addr);
}
else
{
vm::psv::_ref<nse_t<u32>>(context.SP + size) = old_pos;
return context.SP;
}
}
fmt::throw_exception("Invalid thread" HERE);
}
void ARMv7Thread::stack_pop_verbose(u32 addr, u32 size) noexcept
{
if (auto cpu = get_current_cpu_thread())
{
ARMv7Thread& context = static_cast<ARMv7Thread&>(*cpu);
if (context.SP != addr)
{
LOG_ERROR(ARMv7, "Stack inconsistency (addr=0x%x, SP=0x%x, size=0x%x)", addr, context.SP, size);
return;
}
context.SP = vm::psv::_ref<nse_t<u32>>(context.SP + size);
return;
}
LOG_ERROR(ARMv7, "Invalid thread" HERE);
}

View file

@ -196,6 +196,9 @@ public:
}
void fast_call(u32 addr);
static u32 stack_push(u32 size, u32 align_v);
static void stack_pop_verbose(u32 addr, u32 size) noexcept;
};
template<typename T, typename = void>

View file

@ -138,7 +138,7 @@ arm_error_code sceKernelExitThread(ARMv7Thread& cpu, s32 exitStatus)
sceLibKernel.warning("sceKernelExitThread(exitStatus=0x%x)", exitStatus);
// Exit status is stored in r0
cpu.state += cpu_state::exit;
cpu.state += cpu_flag::exit;
return SCE_OK;
}
@ -170,7 +170,7 @@ arm_error_code sceKernelExitDeleteThread(ARMv7Thread& cpu, s32 exitStatus)
{
sceLibKernel.warning("sceKernelExitDeleteThread(exitStatus=0x%x)", exitStatus);
//cpu.state += cpu_state::stop;
//cpu.state += cpu_flag::stop;
// Delete current thread; exit status is stored in r0
fxm::get<arm_tls_manager>()->free(cpu.TLS);
@ -517,7 +517,7 @@ struct psp2_event_flag final
{
idm::get<ARMv7Thread>(cmd.arg, [&](u32, ARMv7Thread& cpu)
{
cpu.state += cpu_state::signal;
cpu.state += cpu_flag::signal;
cpu.lock_notify();
});
@ -545,11 +545,11 @@ struct psp2_event_flag final
{
if (!exec(task::signal, cpu.id))
{
thread_lock{cpu}, thread_ctrl::wait(WRAP_EXPR(cpu.state.test_and_reset(cpu_state::signal)));
thread_lock{cpu}, thread_ctrl::wait(WRAP_EXPR(cpu.state.test_and_reset(cpu_flag::signal)));
}
else
{
cpu.state -= cpu_state::signal;
cpu.state -= cpu_flag::signal;
}
}
}
@ -579,7 +579,7 @@ private:
{
cpu.GPR[0] = SCE_OK;
cpu.GPR[1] = pattern;
cpu.state += cpu_state::signal;
cpu.state += cpu_flag::signal;
cpu->lock_notify();
}
else
@ -679,7 +679,7 @@ private:
{
cpu.GPR[0] = SCE_OK;
cpu.GPR[1] = old_pattern;
cpu.state += cpu_state::signal;
cpu.state += cpu_flag::signal;
cpu.owner = nullptr;
cpu->unlock();
cpu->notify();
@ -713,7 +713,7 @@ private:
{
cpu.GPR[0] = error;
cpu.GPR[1] = pattern;
cpu.state += cpu_state::signal;
cpu.state += cpu_flag::signal;
cpu.owner = nullptr;
cpu->unlock();
cpu->notify();
@ -858,7 +858,7 @@ arm_error_code sceKernelWaitEventFlag(ARMv7Thread& cpu, s32 evfId, u32 bitPatter
cpu.GPR[1] = bitPattern;
// Second chance
if (evf->exec(psp2_event_flag::task::wait, cpu.id) && cpu.state.test_and_reset(cpu_state::signal))
if (evf->exec(psp2_event_flag::task::wait, cpu.id) && cpu.state.test_and_reset(cpu_flag::signal))
{
if (pResultPat) *pResultPat = cpu.GPR[1];
return SCE_OK;
@ -866,7 +866,7 @@ arm_error_code sceKernelWaitEventFlag(ARMv7Thread& cpu, s32 evfId, u32 bitPatter
thread_lock entry(cpu);
if (!thread_ctrl::wait_for(timeout, WRAP_EXPR(cpu.state.test_and_reset(cpu_state::signal))))
if (!thread_ctrl::wait_for(timeout, WRAP_EXPR(cpu.state.test_and_reset(cpu_flag::signal))))
{
// Timeout cleanup
cpu.owner = nullptr;