summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-01-07 02:21:50 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-01-15 22:23:08 +0100
commit84e52a944d0c5dba8c5c9c6c9a0b106f571c7041 (patch)
tree14b010f64fc925980901d99fa2307e006cc57c77 /src
parentLoader: Clean up the NCCH AppLoader. (diff)
downloadyuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.tar
yuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.tar.gz
yuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.tar.bz2
yuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.tar.lz
yuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.tar.xz
yuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.tar.zst
yuzu-84e52a944d0c5dba8c5c9c6c9a0b106f571c7041.zip
Diffstat (limited to 'src')
-rw-r--r--src/core/loader/3dsx.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp
index f3e09ecd6..c3ac1f417 100644
--- a/src/core/loader/3dsx.cpp
+++ b/src/core/loader/3dsx.cpp
@@ -85,7 +85,7 @@ struct THREEloadinfo
u32 seg_sizes[3];
};
-static u32 TranslateAddr(u32 addr, THREEloadinfo *loadinfo, u32* offsets)
+static u32 TranslateAddr(u32 addr, const THREEloadinfo *loadinfo, u32* offsets)
{
if (addr < offsets[0])
return loadinfo->seg_addrs[0] + addr;
@@ -130,8 +130,9 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr)
// Read the relocation headers
u32* relocs = (u32*)(loadinfo.seg_ptrs[2] + hdr.data_seg_size);
- for (u32 current_segment = 0; current_segment < 3; current_segment++) {
- if (file.ReadBytes(&relocs[current_segment*n_reloc_tables], n_reloc_tables * 4) != n_reloc_tables * 4)
+ for (unsigned current_segment = 0; current_segment < 3; current_segment++) {
+ size_t size = n_reloc_tables * 4;
+ if (file.ReadBytes(&relocs[current_segment * n_reloc_tables], size) != size)
return ERROR_READ;
}
@@ -147,9 +148,9 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr)
memset((char*)loadinfo.seg_ptrs[2] + hdr.data_seg_size - hdr.bss_size, 0, hdr.bss_size);
// Relocate the segments
- for (u32 current_segment = 0; current_segment < 3; current_segment++) {
- for (u32 current_segment_reloc_table = 0; current_segment_reloc_table < n_reloc_tables; current_segment_reloc_table++) {
- u32 n_relocs = relocs[current_segment*n_reloc_tables + current_segment_reloc_table];
+ for (unsigned current_segment = 0; current_segment < 3; current_segment++) {
+ for (unsigned current_segment_reloc_table = 0; current_segment_reloc_table < n_reloc_tables; current_segment_reloc_table++) {
+ u32 n_relocs = relocs[current_segment * n_reloc_tables + current_segment_reloc_table];
if (current_segment_reloc_table >= 2) {
// We are not using this table - ignore it because we don't know what it dose
file.Seek(n_relocs*sizeof(THREEDSX_Reloc), SEEK_CUR);
@@ -158,29 +159,35 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr)
static THREEDSX_Reloc reloc_table[RELOCBUFSIZE];
u32* pos = (u32*)loadinfo.seg_ptrs[current_segment];
- u32* end_pos = pos + (loadinfo.seg_sizes[current_segment] / 4);
+ const u32* end_pos = pos + (loadinfo.seg_sizes[current_segment] / 4);
while (n_relocs) {
u32 remaining = std::min(RELOCBUFSIZE, n_relocs);
n_relocs -= remaining;
- if (file.ReadBytes(reloc_table, remaining*sizeof(THREEDSX_Reloc)) != remaining*sizeof(THREEDSX_Reloc))
+ if (file.ReadBytes(reloc_table, remaining * sizeof(THREEDSX_Reloc)) != remaining * sizeof(THREEDSX_Reloc))
return ERROR_READ;
- for (u32 current_inprogress = 0; current_inprogress < remaining && pos < end_pos; current_inprogress++) {
- LOG_TRACE(Loader, "(t=%d,skip=%u,patch=%u)\n",
- current_segment_reloc_table, (u32)reloc_table[current_inprogress].skip, (u32)reloc_table[current_inprogress].patch);
- pos += reloc_table[current_inprogress].skip;
- s32 num_patches = reloc_table[current_inprogress].patch;
+ for (unsigned current_inprogress = 0; current_inprogress < remaining && pos < end_pos; current_inprogress++) {
+ const auto& table = reloc_table[current_inprogress];
+ LOG_TRACE(Loader, "(t=%d,skip=%u,patch=%u)\n", current_segment_reloc_table,
+ (u32)table.skip, (u32)table.patch);
+ pos += table.skip;
+ s32 num_patches = table.patch;
while (0 < num_patches && pos < end_pos) {
u32 in_addr = (char*)pos - (char*)&all_mem[0];
u32 addr = TranslateAddr(*pos, &loadinfo, offsets);
LOG_TRACE(Loader, "Patching %08X <-- rel(%08X,%d) (%08X)\n",
- base_addr + in_addr, addr, current_segment_reloc_table, *pos);
+ base_addr + in_addr, addr, current_segment_reloc_table, *pos);
switch (current_segment_reloc_table) {
- case 0: *pos = (addr); break;
- case 1: *pos = (addr - in_addr); break;
- default: break; //this should never happen
+ case 0:
+ *pos = (addr);
+ break;
+ case 1:
+ *pos = (addr - in_addr);
+ break;
+ default:
+ break; //this should never happen
}
pos++;
num_patches--;