From 7eb4bc34591cca3e24a6415d5ce01aea56ae1ac3 Mon Sep 17 00:00:00 2001 From: Ethan Lafrenais Date: Thu, 16 Jan 2025 00:32:33 -0500 Subject: [PATCH] Runtime support for RSP overlays (#77) --- librecomp/include/librecomp/rsp.hpp | 25 ++++++++++++++++++++----- librecomp/src/rsp.cpp | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/librecomp/include/librecomp/rsp.hpp b/librecomp/include/librecomp/rsp.hpp index 1bc91e4..748558c 100644 --- a/librecomp/include/librecomp/rsp.hpp +++ b/librecomp/include/librecomp/rsp.hpp @@ -14,10 +14,25 @@ enum class RspExitReason { Broke, ImemOverrun, UnhandledJumpTarget, - Unsupported + Unsupported, + SwapOverlay, + UnhandledResumeTarget }; -using RspUcodeFunc = RspExitReason(uint8_t* rdram); +struct RspContext { + uint32_t r1, r2, r3, r4, r5, r6, r7, + r8, r9, r10, r11, r12, r13, r14, r15, + r16, r17, r18, r19, r20, r21, r22, r23, + r24, r25, r26, r27, r28, r29, r30, r31; + uint32_t dma_mem_address; + uint32_t dma_dram_address; + uint32_t jump_target; + RSP rsp; + uint32_t resume_address; + bool resume_delay; +}; + +using RspUcodeFunc = RspExitReason(uint8_t* rdram, uint32_t ucode_addr); extern uint8_t dmem[]; extern uint16_t rspReciprocals[512]; @@ -74,10 +89,10 @@ static inline void RSP_MEM_H_STORE(uint32_t offset, uint32_t addr, uint32_t val) #define RSP_SIGNED(val) \ ((int32_t)(val)) -#define SET_DMA_DMEM(dmem_addr) dma_dmem_address = (dmem_addr) +#define SET_DMA_MEM(mem_addr) dma_mem_address = (mem_addr) #define SET_DMA_DRAM(dram_addr) dma_dram_address = (dram_addr) -#define DO_DMA_READ(rd_len) dma_rdram_to_dmem(rdram, dma_dmem_address, dma_dram_address, (rd_len)) -#define DO_DMA_WRITE(wr_len) dma_dmem_to_rdram(rdram, dma_dmem_address, dma_dram_address, (wr_len)) +#define DO_DMA_READ(rd_len) dma_rdram_to_dmem(rdram, dma_mem_address, dma_dram_address, (rd_len)) +#define DO_DMA_WRITE(wr_len) dma_dmem_to_rdram(rdram, dma_mem_address, dma_dram_address, (wr_len)) static inline void dma_rdram_to_dmem(uint8_t* rdram, uint32_t dmem_addr, uint32_t dram_addr, uint32_t rd_len) { rd_len += 1; // Read length is inclusive diff --git a/librecomp/src/rsp.cpp b/librecomp/src/rsp.cpp index 50bf73b..1cb3f6a 100644 --- a/librecomp/src/rsp.cpp +++ b/librecomp/src/rsp.cpp @@ -49,7 +49,7 @@ bool recomp::rsp::run_task(uint8_t* rdram, const OSTask* task) { dma_rdram_to_dmem(rdram, 0x0000, task->t.ucode_data, 0xF80 - 1); // Run the ucode - RspExitReason exit_reason = ucode_func(rdram); + RspExitReason exit_reason = ucode_func(rdram, task->t.ucode); // Ensure that the ucode exited correctly if (exit_reason != RspExitReason::Broke) {