Skip to content

Commit

Permalink
Runtime support for RSP overlays (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Francessco121 authored Jan 16, 2025
1 parent 50029c7 commit 7eb4bc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions librecomp/include/librecomp/rsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion librecomp/src/rsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7eb4bc3

Please sign in to comment.