Some loadfragment2.c progress

This commit is contained in:
rozlette 2020-03-01 14:57:16 -06:00
parent dc37a6f9f5
commit 759fef3928
9 changed files with 135 additions and 7 deletions

View File

@ -28,7 +28,7 @@ build/src/boot_O2_g3_trapuv/%: OPTIMIZATION := -O2 -g3
build/src/code/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/actors/%: CFLAGS := $(CFLAGS) -Wab,-r4300_mul
build/src/boot_O2_g3_trapuv/%: CFLAGS := $(CFLAGS) -trapuv
test.txt: OPTIMIZATION := -O2 -g3
test.txt: OPTIMIZATION := -O2
test.txt: CC := $(QEMU_IRIX) -L $(IRIX_71_ROOT) $(IRIX_71_ROOT)/usr/bin/cc
test.txt: CFLAGS := $(CFLAGS) -Wab,-r4300_mul

View File

@ -112,7 +112,7 @@ void FaultDrawer_Init(void); // func_800848B8
void func_80084940(void); // func_80084940
void func_80084968(void); // func_80084968
void Load_Relocate(u32 allocatedVRamAddr, OverlayBlockSizes* overlayInfo, u32 vRamStart); // func_800849A0
unsigned int Load_LoadOverlay(u32 vRomStart, int vRomEnd, u32 vRamStart, u32 allocatedVRamAddr, u32 allocatedBytes); // func_80084C0C
s32 Load_LoadOverlay(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 allocatedVRamAddr, u32 allocatedBytes); // func_80084C0C
void* Load_AllocateAndLoad(u32 vRomStart, u32 vRomEnd, u32 vRamStart); // func_80084CD0
void Load2_Relocate(u32 allocatedVRamAddr, OverlayBlockSizes* overlayInfo, u32 vRamStart); // func_80084DB0
s32 Load2_LoadOverlay(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamEnd, u32 allocatedVRamAddr); // func_8008501C

View File

@ -17,8 +17,9 @@ SECTIONS
build/src/boot_O2_g3/boot_0x80081920.o(.text)
build/src/boot_O2_g3_trapuv/fault.o(.text)
build/src/boot_O2_g3_trapuv/fault_drawer.o(.text)
build/src/boot_O1/boot_0x80084940.o(.text)
build/asm/loadfragment.o(.text)
build/asm/loadfragment2.o(.text)
build/src/boot_O2/loadfragment2.o(.text)
build/asm/boot_0x80085130.o(.text)
build/src/boot_O2/stackcheck.o(.text)
build/asm/boot_0x80085570.o(.text)
@ -214,7 +215,7 @@ SECTIONS
build/asm/boot_data_fault.o(.text)
build/src/boot_O2_g3_trapuv/fault_drawer.o(.data)
build/asm/boot_data_loadfragment.o(.text)
build/asm/boot_data_loadfragment2.o(.text)
build/src/boot_O2/loadfragment2.o(.data)
build/src/boot_O2/stackcheck.o(.data)
build/asm/boot_data_0x80085570.o(.text)
build/asm/boot_data_0x800862E0.o(.text)

View File

@ -0,0 +1,15 @@
#include <ultra64.h>
#include <global.h>
void func_80084940(void) {
u32 sp;
sp = __osSpGetStatus();
osDpGetStatus();
}
void func_80084968(void) {
func_80084940();
osDpSetStatus(0x28);
__osSpSetStatus(0x4082);
func_80084940();
}

109
src/boot_O2/loadfragment2.c Normal file
View File

@ -0,0 +1,109 @@
#include <ultra64.h>
#include <global.h>
UNK_TYPE4 D_80096C30 = 2;
#ifdef NON_MATCHING
// This needs lots of work. Mostly regalloc and getting the address of D_80096C30 placed in s5 at the beginning of the function
void Load2_Relocate(u32 allocatedVRamAddr, OverlayBlockSizes* overlayInfo, u32 vRamStart) {
s32 sectionLocations [4];
u32* regReferences[32];
u32 regValues[32];
u32 i;
u32 relocatedAddress;
s32 signedOffset;
u32* lastInst;
u32* inst;
u32 relocation;
u32 relocationIndex;
sectionLocations[0] = 0;
sectionLocations[1] = allocatedVRamAddr;
sectionLocations[2] = overlayInfo->textSize + allocatedVRamAddr;
sectionLocations[3] = sectionLocations[2] + overlayInfo->dataSize;
for (i = 0, relocationIndex = 0; i < overlayInfo->amountOfRelocations; relocationIndex++) {
relocation = overlayInfo->relocations[relocationIndex];
i++;
inst = (u32 *)(sectionLocations[relocation >> 0x1e] + (relocation & 0xffffff));
switch (relocation & 0x3f000000) {
case 0x2000000:
if ((*inst & 0xf000000) == 0) {
*inst = (*inst - vRamStart) + allocatedVRamAddr;
} else {
if (D_80096C30 > 2);
}
break;
case 0x4000000:
*inst = (*inst & 0xfc000000) |
(((((*inst & 0x3ffffff) << 2 | 0x80000000) - vRamStart) + allocatedVRamAddr & 0xfffffff) >> 2);
break;
case 0x5000000:
regReferences[*inst >> 0x10 & 0x1f] = inst;
regValues[*inst >> 0x10 & 0x1f] = *inst;
break;
case 0x6000000:
lastInst = regReferences[*inst >> 0x15 & 0x1f];
signedOffset = (s16)*inst;
if ((signedOffset + *lastInst * 0x10000 & 0xf000000) == 0) {
relocatedAddress = ((signedOffset + regValues[*inst >> 0x15 & 0x1f] * 0x10000) - vRamStart) + allocatedVRamAddr;
*lastInst = (((relocatedAddress >> 0x10) & 0xFFFF) + ((relocatedAddress & 0x8000)? 1 : 0)) |
(*lastInst & 0xffff0000);
*inst = *inst & 0xffff0000 | relocatedAddress & 0xffff;
}
break;
}
}
}
#else
GLOBAL_ASM("./asm/non_matchings/loadfragment2/Load2_Relocate.asm")
#endif
#ifdef NON_MATCHING
// Very minor stack stuff with a saved value
s32 Load2_LoadOverlay(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamEnd, u32 allocatedVRamAddr) {
int nbytes;
u32 pad;
u32 size;
void* end;
OverlayBlockSizes* overlayInfo;
size = vRomEnd - vRomStart;
if(1);
Dmamgr_SendRequestAndWait(allocatedVRamAddr, vRomStart, size);
end = (void*)(allocatedVRamAddr + size);
overlayInfo = (OverlayBlockSizes*)((int)end - *(int*)((int)end + -4));
if(1);
Load2_Relocate(allocatedVRamAddr, overlayInfo, vRamStart);
if (overlayInfo->bssSize != 0) {
bzero(end, overlayInfo->bssSize);
}
nbytes = vRamEnd - vRamStart;
osWritebackDCache((void*)allocatedVRamAddr, nbytes);
osInvalICache((void*)allocatedVRamAddr, nbytes);
return nbytes;
}
#else
GLOBAL_ASM("./asm/non_matchings/loadfragment2/Load2_LoadOverlay.asm")
#endif
void* Load2_AllocateAndLoad(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamEnd) {
void* allocatedVRamAddr;
u32 size;
size = vRamEnd - vRamStart;
allocatedVRamAddr = StartHeap_AllocR(size);
if (allocatedVRamAddr != NULL) {
Load2_LoadOverlay(vRomStart, vRomEnd, vRamStart, vRamEnd, (u32)allocatedVRamAddr);
}
return allocatedVRamAddr;
}

View File

@ -66,7 +66,7 @@
('decomp/', 'ovl_En_Floormas', 0x808D0680, ((0x808D3880, 0x808D3E1F),),()),
('decomp/', 'ovl_En_Rd', 0x808D3E20, ((0x808D70C0, 0x808D754F),),()),
('decomp/', 'ovl_Bg_F40_Flift', 0x808D7550, ((0x808D7810, 0x808D78CF),),()),
('decomp/', 'ovl_Obj_Mure', 0x808D78D0, ((0x808D8760, 0x808D893F),),()), # TODO figure this one out
('decomp/', 'ovl_Obj_Mure', 0x808D78D0, ((0x808D8760, 0x808D893F),),()),
('decomp/', 'ovl_En_Sw', 0x808D8940, ((0x808DB9C0, 0x808DBE7F),),()),
('decomp/', 'ovl_Object_Kankyo', 0x808DBE80, ((0x808DE320, 0x808DE5AF),),((0x808DE5B0,0x808DE5BF),)),
('decomp/', 'ovl_En_Horse_Link_Child', 0x808DE5C0, ((0x808DFEA0, 0x808E019F),),()),

View File

@ -3,6 +3,8 @@ boot_0x800968B0
fault
fault_drawer
idle
loadfragment
loadfragment2
stackcheck
z_actor
z_DLF

View File

@ -109,7 +109,7 @@
0x80084940:("func_80084940","void","void"),
0x80084968:("func_80084968","void","void"),
0x800849A0:("Load_Relocate","void","u32 allocatedVRamAddr, OverlayBlockSizes* overlayInfo, u32 vRamStart"),
0x80084C0C:("Load_LoadOverlay","unsigned int","u32 vRomStart, int vRomEnd, u32 vRamStart, u32 allocatedVRamAddr, u32 allocatedBytes"),
0x80084C0C:("Load_LoadOverlay","s32","u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 allocatedVRamAddr, u32 allocatedBytes"),
0x80084CD0:("Load_AllocateAndLoad","void*","u32 vRomStart, u32 vRomEnd, u32 vRamStart"),
0x80084DB0:("Load2_Relocate","void","u32 allocatedVRamAddr, OverlayBlockSizes* overlayInfo, u32 vRamStart"),
0x8008501C:("Load2_LoadOverlay","s32","u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamEnd, u32 allocatedVRamAddr"),

View File

@ -9,7 +9,8 @@
0x80081920:"",
0x80081980:"fault",
0x80083EB0:"fault_drawer",
0x80084940:"loadfragment",
0x80084940:"",
0x800849A0:"loadfragment",
0x80084DB0:"loadfragment2",
0x80085130:"",
0x80085320:"stackcheck",