From b335bb56d0116b1b99f0bc1f9f20e23b719c732c Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Tue, 21 Sep 2021 21:01:42 -0400 Subject: [PATCH] Remove HW_REG I added to rcp.h, and replace all uses with IO_WRITE / IO_READ --- include/PR/rcp.h | 2 -- lib/src/os/__osSiRawReadIo.c | 13 +++++++------ lib/src/os/__osSiRawWriteIo.c | 16 ++++++++-------- lib/src/os/__osSpSetStatus.c | 2 +- lib/src/unknown_0D3160.c | 16 +++++++--------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/PR/rcp.h b/include/PR/rcp.h index 03786ca5..fc07e79a 100644 --- a/include/PR/rcp.h +++ b/include/PR/rcp.h @@ -68,8 +68,6 @@ The Indy development board use cartridge domain 1: **************************************************************************/ -#define HW_REG(reg, type) *(volatile type *)(u32*)(reg | 0xa0000000) - /************************************************************************* * RDRAM Memory (Assumes that maximum size is 4 MB) */ diff --git a/lib/src/os/__osSiRawReadIo.c b/lib/src/os/__osSiRawReadIo.c index 5ceee26b..799831ad 100644 --- a/lib/src/os/__osSiRawReadIo.c +++ b/lib/src/os/__osSiRawReadIo.c @@ -2,14 +2,15 @@ /* RAM_POS: 0x800D4590 */ #include "types.h" +#include "siint.h" +#include "PR/rcp.h" -#define PHYS_TO_K1(x) ((u32)(x)|0xA0000000) /* physical to kseg1 */ -#define IO_READ(addr) (*(vu32 *)PHYS_TO_K1(addr)) - -s32 __osSiRawReadIo(u32 devAddr, u32 *data) -{ - if (__osSiDeviceBusy()) +s32 __osSiRawReadIo(u32 devAddr, u32 *data) { + if (__osSiDeviceBusy()) { return -1; + } + *data = IO_READ(devAddr); + return 0; } diff --git a/lib/src/os/__osSiRawWriteIo.c b/lib/src/os/__osSiRawWriteIo.c index ba8f340e..877a5931 100644 --- a/lib/src/os/__osSiRawWriteIo.c +++ b/lib/src/os/__osSiRawWriteIo.c @@ -2,15 +2,15 @@ /* RAM_POS: 0x800D45E0 */ #include "types.h" +#include "siint.h" +#include "PR/rcp.h" -#define PHYS_TO_K1(x) ((u32)(x)|0xA0000000) /* physical to kseg1 */ -#define IO_WRITE(addr,data) (*(vu32 *)PHYS_TO_K1(addr)=(u32)(data)) - -s32 __osSiRawWriteIo(u32 devAddr, u32 data) -{ - - if (__osSiDeviceBusy()) +s32 __osSiRawWriteIo(u32 devAddr, u32 data) { + if (__osSiDeviceBusy()) { return -1; + } + IO_WRITE(devAddr, data); + return 0; -} \ No newline at end of file +} diff --git a/lib/src/os/__osSpSetStatus.c b/lib/src/os/__osSpSetStatus.c index 580cf8a7..9355883a 100644 --- a/lib/src/os/__osSpSetStatus.c +++ b/lib/src/os/__osSpSetStatus.c @@ -6,5 +6,5 @@ #include "PR/rcp.h" void __osSpSetStatus(u32 status) { - HW_REG(SP_STATUS_REG, u32) = status; + IO_WRITE(SP_STATUS_REG, status); } diff --git a/lib/src/unknown_0D3160.c b/lib/src/unknown_0D3160.c index 35ed4a6e..754460cd 100644 --- a/lib/src/unknown_0D3160.c +++ b/lib/src/unknown_0D3160.c @@ -9,24 +9,22 @@ GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3160/__osDisableInt.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3160/__osRestoreInt.s") -s32 osPiRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size) -{ +s32 osPiRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size) { register int status; - status = HW_REG(PI_STATUS_REG, u32); + status = IO_READ(PI_STATUS_REG); while (status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY | PI_STATUS_ERROR)) { - status = HW_REG(PI_STATUS_REG, u32); + status = IO_READ(PI_STATUS_REG); } - HW_REG(PI_DRAM_ADDR_REG, void *) = (void *) osVirtualToPhysical(dramAddr); - - HW_REG(PI_CART_ADDR_REG, void *) = (void *) (((uintptr_t) osRomBase | devAddr) & 0x1fffffff); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(osRomBase | devAddr)); switch (direction) { case OS_READ: - HW_REG(PI_WR_LEN_REG, u32) = size - 1; + IO_WRITE(PI_WR_LEN_REG, size - 1); break; case OS_WRITE: - HW_REG(PI_RD_LEN_REG, u32) = size - 1; + IO_WRITE(PI_RD_LEN_REG, size - 1); break; default: return -1;