11#include "irx_imports.h"
17IRX_ID(
"IOP_SIF_rpc_interface", 2, 8);
30 unsigned int *sregs_ptr;
32 void (*sif_1_callback)(
void *userdata);
33 void *sif_1_callback_userdata;
35 unsigned int sregs[32];
45static u8 sif_iop_recvbuf[0x80];
46static u8 sif_unused[0x40];
52 sci->sregs_ptr[pkt->index] = pkt->value;
57 sci->sif_send_eebuf = pkt->newaddr;
60unsigned int sceSifGetSreg(
int index)
62 return sif_cmd_data.sregs[index];
65void sceSifSetSreg(
int index,
unsigned int value)
67 sif_cmd_data.sregs[index] = value;
79 if ( pkt->header.
opt )
81 iSetEventFlag(sci->ef, 0x800u);
85 iSetEventFlag(sci->ef, 0x100u);
87 sci->sif_send_eebuf = pkt->newaddr;
91int _start(
int ac,
char **av)
98 BootMode3 = QueryBootMode(3);
103 BootMode3_1 = BootMode3[1];
104 if ( (BootMode3_1 & 1) != 0 )
106 printf(
" No SIF service(sifcmd)\n");
109 if ( (BootMode3_1 & 2) != 0 )
111 printf(
" No SIFCMD/RPC service\n");
115 if ( !sceSifCheckInit() )
117 if ( RegisterLibraryEntries(&_exp_sifcmd) == 0 )
121 sif_cmd_data.pktbuf = sif_iop_recvbuf;
122 sif_cmd_data.unused = sif_unused;
123 sif_cmd_data.sys_cmd_handlers = sif_cmd_data.sys_cmd_handler_handler;
124 sif_cmd_data.nr_sys_handlers =
125 sizeof(sif_cmd_data.sys_cmd_handler_handler) /
sizeof(sif_cmd_data.sys_cmd_handler_handler[0]);
126 sif_cmd_data.sif_send_eebuf = 0;
127 sif_cmd_data.usr_cmd_handlers = 0;
128 sif_cmd_data.nr_usr_handlers = 0;
129 sif_cmd_data.sregs_ptr = sif_cmd_data.sregs;
130 sif_cmd_data.sif_1_callback = 0;
131 sif_cmd_data.sif_1_callback_userdata = 0;
132 for ( i = 0; i <
sizeof(sif_cmd_data.sys_cmd_handler_handler) /
sizeof(sif_cmd_data.sys_cmd_handler_handler[0]);
135 sif_cmd_data.sys_cmd_handler_handler[i].handler = NULL;
136 sif_cmd_data.sys_cmd_handler_handler[i].harg = NULL;
138 for ( i = 0; i <
sizeof(sif_cmd_data.sregs) /
sizeof(sif_cmd_data.sregs[0]); i += 1 )
140 sif_cmd_data.sregs[i] = 0;
142 sif_cmd_data.sys_cmd_handler_handler[0].handler = (SifCmdHandler_t)sif_sys_cmd_handler_change_addr;
143 sif_cmd_data.sys_cmd_handler_handler[0].harg = &sif_cmd_data;
144 sif_cmd_data.sys_cmd_handler_handler[1].handler = (SifCmdHandler_t)sif_sys_cmd_handler_set_sreg;
145 sif_cmd_data.sys_cmd_handler_handler[1].harg = &sif_cmd_data;
146 sif_cmd_data.ef = GetSystemStatusFlag();
147 sif_cmd_data.sys_cmd_handler_handler[2].handler = (SifCmdHandler_t)sif_sys_cmd_handler_init_from_ee;
148 sif_cmd_data.sys_cmd_handler_handler[2].harg = &sif_cmd_data;
149 RegisterIntrHandler(IOP_IRQ_DMA_SIF1, 1, (
int (*)(
void *))sif_cmd_int_handler, &sif_cmd_data);
151 sceSifSetSubAddr((u32)sif_iop_recvbuf);
157int sifcmd_deinit(
void)
170void sceSifInitCmd(
void)
173 WaitEventFlag(sif_cmd_data.ef, 0x100u, 0, 0);
176void sceSifExitCmd(
void)
186 sif_cmd_data.usr_cmd_handlers = cmdBuffer;
187 sif_cmd_data.nr_usr_handlers = size;
192 sif_cmd_data.sys_cmd_handlers = sysCmdBuffer;
193 sif_cmd_data.nr_sys_handlers = size;
196void sceSifAddCmdHandler(
int cid, SifCmdHandler_t handler,
void *harg)
200 sif_cmd_data.usr_cmd_handlers[cid].handler = handler;
201 sif_cmd_data.usr_cmd_handlers[cid].harg = harg;
205 sif_cmd_data.sys_cmd_handlers[cid + (cid & 0x7FFFFFFF)].handler = handler;
206 sif_cmd_data.sys_cmd_handlers[cid + (cid & 0x7FFFFFFF)].harg = harg;
210void sceSifRemoveCmdHandler(
int cid)
213 sif_cmd_data.usr_cmd_handlers[cid].handler = NULL;
215 sif_cmd_data.sys_cmd_handlers[cid + (cid & 0x7FFFFFFF)].handler = NULL;
218static int sif_send_cmd_common(
226 void (*completion_cb)(
void *),
227 void *completion_cb_userdata)
237 if ( (
unsigned int)(packet_size - 16) >= 0x61 )
240 if ( size_extra <= 0 )
244 tmp1 = *(u8 *)packet;
246 *(u32 *)packet = tmp1;
253 dmat[0].dest = dest_extra;
254 dmat[0].size = size_extra;
256 dmat[0].src = src_extra;
257 tmp2 = *(u8 *)packet;
258 packet->
dest = dest_extra;
259 *(u32 *)packet = tmp2 | (size_extra << 8);
261 dmatp = &dmat[dmatc1];
263 *(u8 *)packet = packet_size;
266 sif_send_eebuf = sif_cmd_data.sif_send_eebuf;
268 dmatp->size = packet_size;
269 dmatp->dest = (
void *)sif_send_eebuf;
270 if ( (flags & 1) != 0 )
272 if ( (flags & 8) != 0 )
273 return sceSifSetDmaIntr(dmat, dmatc2, completion_cb, completion_cb_userdata);
275 return sceSifSetDma(dmat, dmatc2);
282 if ( (flags & 8) != 0 )
283 dmar2 = sceSifSetDmaIntr(dmat, dmatc2, completion_cb, completion_cb_userdata);
285 dmar2 = sceSifSetDma(dmat, dmatc2);
292unsigned int sceSifSendCmd(
int cmd,
void *packet,
int packet_size,
void *src_extra,
void *dest_extra,
int size_extra)
294 return sif_send_cmd_common(cmd, 0, (
SifCmdHeader_t *)packet, packet_size, src_extra, dest_extra, size_extra, 0, 0);
297unsigned int sceSifSendCmdIntr(
304 void (*completion_cb)(
void *),
305 void *completion_cb_userdata)
307 return sif_send_cmd_common(
315 (
void (*)(
void *))completion_cb,
316 completion_cb_userdata);
319unsigned int isceSifSendCmd(
int cmd,
void *packet,
int packet_size,
void *src_extra,
void *dest_extra,
int size_extra)
321 return sif_send_cmd_common(cmd, 1, (
SifCmdHeader_t *)packet, packet_size, src_extra, dest_extra, size_extra, 0, 0);
324unsigned int isceSifSendCmdIntr(
331 void (*completion_cb)(
void *),
332 void *completion_cb_userdata)
334 return sif_send_cmd_common(
342 (
void (*)(
void *))completion_cb,
343 completion_cb_userdata);
346void sceSifSetSif1CB(
void (*func)(
void *userdata),
void *userdata)
348 sif_cmd_data.sif_1_callback = func;
349 sif_cmd_data.sif_1_callback_userdata = userdata;
352void sceSifClearSif1CB(
void)
354 sif_cmd_data.sif_1_callback = NULL;
355 sif_cmd_data.sif_1_callback_userdata = NULL;
360 void (*sif_1_callback)(
void *);
370 sif_1_callback = sci->sif_1_callback;
371 if ( sif_1_callback )
372 sif_1_callback(sci->sif_1_callback_userdata);
374 size = *(u8 *)sci->pktbuf;
375 if ( !*(u8 *)sci->pktbuf )
381 size_calc1 = size + 3;
384 size_calc1 = size + 6;
385 pktwords = size_calc1 >> 2;
388 if ( size_calc1 >> 2 > 0 )
395 tmp1 = *(u32 *)pktbuf2;
399 }
while ( i < pktwords );
402 if ( (tmpbuf1[2] & 0x80000000) == 0 )
404 if ( (
int)tmpbuf1[2] < sci->nr_usr_handlers )
406 if ( sif_cmd_data.usr_cmd_handlers[tmpbuf1[2]].handler != NULL )
408 sif_cmd_data.usr_cmd_handlers[tmpbuf1[2]].handler(tmpbuf1, sif_cmd_data.usr_cmd_handlers[tmpbuf1[2]].harg);
412 else if ( (
signed int)(tmpbuf1[2] & 0x7FFFFFFF) < sci->nr_sys_handlers )
414 if ( sif_cmd_data.sys_cmd_handlers[tmpbuf1[2] + (tmpbuf1[2] & 0x7FFFFFFF)].handler != NULL )
416 sif_cmd_data.sys_cmd_handlers[tmpbuf1[2] + (tmpbuf1[2] & 0x7FFFFFFF)].handler(
417 tmpbuf1, sif_cmd_data.usr_cmd_handlers[tmpbuf1[2] + (tmpbuf1[2] & 0x7FFFFFFF)].harg);
int CpuResumeIntr(int state)
int RegisterIntrHandler(int irq, int mode, int(*handler)(void *), void *arg)
int ReleaseIntrHandler(int irq)
int DisableIntr(int irq, int *res)
int CpuSuspendIntr(int *state)