1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-25 09:45:02 +00:00

Overlay_Relocate and Overlay_Load retail OK (#1662)

* Overlay_Relocate OK

* Overlay_Load

* format

* PR + better match for Overlay_Load
This commit is contained in:
Derek Hensley 2024-01-30 16:30:27 -08:00 committed by GitHub
parent 2beff8cbf4
commit 77c9c97ff9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 38 deletions

View file

@ -247,6 +247,7 @@ $(BUILD_DIR)/src/code/code_800FD970.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/gfxprint.o: OPTFLAGS := -O2 $(BUILD_DIR)/src/code/gfxprint.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/jpegutils.o: OPTFLAGS := -O2 $(BUILD_DIR)/src/code/jpegutils.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/jpegdecoder.o: OPTFLAGS := -O2 $(BUILD_DIR)/src/code/jpegdecoder.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/load.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/loadfragment2.o: OPTFLAGS := -O2 $(BUILD_DIR)/src/code/loadfragment2.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/logutils.o: OPTFLAGS := -O2 $(BUILD_DIR)/src/code/logutils.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/mtxuty-cvt.o: OPTFLAGS := -O2 $(BUILD_DIR)/src/code/mtxuty-cvt.o: OPTFLAGS := -O2

View file

@ -1717,8 +1717,8 @@ void RcpUtils_Reset(void);
void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd); void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd);
void MtxConv_F2L(Mtx* m1, MtxF* m2); void MtxConv_F2L(Mtx* m1, MtxF* m2);
void MtxConv_L2F(MtxF* m1, Mtx* m2); void MtxConv_L2F(MtxF* m1, Mtx* m2);
void Overlay_Relocate(void* allocatedRamAddress, OverlayRelocationSection* ovlRelocs, void* vramStart); void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelocs, void* vramStart);
s32 Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr); size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr);
// ? func_800FC800(?); // ? func_800FC800(?);
// ? func_800FC83C(?); // ? func_800FC83C(?);
// ? func_800FCAB4(?); // ? func_800FCAB4(?);

View file

@ -5,8 +5,8 @@
void osSyncPrintf(const char* fmt, ...); void osSyncPrintf(const char* fmt, ...);
void bzero(void* __s, size_t __n); void bzero(void* __s, int __n);
int bcmp(const void* __sl, const void* __s2, size_t __n); int bcmp(const void* __sl, const void* __s2, int __n);
void bcopy(const void* __src, void* __dest, size_t __n); void bcopy(const void* __src, void* __dest, int __n);
#endif #endif

View file

@ -1,20 +1,20 @@
#include "global.h" #include "global.h"
s32 Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr) { size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr) {
s32 pad[3]; s32 pad[3];
uintptr_t end; uintptr_t end;
OverlayRelocationSection* ovlRelocs; OverlayRelocationSection* ovlRelocs;
u32 relocSectionOffset; u32 relocSectionOffset = 0;
size_t size; s32 size = vromEnd - vromStart;
size = vromEnd - vromStart;
end = (uintptr_t)allocatedRamAddr + size;
if (gOverlayLogSeverity >= 3) { if (gOverlayLogSeverity >= 3) {
// "Start loading dynamic link function" // "Start loading dynamic link function"
PRINTF("\nダイナミックリンクファンクションのロードを開始します\n"); PRINTF("\nダイナミックリンクファンクションのロードを開始します\n");
} }
size = vromEnd - vromStart;
end = (uintptr_t)allocatedRamAddr + size;
if (gOverlayLogSeverity >= 3) { if (gOverlayLogSeverity >= 3) {
// "DMA transfer of TEXT, DATA, RODATA + rel (%08x-%08x)" // "DMA transfer of TEXT, DATA, RODATA + rel (%08x-%08x)"
PRINTF("TEXT,DATA,RODATA+relを転送します(%08x-%08x)\n", allocatedRamAddr, end); PRINTF("TEXT,DATA,RODATA+relを転送します(%08x-%08x)\n", allocatedRamAddr, end);
@ -46,10 +46,10 @@ s32 Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void*
// "Clear BSS area (% 08x-% 08x)" // "Clear BSS area (% 08x-% 08x)"
PRINTF("BSS領域をクリアします(%08x-%08x)\n", end, end + ovlRelocs->bssSize); PRINTF("BSS領域をクリアします(%08x-%08x)\n", end, end + ovlRelocs->bssSize);
} }
bzero((void*)end, (s32)ovlRelocs->bssSize); bzero((void*)end, ovlRelocs->bssSize);
} }
size = (uintptr_t)&ovlRelocs->relocations[ovlRelocs->nRelocations] - (uintptr_t)ovlRelocs; size = (uintptr_t)(ovlRelocs->relocations + ovlRelocs->nRelocations) - (uintptr_t)ovlRelocs;
if (gOverlayLogSeverity >= 3) { if (gOverlayLogSeverity >= 3) {
// "Clear REL area (%08x-%08x)" // "Clear REL area (%08x-%08x)"
@ -68,5 +68,6 @@ s32 Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void*
// "Finish loading dynamic link function" // "Finish loading dynamic link function"
PRINTF("ダイナミックリンクファンクションのロードを終了します\n\n"); PRINTF("ダイナミックリンクファンクションのロードを終了します\n\n");
} }
return size; return size;
} }

View file

@ -33,19 +33,19 @@
* - [29:24] 6-bit relocation type describing which relocation operation should be performed. Same as ELF32 MIPS. * - [29:24] 6-bit relocation type describing which relocation operation should be performed. Same as ELF32 MIPS.
* - [23: 0] 24-bit section-relative offset indicating where in the section to apply this relocation. * - [23: 0] 24-bit section-relative offset indicating where in the section to apply this relocation.
* *
* @param allocatedRamAddress Memory address the binary was loaded at. * @param allocatedRamAddr Memory address the binary was loaded at.
* @param ovlRelocs Overlay relocation section containing overlay section layout and runtime relocations. * @param ovlRelocs Overlay relocation section containing overlay section layout and runtime relocations.
* @param vramStart Virtual RAM address that the overlay was compiled at. * @param vramStart Virtual RAM address that the overlay was compiled at.
*/ */
void Overlay_Relocate(void* allocatedRamAddress, OverlayRelocationSection* ovlRelocs, void* vramStart) { void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelocs, void* vramStart) {
uintptr_t sections[RELOC_SECTION_MAX]; uintptr_t sections[RELOC_SECTION_MAX];
u32 relocatedValue;
u32 dbg;
u32 relocOffset;
u32 relocData;
uintptr_t unrelocatedAddress;
u32 i;
u32* relocDataP; u32* relocDataP;
u32 reloc;
u32 relocData;
u32 isLoNeg;
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
u32 i;
u32* regValP;
//! MIPS ELF relocation does not generally require tracking register values, so at first glance it appears this //! MIPS ELF relocation does not generally require tracking register values, so at first glance it appears this
//! register tracking was an unnecessary complication. However there is a bug in the IDO compiler that can cause //! register tracking was an unnecessary complication. However there is a bug in the IDO compiler that can cause
//! relocations to be emitted in the wrong order under rare circumstances when the compiler attempts to reuse a //! relocations to be emitted in the wrong order under rare circumstances when the compiler attempts to reuse a
@ -54,21 +54,16 @@ void Overlay_Relocate(void* allocatedRamAddress, OverlayRelocationSection* ovlRe
//! due to the incorrect ordering. //! due to the incorrect ordering.
u32* luiRefs[32]; u32* luiRefs[32];
u32 luiVals[32]; u32 luiVals[32];
uintptr_t relocatedAddress;
u32 reloc;
u32* luiInstRef; u32* luiInstRef;
uintptr_t allocu32 = (uintptr_t)allocatedRamAddress; u32 dbg;
u32* regValP; s32 relocOffset = 0;
u32 isLoNeg; u32 relocatedValue = 0;
uintptr_t unrelocatedAddress = 0;
uintptr_t relocatedAddress = 0;
s32 pad; s32 pad;
relocOffset = 0;
relocatedValue = 0;
unrelocatedAddress = 0;
relocatedAddress = 0;
if (gOverlayLogSeverity >= 3) { if (gOverlayLogSeverity >= 3) {
PRINTF("DoRelocation(%08x, %08x, %08x)\n", allocatedRamAddress, ovlRelocs, vramStart); PRINTF("DoRelocation(%08x, %08x, %08x)\n", allocatedRamAddr, ovlRelocs, vramStart);
PRINTF("text=%08x, data=%08x, rodata=%08x, bss=%08x\n", ovlRelocs->textSize, ovlRelocs->dataSize, PRINTF("text=%08x, data=%08x, rodata=%08x, bss=%08x\n", ovlRelocs->textSize, ovlRelocs->dataSize,
ovlRelocs->rodataSize, ovlRelocs->bssSize); ovlRelocs->rodataSize, ovlRelocs->bssSize);
} }
@ -105,12 +100,13 @@ void Overlay_Relocate(void* allocatedRamAddress, OverlayRelocationSection* ovlRe
// Handles 26-bit address relocation, used for jumps and jals. // Handles 26-bit address relocation, used for jumps and jals.
// Extract the address from the target field of the J-type MIPS instruction. // Extract the address from the target field of the J-type MIPS instruction.
// Relocate the address and update the instruction. // Relocate the address and update the instruction.
if (1) {
unrelocatedAddress = PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)); relocOffset = PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - (uintptr_t)vramStart;
relocOffset = unrelocatedAddress - (uintptr_t)vramStart; unrelocatedAddress = PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP));
relocatedValue = (*relocDataP & 0xFC000000) | (((allocu32 + relocOffset) & 0x0FFFFFFF) >> 2); relocatedValue = (*relocDataP & 0xFC000000) | (((allocu32 + relocOffset) & 0x0FFFFFFF) >> 2);
relocatedAddress = PHYS_TO_K0(MIPS_JUMP_TARGET(relocatedValue)); relocatedAddress = PHYS_TO_K0(MIPS_JUMP_TARGET(relocatedValue));
*relocDataP = relocatedValue; *relocDataP = relocatedValue;
}
break; break;
case R_MIPS_HI16 << RELOC_TYPE_SHIFT: case R_MIPS_HI16 << RELOC_TYPE_SHIFT: