diff --git a/include/macros.h b/include/macros.h index 59d2319aa7..70c85f2a8e 100644 --- a/include/macros.h +++ b/include/macros.h @@ -4,6 +4,8 @@ #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) +// UB: u32 casts here should be uintptr_t casts. +// TODO: After uintptr_t cast change should have an AVOID_UB target that just toggles the KSEG0 bit in the address rather than add/sub 0x80000000 #define PHYSICAL_TO_VIRTUAL(addr) ((u32)(addr) + 0x80000000) #define PHYSICAL_TO_VIRTUAL2(addr) ((u32)(addr) - 0x80000000) #define SEGMENTED_TO_VIRTUAL(addr) (void*)(PHYSICAL_TO_VIRTUAL(gRspSegmentPhysAddrs[SEGMENT_NUMBER(addr)]) + SEGMENT_OFFSET(addr)) diff --git a/include/variables.h b/include/variables.h index e4ee37e58a..2e25cbaef7 100644 --- a/include/variables.h +++ b/include/variables.h @@ -4109,7 +4109,7 @@ extern UNK_TYPE1 D_801F80F8; // D_801F80F8 extern u64 lastRenderFrameTimestamp; // D_801F8150 extern OSMesgQueue siEventCallbackQueue; // D_801F8160 extern OSMesg siEventCallbackBuffer[1]; // D_801F8178 -extern u32 gRspSegmentPhysAddrs[NUM_SEGMENTS]; // D_801F8180 +extern u32 gRspSegmentPhysAddrs[NUM_SEGMENTS]; // D_801F8180 // u32 type should be uintptr_t extern SchedThreadStruct schedContext; // D_801F81C0 extern OSMesgQueueListNode mainIrqmgrCallbackNode; // D_801F84F8 extern OSMesgQueue mainIrqmgrCallbackQueue; // D_801F8500 diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 24628cdd20..ccdfc7230e 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -145,7 +145,6 @@ void* func_8012F73C(SceneContext* sceneCtxt, s32 iParm2, s16 id) { vromSize = fileTableEntry->vromEnd - fileTableEntry->vromStart; // TODO: UB to cast void to u32 addr = ((u32)sceneCtxt->objects[iParm2].vramAddr) + vromSize; - // TODO: This is ALIGN16 macro from OOT. Seems to be aligning an address to DMA addr = ALIGN16(addr); // UB to cast u32 to pointer return (void*)addr; diff --git a/src/libultra/os/virtualtophysical.c b/src/libultra/os/virtualtophysical.c index 6879f2e951..8150a1a23b 100644 --- a/src/libultra/os/virtualtophysical.c +++ b/src/libultra/os/virtualtophysical.c @@ -2,6 +2,7 @@ #include u32 osVirtualToPhysical(void* virtualAddress) { + // UB: u32 casts here should be uintptr_t casts. if (((u32)virtualAddress >= 0x80000000) && ((u32)virtualAddress < 0xA0000000)) { return (u32)virtualAddress & 0x1FFFFFFF; } else if (((u32)virtualAddress >= 0xA0000000) && ((u32)virtualAddress < 0xC0000000)) {