bool LV2::init(U32 entry) { // Load and start liblv2.sprx module S32 moduleId = sys_prx_load_module("/dev_flash/sys/external/liblv2.sprx", 0, 0); if (moduleId <= CELL_OK) { logger.error(LOG_HLE, "You need to provide the /dev_flash/sys/external/ firmware files."); return false; } sys_prx_start_module_option_t startFunc; sys_prx_start_module(moduleId, 0, &startFunc); BE<U64> thread_id; sys_ppu_thread_attr_t attr; attr.entry = startFunc.entry.ToLE(); attr.tls_addr = 0; sys_ppu_thread_create(&thread_id, &attr, 0, 0, 500/*TODO*/, 0x10000, 0, "main"/*TODO*/); // Set sys_initialize_tls arguments for liblv2.sprx's start function auto* state = objects.get<sys_ppu_thread_t>(thread_id)->thread->state.get(); state->r[7] = 0x0; // TODO state->r[8] = 0x0; // TODO state->r[9] = 0x0; // TODO state->r[10] = 0x90; state->r[11] = entry; sys_ppu_thread_start(thread_id); return true; }
s32 sys_ppu_thread_create(vm::ptr<u64> thread_id, u32 entry, u64 arg, s32 prio, u32 stacksize, u64 flags, vm::cptr<char> threadname) { sysPrxForUser.Warning("sys_ppu_thread_create(thread_id=*0x%x, entry=0x%x, arg=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=*0x%x)", thread_id, entry, arg, prio, stacksize, flags, threadname); // (allocate TLS) // (return CELL_ENOMEM if failed) // ... // call the syscall if (s32 res = _sys_ppu_thread_create(thread_id, vm::make_var(ppu_thread_param_t{ entry, 0 }), arg, 0, prio, stacksize, flags, threadname)) { return res; } // run the thread return flags & SYS_PPU_THREAD_CREATE_INTERRUPT ? CELL_OK : sys_ppu_thread_start(static_cast<u32>(*thread_id)); }
s32 sys_ppu_thread_create(vm::ptr<u64> thread_id, u32 entry, u64 arg, s32 prio, u32 stacksize, u64 flags, vm::cptr<char> threadname) { sysPrxForUser.warning("sys_ppu_thread_create(thread_id=*0x%x, entry=0x%x, arg=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=%s)", thread_id, entry, arg, prio, stacksize, flags, threadname); // Allocate TLS const u32 tls_addr = ppu_alloc_tls(); if (!tls_addr) { return CELL_ENOMEM; } // Call the syscall if (s32 res = _sys_ppu_thread_create(thread_id, vm::make_var(ppu_thread_param_t{ entry, tls_addr + 0x7030 }), arg, 0, prio, stacksize, flags, threadname)) { return res; } if (flags & SYS_PPU_THREAD_CREATE_INTERRUPT) { return CELL_OK; } // Run the thread if (s32 res = sys_ppu_thread_start(static_cast<u32>(*thread_id))) { return res; } // Dirty hack for sound: confirm the creation of _mxr000 event queue if (threadname && std::memcmp(threadname.get_ptr(), "_cellsurMixerMain", 18) == 0) { while (!idm::select<lv2_event_queue>([](u32, lv2_event_queue& eq) { return eq.name == "_mxr000\0"_u64; })) { thread_ctrl::sleep(50000); } } return CELL_OK; }
s32 sys_ppu_thread_create(PPUThread& CPU, vm::ptr<u64> thread_id, u32 entry, u64 arg, s32 prio, u32 stacksize, u64 flags, vm::ptr<const char> threadname) { sysPrxForUser.Warning("sys_ppu_thread_create(thread_id=*0x%x, entry=0x%x, arg=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=*0x%x)", thread_id, entry, arg, prio, stacksize, flags, threadname); // (allocate TLS) // (return CELL_ENOMEM if failed) // ... vm::stackvar<ppu_thread_param_t> attr(CPU); attr->entry = entry; attr->tls = 0; // call the syscall if (s32 res = _sys_ppu_thread_create(thread_id, attr, arg, 0, prio, stacksize, flags, threadname)) { return res; } // run the thread return flags & SYS_PPU_THREAD_CREATE_INTERRUPT ? CELL_OK : sys_ppu_thread_start(static_cast<u32>(*thread_id)); }