Misc Clean (#1680)

* vramu32 in Overlay_Relocate

* Actor_SetColorFilter args

* Effect Hitmark enum

* Actor_WorldToActorCoords

* Some fault clean up

* contoller.h

* macros.h no longer needs stdint.h
This commit is contained in:
Derek Hensley
2024-09-07 21:55:59 -06:00
committed by GitHub
parent 2e2b2e2c7a
commit 6eaf196927
49 changed files with 151 additions and 133 deletions
+26 -26
View File
@@ -14,7 +14,7 @@
#include "libc64/malloc.h"
#include "loadfragment.h"
s32 gLoadLogSeverity = 2;
s32 gFragmentLogSeverity = 2;
// Extract MIPS register rs from an instruction word
#define MIPS_REG_RS(insn) (((insn) >> 0x15) & 0x1F)
@@ -52,7 +52,7 @@ void Fragment_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelo
uintptr_t relocatedAddress;
u32 i;
u32* luiInstRef;
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
u32 isLoNeg;
u32* regValP;
//! 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
@@ -62,9 +62,10 @@ void Fragment_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelo
//! due to the incorrect ordering.
u32* luiRefs[32];
u32 luiVals[32];
u32 isLoNeg;
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
uintptr_t vramu32 = (uintptr_t)vramStart;
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// "DoRelocation(%08x, %08x, %08x)\n"
}
@@ -88,8 +89,8 @@ void Fragment_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelo
// Check address is valid for relocation
if ((*relocDataP & 0x0F000000) == 0) {
*relocDataP = *relocDataP - (uintptr_t)vramStart + allocu32;
} else if (gLoadLogSeverity >= 3) {
*relocDataP = *relocDataP - vramu32 + allocu32;
} else if (gFragmentLogSeverity >= 3) {
// Segment pointer 32 %08x
// "セグメントポインタ32です %08x\n"
}
@@ -103,9 +104,8 @@ void Fragment_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelo
if (1) {
*relocDataP =
(*relocDataP & 0xFC000000) |
(((PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - (uintptr_t)vramStart + allocu32) & 0x0FFFFFFF) >>
2);
} else if (gLoadLogSeverity >= 3) {
(((PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - vramu32 + allocu32) & 0x0FFFFFFF) >> 2);
} else if (gFragmentLogSeverity >= 3) {
// Segment pointer 26 %08x
// "セグメントポインタ26です %08x\n"
}
@@ -132,11 +132,11 @@ void Fragment_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelo
// Check address is valid for relocation
if ((((*luiInstRef << 0x10) + (s16)*relocDataP) & 0x0F000000) == 0) {
relocatedAddress = ((*regValP << 0x10) + (s16)*relocDataP) - (uintptr_t)vramStart + allocu32;
relocatedAddress = ((*regValP << 0x10) + (s16)*relocDataP) - vramu32 + allocu32;
isLoNeg = (relocatedAddress & 0x8000) ? 1 : 0;
*luiInstRef = (*luiInstRef & 0xFFFF0000) | (((relocatedAddress >> 0x10) & 0xFFFF) + isLoNeg);
*relocDataP = (*relocDataP & 0xFFFF0000) | (relocatedAddress & 0xFFFF);
} else if (gLoadLogSeverity >= 3) {
} else if (gFragmentLogSeverity >= 3) {
// Segment pointer 16 %08x %08x %08x
// "セグメントポインタ16です %08x %08x %08x"
}
@@ -152,11 +152,11 @@ size_t Fragment_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, vo
s32 pad;
OverlayRelocationSection* ovlRelocs;
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Starting loading dynamic link function
// "\nダイナミックリンクファンクションのロードを開始します\n"
}
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// DMA transfer TEXT, DATA, RODATA+rel (%08x-%08x)
// "TEXT,DATA,RODATA+relをDMA転送します(%08x-%08x)\n"
}
@@ -166,12 +166,12 @@ size_t Fragment_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, vo
ovlRelocs = (OverlayRelocationSection*)(end - ((s32*)end)[-1]);
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// "TEXT(%08x), DATA(%08x), RODATA(%08x), BSS(%08x)\n"
}
if (allocatedBytes < ovlRelocs->bssSize + size) {
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// ramSize is too small (ramSize=%08x, NeedRamSize=%08x)
// "ramSizeが小さすぎます(ramSize=%08x, NeedRamSize=%08x)\n"
}
@@ -180,7 +180,7 @@ size_t Fragment_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, vo
allocatedBytes = ovlRelocs->bssSize + size;
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// I will relocate
// "リロケーションします\n"
}
@@ -188,7 +188,7 @@ size_t Fragment_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, vo
Fragment_Relocate(allocatedRamAddr, ovlRelocs, vramStart);
if (ovlRelocs->bssSize != 0) {
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Clear BSS area (%08x-%08x)
// "BSS領域をクリアします(%08x-%08x)\n"
}
@@ -198,7 +198,7 @@ size_t Fragment_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, vo
osWritebackDCache(allocatedRamAddr, allocatedBytes);
osInvalICache(allocatedRamAddr, allocatedBytes);
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Finish loading the dynamic link function
// "ダイナミックリンクファンクションのロードを終了します\n\n"
}
@@ -214,7 +214,7 @@ void* Fragment_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vra
OverlayRelocationSection* ovlRelocs;
size_t allocatedBytes;
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Start loading dynamic link function
// "\nダイナミックリンクファンクションのロードを開始します\n"
@@ -224,14 +224,14 @@ void* Fragment_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vra
allocatedRamAddr = malloc_r(size);
end = (uintptr_t)allocatedRamAddr + size;
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// DMA transfer TEXT, DATA, RODATA+rel (%08x-%08x)
// "TEXT,DATA,RODATA+relをDMA転送します(%08x-%08x)\n"
}
DmaMgr_RequestSync(allocatedRamAddr, vromStart, size);
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// "TEXT(%08x), DATA(%08x), RODATA(%08x), BSS(%08x)\n"
}
@@ -245,13 +245,13 @@ void* Fragment_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vra
allocatedRamAddr = realloc(allocatedRamAddr, allocatedBytes);
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// No reallocation.
// "リアロケーションしません。\n"
}
if (allocatedRamAddr == NULL) {
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Reallocation failed. .
// "リアロケーションに失敗しました。"
}
@@ -261,7 +261,7 @@ void* Fragment_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vra
end = (uintptr_t)allocatedRamAddr + size;
ovlRelocs = (OverlayRelocationSection*)(end - *(uintptr_t*)ovlOffset);
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// I will relocate
// "リロケーションします\n"
}
@@ -269,7 +269,7 @@ void* Fragment_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vra
Fragment_Relocate(allocatedRamAddr, ovlRelocs, vramStart);
if (ovlRelocs->bssSize != 0) {
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Clear BSS area (%08x-%08x)
// "BSS領域をクリアします(%08x-%08x)\n"
}
@@ -278,7 +278,7 @@ void* Fragment_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vra
osInvalICache(allocatedRamAddr, allocatedBytes);
if (gLoadLogSeverity >= 3) {
if (gFragmentLogSeverity >= 3) {
// Finish loading the dynamic link function
// "ダイナミックリンクファンクションのロードを終了します\n\n"
}
+6 -6
View File
@@ -48,7 +48,7 @@ void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlReloc
uintptr_t relocatedAddress;
u32 i;
u32* luiInstRef;
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
u32 isLoNeg;
u32* regValP;
//! 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
@@ -58,7 +58,8 @@ void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlReloc
//! due to the incorrect ordering.
u32* luiRefs[32];
u32 luiVals[32];
u32 isLoNeg;
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
uintptr_t vramu32 = (uintptr_t)vramStart;
if (gOverlayLogSeverity >= 3) {
// "DoRelocation(%08x, %08x, %08x)\n"
@@ -84,7 +85,7 @@ void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlReloc
// Check address is valid for relocation
if ((*relocDataP & 0x0F000000) == 0) {
*relocDataP = *relocDataP - (uintptr_t)vramStart + allocu32;
*relocDataP = *relocDataP - vramu32 + allocu32;
} else if (gOverlayLogSeverity >= 3) {
// Segment pointer 32 %08x
// "セグメントポインタ32です %08x\n"
@@ -99,8 +100,7 @@ void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlReloc
if (1) {
*relocDataP =
(*relocDataP & 0xFC000000) |
(((PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - (uintptr_t)vramStart + allocu32) & 0x0FFFFFFF) >>
2);
(((PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - vramu32 + allocu32) & 0x0FFFFFFF) >> 2);
} else if (gOverlayLogSeverity >= 3) {
// Segment pointer 26 %08x
// "セグメントポインタ26です %08x\n"
@@ -128,7 +128,7 @@ void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlReloc
// Check address is valid for relocation
if ((((*luiInstRef << 0x10) + (s16)*relocDataP) & 0x0F000000) == 0) {
relocatedAddress = ((*regValP << 0x10) + (s16)*relocDataP) - (uintptr_t)vramStart + allocu32;
relocatedAddress = ((*regValP << 0x10) + (s16)*relocDataP) - vramu32 + allocu32;
isLoNeg = (relocatedAddress & 0x8000) ? 1 : 0;
*luiInstRef = (*luiInstRef & 0xFFFF0000) | (((relocatedAddress >> 0x10) & 0xFFFF) + isLoNeg);
*relocDataP = (*relocDataP & 0xFFFF0000) | (relocatedAddress & 0xFFFF);
+17 -17
View File
@@ -46,6 +46,7 @@
#include "libc64/sprintf.h"
#include "PR/osint.h"
#include "controller.h"
#include "macros.h"
#include "main.h"
#include "vt.h"
@@ -55,7 +56,6 @@
FaultMgr* sFaultInstance;
f32 sFaultTimeTotal; // read but not set anywhere
// data
const char* sCpuExceptions[] = {
"Interrupt",
"TLB modification",
@@ -348,9 +348,9 @@ void Fault_DrawCornerRec(u16 color) {
void Fault_PrintFReg(s32 index, f32* value) {
u32 raw = *(u32*)value;
s32 exp = ((raw & 0x7F800000) >> 0x17) - 0x7F;
s32 exp = ((raw & 0x7F800000) >> 23) - 127;
if (((exp > -0x7F) && (exp <= 0x7F)) || (raw == 0)) {
if (((exp > -127) && (exp <= 127)) || (raw == 0)) {
FaultDrawer_Printf("F%02d:%14.7e ", index, *value);
} else {
// Print subnormal floats as their IEEE-754 hex representation
@@ -360,9 +360,9 @@ void Fault_PrintFReg(s32 index, f32* value) {
void Fault_LogFReg(s32 index, f32* value) {
u32 raw = *(u32*)value;
s32 exp = ((raw & 0x7F800000) >> 0x17) - 0x7F;
s32 exp = ((raw & 0x7F800000) >> 23) - 127;
if (((exp > -0x7F) && (exp <= 0x7F)) || (raw == 0)) {
if (((exp > -127) && (exp <= 127)) || (raw == 0)) {
osSyncPrintf("F%02d:%14.7e ", index, *value);
} else {
osSyncPrintf("F%02d: %08x(16) ", index, *(u32*)value);
@@ -444,22 +444,22 @@ void Fault_PrintThreadContext(OSThread* thread) {
Fault_PrintFReg(6, &threadCtx->fp6.f.f_even);
FaultDrawer_Printf("\n");
Fault_PrintFReg(8, &threadCtx->fp8.f.f_even);
Fault_PrintFReg(0xA, &threadCtx->fp10.f.f_even);
Fault_PrintFReg(10, &threadCtx->fp10.f.f_even);
FaultDrawer_Printf("\n");
Fault_PrintFReg(0xC, &threadCtx->fp12.f.f_even);
Fault_PrintFReg(0xE, &threadCtx->fp14.f.f_even);
Fault_PrintFReg(12, &threadCtx->fp12.f.f_even);
Fault_PrintFReg(14, &threadCtx->fp14.f.f_even);
FaultDrawer_Printf("\n");
Fault_PrintFReg(0x10, &threadCtx->fp16.f.f_even);
Fault_PrintFReg(0x12, &threadCtx->fp18.f.f_even);
Fault_PrintFReg(16, &threadCtx->fp16.f.f_even);
Fault_PrintFReg(18, &threadCtx->fp18.f.f_even);
FaultDrawer_Printf("\n");
Fault_PrintFReg(0x14, &threadCtx->fp20.f.f_even);
Fault_PrintFReg(0x16, &threadCtx->fp22.f.f_even);
Fault_PrintFReg(20, &threadCtx->fp20.f.f_even);
Fault_PrintFReg(22, &threadCtx->fp22.f.f_even);
FaultDrawer_Printf("\n");
Fault_PrintFReg(0x18, &threadCtx->fp24.f.f_even);
Fault_PrintFReg(0x1A, &threadCtx->fp26.f.f_even);
Fault_PrintFReg(24, &threadCtx->fp24.f.f_even);
Fault_PrintFReg(26, &threadCtx->fp26.f.f_even);
FaultDrawer_Printf("\n");
Fault_PrintFReg(0x1C, &threadCtx->fp28.f.f_even);
Fault_PrintFReg(0x1E, &threadCtx->fp30.f.f_even);
Fault_PrintFReg(28, &threadCtx->fp28.f.f_even);
Fault_PrintFReg(30, &threadCtx->fp30.f.f_even);
FaultDrawer_Printf("\n");
FaultDrawer_SetCharPad(0, 0);
@@ -1047,7 +1047,7 @@ void Fault_ThreadEntry(void* arg) {
Fault_ProcessClients();
// Memory dump page
Fault_DrawMemDump((u32)(faultedThread->context.pc - 0x100), (u32)faultedThread->context.sp, 0, 0);
Fault_DrawMemDump(faultedThread->context.pc - 0x100, faultedThread->context.sp, 0, 0);
Fault_DrawStackTrace(faultedThread, 1);
Fault_LogStackTrace(faultedThread, 1);
Fault_WaitForInput();