sceLibc: memcpy, stack arguments

This commit is contained in:
Nekotekina 2014-11-06 18:29:14 +03:00
parent af0ab4e8ad
commit 8ad141de6f
6 changed files with 187 additions and 17 deletions

View file

@ -32,9 +32,9 @@ void ARMv7Thread::InitStack()
} }
} }
void ARMv7Thread::SetArg(const uint pos, const u64 arg) u32 ARMv7Thread::GetStackArg(u32 pos)
{ {
assert(0); return vm::psv::read32(SP + sizeof(u32) * (pos - 5));
} }
std::string ARMv7Thread::RegsToString() std::string ARMv7Thread::RegsToString()

View file

@ -122,7 +122,7 @@ public:
public: public:
virtual void InitRegs(); virtual void InitRegs();
virtual void InitStack(); virtual void InitStack();
virtual void SetArg(const uint pos, const u64 arg); u32 GetStackArg(u32 pos);
public: public:
virtual std::string RegsToString(); virtual std::string RegsToString();
@ -137,4 +137,4 @@ protected:
virtual void DoStop(); virtual void DoStop();
virtual void DoCode(); virtual void DoCode();
}; };

View file

@ -5,7 +5,28 @@
extern psv_log_base sceLibKernel; extern psv_log_base sceLibKernel;
typedef s32(*SceKernelThreadEntry)(u32 argSize, vm::psv::ptr<void> pArgBlock);
struct SceKernelThreadOptParam
{
u32 size;
u32 attr;
};
s32 sceKernelCreateThread(
vm::psv::ptr<const char> pName,
vm::psv::ptr<SceKernelThreadEntry> entry,
s32 initPriority,
u32 stackSize,
u32 attr,
s32 cpuAffinityMask,
vm::psv::ptr<const SceKernelThreadOptParam> pOptParam)
{
sceLibKernel.Todo("sceKernelCreateThread(pName_addr=0x%x ('%s'), entry_addr=0x%x, initPriority=%d, stackSize=0x%x, attr=0x%x, cpuAffinityMask=0x%x, pOptParam_addr=0x%x)",
pName.addr(), pName.get_ptr(), entry.addr(), initPriority, stackSize, attr, cpuAffinityMask, pOptParam.addr());
return SCE_OK;
}
#define REG_FUNC(nid, name) reg_psv_func(nid, &sceLibKernel, #name, &name) #define REG_FUNC(nid, name) reg_psv_func(nid, &sceLibKernel, #name, &name)
@ -269,7 +290,7 @@ psv_log_base sceLibKernel = []() -> psv_log_base
//REG_FUNC(0xADCA94E5, sceKernelWaitSignal); //REG_FUNC(0xADCA94E5, sceKernelWaitSignal);
//REG_FUNC(0x24460BB3, sceKernelWaitSignalCB); //REG_FUNC(0x24460BB3, sceKernelWaitSignalCB);
//REG_FUNC(0x7BE9C4C8, sceKernelSendSignal); //REG_FUNC(0x7BE9C4C8, sceKernelSendSignal);
//REG_FUNC(0xC5C11EE7, sceKernelCreateThread); REG_FUNC(0xC5C11EE7, sceKernelCreateThread);
//REG_FUNC(0x6C60AC61, sceIoOpen); //REG_FUNC(0x6C60AC61, sceIoOpen);
//REG_FUNC(0xF5C6F098, sceIoClose); //REG_FUNC(0xF5C6F098, sceIoClose);
//REG_FUNC(0x713523E1, sceIoRead); //REG_FUNC(0x713523E1, sceIoRead);

View file

@ -36,18 +36,26 @@ namespace sce_libc_func
{ {
sceLibc.Error("__cxa_set_dso_handle_main()"); sceLibc.Error("__cxa_set_dso_handle_main()");
} }
void memcpy(vm::psv::ptr<void> dst, vm::psv::ptr<const void> src, u32 size)
{
sceLibc.Error("memcpy(dst_addr=0x%x, src_addr=0x%x, size=0x%x)", dst.addr(), src.addr(), size);
::memcpy(dst.get_ptr(), src.get_ptr(), size);
}
void _Assert()
{
sceLibc.Todo(__FUNCTION__);
Emu.Pause();
}
} }
#define REG_FUNC(nid, name) reg_psv_func(nid, &sceLibc, #name, &sce_libc_func::name) #define REG_FUNC(nid, name) reg_psv_func(nid, &sceLibc, #name, &sce_libc_func::name)
psv_log_base sceLibc = []() -> psv_log_base psv_log_base sceLibc = []() -> psv_log_base
{ {
REG_FUNC(0x33b83b70, __cxa_atexit); REG_FUNC(0xE4531F85, _Assert);
REG_FUNC(0x826bbbaf, exit);
REG_FUNC(0x9a004680, printf);
REG_FUNC(0xbfe02b3a, __cxa_set_dso_handle_main);
//REG_FUNC(0xE4531F85, _Assert);
//REG_FUNC(0xE71C5CDE, _Stoul); //REG_FUNC(0xE71C5CDE, _Stoul);
//REG_FUNC(0x7A5CA6A3, _Stoulx); //REG_FUNC(0x7A5CA6A3, _Stoulx);
//REG_FUNC(0x6794B3C6, _Stoull); //REG_FUNC(0x6794B3C6, _Stoull);
@ -125,6 +133,7 @@ psv_log_base sceLibc = []() -> psv_log_base
//REG_FUNC(0x4790BF1E, getchar); //REG_FUNC(0x4790BF1E, getchar);
//REG_FUNC(0xF97B8CA3, gets); //REG_FUNC(0xF97B8CA3, gets);
//REG_FUNC(0x4696E7BE, perror); //REG_FUNC(0x4696E7BE, perror);
REG_FUNC(0x9a004680, printf);
//REG_FUNC(0x995708A6, putc); //REG_FUNC(0x995708A6, putc);
//REG_FUNC(0x7CDAC89C, putchar); //REG_FUNC(0x7CDAC89C, putchar);
//REG_FUNC(0x59C3E171, puts); //REG_FUNC(0x59C3E171, puts);
@ -153,6 +162,7 @@ psv_log_base sceLibc = []() -> psv_log_base
//REG_FUNC(0x875994F3, atoll); //REG_FUNC(0x875994F3, atoll);
//REG_FUNC(0xD1BC28E7, bsearch); //REG_FUNC(0xD1BC28E7, bsearch);
//REG_FUNC(0xE9F823C0, div); //REG_FUNC(0xE9F823C0, div);
REG_FUNC(0x826bbbaf, exit);
//REG_FUNC(0xB53B345B, _Exit); //REG_FUNC(0xB53B345B, _Exit);
//REG_FUNC(0xBCEA304B, labs); //REG_FUNC(0xBCEA304B, labs);
//REG_FUNC(0x9D2D17CD, llabs); //REG_FUNC(0x9D2D17CD, llabs);
@ -185,7 +195,7 @@ psv_log_base sceLibc = []() -> psv_log_base
//REG_FUNC(0x54A54EB1, malloc_usable_size); //REG_FUNC(0x54A54EB1, malloc_usable_size);
//REG_FUNC(0x2F3E5B16, memchr); //REG_FUNC(0x2F3E5B16, memchr);
//REG_FUNC(0x7747F6D7, memcmp); //REG_FUNC(0x7747F6D7, memcmp);
//REG_FUNC(0x7205BFDB, memcpy); REG_FUNC(0x7205BFDB, memcpy);
//REG_FUNC(0xAF5C218D, memmove); //REG_FUNC(0xAF5C218D, memmove);
//REG_FUNC(0x6DC1F0D8, memset); //REG_FUNC(0x6DC1F0D8, memset);
//REG_FUNC(0x1434FA46, strcat); //REG_FUNC(0x1434FA46, strcat);
@ -303,11 +313,13 @@ psv_log_base sceLibc = []() -> psv_log_base
//REG_FUNC(0xA967B88D, wctype); //REG_FUNC(0xA967B88D, wctype);
//REG_FUNC(0x9D885076, _Towctrans); //REG_FUNC(0x9D885076, _Towctrans);
//REG_FUNC(0xE980110A, _Iswctype); //REG_FUNC(0xE980110A, _Iswctype);
REG_FUNC(0x33b83b70, __cxa_atexit);
//REG_FUNC(0xEDC939E1, __aeabi_atexit); //REG_FUNC(0xEDC939E1, __aeabi_atexit);
//REG_FUNC(0xB538BF48, __cxa_finalize); //REG_FUNC(0xB538BF48, __cxa_finalize);
//REG_FUNC(0xD0310E31, __cxa_guard_acquire); //REG_FUNC(0xD0310E31, __cxa_guard_acquire);
//REG_FUNC(0x4ED1056F, __cxa_guard_release); //REG_FUNC(0x4ED1056F, __cxa_guard_release);
//REG_FUNC(0xD18E461D, __cxa_guard_abort); //REG_FUNC(0xD18E461D, __cxa_guard_abort);
REG_FUNC(0xbfe02b3a, __cxa_set_dso_handle_main);
//REG_FUNC(0x64DA2C47, _Unlocksyslock); //REG_FUNC(0x64DA2C47, _Unlocksyslock);
//REG_FUNC(0x7DBC0575, _Locksyslock); //REG_FUNC(0x7DBC0575, _Locksyslock);
//REG_FUNC(0x5044FC32, _Lockfilelock); //REG_FUNC(0x5044FC32, _Lockfilelock);

View file

@ -30,10 +30,6 @@ namespace sce_libstdcxx_func
psv_log_base sceLibstdcxx = []() -> psv_log_base psv_log_base sceLibstdcxx = []() -> psv_log_base
{ {
REG_FUNC(0x173E7421, __aeabi_unwind_cpp_pr0);
REG_FUNC(0x3C78DDE3, __aeabi_unwind_cpp_pr1);
REG_FUNC(0xF95BDD36, __aeabi_unwind_cpp_pr2);
//REG_FUNC(0x52B0C625, std::bad_typeid::what() const); //REG_FUNC(0x52B0C625, std::bad_typeid::what() const);
//REG_FUNC(0x64D7D074, std::bad_typeid::_Doraise() const); //REG_FUNC(0x64D7D074, std::bad_typeid::_Doraise() const);
//REG_FUNC(0x15FB88E2, std::logic_error::what() const); //REG_FUNC(0x15FB88E2, std::logic_error::what() const);
@ -377,6 +373,9 @@ psv_log_base sceLibstdcxx = []() -> psv_log_base
//REG_FUNC(0xE7889A5B, _Unwind_VRS_Get); //REG_FUNC(0xE7889A5B, _Unwind_VRS_Get);
//REG_FUNC(0xF106D050, _Unwind_VRS_Pop); //REG_FUNC(0xF106D050, _Unwind_VRS_Pop);
//REG_FUNC(0x91CDA2F9, _Unwind_VRS_Set); //REG_FUNC(0x91CDA2F9, _Unwind_VRS_Set);
REG_FUNC(0x173E7421, __aeabi_unwind_cpp_pr0);
REG_FUNC(0x3C78DDE3, __aeabi_unwind_cpp_pr1);
REG_FUNC(0xF95BDD36, __aeabi_unwind_cpp_pr2);
//REG_FUNC(0x8C93EFDA, __cxa_allocate_exception); //REG_FUNC(0x8C93EFDA, __cxa_allocate_exception);
//REG_FUNC(0x6165EE89, __cxa_begin_catch); //REG_FUNC(0x6165EE89, __cxa_begin_catch);
//REG_FUNC(0x5D74285C, __cxa_begin_cleanup); //REG_FUNC(0x5D74285C, __cxa_begin_cleanup);
@ -1328,6 +1327,7 @@ REG_FUNC(0x13D5D5A1, _Unwind_Resume);
REG_FUNC(0xE7889A5B, _Unwind_VRS_Get); REG_FUNC(0xE7889A5B, _Unwind_VRS_Get);
REG_FUNC(0xF106D050, _Unwind_VRS_Pop); REG_FUNC(0xF106D050, _Unwind_VRS_Pop);
REG_FUNC(0x91CDA2F9, _Unwind_VRS_Set); REG_FUNC(0x91CDA2F9, _Unwind_VRS_Set);
REG_FUNC(0x173E7421, __aeabi_unwind_cpp_pr0);
REG_FUNC(0x3C78DDE3, __aeabi_unwind_cpp_pr1); REG_FUNC(0x3C78DDE3, __aeabi_unwind_cpp_pr1);
REG_FUNC(0xF95BDD36, __aeabi_unwind_cpp_pr2); REG_FUNC(0xF95BDD36, __aeabi_unwind_cpp_pr2);
REG_FUNC(0x8C93EFDA, __cxa_allocate_exception); REG_FUNC(0x8C93EFDA, __cxa_allocate_exception);

View file

@ -19,6 +19,140 @@ public:
}; };
enum psv_error_codes
{
SCE_OK = 0,
SCE_ERROR_ERRNO_EPERM = 0x80010001,
SCE_ERROR_ERRNO_ENOENT = 0x80010002,
SCE_ERROR_ERRNO_ESRCH = 0x80010003,
SCE_ERROR_ERRNO_EINTR = 0x80010004,
SCE_ERROR_ERRNO_EIO = 0x80010005,
SCE_ERROR_ERRNO_ENXIO = 0x80010006,
SCE_ERROR_ERRNO_E2BIG = 0x80010007,
SCE_ERROR_ERRNO_ENOEXEC = 0x80010008,
SCE_ERROR_ERRNO_EBADF = 0x80010009,
SCE_ERROR_ERRNO_ECHILD = 0x8001000A,
SCE_ERROR_ERRNO_EAGAIN = 0x8001000B,
SCE_ERROR_ERRNO_ENOMEM = 0x8001000C,
SCE_ERROR_ERRNO_EACCES = 0x8001000D,
SCE_ERROR_ERRNO_EFAULT = 0x8001000E,
SCE_ERROR_ERRNO_ENOTBLK = 0x8001000F,
SCE_ERROR_ERRNO_EBUSY = 0x80010010,
SCE_ERROR_ERRNO_EEXIST = 0x80010011,
SCE_ERROR_ERRNO_EXDEV = 0x80010012,
SCE_ERROR_ERRNO_ENODEV = 0x80010013,
SCE_ERROR_ERRNO_ENOTDIR = 0x80010014,
SCE_ERROR_ERRNO_EISDIR = 0x80010015,
SCE_ERROR_ERRNO_EINVAL = 0x80010016,
SCE_ERROR_ERRNO_ENFILE = 0x80010017,
SCE_ERROR_ERRNO_EMFILE = 0x80010018,
SCE_ERROR_ERRNO_ENOTTY = 0x80010019,
SCE_ERROR_ERRNO_ETXTBSY = 0x8001001A,
SCE_ERROR_ERRNO_EFBIG = 0x8001001B,
SCE_ERROR_ERRNO_ENOSPC = 0x8001001C,
SCE_ERROR_ERRNO_ESPIPE = 0x8001001D,
SCE_ERROR_ERRNO_EROFS = 0x8001001E,
SCE_ERROR_ERRNO_EMLINK = 0x8001001F,
SCE_ERROR_ERRNO_EPIPE = 0x80010020,
SCE_ERROR_ERRNO_EDOM = 0x80010021,
SCE_ERROR_ERRNO_ERANGE = 0x80010022,
SCE_ERROR_ERRNO_ENOMSG = 0x80010023,
SCE_ERROR_ERRNO_EIDRM = 0x80010024,
SCE_ERROR_ERRNO_ECHRNG = 0x80010025,
SCE_ERROR_ERRNO_EL2NSYNC = 0x80010026,
SCE_ERROR_ERRNO_EL3HLT = 0x80010027,
SCE_ERROR_ERRNO_EL3RST = 0x80010028,
SCE_ERROR_ERRNO_ELNRNG = 0x80010029,
SCE_ERROR_ERRNO_EUNATCH = 0x8001002A,
SCE_ERROR_ERRNO_ENOCSI = 0x8001002B,
SCE_ERROR_ERRNO_EL2HLT = 0x8001002C,
SCE_ERROR_ERRNO_EDEADLK = 0x8001002D,
SCE_ERROR_ERRNO_ENOLCK = 0x8001002E,
SCE_ERROR_ERRNO_EFORMAT = 0x8001002F,
SCE_ERROR_ERRNO_EUNSUP = 0x80010030,
SCE_ERROR_ERRNO_EBADE = 0x80010032,
SCE_ERROR_ERRNO_EBADR = 0x80010033,
SCE_ERROR_ERRNO_EXFULL = 0x80010034,
SCE_ERROR_ERRNO_ENOANO = 0x80010035,
SCE_ERROR_ERRNO_EBADRQC = 0x80010036,
SCE_ERROR_ERRNO_EBADSLT = 0x80010037,
SCE_ERROR_ERRNO_EDEADLOCK = 0x80010038,
SCE_ERROR_ERRNO_EBFONT = 0x80010039,
SCE_ERROR_ERRNO_ENOSTR = 0x8001003C,
SCE_ERROR_ERRNO_ENODATA = 0x8001003D,
SCE_ERROR_ERRNO_ETIME = 0x8001003E,
SCE_ERROR_ERRNO_ENOSR = 0x8001003F,
SCE_ERROR_ERRNO_ENONET = 0x80010040,
SCE_ERROR_ERRNO_ENOPKG = 0x80010041,
SCE_ERROR_ERRNO_EREMOTE = 0x80010042,
SCE_ERROR_ERRNO_ENOLINK = 0x80010043,
SCE_ERROR_ERRNO_EADV = 0x80010044,
SCE_ERROR_ERRNO_ESRMNT = 0x80010045,
SCE_ERROR_ERRNO_ECOMM = 0x80010046,
SCE_ERROR_ERRNO_EPROTO = 0x80010047,
SCE_ERROR_ERRNO_EMULTIHOP = 0x8001004A,
SCE_ERROR_ERRNO_ELBIN = 0x8001004B,
SCE_ERROR_ERRNO_EDOTDOT = 0x8001004C,
SCE_ERROR_ERRNO_EBADMSG = 0x8001004D,
SCE_ERROR_ERRNO_EFTYPE = 0x8001004F,
SCE_ERROR_ERRNO_ENOTUNIQ = 0x80010050,
SCE_ERROR_ERRNO_EBADFD = 0x80010051,
SCE_ERROR_ERRNO_EREMCHG = 0x80010052,
SCE_ERROR_ERRNO_ELIBACC = 0x80010053,
SCE_ERROR_ERRNO_ELIBBAD = 0x80010054,
SCE_ERROR_ERRNO_ELIBSCN = 0x80010055,
SCE_ERROR_ERRNO_ELIBMAX = 0x80010056,
SCE_ERROR_ERRNO_ELIBEXEC = 0x80010057,
SCE_ERROR_ERRNO_ENOSYS = 0x80010058,
SCE_ERROR_ERRNO_ENMFILE = 0x80010059,
SCE_ERROR_ERRNO_ENOTEMPTY = 0x8001005A,
SCE_ERROR_ERRNO_ENAMETOOLONG = 0x8001005B,
SCE_ERROR_ERRNO_ELOOP = 0x8001005C,
SCE_ERROR_ERRNO_EOPNOTSUPP = 0x8001005F,
SCE_ERROR_ERRNO_EPFNOSUPPORT = 0x80010060,
SCE_ERROR_ERRNO_ECONNRESET = 0x80010068,
SCE_ERROR_ERRNO_ENOBUFS = 0x80010069,
SCE_ERROR_ERRNO_EAFNOSUPPORT = 0x8001006A,
SCE_ERROR_ERRNO_EPROTOTYPE = 0x8001006B,
SCE_ERROR_ERRNO_ENOTSOCK = 0x8001006C,
SCE_ERROR_ERRNO_ENOPROTOOPT = 0x8001006D,
SCE_ERROR_ERRNO_ESHUTDOWN = 0x8001006E,
SCE_ERROR_ERRNO_ECONNREFUSED = 0x8001006F,
SCE_ERROR_ERRNO_EADDRINUSE = 0x80010070,
SCE_ERROR_ERRNO_ECONNABORTED = 0x80010071,
SCE_ERROR_ERRNO_ENETUNREACH = 0x80010072,
SCE_ERROR_ERRNO_ENETDOWN = 0x80010073,
SCE_ERROR_ERRNO_ETIMEDOUT = 0x80010074,
SCE_ERROR_ERRNO_EHOSTDOWN = 0x80010075,
SCE_ERROR_ERRNO_EHOSTUNREACH = 0x80010076,
SCE_ERROR_ERRNO_EINPROGRESS = 0x80010077,
SCE_ERROR_ERRNO_EALREADY = 0x80010078,
SCE_ERROR_ERRNO_EDESTADDRREQ = 0x80010079,
SCE_ERROR_ERRNO_EMSGSIZE = 0x8001007A,
SCE_ERROR_ERRNO_EPROTONOSUPPORT = 0x8001007B,
SCE_ERROR_ERRNO_ESOCKTNOSUPPORT = 0x8001007C,
SCE_ERROR_ERRNO_EADDRNOTAVAIL = 0x8001007D,
SCE_ERROR_ERRNO_ENETRESET = 0x8001007E,
SCE_ERROR_ERRNO_EISCONN = 0x8001007F,
SCE_ERROR_ERRNO_ENOTCONN = 0x80010080,
SCE_ERROR_ERRNO_ETOOMANYREFS = 0x80010081,
SCE_ERROR_ERRNO_EPROCLIM = 0x80010082,
SCE_ERROR_ERRNO_EUSERS = 0x80010083,
SCE_ERROR_ERRNO_EDQUOT = 0x80010084,
SCE_ERROR_ERRNO_ESTALE = 0x80010085,
SCE_ERROR_ERRNO_ENOTSUP = 0x80010086,
SCE_ERROR_ERRNO_ENOMEDIUM = 0x80010087,
SCE_ERROR_ERRNO_ENOSHARE = 0x80010088,
SCE_ERROR_ERRNO_ECASECLASH = 0x80010089,
SCE_ERROR_ERRNO_EILSEQ = 0x8001008A,
SCE_ERROR_ERRNO_EOVERFLOW = 0x8001008B,
SCE_ERROR_ERRNO_ECANCELED = 0x8001008C,
SCE_ERROR_ERRNO_ENOTRECOVERABLE = 0x8001008D,
SCE_ERROR_ERRNO_EOWNERDEAD = 0x8001008E,
};
class psv_func_caller class psv_func_caller
{ {
public: public:
@ -58,6 +192,7 @@ namespace psv_func_detail
static __forceinline T func(ARMv7Thread& CPU) static __forceinline T func(ARMv7Thread& CPU)
{ {
return 0.0f;
} }
}; };
@ -69,19 +204,21 @@ namespace psv_func_detail
static __forceinline T func(ARMv7Thread& CPU) static __forceinline T func(ARMv7Thread& CPU)
{ {
return {};
} }
}; };
template<typename T, int g_count, int f_count, int v_count> template<typename T, int g_count, int f_count, int v_count>
struct bind_arg<T, ARG_STACK, g_count, f_count, v_count> struct bind_arg<T, ARG_STACK, g_count, f_count, v_count>
{ {
static_assert(f_count <= 4, "TODO: Unsupported stack argument type (general)");
static_assert(f_count <= 0, "TODO: Unsupported stack argument type (float)"); static_assert(f_count <= 0, "TODO: Unsupported stack argument type (float)");
static_assert(v_count <= 0, "TODO: Unsupported stack argument type (vector)"); static_assert(v_count <= 0, "TODO: Unsupported stack argument type (vector)");
static_assert(sizeof(T) <= 4, "Invalid function argument type for ARG_STACK"); static_assert(sizeof(T) <= 4, "Invalid function argument type for ARG_STACK");
static __forceinline T func(ARMv7Thread& CPU) static __forceinline T func(ARMv7Thread& CPU)
{ {
const u32 res = CPU.GetStackArg(g_count);
return (T&)res;
} }
}; };