cpu_init removed

This commit is contained in:
Nekotekina 2016-08-13 17:58:19 +03:00
parent 949200cd3e
commit 5e0489dcc0
10 changed files with 34 additions and 52 deletions

View File

@ -145,3 +145,8 @@ void cpu_thread::run()
state -= cpu_flag::stop;
lock_notify();
}
std::string cpu_thread::dump() const
{
return fmt::format("Type: %s\n" "State: %s\n", typeid(*this).name(), state.load());
}

View File

@ -3,7 +3,7 @@
#include "../Utilities/Thread.h"
#include "../Utilities/bit_set.h"
// cpu_thread state flags
// Thread state flags
enum class cpu_flag : u32
{
stop, // Thread not running (HLE, initial state)
@ -20,12 +20,12 @@ enum class cpu_flag : u32
__bitset_enum_max
};
// cpu_flag set for pause state
// Flag set for pause state
constexpr bs_t<cpu_flag> cpu_state_pause = cpu_flag::suspend + cpu_flag::dbg_global_pause + cpu_flag::dbg_pause;
class cpu_thread : public named_thread
{
void on_task() override;
void on_task() override final;
public:
virtual void on_stop() override;
@ -47,8 +47,10 @@ public:
// Run thread
void run();
virtual std::string dump() const = 0; // Print CPU state
virtual void cpu_init() {} // Obsolete, must be removed
// Print CPU state
virtual std::string dump() const;
// Thread entry point function
virtual void cpu_task() = 0;
};

View File

@ -78,9 +78,7 @@ std::string ppu_thread::get_name() const
std::string ppu_thread::dump() const
{
std::string ret;
ret += fmt::format("Type: %s\n", typeid(*this).name());
ret += fmt::format("State: %s\n", state.load());
std::string ret = cpu_thread::dump();
ret += fmt::format("Priority: %d\n", prio);
ret += "\nRegisters:\n=========\n";

View File

@ -26,7 +26,6 @@ public:
virtual std::string get_name() const override;
virtual std::string dump() const override;
virtual void cpu_init() override final {}
virtual void cpu_task() override;
virtual ~ppu_thread() override;

View File

@ -128,7 +128,8 @@ std::string SPUThread::get_name() const
std::string SPUThread::dump() const
{
std::string ret = "Registers:\n=========\n";
std::string&& ret = cpu_thread::dump();
ret += "Registers:\n=========\n";
for (uint i = 0; i<128; ++i) ret += fmt::format("GPR[%d] = %s\n", i, gpr[i]);

View File

@ -493,9 +493,9 @@ class SPUThread : public cpu_thread
public:
virtual std::string get_name() const override;
virtual std::string dump() const override;
virtual void cpu_init() override;
virtual void cpu_task() override;
virtual ~SPUThread() override;
void cpu_init();
protected:
SPUThread(const std::string& name);

View File

@ -636,12 +636,9 @@ void arm_load_exec(const arm_exec_object& elf)
const u32 stack_size = proc_param->sceUserMainThreadStackSize ? proc_param->sceUserMainThreadStackSize->value() : 256 * 1024;
const u32 priority = proc_param->sceUserMainThreadPriority ? proc_param->sceUserMainThreadPriority->value() : 160;
auto thread = idm::make_ptr<ARMv7Thread>(thread_name);
auto thread = idm::make_ptr<ARMv7Thread>(thread_name, priority, stack_size);
thread->PC = entry_point;
thread->stack_size = stack_size;
thread->prio = priority;
thread->cpu_init();
thread->write_pc(entry_point, 0);
thread->TLS = fxm::make_always<arm_tls_manager>(tls_faddr + start_addr, tls_fsize, tls_vsize)->alloc();
// Initialize args

View File

@ -17,7 +17,8 @@ std::string ARMv7Thread::get_name() const
std::string ARMv7Thread::dump() const
{
std::string result = "Registers:\n=========\n";
std::string result = cpu_thread::dump();
result += "Registers:\n=========\n";
for(int i=0; i<15; ++i)
{
result += fmt::format("r%u\t= 0x%08x\n", i, GPR[i]);
@ -34,33 +35,6 @@ std::string ARMv7Thread::dump() const
return result;
}
void ARMv7Thread::cpu_init()
{
if (!stack_addr)
{
if (!stack_size)
{
fmt::throw_exception("Invalid stack size" HERE);
}
stack_addr = vm::alloc(stack_size, vm::main);
if (!stack_addr)
{
fmt::throw_exception("Out of stack memory" HERE);
}
}
memset(GPR, 0, sizeof(GPR));
APSR.APSR = 0;
IPSR.IPSR = 0;
ISET = PC & 1 ? Thumb : ARM; // select instruction set
PC = PC & ~1; // and fix PC
ITSTATE.IT = 0;
SP = stack_addr + stack_size;
TLS = 0;
}
extern thread_local std::string(*g_tls_log_prefix)();
void ARMv7Thread::cpu_task()
@ -119,10 +93,20 @@ ARMv7Thread::~ARMv7Thread()
}
}
ARMv7Thread::ARMv7Thread(const std::string& name)
ARMv7Thread::ARMv7Thread(const std::string& name, u32 prio, u32 stack)
: cpu_thread()
, m_name(name)
, prio(prio)
, stack_addr(vm::alloc(stack, vm::main))
, stack_size(stack)
{
verify(__func__), stack_size, stack_addr;
std::memset(GPR, 0, sizeof(GPR));
APSR.APSR = 0;
IPSR.IPSR = 0;
ITSTATE.IT = 0;
SP = stack_addr + stack_size;
}
void ARMv7Thread::fast_call(u32 addr)

View File

@ -16,12 +16,11 @@ class ARMv7Thread final : public cpu_thread
public:
virtual std::string get_name() const override;
virtual std::string dump() const override;
virtual void cpu_init() override;
virtual void cpu_task() override;
virtual void cpu_task_main();
virtual ~ARMv7Thread() override;
ARMv7Thread(const std::string& name);
ARMv7Thread(const std::string& name, u32 prio = 160, u32 stack = 256 * 1024);
union
{

View File

@ -93,12 +93,9 @@ arm_error_code sceKernelCreateThread(vm::cptr<char> pName, vm::ptr<SceKernelThre
sceLibKernel.warning("sceKernelCreateThread(pName=%s, entry=*0x%x, initPriority=%d, stackSize=0x%x, attr=0x%x, cpuAffinityMask=0x%x, pOptParam=*0x%x)",
pName, entry, initPriority, stackSize, attr, cpuAffinityMask, pOptParam);
const auto thread = idm::make_ptr<ARMv7Thread>(pName.get_ptr());
const auto thread = idm::make_ptr<ARMv7Thread>(pName.get_ptr(), initPriority, stackSize);
thread->PC = entry.addr();
thread->prio = initPriority;
thread->stack_size = stackSize;
thread->cpu_init();
thread->write_pc(entry.addr(), 0);
thread->TLS = fxm::get<arm_tls_manager>()->alloc();
return NOT_AN_ERROR(thread->id);