diff --git a/rpcs3/Emu/Cell/Modules/sys_spu_.cpp b/rpcs3/Emu/Cell/Modules/sys_spu_.cpp index 70d5abf836..2c584a7fed 100644 --- a/rpcs3/Emu/Cell/Modules/sys_spu_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_spu_.cpp @@ -389,7 +389,7 @@ error_code sys_raw_spu_load(s32 id, vm::cptr path, vm::ptr entry) sys_spu_image img; img.load(elf_file); - img.deploy(vm::_ptr(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), img.segs.get_ptr(), img.nsegs); + img.deploy(vm::_ptr(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), std::span(img.segs.get_ptr(), img.nsegs)); img.free(); *entry = img.entry_point; @@ -402,7 +402,7 @@ error_code sys_raw_spu_image_load(s32 id, vm::ptr img) sysPrxForUser.warning("sys_raw_spu_image_load(id=%d, img=*0x%x)", id, img); // Load SPU segments - img->deploy(vm::_ptr(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), img->segs.get_ptr(), img->nsegs); + img->deploy(vm::_ptr(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), std::span(img->segs.get_ptr(), img->nsegs)); // Use MMIO vm::write32(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id + RAW_SPU_PROB_OFFSET + SPU_NPC_offs, img->entry_point); diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index fd78ae3ae0..8180fbc365 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -109,7 +109,7 @@ void sys_spu_image::free() const } } -void sys_spu_image::deploy(u8* loc, sys_spu_segment* segs, u32 nsegs) +void sys_spu_image::deploy(u8* loc, std::span segs) { // Segment info dump std::string dump; @@ -119,20 +119,18 @@ void sys_spu_image::deploy(u8* loc, sys_spu_segment* segs, u32 nsegs) sha1_starts(&sha); u8 sha1_hash[20]; - for (u32 i = 0; i < nsegs; i++) + for (const auto& seg : segs) { - auto& seg = segs[i]; + fmt::append(dump, "\n\t[%u] t=0x%x, ls=0x%x, size=0x%x, addr=0x%x", &seg - segs.data(), seg.type, seg.ls, seg.size, seg.addr); - fmt::append(dump, "\n\t[%d] t=0x%x, ls=0x%x, size=0x%x, addr=0x%x", i, seg.type, seg.ls, seg.size, seg.addr); - - sha1_update(&sha, reinterpret_cast(&seg.type), sizeof(seg.type)); + sha1_update(&sha, reinterpret_cast(&seg.type), sizeof(seg.type)); // Hash big-endian values if (seg.type == SYS_SPU_SEGMENT_TYPE_COPY) { std::memcpy(loc + seg.ls, vm::base(seg.addr), seg.size); - sha1_update(&sha, reinterpret_cast(&seg.size), sizeof(seg.size)); - sha1_update(&sha, reinterpret_cast(&seg.ls), sizeof(seg.ls)); + sha1_update(&sha, reinterpret_cast(&seg.size), sizeof(seg.size)); + sha1_update(&sha, reinterpret_cast(&seg.ls), sizeof(seg.ls)); sha1_update(&sha, vm::_ptr(seg.addr), seg.size); } else if (seg.type == SYS_SPU_SEGMENT_TYPE_FILL) @@ -143,9 +141,9 @@ void sys_spu_image::deploy(u8* loc, sys_spu_segment* segs, u32 nsegs) } std::fill_n(reinterpret_cast*>(loc + seg.ls), seg.size / 4, seg.addr); - sha1_update(&sha, reinterpret_cast(&seg.size), sizeof(seg.size)); - sha1_update(&sha, reinterpret_cast(&seg.ls), sizeof(seg.ls)); - sha1_update(&sha, reinterpret_cast(&seg.addr), sizeof(seg.addr)); + sha1_update(&sha, reinterpret_cast(&seg.size), sizeof(seg.size)); + sha1_update(&sha, reinterpret_cast(&seg.ls), sizeof(seg.ls)); + sha1_update(&sha, reinterpret_cast(&seg.addr), sizeof(seg.addr)); } else if (seg.type == SYS_SPU_SEGMENT_TYPE_INFO) { @@ -417,7 +415,7 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr thread, u32 g *thread = tid; group->args[inited] = {arg->arg1, arg->arg2, arg->arg3, arg->arg4}; - group->imgs[inited].first = image; + group->imgs[inited].first = image.entry_point; group->imgs[inited].second.assign(image.segs.get_ptr(), image.segs.get_ptr() + image.nsegs); if (++group->init == group->max_num) @@ -725,7 +723,7 @@ error_code sys_spu_thread_group_start(ppu_thread& ppu, u32 id) auto& args = group->args[thread->lv2_id >> 24]; auto& img = group->imgs[thread->lv2_id >> 24]; - sys_spu_image::deploy(thread->ls, img.second.data(), img.first.nsegs); + sys_spu_image::deploy(thread->ls, std::span(img.second.data(), img.second.size())); thread->cpu_init(); thread->gpr[3] = v128::from64(0, args[0]); @@ -733,7 +731,7 @@ error_code sys_spu_thread_group_start(ppu_thread& ppu, u32 id) thread->gpr[5] = v128::from64(0, args[2]); thread->gpr[6] = v128::from64(0, args[3]); - thread->status_npc = {SPU_STATUS_RUNNING, img.first.entry_point}; + thread->status_npc = {SPU_STATUS_RUNNING, img.first}; } } @@ -1903,7 +1901,7 @@ error_code sys_isolated_spu_create(ppu_thread& ppu, vm::ptr id, vm::ptr(img.entry_point); - img.deploy(thread->ls, image_info->segs.get_ptr(), image_info->nsegs); + img.deploy(thread->ls, std::span(image_info->segs.get_ptr(), image_info->nsegs)); thread->write_reg(ls_addr + RAW_SPU_PROB_OFFSET + SPU_NPC_offs, image_info->e_entry); ensure(idm::remove_verify(img.entry_point, std::move(image_info))); diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.h b/rpcs3/Emu/Cell/lv2/sys_spu.h index 418cc04d93..d513f76ef0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.h +++ b/rpcs3/Emu/Cell/lv2/sys_spu.h @@ -8,6 +8,8 @@ #include "Emu/Memory/vm_ptr.h" #include "Utilities/File.h" +#include + struct lv2_memory_container; enum : s32 @@ -223,7 +225,7 @@ struct sys_spu_image void load(const fs::file& stream); void free() const; - static void deploy(u8* loc, sys_spu_segment* segs, u32 nsegs); + static void deploy(u8* loc, std::span segs); }; enum : u32 @@ -288,7 +290,7 @@ struct lv2_spu_group std::array>, 8> threads; // SPU Threads std::array threads_map; // SPU Threads map based number - std::array>, 8> imgs; // SPU Images + std::array>, 8> imgs; // Entry points, SPU image segments std::array, 8> args; // SPU Thread Arguments std::weak_ptr ep_run; // port for SYS_SPU_THREAD_GROUP_EVENT_RUN events