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_DMA_SPADDR ((volatile uint32_t*)0xA4040000)
178#define SP_DMA_RAMADDR ((volatile uint32_t*)0xA4040004)
180#define SP_DMA_RDLEN ((volatile uint32_t*)0xA4040008)
182#define SP_DMA_WRLEN ((volatile uint32_t*)0xA404000C)
185#define SP_STATUS ((volatile uint32_t*)0xA4040010)
188#define SP_DMA_FULL ((volatile uint32_t*)0xA4040014)
191#define SP_DMA_BUSY ((volatile uint32_t*)0xA4040018)
194#define SP_SEMAPHORE ((volatile uint32_t*)0xA404001C)
197#define SP_STATUS_HALTED (1 << 0)
199#define SP_STATUS_BROKE (1 << 1)
201#define SP_STATUS_DMA_BUSY (1 << 2)
203#define SP_STATUS_DMA_FULL (1 << 3)
205#define SP_STATUS_IO_BUSY (1 << 4)
207#define SP_STATUS_SSTEP (1 << 5)
209#define SP_STATUS_INTERRUPT_ON_BREAK (1 << 6)
211#define SP_STATUS_SIG0 (1 << 7)
213#define SP_STATUS_SIG1 (1 << 8)
215#define SP_STATUS_SIG2 (1 << 9)
217#define SP_STATUS_SIG3 (1 << 10)
219#define SP_STATUS_SIG4 (1 << 11)
221#define SP_STATUS_SIG5 (1 << 12)
223#define SP_STATUS_SIG6 (1 << 13)
225#define SP_STATUS_SIG7 (1 << 14)
227#define SP_WSTATUS_CLEAR_HALT 0x00001
228#define SP_WSTATUS_SET_HALT 0x00002
229#define SP_WSTATUS_CLEAR_BROKE 0x00004
230#define SP_WSTATUS_CLEAR_INTR 0x00008
231#define SP_WSTATUS_SET_INTR 0x00010
232#define SP_WSTATUS_CLEAR_SSTEP 0x00020
233#define SP_WSTATUS_SET_SSTEP 0x00040
234#define SP_WSTATUS_CLEAR_INTR_BREAK 0x00080
235#define SP_WSTATUS_SET_INTR_BREAK 0x00100
236#define SP_WSTATUS_CLEAR_SIG0 0x00200
237#define SP_WSTATUS_SET_SIG0 0x00400
238#define SP_WSTATUS_CLEAR_SIG1 0x00800
239#define SP_WSTATUS_SET_SIG1 0x01000
240#define SP_WSTATUS_CLEAR_SIG2 0x02000
241#define SP_WSTATUS_SET_SIG2 0x04000
242#define SP_WSTATUS_CLEAR_SIG3 0x08000
243#define SP_WSTATUS_SET_SIG3 0x10000
244#define SP_WSTATUS_CLEAR_SIG4 0x20000
245#define SP_WSTATUS_SET_SIG4 0x40000
246#define SP_WSTATUS_CLEAR_SIG5 0x80000
247#define SP_WSTATUS_SET_SIG5 0x100000
248#define SP_WSTATUS_CLEAR_SIG6 0x200000
249#define SP_WSTATUS_SET_SIG6 0x400000
250#define SP_WSTATUS_CLEAR_SIG7 0x800000
251#define SP_WSTATUS_SET_SIG7 0x1000000
261 uint16_t vaccum[3][8];
265 uint8_t dmem[4096] __attribute__((aligned(8)));
266 uint8_t imem[4096] __attribute__((aligned(8)));
344#define DEFINE_RSP_UCODE(ucode_name, ...) \
345 extern uint8_t ucode_name ## _text_start[]; \
346 extern uint8_t ucode_name ## _data_start[]; \
347 extern uint8_t ucode_name ## _text_end[0]; \
348 extern uint8_t ucode_name ## _data_end[0]; \
349 rsp_ucode_t ucode_name = (rsp_ucode_t){ \
350 .code = ucode_name ## _text_start, \
351 .data = ucode_name ## _data_start, \
352 .code_end = ucode_name ## _text_end, \
353 .data_end = ucode_name ## _data_end, \
354 .name = #ucode_name, .start_pc = 0, \
355 .crash_handler = 0, .assert_handler = 0, \
416void rsp_load_code(
void* code,
unsigned long size,
unsigned int imem_offset);
429void rsp_load_data(
void* data,
unsigned long size,
unsigned int dmem_offset);
443void rsp_read_code(
void* code,
unsigned long size,
unsigned int imem_offset);
456void rsp_read_data(
void* data,
unsigned long size,
unsigned int dmem_offset);
482#define rsp_crash() ({ \
483 __rsp_crash(__FILE__, __LINE__, __func__, NULL); \
486#define rsp_crash() abort()
505#define rsp_crashf(msg, ...) ({ \
506 __rsp_crash(__FILE__, __LINE__, __func__, msg, ##__VA_ARGS__); \
509#define rsp_crashf(msg, ...) abort()
537#define RSP_WAIT_LOOP(timeout_ms) \
538 for (uint32_t __t = TICKS_READ() + TICKS_FROM_MS(timeout_ms); \
539 TICKS_BEFORE(TICKS_READ(), __t) || (rsp_crashf("wait loop timed out (%d ms)", timeout_ms), false); \
540 __rsp_check_assert(__FILE__, __LINE__, __func__))
542static inline __attribute__((deprecated(
"use rsp_load_code instead")))
543void load_ucode(
void * start,
unsigned long size) {
547static inline __attribute__((deprecated(
"use rsp_read_code instead")))
548void read_ucode(
void * start,
unsigned long size) {
552static inline __attribute__((deprecated(
"use rsp_load_data instead")))
553void load_data(
void * start,
unsigned long size) {
557static inline __attribute__((deprecated(
"use rsp_read_data instead")))
558void read_data(
void * start,
unsigned long size) {
562static inline __attribute__((deprecated(
"use rsp_run_async instead")))
563void run_ucode(
void) {
571void __rsp_crash(
const char *file,
int line,
const char *func,
const char *msg, ...)
572 __attribute__((noreturn, format(printf, 4, 5)));
573void __rsp_check_assert(const
char *file,
int line, const
char *func);
575static 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:150
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:66
uint32_t pc
Program counter.
Definition rsp.h:264
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:108
void rsp_wait(void)
Wait until RSP has finished processing.
Definition rsp.c:158
void rsp_run_async(void)
Run RSP async.
Definition rsp.h:388
void rsp_run(void)
Run RSP ucode.
Definition rsp.c:169
void rsp_load(rsp_ucode_t *ucode)
Load a RSP ucode.
Definition rsp.c:58
void rsp_init(void)
Initialize the RSP subsytem.
Definition rsp.c:49
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:89
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:129
#define SP_WSTATUS_SET_INTR_BREAK
SP_STATUS write mask: set SSTEP bit.
Definition rsp.h:235
Snapshot of the register status of the RSP.
Definition rsp.h:258
RSP ucode definition.
Definition rsp.h:279
void * code_end
Pointer past the end of the code segment.
Definition rsp.h:281
uint8_t * code
Pointer to the code segment.
Definition rsp.h:280
const char * name
Name of the ucode.
Definition rsp.h:285
void * data_end
Pointer past the end of the data segment.
Definition rsp.h:283
uint32_t start_pc
Initial RSP PC.
Definition rsp.h:286
uint8_t * data
Pointer to the data segment.
Definition rsp.h:282