Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions ee/kernel/src/delaythread.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,31 @@ static u64 DelayThreadWakeup_callback(s32 alarm_id, u64 scheduled_time, u64 actu
(void)actual_time;
(void)pc_value;

iSignalSema((s32)arg);
iWakeupThread((s32)arg);
ExitHandler();
return 0;
}

s32 DelayThread(s32 microseconds)
{
u32 eie;
s32 sema_id;
volatile s32 thread_id;
s32 timer_alarm_id;
ee_sema_t sema;

eie = get_mips_cop_reg(0, COP0_REG_Status);
if ((eie & 0x10000) == 0)
{
return 0x80008008; // ECPUDI
}
sema.max_count = 1;
sema.option = (u32)"DelayThread";
sema.init_count = 0;
sema_id = CreateSema(&sema);
if (sema_id < 0)
{
return 0x80008003; // ESEMAPHORE
}
timer_alarm_id = SetTimerAlarm(TimerUSec2BusClock(0, microseconds), DelayThreadWakeup_callback, (void *)sema_id);
thread_id = GetThreadId();
timer_alarm_id = SetTimerAlarm(TimerUSec2BusClock(0, microseconds), DelayThreadWakeup_callback, (void *)thread_id);
if (timer_alarm_id < 0)
{
DeleteSema(sema_id);
thread_id = -1;
return timer_alarm_id;
}
WaitSema(sema_id);
DeleteSema(sema_id);
SleepThread();
thread_id = -1;
return 0;
}
#endif
51 changes: 16 additions & 35 deletions ee/kernel/src/sifrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void *_rpc_get_fpacket(struct rpc_data *rpc_data)
#ifdef F_sceSifBindRpc
int sceSifBindRpc(SifRpcClientData_t *cd, int sid, int mode)
{
ee_sema_t sema;
SifRpcBindPkt_t *bind;

bind = (SifRpcBindPkt_t *)_rpc_get_packet(&_sif_rpc_data);
Expand All @@ -138,22 +137,16 @@ int sceSifBindRpc(SifRpcClientData_t *cd, int sid, int mode)
return 0;
}

sema.max_count = 1;
sema.init_count = 0;
cd->hdr.sema_id = CreateSema(&sema);
if (cd->hdr.sema_id < 0) {
rpc_packet_free(bind);
return -E_LIB_SEMA_CREATE;
}
cd->hdr.sema_id = GetThreadId();

if (!sceSifSendCmd(SIF_CMD_RPC_BIND, bind, RPC_PACKET_SIZE, NULL, NULL, 0)) {
rpc_packet_free(bind);
DeleteSema(cd->hdr.sema_id);
cd->hdr.sema_id = -1;
return -E_SIF_PKT_SEND;
}

WaitSema(cd->hdr.sema_id);
DeleteSema(cd->hdr.sema_id);
SleepThread();
cd->hdr.sema_id = -1;

return 0;
}
Expand All @@ -163,7 +156,6 @@ int sceSifBindRpc(SifRpcClientData_t *cd, int sid, int mode)
int sceSifCallRpc(SifRpcClientData_t *cd, int rpc_number, int mode, void *sendbuf,
int ssize, void *recvbuf, int rsize, SifRpcEndFunc_t end_function, void *end_param)
{
ee_sema_t sema;
SifRpcCallPkt_t *call;

call = (SifRpcCallPkt_t *)_rpc_get_packet(&_sif_rpc_data);
Expand Down Expand Up @@ -204,22 +196,16 @@ int sceSifCallRpc(SifRpcClientData_t *cd, int rpc_number, int mode, void *sendbu
return 0;
}

sema.max_count = 1;
sema.init_count = 0;
cd->hdr.sema_id = CreateSema(&sema);
if (cd->hdr.sema_id < 0) {
rpc_packet_free(call);
return -E_LIB_SEMA_CREATE;
}
cd->hdr.sema_id = GetThreadId();

if (!sceSifSendCmd(SIF_CMD_RPC_CALL, call, RPC_PACKET_SIZE, sendbuf, cd->buf, ssize)) {
rpc_packet_free(call);
DeleteSema(cd->hdr.sema_id);
cd->hdr.sema_id = -1;
return -E_SIF_PKT_SEND;
}

WaitSema(cd->hdr.sema_id);
DeleteSema(cd->hdr.sema_id);
SleepThread();
cd->hdr.sema_id = -1;

return 0;
}
Expand All @@ -228,7 +214,6 @@ int sceSifCallRpc(SifRpcClientData_t *cd, int rpc_number, int mode, void *sendbu
#ifdef F_sceSifGetOtherData
int sceSifGetOtherData(SifRpcReceiveData_t *rd, void *src, void *dest, int size, int mode)
{
ee_sema_t sema;
SifRpcOtherDataPkt_t *other;

other = (SifRpcOtherDataPkt_t *)_rpc_get_packet(&_sif_rpc_data);
Expand All @@ -253,22 +238,16 @@ int sceSifGetOtherData(SifRpcReceiveData_t *rd, void *src, void *dest, int size,
return 0;
}

sema.max_count = 1;
sema.init_count = 0;
rd->hdr.sema_id = CreateSema(&sema);
if (rd->hdr.sema_id < 0) {
rpc_packet_free(other);
return -E_LIB_SEMA_CREATE;
}
rd->hdr.sema_id = GetThreadId();

if (!sceSifSendCmd(SIF_CMD_RPC_RDATA, other, RPC_PACKET_SIZE, NULL, NULL, 0)) {
rpc_packet_free(other);
DeleteSema(rd->hdr.sema_id);
rd->hdr.sema_id = -1;
return -E_SIF_PKT_SEND;
}

WaitSema(rd->hdr.sema_id);
DeleteSema(rd->hdr.sema_id);
SleepThread();
rd->hdr.sema_id = -1;

return 0;
}
Expand Down Expand Up @@ -312,8 +291,10 @@ static void _request_end(SifRpcRendPkt_t *request, void *data)
cd->cbuf = request->cbuf;
}

if (cd->hdr.sema_id >= 0)
iSignalSema(cd->hdr.sema_id);
if (cd->hdr.sema_id >= 0) {
iWakeupThread(cd->hdr.sema_id);
cd->hdr.sema_id = -1;
}

rpc_packet_free(cd->hdr.pkt_addr);
cd->hdr.pkt_addr = NULL;
Expand Down
24 changes: 7 additions & 17 deletions ee/libcglue/src/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,33 @@ static u64 nanosleep_wakeup_callback(s32 alarm_id, u64 scheduled_time, u64 actua
(void)actual_time;
(void)pc_value;

iSignalSema((s32)arg);
iWakeupThread((s32)arg);
ExitHandler();
return 0;
}

int nanosleep(const struct timespec *req, struct timespec *rem)
{
u32 eie;
s32 sema_id;
volatile s32 thread_id;
s32 timer_alarm_id;
ee_sema_t sema;

eie = get_mips_cop_reg(0, COP0_REG_Status);
if ((eie & 0x10000) == 0)
{
errno = ENOSYS; // Functionality not available
return -1;
}
sema.max_count = 1;
sema.option = (u32)"nanosleep";
sema.init_count = 0;
sema_id = CreateSema(&sema);
if (sema_id < 0)
{
errno = EAGAIN; // Resource temporarily unavailable
return -1;
}
timer_alarm_id = SetTimerAlarm(Sec2TimerBusClock(req->tv_sec) + NSec2TimerBusClock(req->tv_nsec), nanosleep_wakeup_callback, (void *)sema_id);
thread_id = GetThreadId();
timer_alarm_id = SetTimerAlarm(Sec2TimerBusClock(req->tv_sec) + NSec2TimerBusClock(req->tv_nsec), nanosleep_wakeup_callback, (void *)thread_id);
if (timer_alarm_id < 0)
{
DeleteSema(sema_id);
thread_id = -1;
errno = EAGAIN; // Resource temporarily unavailable
return -1;
}
WaitSema(sema_id);
DeleteSema(sema_id);

SleepThread();
thread_id = -1;
if (rem != NULL)
{
rem->tv_sec = 0;
Expand Down
15 changes: 5 additions & 10 deletions ee/mpeg/src/libmpeg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int (*s_SetDMA_func)(void *userdata);
static void *s_SetDMA_arg;
static struct IPUState s_IPUState;
static int *s_pEOF;
static int s_Sema;
static volatile s32 s_Thread;
static struct CSCParam s_CSCParam;
static int s_CSCID;
static u8 s_CSCFlag;
Expand Down Expand Up @@ -126,7 +126,6 @@ extern s32 _mpeg_dmac_handler(s32 channel, void *arg, void *addr);
void _MPEG_Initialize(_MPEGContext *mc, int (*data_cb)(void *userdata), void *cb_user, int *eof_flag)
{
(void)mc;
ee_sema_t sema;

*R_EE_IPU_CTRL = IPU_CTRL_RST;
while (*R_EE_IPU_CTRL & IPU_CTRL_BUSY)
Expand All @@ -142,11 +141,6 @@ void _MPEG_Initialize(_MPEGContext *mc, int (*data_cb)(void *userdata), void *cb
s_pEOF = eof_flag;
*s_pEOF = 0;

memset(&sema, 0, sizeof(sema));
sema.init_count = 0;
sema.max_count = 1;
sema.option = 0;
s_Sema = CreateSema(&sema);
s_CSCID = AddDmacHandler2(3, _mpeg_dmac_handler, 0, &s_CSCParam);
s_BitsBuffered = 0;
s_LocalBits = 0;
Expand All @@ -157,7 +151,6 @@ void _MPEG_Destroy(void)
while (READ_ONCE(s_CSCFlag) != 0)
;
RemoveDmacHandler(3, s_CSCID);
DeleteSema(s_Sema);
}

void _ipu_suspend(void)
Expand Down Expand Up @@ -248,7 +241,7 @@ s32 _mpeg_dmac_handler(s32 channel, void *arg, void *addr)

if (cp->blocks == 0) {
iDisableDmac(3);
iSignalSema(s_Sema);
iWakeupThread(s_Thread);
WRITE_ONCE(s_CSCFlag, 0);
return -1;
}
Expand Down Expand Up @@ -291,13 +284,15 @@ int _MPEG_CSCImage(void *source, void *dest, int mbcount)

*R_EE_D4_QWC = (mbc * sizeof(_MPEGMacroBlock8)) >> 4;
*R_EE_D3_QWC = (mbc * RGBA32_BLOCK_SIZE) >> 4;
s_Thread = GetThreadId();
EnableDmac(3);
*R_EE_D4_CHCR = 0x101;
*R_EE_IPU_CMD = IPU_COMMAND_CSC | mbc;
*R_EE_D3_CHCR = 0x100;

WRITE_ONCE(s_CSCFlag, 1);
WaitSema(s_Sema);
SleepThread();
s_Thread = -1;
_ipu_resume();
return mbc;
}
Expand Down
10 changes: 3 additions & 7 deletions iop/cdvd/poffsim/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ sysmem_IMPORTS_end

thbase_IMPORTS_start
I_SetAlarm
I_GetThreadId
I_iWakeupThread
I_SleepThread
thbase_IMPORTS_end

thevent_IMPORTS_start
I_iSetEventFlag
thevent_IMPORTS_end

thsemap_IMPORTS_start
I_CreateSema
I_DeleteSema
I_iSignalSema
I_WaitSema
thsemap_IMPORTS_end
1 change: 0 additions & 1 deletion iop/cdvd/poffsim/src/irx_imports.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
#include <sysmem.h>
#include <thbase.h>
#include <thevent.h>
#include <thsemap.h>

#endif /* IOP_IRX_IMPORTS_H */
16 changes: 6 additions & 10 deletions iop/cdvd/poffsim/src/poweroff.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct poffemu_param_stru
int m_cdvdman_intr_efid;
void (*m_cdvdman_poff_cb)(void *arg);
void *m_cdvdman_poffarg;
int m_sema_id;
int m_thread_id;
};

static struct poffemu_param_stru sCdPtbl;
Expand All @@ -32,25 +32,21 @@ static unsigned int _sceCdPoffEmu(void *userdata)
iSetEventFlag(arg->m_cdvdman_intr_efid, 0x10);
if ( arg->m_cdvdman_poff_cb )
arg->m_cdvdman_poff_cb(arg->m_cdvdman_poffarg);
iSignalSema(arg->m_sema_id);
iWakeupThread(arg->m_thread_id);
return 0;
}

int _start(int ac, char **av)
{
int unusedval;
iop_sema_t semaparam;
// Unofficial: the following variable has been made local stack
iop_sys_clock_t sCdPoff_time;

(void)ac;
(void)av;

semaparam.attr = 1;
semaparam.initial = 0;
semaparam.max = 1;
semaparam.option = 0;
sCdPtbl.m_sema_id = CreateSema(&semaparam);
// Unofficial: Use GetThreadId/iWakeupThread/SleepThread instead of CreateSema/iSignalSema/WaitSema
sCdPtbl.m_thread_id = GetThreadId();
sCdPtbl.m_cdvdman_intr_efid = sceCdSC(0xFFFFFFF5, &unusedval);
sCdPtbl.m_cdvdman_poff_cb = 0;
if ( (unsigned int)sceCdSC(0xFFFFFFF7, &unusedval) < 0x222 )
Expand All @@ -64,7 +60,7 @@ int _start(int ac, char **av)
sCdPoff_time.hi = 0;
sCdPoff_time.lo = 0x90000;
SetAlarm(&sCdPoff_time, _sceCdPoffEmu, &sCdPtbl);
WaitSema(sCdPtbl.m_sema_id);
DeleteSema(sCdPtbl.m_sema_id);
SleepThread();
sCdPtbl.m_thread_id = -1;
return 1;
}
1 change: 0 additions & 1 deletion iop/usb/usbhdfsd/include/usbhdfsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ struct _mass_dev
unsigned char interfaceAlt; // interface alternate setting
unsigned int sectorSize; // = 512; // store size of sector from usb mass
unsigned int maxLBA;
int ioSema;
cache_set *cache;
usbmass_cb_t callback;
};
Expand Down
3 changes: 3 additions & 0 deletions iop/usb/usbhdfsd/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ sysclib_IMPORTS_end

thbase_IMPORTS_start
I_DelayThread
I_GetThreadId
I_WakeupThread
I_SleepThread
thbase_IMPORTS_end

thsemap_IMPORTS_start
Expand Down
Loading
Loading