From 41b68ef353a4289b7ad0650391e557d751bc26ce Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 23 Apr 2021 20:25:55 +0200 Subject: [PATCH] some more constants --- rpcs3/Emu/Cell/Modules/cellSpurs.cpp | 4 +-- rpcs3/Emu/Cell/PPUModule.cpp | 29 +++++++++--------- rpcs3/Emu/Cell/lv2/sys_process.h | 44 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp index cf3876eb3f..92d19d6200 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpurs.cpp @@ -3790,7 +3790,7 @@ s32 _spurs::create_taskset(ppu_thread& ppu, vm::ptr spurs, vm::ptrsize = size; vm::var wkl_attr; - _cellSpursWorkloadAttributeInitialize(ppu, wkl_attr, 1, 0x330000, vm::cptr::make(SPURS_IMG_ADDR_TASKSET_PM), 0x1E40 /*pm_size*/, + _cellSpursWorkloadAttributeInitialize(ppu, wkl_attr, 1, SYS_PROCESS_PARAM_VERSION_330_0, vm::cptr::make(SPURS_IMG_ADDR_TASKSET_PM), 0x1E40 /*pm_size*/, taskset.addr(), priority, 8, max_contention); // TODO: Check return code @@ -4533,7 +4533,7 @@ s32 _spurs::create_job_chain(ppu_thread& ppu, vm::ptr spurs, vm::ptr< vm::var wid; // TODO - if (auto err = _cellSpursWorkloadAttributeInitialize(ppu, +attr_wkl, 1, 0x330000, vm::null, 0, jobChain.addr(), prio, 1, maxContention)) + if (auto err = _cellSpursWorkloadAttributeInitialize(ppu, +attr_wkl, 1, SYS_PROCESS_PARAM_VERSION_330_0, vm::null, 0, jobChain.addr(), prio, 1, maxContention)) { return as_job_error(err); } diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index bfaf69c8de..15a34ed8df 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -817,8 +817,8 @@ void try_spawn_ppu_if_exclusive_program(const ppu_module& m) { ppu_thread_params p { - .stack_addr = vm::cast(vm::alloc(0x100000, vm::stack, 4096)), - .stack_size = 0x100000, + .stack_addr = vm::cast(vm::alloc(SYS_PROCESS_PARAM_STACK_SIZE_MAX, vm::stack, 4096)), + .stack_size = SYS_PROCESS_PARAM_STACK_SIZE_MAX, }; auto ppu = idm::make_ptr>("PPU[0x1000000] Thread (test_thread)", p, "test_thread", 0); @@ -1232,10 +1232,10 @@ bool ppu_load_exec(const ppu_exec_object& elf) u32 tls_vsize = 0; // Process information - u32 sdk_version = 0xffffffff; + u32 sdk_version = SYS_PROCESS_PARAM_SDK_VERSION_UNKNOWN; s32 primary_prio = 1001; - u32 primary_stacksize = 0x100000; - u32 malloc_pagesize = 0x100000; + u32 primary_stacksize = SYS_PROCESS_PARAM_STACK_SIZE_MAX; + u32 malloc_pagesize = SYS_PROCESS_PARAM_MALLOC_PAGE_SIZE_1M; u32 ppc_seg = 0; // Limit for analysis @@ -1466,7 +1466,7 @@ bool ppu_load_exec(const ppu_exec_object& elf) ppu_loader.warning("Bad process_param size! [0x%x : 0x%x]", info.size, sizeof(process_param_t)); } - if (info.magic != 0x13bcc5f6u) + if (info.magic != SYS_PROCESS_PARAM_MAGIC) { ppu_loader.error("Bad process_param magic! [0x%x]", info.magic); } @@ -1674,16 +1674,17 @@ bool ppu_load_exec(const ppu_exec_object& elf) // Fix primary stack size switch (u32 sz = primary_stacksize) { - case 0x10: primary_stacksize = 32 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_32K - case 0x20: primary_stacksize = 64 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_64K - case 0x30: primary_stacksize = 96 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_96K - case 0x40: primary_stacksize = 128 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_128K - case 0x50: primary_stacksize = 256 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_256K - case 0x60: primary_stacksize = 512 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_512K - case 0x70: primary_stacksize = 1024 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_1M + case SYS_PROCESS_PRIMARY_STACK_SIZE_32K: primary_stacksize = 32 * 1024; break; + case SYS_PROCESS_PRIMARY_STACK_SIZE_64K: primary_stacksize = 64 * 1024; break; + case SYS_PROCESS_PRIMARY_STACK_SIZE_96K: primary_stacksize = 96 * 1024; break; + case SYS_PROCESS_PRIMARY_STACK_SIZE_128K: primary_stacksize = 128 * 1024; break; + case SYS_PROCESS_PRIMARY_STACK_SIZE_256K: primary_stacksize = 256 * 1024; break; + case SYS_PROCESS_PRIMARY_STACK_SIZE_512K: primary_stacksize = 512 * 1024; break; + case SYS_PROCESS_PRIMARY_STACK_SIZE_1M: primary_stacksize = 1024 * 1024; break; default: { - primary_stacksize = utils::align(std::clamp(sz, 0x10000, 0x100000), 4096); + // According to elad335, the min value seems to be 64KB instead of the expected 4KB (SYS_PROCESS_PARAM_STACK_SIZE_MIN) + primary_stacksize = utils::align(std::clamp(sz, 0x10000, SYS_PROCESS_PARAM_STACK_SIZE_MAX), 4096); break; } } diff --git a/rpcs3/Emu/Cell/lv2/sys_process.h b/rpcs3/Emu/Cell/lv2/sys_process.h index 1bc732d207..9624c57510 100644 --- a/rpcs3/Emu/Cell/lv2/sys_process.h +++ b/rpcs3/Emu/Cell/lv2/sys_process.h @@ -28,6 +28,50 @@ enum : u32 SYS_EVENT_FLAG_OBJECT = 0x98, }; +enum : u64 +{ + SYS_PROCESS_PRIMARY_STACK_SIZE_32K = 0x0000000000000010, + SYS_PROCESS_PRIMARY_STACK_SIZE_64K = 0x0000000000000020, + SYS_PROCESS_PRIMARY_STACK_SIZE_96K = 0x0000000000000030, + SYS_PROCESS_PRIMARY_STACK_SIZE_128K = 0x0000000000000040, + SYS_PROCESS_PRIMARY_STACK_SIZE_256K = 0x0000000000000050, + SYS_PROCESS_PRIMARY_STACK_SIZE_512K = 0x0000000000000060, + SYS_PROCESS_PRIMARY_STACK_SIZE_1M = 0x0000000000000070, +}; + +constexpr auto SYS_PROCESS_PARAM_SECTION_NAME = ".sys_proc_param"; + +enum +{ + SYS_PROCESS_PARAM_INVALID_PRIO = -32768, +}; + +enum : u32 +{ + SYS_PROCESS_PARAM_INVALID_STACK_SIZE = 0xffffffff, + + SYS_PROCESS_PARAM_STACK_SIZE_MIN = 0x1000, // 4KB + SYS_PROCESS_PARAM_STACK_SIZE_MAX = 0x100000, // 1MB + + SYS_PROCESS_PARAM_VERSION_INVALID = 0xffffffff, + SYS_PROCESS_PARAM_VERSION_1 = 0x00000001, // for SDK 08X + SYS_PROCESS_PARAM_VERSION_084_0 = 0x00008400, + SYS_PROCESS_PARAM_VERSION_090_0 = 0x00009000, + SYS_PROCESS_PARAM_VERSION_330_0 = 0x00330000, + + SYS_PROCESS_PARAM_MAGIC = 0x13bcc5f6, + + SYS_PROCESS_PARAM_MALLOC_PAGE_SIZE_NONE = 0x00000000, + SYS_PROCESS_PARAM_MALLOC_PAGE_SIZE_64K = 0x00010000, + SYS_PROCESS_PARAM_MALLOC_PAGE_SIZE_1M = 0x00100000, + + SYS_PROCESS_PARAM_PPC_SEG_DEFAULT = 0x00000000, + SYS_PROCESS_PARAM_PPC_SEG_OVLM = 0x00000001, + SYS_PROCESS_PARAM_PPC_SEG_FIXEDADDR_PRX = 0x00000002, + + SYS_PROCESS_PARAM_SDK_VERSION_UNKNOWN = 0xffffffff, +}; + struct sys_exit2_param { be_t x0; // 0x85