static arch_message *try_alloc_msg(void) { unsigned int i; arch_message *message; int OldState; if(PollSema(MsgCountSema)==0){ 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); }else message=NULL; return message; }
s32 sceCdSearchFile(sceCdlFILE * file, const char *name) { s32 i; sceCdSemaInit(); if (PollSema(nCmdSemaId) != nCmdSemaId) return 0; nCmdNum = CD_SERVER_SEARCHFILE; ReferThreadStatus(sceCdThreadId, &sceCdThreadParam); if (sceCdSync(1)) { SignalSema(nCmdSemaId); return 0; } SifInitRpc(0); if (bindSearchFile < 0) { while (1) { if (SifBindRpc(&clientSearchFile, CD_SERVER_SEARCHFILE, 0) < 0) { if (sceCdDebug > 0) printf("libsceCdvd bind err sceCdSearchFile\n"); } if (clientSearchFile.server != 0) break; i = 0x10000; while (i--); } bindSearchFile = 0; } strncpy(searchFileSendBuff.name, name, 255); searchFileSendBuff.name[255] = '\0'; searchFileSendBuff.dest = &searchFileSendBuff; if (sceCdDebug > 0) printf("ee call cmd search %s\n", searchFileSendBuff.name); if (SifCallRpc(&clientSearchFile, 0, 0, &searchFileSendBuff, sizeof(SearchFilePkt), nCmdRecvBuff, 4, 0, 0) < 0) { SignalSema(nCmdSemaId); return 0; } memcpy(file, UNCACHED_SEG(&searchFileSendBuff), 32); if (sceCdDebug > 0) { printf("search name %s\n", file->name); printf("search size %d\n", file->size); printf("search loc lnn %d\n", file->lsn); printf("search loc date %02X %02X %02X %02X %02X %02X %02X %02X\n", file->date[0], file->date[1], file->date[2], file->date[3], file->date[4], file->date[5], file->date[6], file->date[7]); printf("search loc date %02d %02d %02d %02d %02d %02d %02d %02d\n", file->date[0], file->date[1], file->date[2], file->date[3], file->date[4], file->date[5], file->date[6], file->date[7]); } SignalSema(nCmdSemaId); // return 1; return *(s32*)UNCACHED_SEG(nCmdRecvBuff); }
bool AsyncFio::fioAvail(void) { bool retVal = false; if (PollSema(_ioSema) > 0) { if (_runningOp) { if (fileXioWaitAsync(FXIO_NOWAIT, (int *)_runningOp) == FXIO_COMPLETE) { _runningOp = NULL; retVal = true; } else retVal = false; } else retVal = true; SignalSema(_ioSema); } return retVal; }
bool AsyncFio::poll(int fd) { bool retVal = false; if (PollSema(_ioSema) >= 0) { if (_runningOp == _ioSlots + fd) { if (fileXioWaitAsync(FXIO_NOWAIT, (int *)_runningOp) == FXIO_COMPLETE) { _runningOp = NULL; retVal = true; } else retVal = false; } else retVal = true; SignalSema(_ioSema); } return retVal; }
u32_t sys_arch_sem_wait(sys_sem_t Sema,u32_t u32Timeout) { //Wait u32Timeout msec for the Sema to receive a signal. dbgprintf("sys_arch_sem_wait: Sema: %d, Timeout: %x (TID: %d)\n",Sema,u32Timeout,GetThreadId()); if(u32Timeout==0) { //Wait with no timeouts. return WaitSema(Sema)==0 ? 0:SYS_ARCH_TIMEOUT; } else if(u32Timeout==1) { //Poll. return PollSema(Sema)==0 ? 0:SYS_ARCH_TIMEOUT; } else { //Use alarm to timeout. iop_sys_clock_t ClockTicks; iop_sys_clock_t Start; iop_sys_clock_t End; int iPID=GetThreadId(); u32_t u32WaitTime; GetSystemTime(&Start); USec2SysClock(u32Timeout*1000,&ClockTicks); SetAlarm(&ClockTicks,TimeoutHandler,(void*)iPID); if(WaitSema(Sema)!=0) { return SYS_ARCH_TIMEOUT; } CancelAlarm(TimeoutHandler,(void*)iPID); GetSystemTime(&End); u32WaitTime=ComputeTimeDiff(&Start,&End); return u32WaitTime<=u32Timeout ? u32WaitTime:u32Timeout; } }
int PS2KbdReadRaw(PS2KbdRawKey *key) /* Reads 1 raw character from the keyboard */ { int res; if ((!kbdInitialized) || (curr_readmode != PS2KBD_READMODE_RAW)) return -1; if (PollSema(kbdRpcSema) >= 0) { // last rpc call completed res = (rpcKey != 0); *key = *(PS2KbdRawKey *)UNCACHED_SEG(&rpcKey); SifCallRpc(&cd0, KBD_RPC_READRAW, SIF_RPC_M_NOWAIT, rpcBuf, 0, &rpcKey, 4, rpcCompleteIntr, NULL); return res; } else // rpc still running return 0; }
static arch_message *try_alloc_msg(void) { arch_message *message; int OldState; if(PollSema(MsgCountSema)==0) { CpuSuspendIntr(&OldState); message = free_head; free_head = free_head->next; CpuResumeIntr(OldState); }else message=NULL; return message; }
s32 sceCdDiskReady(s32 mode) { s32 i; if (sceCdDebug > 0) printf("DiskReady 0\n"); sceCdSemaInit(); if (PollSema(sCmdSemaId) != sCmdSemaId) return SCECdNotReady; if (sceCdSyncS(1)) { SignalSema(sCmdSemaId); return SCECdNotReady; } SifInitRpc(0); if (bindDiskReady < 0) { while (1) { if (SifBindRpc(&clientDiskReady, CD_SERVER_DISKREADY, 0) < 0) { if (sceCdDebug > 0) printf("LibsceCdvd bind err CdDiskReady\n"); } if (clientDiskReady.server != 0) break; i = 0x10000; while (i--); } } bindDiskReady = 0; diskReadyMode = mode; if (SifCallRpc(&clientDiskReady, 0, 0, &diskReadyMode, 4, sCmdRecvBuff, 4, 0, 0) < 0) { SignalSema(sCmdSemaId); return 6; } if (sceCdDebug > 0) printf("DiskReady ended\n"); SignalSema(sCmdSemaId); return *(s32 *) UNCACHED_SEG(sCmdRecvBuff); }
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { //Wait TimeElaspedout msec for the Sema to receive a signal. dbgprintf("sys_arch_sem_wait: Sema: %d, Timeout: %x (TID: %d)\n", *sem, timeout, GetThreadId()); u32_t result; if(timeout==0) { //Wait with no timeouts. result=(WaitSema(*sem)==0)?0:SYS_ARCH_TIMEOUT; } else if(timeout==1) { //Poll. result=(PollSema(*sem)==0)?0:SYS_ARCH_TIMEOUT; } else { //Use alarm to timeout. iop_sys_clock_t ClockTicks; iop_sys_clock_t Start; iop_sys_clock_t End; int iPID=GetThreadId(); u32_t u32WaitTime; GetSystemTime(&Start); USec2SysClock(timeout*1000,&ClockTicks); SetAlarm(&ClockTicks, &TimeoutHandler, (void*)iPID); if(WaitSema(*sem)==0){ CancelAlarm(TimeoutHandler,(void*)iPID); GetSystemTime(&End); u32WaitTime=ComputeTimeDiff(&Start, &End); result=(u32WaitTime<=timeout)?u32WaitTime:timeout; }else result=SYS_ARCH_TIMEOUT; } return result; }
int fioSync(int mode, int *retVal) { int res; if ((res = fioInit()) < 0) return res; if(_fio_block_mode != FIO_NOWAIT) return -E_LIB_UNSUPPORTED; switch(mode) { case FIO_WAIT: WaitSema(_fio_completion_sema); SignalSema(_fio_completion_sema); if(retVal != NULL) *retVal = *(int *)UNCACHED_SEG(&_fio_recv_data[0]); return FIO_COMPLETE; case FIO_NOWAIT: if(PollSema(_fio_completion_sema) < 0) return FIO_INCOMPLETE; SignalSema(_fio_completion_sema); if(retVal != NULL) *retVal = *(int *)UNCACHED_SEG(&_fio_recv_data[0]); return FIO_COMPLETE; default: return -E_LIB_UNSUPPORTED; } }