mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-05 15:34:41 +00:00
Match Overlay_Relocate (#330)
* Finally match Overlay_DoRelocation * remove asm, rename Overlay_DoRelocation to Overlay_Relocate * formatter * comment updates * comment update
This commit is contained in:
parent
07e6d25be2
commit
4ad461c797
7 changed files with 45 additions and 313 deletions
|
@ -58,7 +58,7 @@ s32 Overlay_Load(u32 vRomStart, u32 vRomEnd, void* vRamStart, void* vRamEnd, voi
|
|||
osSyncPrintf("リロケーションします\n");
|
||||
}
|
||||
|
||||
Overlay_DoRelocation(allocatedVRamAddr, ovl, vRamStart);
|
||||
Overlay_Relocate(allocatedVRamAddr, ovl, vRamStart);
|
||||
|
||||
bssSize = ovl->bssSize;
|
||||
if (bssSize != 0) {
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
#include <global.h>
|
||||
|
||||
#ifdef NON_MATCHING
|
||||
void Overlay_DoRelocation(void* allocatedVRamAddress, OverlayRelocationSection* overlayInfo, void* vRamAddress) {
|
||||
// mostly regalloc, more specific issues described below.
|
||||
void Overlay_Relocate(void* allocatedVRamAddress, OverlayRelocationSection* overlayInfo, void* vRamAddress) {
|
||||
u32 sections[4];
|
||||
u32 unrelocatedAddress;
|
||||
u32 dbg;
|
||||
u32 relocatedValue;
|
||||
u32 dbg;
|
||||
u32 relocOffset;
|
||||
u32 relocatedAddress;
|
||||
u32 relocData;
|
||||
u32 unrelocatedAddress;
|
||||
u32 i;
|
||||
u32* relocDataP;
|
||||
u32* luiRefs[32];
|
||||
u32 luiVals[32];
|
||||
u32 relocData;
|
||||
u32 relocatedAddress;
|
||||
u32 reloc;
|
||||
u32 vaddr;
|
||||
u32* luiInstRef;
|
||||
u32 addrToLoad;
|
||||
u32 luiInst;
|
||||
u32 allocu32 = (u32)allocatedVRamAddress;
|
||||
u32* regValP;
|
||||
u32 isLoNeg;
|
||||
|
||||
|
@ -34,8 +31,8 @@ void Overlay_DoRelocation(void* allocatedVRamAddress, OverlayRelocationSection*
|
|||
}
|
||||
|
||||
sections[0] = 0;
|
||||
sections[1] = (u32)allocatedVRamAddress;
|
||||
sections[2] = sections[1] + overlayInfo->textSize;
|
||||
sections[1] = allocu32;
|
||||
sections[2] = allocu32 + overlayInfo->textSize;
|
||||
sections[3] = sections[2] + overlayInfo->dataSize;
|
||||
|
||||
for (i = 0; i < overlayInfo->nRelocations; i++) {
|
||||
|
@ -45,31 +42,31 @@ void Overlay_DoRelocation(void* allocatedVRamAddress, OverlayRelocationSection*
|
|||
switch (reloc & 0x3F000000) {
|
||||
case 0x2000000:
|
||||
/* R_MIPS_32
|
||||
* handles 32-bit address relocation. Used in things such as
|
||||
* Handles 32-bit address relocation. Used in things such as
|
||||
* jump tables.
|
||||
*/
|
||||
if ((*relocDataP & 0xF000000) == 0) {
|
||||
relocOffset = *relocDataP - (u32)vRamAddress;
|
||||
relocatedAddress = relocOffset + (u32)allocatedVRamAddress;
|
||||
relocatedValue = relocatedAddress;
|
||||
luiInstRef = vRamAddress;
|
||||
relocOffset = *relocDataP - (u32)luiInstRef;
|
||||
relocatedValue = relocOffset + allocu32;
|
||||
relocatedAddress = relocatedValue;
|
||||
unrelocatedAddress = relocData;
|
||||
*relocDataP = relocatedAddress;
|
||||
}
|
||||
break;
|
||||
case 0x4000000:
|
||||
/* R_MIPS_26
|
||||
* handles 26-bit address relocation, used for jumps and jals
|
||||
* Handles 26-bit address relocation, used for jumps and jals
|
||||
*/
|
||||
unrelocatedAddress = ((*relocDataP & 0x3FFFFFF) << 2) | 0x80000000;
|
||||
relocOffset = unrelocatedAddress - (u32)vRamAddress;
|
||||
relocatedValue =
|
||||
(*relocDataP & 0xFC000000) | ((((u32)allocatedVRamAddress + relocOffset) & 0xFFFFFFF) >> 2);
|
||||
relocatedAddress = ((relocatedValue & 0x3FFFFFF) << 4) | 0x80000000;
|
||||
relocatedValue = (*relocDataP & 0xFC000000) | (((allocu32 + relocOffset) & 0xFFFFFFF) >> 2);
|
||||
relocatedAddress = ((relocatedValue & 0x3FFFFFF) << 2) | 0x80000000;
|
||||
*relocDataP = relocatedValue;
|
||||
break;
|
||||
case 0x5000000:
|
||||
/* R_MIPS_HI16
|
||||
* Handles relocation for a lui instruciton, we just store the reference to
|
||||
* Handles relocation for a lui instruciton, store the reference to
|
||||
* the instruction, and will update it in the R_MIPS_LO16 section.
|
||||
*/
|
||||
luiRefs[(*relocDataP >> 0x10) & 0x1F] = relocDataP;
|
||||
|
@ -77,53 +74,39 @@ void Overlay_DoRelocation(void* allocatedVRamAddress, OverlayRelocationSection*
|
|||
break;
|
||||
case 0x6000000:
|
||||
/* R_MIPS_LO16
|
||||
* here we will update the LUI instruction to reflect the relocated address.
|
||||
* Updates the LUI instruction to reflect the relocated address.
|
||||
* The full address is calculated from the LUI and lo parts, and then updated.
|
||||
* if the lo part is negative, we make sure to add 1 to the lui.
|
||||
* if the lo part is negative, add 1 to the lui.
|
||||
*/
|
||||
regValP = &luiVals[((*relocDataP >> 0x15) & 0x1F)];
|
||||
vaddr = (*regValP << 0x10) + (s16)*relocDataP;
|
||||
luiInstRef = luiRefs[((*relocDataP >> 0x15) & 0x1F)];
|
||||
if ((vaddr & 0xF000000) == 0) {
|
||||
relocOffset = vaddr - (u32)vRamAddress;
|
||||
addrToLoad = relocOffset + (u32)allocatedVRamAddress;
|
||||
isLoNeg = ((addrToLoad & 0x8000) ? 1 : 0);
|
||||
luiInst = *luiInstRef;
|
||||
*luiInstRef = (luiInst & 0xFFFF0000) | (((addrToLoad >> 0x10) & 0xFFFF) + isLoNeg);
|
||||
unrelocatedAddress = (luiInst << 0x10) + (((s16)relocData) & (0xFFFFFFFFFFFFFFFFu));
|
||||
relocatedValue = (*relocDataP & 0xFFFF0000) | (addrToLoad & 0xFFFF);
|
||||
vaddr = (s16)relocData;
|
||||
isLoNeg = (((relocOffset + allocu32) & 0x8000) ? 1 : 0);
|
||||
unrelocatedAddress = (*luiInstRef << 0x10) + vaddr;
|
||||
*luiInstRef = *luiInstRef & 0xFFFF0000 | ((((relocOffset + allocu32) >> 0x10) & 0xFFFF) + isLoNeg);
|
||||
relocatedValue = (*relocDataP & 0xFFFF0000) | ((relocOffset + allocu32) & 0xFFFF);
|
||||
|
||||
// The conversion of relocatedAddress to s16 is wrapped around the OR operation of
|
||||
// relocated value
|
||||
relocatedAddress = (*luiInstRef << 0x10) + (s16)relocatedValue;
|
||||
*relocDataP = relocatedValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (1) {
|
||||
dbg = 0x10;
|
||||
switch (reloc & 0x3F000000) {
|
||||
case 0x2000000:
|
||||
dbg = 0x16;
|
||||
case 0x4000000:
|
||||
dbg += 0xA;
|
||||
case 0x6000000:
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf("%02d %08x %08x %08x ", dbg, relocDataP, relocatedValue, relocatedAddress);
|
||||
osSyncPrintf(" %08x %08x %08x %08x\n",
|
||||
((u32)relocDataP + (u32)vRamAddress) - (u32)allocatedVRamAddress, relocData,
|
||||
unrelocatedAddress, relocOffset);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
dbg = 0x10;
|
||||
switch (reloc & 0x3F000000) {
|
||||
case 0x2000000:
|
||||
dbg = 0x16;
|
||||
case 0x4000000:
|
||||
dbg += 0xA;
|
||||
case 0x6000000:
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf("%02d %08x %08x %08x ", dbg, relocDataP, relocatedValue, relocatedAddress);
|
||||
osSyncPrintf(" %08x %08x %08x %08x\n", ((u32)relocDataP + (u32)vRamAddress) - allocu32, relocData,
|
||||
unrelocatedAddress, relocOffset);
|
||||
}
|
||||
}
|
||||
// The loop seems to be incremented, then checked, but the conditional is a likely vs non, so it could
|
||||
// potentially resolve itself.
|
||||
}
|
||||
}
|
||||
#else
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/relocation/Overlay_DoRelocation.s")
|
||||
#endif
|
||||
|
|
|
@ -48,7 +48,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32
|
|||
* Creates a line segment which is perpendicular to the line segments `lineAPointA`->`lineAPointB` and
|
||||
* `lineBPointA`->`lineBPointB`
|
||||
*
|
||||
*/
|
||||
*/
|
||||
#ifdef NON_MATCHING
|
||||
/**
|
||||
* NON_MATCHING:
|
||||
|
@ -1900,7 +1900,7 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) {
|
|||
minDistSq = distFromPointAToIntersectASq;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (minDistSq != 1.e38f) {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue