155#ifndef __LIBDRAGON_RSP_H
156#define __LIBDRAGON_RSP_H
167#define SP_DMEM ((volatile uint32_t*)0xA4000000)
170#define SP_IMEM ((volatile uint32_t*)0xA4001000)
173#define SP_PC ((volatile uint32_t*)0xA4080000)
176#define SP_STATUS ((volatile uint32_t*)0xA4040010)
179#define SP_DMA_FULL ((volatile uint32_t*)0xA4040014)
182#define SP_DMA_BUSY ((volatile uint32_t*)0xA4040018)
185#define SP_SEMAPHORE ((volatile uint32_t*)0xA404001C)
188#define SP_STATUS_HALTED (1 << 0)
190#define SP_STATUS_BROKE (1 << 1)
192#define SP_STATUS_DMA_BUSY (1 << 2)
194#define SP_STATUS_DMA_FULL (1 << 3)
196#define SP_STATUS_IO_BUSY (1 << 4)
198#define SP_STATUS_SSTEP (1 << 5)
200#define SP_STATUS_INTERRUPT_ON_BREAK (1 << 6)
202#define SP_STATUS_SIG0 (1 << 7)
204#define SP_STATUS_SIG1 (1 << 8)
206#define SP_STATUS_SIG2 (1 << 9)
208#define SP_STATUS_SIG3 (1 << 10)
210#define SP_STATUS_SIG4 (1 << 11)
212#define SP_STATUS_SIG5 (1 << 12)
214#define SP_STATUS_SIG6 (1 << 13)
216#define SP_STATUS_SIG7 (1 << 14)
218#define SP_WSTATUS_CLEAR_HALT 0x00001
219#define SP_WSTATUS_SET_HALT 0x00002
220#define SP_WSTATUS_CLEAR_BROKE 0x00004
221#define SP_WSTATUS_CLEAR_INTR 0x00008
222#define SP_WSTATUS_SET_INTR 0x00010
223#define SP_WSTATUS_CLEAR_SSTEP 0x00020
224#define SP_WSTATUS_SET_SSTEP 0x00040
225#define SP_WSTATUS_CLEAR_INTR_BREAK 0x00080
226#define SP_WSTATUS_SET_INTR_BREAK 0x00100
227#define SP_WSTATUS_CLEAR_SIG0 0x00200
228#define SP_WSTATUS_SET_SIG0 0x00400
229#define SP_WSTATUS_CLEAR_SIG1 0x00800
230#define SP_WSTATUS_SET_SIG1 0x01000
231#define SP_WSTATUS_CLEAR_SIG2 0x02000
232#define SP_WSTATUS_SET_SIG2 0x04000
233#define SP_WSTATUS_CLEAR_SIG3 0x08000
234#define SP_WSTATUS_SET_SIG3 0x10000
235#define SP_WSTATUS_CLEAR_SIG4 0x20000
236#define SP_WSTATUS_SET_SIG4 0x40000
237#define SP_WSTATUS_CLEAR_SIG5 0x80000
238#define SP_WSTATUS_SET_SIG5 0x100000
239#define SP_WSTATUS_CLEAR_SIG6 0x200000
240#define SP_WSTATUS_SET_SIG6 0x400000
241#define SP_WSTATUS_CLEAR_SIG7 0x800000
242#define SP_WSTATUS_SET_SIG7 0x1000000
252 uint16_t vaccum[3][8];
256 uint8_t dmem[4096] __attribute__((aligned(8)));
257 uint8_t imem[4096] __attribute__((aligned(8)));
335#define DEFINE_RSP_UCODE(ucode_name, ...) \
336 extern uint8_t ucode_name ## _text_start[]; \
337 extern uint8_t ucode_name ## _data_start[]; \
338 extern uint8_t ucode_name ## _text_end[0]; \
339 extern uint8_t ucode_name ## _data_end[0]; \
340 rsp_ucode_t ucode_name = (rsp_ucode_t){ \
341 .code = ucode_name ## _text_start, \
342 .data = ucode_name ## _data_start, \
343 .code_end = ucode_name ## _text_end, \
344 .data_end = ucode_name ## _data_end, \
345 .name = #ucode_name, .start_pc = 0, \
346 .crash_handler = 0, .assert_handler = 0, \
407void rsp_load_code(
void* code,
unsigned long size,
unsigned int imem_offset);
420void rsp_load_data(
void* data,
unsigned long size,
unsigned int dmem_offset);
434void rsp_read_code(
void* code,
unsigned long size,
unsigned int imem_offset);
447void rsp_read_data(
void* data,
unsigned long size,
unsigned int dmem_offset);
473#define rsp_crash() ({ \
474 __rsp_crash(__FILE__, __LINE__, __func__, NULL); \
477#define rsp_crash() abort()
496#define rsp_crashf(msg, ...) ({ \
497 __rsp_crash(__FILE__, __LINE__, __func__, msg, ##__VA_ARGS__); \
500#define rsp_crashf(msg, ...) abort()
528#define RSP_WAIT_LOOP(timeout_ms) \
529 for (uint32_t __t = TICKS_READ() + TICKS_FROM_MS(timeout_ms); \
530 TICKS_BEFORE(TICKS_READ(), __t) || (rsp_crashf("wait loop timed out (%d ms)", timeout_ms), false); \
531 __rsp_check_assert(__FILE__, __LINE__, __func__))
533static inline __attribute__((deprecated(
"use rsp_load_code instead")))
534void load_ucode(
void * start,
unsigned long size) {
538static inline __attribute__((deprecated(
"use rsp_read_code instead")))
539void read_ucode(
void * start,
unsigned long size) {
543static inline __attribute__((deprecated(
"use rsp_load_data instead")))
544void load_data(
void * start,
unsigned long size) {
548static inline __attribute__((deprecated(
"use rsp_read_data instead")))
549void read_data(
void * start,
unsigned long size) {
553static inline __attribute__((deprecated(
"use rsp_run_async instead")))
554void run_ucode(
void) {
562void __rsp_crash(
const char *file,
int line,
const char *func,
const char *msg, ...)
563 __attribute__((noreturn, format(printf, 4, 5)));
564void __rsp_check_assert(const
char *file,
int line, const
char *func);
566static inline void __rsp_check_assert(
const char *file,
int line,
const char *func) {}
void __rsp_run_async(uint32_t status_flags)
Internal implementation of rsp_run_async.
Definition: rsp.c:148
void rsp_load_code(void *code, unsigned long size, unsigned int imem_offset)
Do a DMA transfer to load a piece of code into RSP IMEM.
Definition: rsp.c:64
uint32_t pc
Program counter.
Definition: rsp.h:255
void rsp_read_code(void *code, unsigned long size, unsigned int imem_offset)
Do a DMA transfer to load a piece of code from RSP IMEM to RDRAM.
Definition: rsp.c:106
void rsp_wait(void)
Wait until RSP has finished processing.
Definition: rsp.c:156
void rsp_run_async(void)
Run RSP async.
Definition: rsp.h:379
void rsp_run(void)
Run RSP ucode.
Definition: rsp.c:167
void rsp_load(rsp_ucode_t *ucode)
Load a RSP ucode.
Definition: rsp.c:56
void rsp_init(void)
Initialize the RSP subsytem.
Definition: rsp.c:47
void rsp_load_data(void *data, unsigned long size, unsigned int dmem_offset)
Do a DMA transfer to load a piece of data into RSP DMEM.
Definition: rsp.c:87
void rsp_read_data(void *data, unsigned long size, unsigned int dmem_offset)
Do a DMA transfer to load a piece of data from RSP DMEM to RDRAM.
Definition: rsp.c:127
#define SP_WSTATUS_SET_INTR_BREAK
SP_STATUS write mask: set SSTEP bit.
Definition: rsp.h:226
Snapshot of the register status of the RSP.
Definition: rsp.h:249
RSP ucode definition.
Definition: rsp.h:270
void * code_end
Pointer past the end of the code segment.
Definition: rsp.h:272
uint8_t * code
Pointer to the code segment.
Definition: rsp.h:271
const char * name
Name of the ucode.
Definition: rsp.h:276
void * data_end
Pointer past the end of the data segment.
Definition: rsp.h:274
uint32_t start_pc
Initial RSP PC.
Definition: rsp.h:277
uint8_t * data
Pointer to the data segment.
Definition: rsp.h:273