//////////////////////////////entrypoint/////////////////////////////// int _start(int argc, char* argv[]){ int x; register int ch; if (RegisterLibraryEntries(&dmacman_stub)) //loadcore return 1; CpuSuspendIntr(&x); //intrman dmacSetDPCR(0x07777777); dmacSetDPCR2(0x07777777); dmacSetDPCR3(0x00000777); for (ch=0; ch<13; ch++){ dmacSetD_MADR(ch, 0); dmacSetD_BCR (ch, 0); dmacSetD_CHCR(ch, 0); } dmacSetD_TADR( DMAch_SPU, 0); dmacSetD_TADR( DMAch_SIF0,0); dmacSet_4_9_A( DMAch_SPU, 0); dmacSet_4_9_A( DMAch_SIF0,0); dmacSet_4_9_A( DMAch_SIF1,0); dmacSetBF801578(1); CpuResumeIntr(x); //intrman return 0; }
static SMapStatus AddToQueue ( PBuf* pBuf ) { int iIntFlags; SMapStatus Ret; CpuSuspendIntr ( &iIntFlags ); if ( !iReqCNT ) { Ret = SMap_Send ( pBuf ); if ( Ret == SMap_TX ) { iTimeoutCNT = 0; goto storeLast; } /* end if */ } else if ( iReqCNT < MAX_REQ_CNT ) { storeLast: apReqQueue[ ( iReqNR + iReqCNT ) % MAX_REQ_CNT ] = pBuf; ++iReqCNT; ++pBuf -> ref; Ret = SMap_OK; } else Ret = SMap_TX; CpuResumeIntr ( iIntFlags ); return Ret; } /* end AddToQueue */
void free(void *ptr){ int flags; CpuSuspendIntr(&flags); FreeSysMemory(ptr); CpuResumeIntr(flags); }
void free(void *buffer){ int OldState; CpuSuspendIntr(&OldState); FreeSysMemory(buffer); CpuResumeIntr(OldState); }
sys_prot_t sys_arch_protect(void) { sys_prot_t Flags; CpuSuspendIntr(&Flags); return Flags; }
int fileXio_getstat_RPC(char *filename, void* eeptr) { iox_stat_t localStat; int res = 0; struct t_SifDmaTransfer dmaStruct; int intStatus; // interrupt status - for dis/en-abling interrupts res = getstat(filename, &localStat); if(res >= 0) { // DMA localStat to the address specified by eeptr // setup the dma struct dmaStruct.src = &localStat; dmaStruct.dest = eeptr; dmaStruct.size = sizeof(iox_stat_t); dmaStruct.attr = 0; // Do the DMA transfer CpuSuspendIntr(&intStatus); SifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); } return(res); }
int AddDrv(iop_device_t *device) { int i, res = -1; int oldIntr; CpuSuspendIntr(&oldIntr); for (i = 0; i < MAX_DEVICES; i++) { if (dev_list[i] == NULL) break; } if (i >= MAX_DEVICES) { CpuResumeIntr(oldIntr); return res; } dev_list[i] = device; CpuResumeIntr(oldIntr); FlushIcache(); if ((res = device->ops->init(device)) < 0) { dev_list[i] = NULL; return(-1); } return(0); }
int fileXio_GetDeviceList_RPC(struct fileXioDevice* ee_devices, int eecount) { int device_count = 0; iop_device_t **devices = GetDeviceList(); struct fileXioDevice local_devices[FILEXIO_MAX_DEVICES]; while (devices[device_count] && device_count < eecount) { iop_device_t *device = devices[device_count]; strncpy(local_devices[device_count].name, device->name, 128); local_devices[device_count].name[127] = '\0'; local_devices[device_count].type = device->type; local_devices[device_count].version = device->version; strncpy(local_devices[device_count].desc, device->desc, 128); local_devices[device_count].desc[127] = '\0'; ++device_count; } if (device_count) { struct t_SifDmaTransfer dmaStruct; int intStatus; // interrupt status - for dis/en-abling interrupts dmaStruct.src = local_devices; dmaStruct.dest = ee_devices; dmaStruct.size = sizeof(struct fileXioDevice) * device_count; dmaStruct.attr = 0; // Do the DMA transfer CpuSuspendIntr(&intStatus); SifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); } return device_count; }
///////////////////////////////////////////////////////////////////////[0E] void SifInitRpc(int mode){ u32 x; _dprintf("%s\n", __FUNCTION__); SifInitCmd(); CpuSuspendIntr(&x); if (sifInitRpc){ CpuResumeIntr(x); }else{ sifInitRpc=1; rpc_common.paddr=(RPC_PACKET*)bufx; rpc_common.size=32; rpc_common.paddr2=0; rpc_common.size2=0; rpc_common.next=(RPC_PACKET*)bufy; rpc_common.count=32; rpc_common.base=0; rpc_common.pid=1; SifAddCmdHandler(0x80000008, (cmdh_func)cmd80000008_END, &rpc_common); SifAddCmdHandler(0x80000009, (cmdh_func)cmd80000009_BIND, &rpc_common); SifAddCmdHandler(0x8000000A, (cmdh_func)cmd8000000A_CALL, &rpc_common); SifAddCmdHandler(0x8000000C, (cmdh_func)cmd8000000C_RDATA, &rpc_common); CpuResumeIntr(x); ((SifCmdSRData*)bufx)->rno =0; ((SifCmdSRData*)bufx)->value=1; SifSendCmd(0x80000001, (void*)bufx, sizeof(SifCmdSRData), 0, 0, 0); } WaitEventFlag(GetSystemStatusFlag(), 0x800, 0, 0); }
RPC_PACKET *rpc_get_packet(struct tag_rpc_common *common){ u32 x; register int pid, i; RPC_PACKET *packet; CpuSuspendIntr(&x); for (i=0, packet=common->paddr; i<common->size; i++) if (packet[i].rec_id & 2==0) goto found; for (i=0, packet=common->paddr2; i<common->size2; i++) if (packet[i].rec_id & 2==0) goto found; CpuResumeIntr(x); return 0; found: packet[i].rec_id |= 2; pid=++common->pid; if (pid == 1) common->pid++; packet[i].pid=pid; packet[i].paddr=&packet[i]; CpuResumeIntr(x); return &packet[i]; }
///////////////////////////////////////////////////////////////////////[11] void SifRegisterRpc(struct sifcmd_RPC_SERVER_DATA *sd, u32 command, rpch_func func, void *buff, rpch_func cfunc, void *cbuff, struct sifcmd_RPC_DATA_QUEUE *qd) { u32 x; register struct sifcmd_RPC_DATA_QUEUE *q, *i; CpuSuspendIntr(&x); sd->command=command; sd->func=func; sd->buff=buff; sd->next=0; sd->link=0; sd->cfunc=cfunc; sd->cbuff=cbuff; sd->base=qd; if (qd->link==0) qd->link=sd; else{ for (q=qd->link, i=q->link; i; i=q->link) q=q->link; q->link=sd; } CpuResumeIntr(x); }
void fileXio_Thread(void* param) { int OldState; printf("fileXio: fileXio RPC Server v1.00\nCopyright (c) 2003 adresd\n"); #ifdef DEBUG printf("fileXio: RPC Initialize\n"); #endif SifInitRpc(0); RWBufferSize=DEFAULT_RWSIZE; CpuSuspendIntr(&OldState); rwbuf = AllocSysMemory(ALLOC_FIRST, RWBufferSize, NULL); CpuResumeIntr(OldState); if (rwbuf == NULL) { #ifdef DEBUG printf("Failed to allocate memory for RW buffer!\n"); #endif SleepThread(); } SifSetRpcQueue(&qd, GetThreadId()); SifRegisterRpc(&sd0, FILEXIO_IRX, &fileXio_rpc_server, fileXio_rpc_buffer, NULL, NULL, &qd); SifRpcLoop(&qd); }
//-------------------------------------------------------------- int _McChDir(void *rpc_buf) { g_nameParam_t *nP = (g_nameParam_t *)rpc_buf; register int status, r; SifDmaTransfer_t dmaStruct; int intStatus; #ifdef DEBUG DPRINTF("mcserv: _McChDir port%d slot%d newdir %s\n", nP->port, nP->slot, nP->name); #endif r = McChDir(nP->port, nP->slot, nP->name, (char *)mcserv_buf); dmaStruct.src = (void *)mcserv_buf; dmaStruct.dest = (void *)nP->mcT; dmaStruct.size = 1024; dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); while (sceSifDmaStat(status) >= 0) DelayThread(100); return r; }
static err_t SMapLowLevelOutput ( NetIF* pNetIF, PBuf* pOutput ) { while ( 1 ) { int iFlags; SMapStatus Res; if ( ( Res = AddToQueue ( pOutput ) ) == SMap_OK ) return ERR_OK; if ( Res == SMap_Err ) return ERR_IF; if ( Res == SMap_Con ) return ERR_CONN; WaitSema ( iSendMutex ); CpuSuspendIntr ( &iFlags ); if ( iReqCNT == MAX_REQ_CNT ) { iSendReq = iSendReqMutex; CpuResumeIntr ( iFlags ); WaitSema ( iSendReqMutex ); } else CpuResumeIntr ( iFlags ); SignalSema ( iSendMutex ); } /* end while */ } /* end SMapLowLevelOutput */
static arch_message *alloc_msg(void) { unsigned int i; arch_message *message; int OldState; WaitSema(MsgCountSema); CpuSuspendIntr(&OldState); for(i=0,message=NULL; i<SYS_MAX_MESSAGES; i++) { if((msg_pool[i].next == NULL) && (msg_pool[i].sys_msg == NULL)) { msg_pool[i].next = (arch_message *) 0xFFFFFFFF; msg_pool[i].sys_msg = (void *) 0xFFFFFFFF; message=&msg_pool[i]; break; } } CpuResumeIntr(OldState); return message; }
//-------------------------------------------------------------- int _McGetInfo2(void *rpc_buf) { g_descParam_t *dP = (g_descParam_t *)rpc_buf; register int status, mc_free, r; g_endParam2_t eP; SifDmaTransfer_t dmaStruct; int intStatus; #ifdef DEBUG DPRINTF("mcserv: _McGetInfo2 port%d slot%d\n", dP->port, dP->slot); #endif mc_free = 0; r = McDetectCard2(dP->port, dP->slot); if (dP->origin > 0) eP.fastIO1_size = McGetMcType(dP->port, dP->slot); if (r < -1) { eP.fastIO2_size = 0; eP.flag = 0; goto dma_transfer; } if (dP->offset > 0) { mc_free = McGetFreeClusters(dP->port, dP->slot); if (mc_free < 0) eP.fastIO2_size = 0; else eP.fastIO2_size = mc_free; } if (dP->size > 0) { eP.flag = 0; if (McGetFormat(dP->port, dP->slot) > 0) eP.flag = 1; } dma_transfer: dmaStruct.src = (void *)&eP; dmaStruct.dest = (void *)dP->param; dmaStruct.size = sizeof (g_endParam2_t); dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); while (sceSifDmaStat(status) >= 0) DelayThread(100); if (mc_free < 0) return mc_free; return r; }
void apaFreeMem(void *ptr) { int intrStat; CpuSuspendIntr(&intrStat); FreeSysMemory(ptr); CpuResumeIntr(intrStat); }
///////////////////////////////////////////////////////////////////////[15] void SifExecRequest(struct sifcmd_RPC_SERVER_DATA *sd){ u32 x; register int size, id, count, i; register void *buff; RPC_PACKET_END *epacket; struct sifman_DMA dma[2]; size=0; if (buff=sd->func(sd->fno, sd->buff, sd->size)) size=sd->rsize; CpuSuspendIntr(&x); epacket=(RPC_PACKET_END *)rpc_get_fpacket(&rpc_common); CpuResumeIntr(x); epacket->command=0x8000000A; epacket->client=sd->client; count=0; if (sd->rmode){ while (SifSendCmd(0x80000008, epacket, 0x40, buff, sd->receive, size)==0); return; }else{ epacket->packet.pid=0; epacket->packet.rec_id=0; if (size>0){ count=1; dma[count-1].data=buff; dma[count-1].size=size; dma[count-1].attr=0; dma[count-1].addr=sd->receive; } count++; dma[count-1].data=epacket; dma[count-1].size=0x40; dma[count-1].attr=0; dma[count-1].addr=sd->pkt_addr; do{ CpuSuspendIntr(&x); id=SifSetDma(dma, count); CpuResumeIntr(x); if (id) break; i=0xFFFF; do --i; while (i!=-1); } while (id==0); } }
void free_msg(arch_message *msg) { int oldIntr; CpuSuspendIntr(&oldIntr); msg->next = NULL; msg->sys_msg = NULL; CpuResumeIntr(oldIntr); }
void* filexioRpc_SetRWBufferSize(void *sbuff) { int OldState; if(rwbuf!=NULL){ CpuSuspendIntr(&OldState); FreeSysMemory(rwbuf); CpuResumeIntr(OldState); } RWBufferSize=((struct fxio_rwbuff*)sbuff)->size; CpuSuspendIntr(&OldState); rwbuf=AllocSysMemory(ALLOC_FIRST, RWBufferSize, NULL); CpuResumeIntr(OldState); ((int*)sbuff)[0] = rwbuf!=NULL?0:-ENOMEM; return sbuff; }
static void InputCB(void* pvArg) { //TCPIP input callback. This function has been registered by ps2ip_input and will be invoked in the context of the //tcpip-thread. Hence, only synchronization for the message-queue is required. InputMSG* pMSG=(InputMSG*)pvArg; PBuf* pInput=pMSG->pInput; NetIF* pNetIF=pMSG->pNetIF; int iFlags; //Remove the first message in the message-queue. BTW: pMSG == &aMSGs[u8FirstMSG]. CpuSuspendIntr(&iFlags); u8FirstMSG=GetNextMSGQueueIndex(u8FirstMSG); CpuResumeIntr(iFlags); //What kind of package is it? switch (htons(((struct eth_hdr*)(pInput->payload))->type)) { case ETHTYPE_IP: //IP-packet. Update ARP table, obtain first queued packet. etharp_ip_input(pNetIF,pInput); //Skip Ethernet header. pbuf_header(pInput,-14); //Pass to network layer. ip_input(pInput,pNetIF); //Send out the ARP reply or ARP queued packet. SendARPReply(pNetIF,NULL); break; case ETHTYPE_ARP: //ARP-packet. Pass pInput to ARP module, get ARP reply or ARP queued packet. etharp_arp_input(pNetIF,(struct eth_addr*)&pNetIF->hwaddr,pInput); //Send out the ARP reply or ARP queued packet. SendARPReply(pNetIF,NULL); break; default: //Unsupported ethernet packet-type. Free pInput. pbuf_free(pInput); } }
void *malloc(int size){ void *result; int OldState; CpuSuspendIntr(&OldState); result = AllocSysMemory(ALLOC_FIRST, size, NULL); CpuResumeIntr(OldState); return result; }
void *malloc(unsigned int nBytes){ int OldState; void *result; CpuSuspendIntr(&OldState); result=AllocSysMemory(ALLOC_FIRST, nBytes, NULL); CpuResumeIntr(OldState); return result; }
void *malloc(unsigned int size){ int flags; void *ptr; CpuSuspendIntr(&flags); ptr=AllocSysMemory(ALLOC_LAST, size, NULL); CpuResumeIntr(flags); return ptr; }
static void free_msg(arch_message *msg) { int oldIntr; CpuSuspendIntr(&oldIntr); msg->next = NULL; msg->sys_msg = NULL; CpuResumeIntr(oldIntr); SignalSema(MsgCountSema); }
void *malloc(unsigned int NumBytes){ int OldState; void *buffer; CpuSuspendIntr(&OldState); buffer=AllocSysMemory(ALLOC_FIRST, NumBytes, NULL); CpuResumeIntr(OldState); return buffer; }
void *apaAllocMem(int size) { int intrStat; void *mem; CpuSuspendIntr(&intrStat); mem = AllocSysMemory(ALLOC_FIRST, size, NULL); CpuResumeIntr(intrStat); return mem; }
static void free_msg(arch_message *msg) { int oldIntr; CpuSuspendIntr(&oldIntr); msg->next = free_head; free_head = msg; CpuResumeIntr(oldIntr); SignalSema(MsgCountSema); }
//////////////////////////////entrypoint/////////////////////////////// int _start(int argc, char* argv[]){ int x; CpuSuspendIntr(&x); if (RegisterLibraryEntries(&export_stub)==0) { CpuResumeIntr(x); return 0; } CpuResumeIntr(x); return 1; }
int _stop ( void ) { int lState; CpuSuspendIntr ( &lState ); DisableIntr ( IOP_IRQ_SIO2, 0 ); ReleaseIntrHandler ( IOP_IRQ_SIO2 ); CpuResumeIntr ( lState ); dmac_disable ( IOP_DMAC_SIO2in ); dmac_disable ( IOP_DMAC_SIO2out ); return GetThreadId (); } /* end _stop */