2008-01-15 20:27:44 +00:00
|
|
|
#include "Iop_Thsema.h"
|
|
|
|
#include "IopBios.h"
|
2025-03-11 12:48:26 -04:00
|
|
|
#include "Log.h"
|
2012-06-28 06:06:30 +00:00
|
|
|
|
|
|
|
#define LOG_NAME ("iop_thsema")
|
2008-01-15 20:27:44 +00:00
|
|
|
|
|
|
|
using namespace Iop;
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
#define FUNCTION_CREATESEMAPHORE "CreateSemaphore"
|
|
|
|
#define FUNCTION_DELETESEMAPHORE "DeleteSemaphore"
|
|
|
|
#define FUNCTION_SIGNALSEMAPHORE "SignalSemaphore"
|
|
|
|
#define FUNCTION_ISIGNALSEMAPHORE "iSignalSemaphore"
|
|
|
|
#define FUNCTION_WAITSEMAPHORE "WaitSemaphore"
|
|
|
|
#define FUNCTION_POLLSEMAPHORE "PollSemaphore"
|
|
|
|
#define FUNCTION_REFERSEMASTATUS "ReferSemaStatus"
|
2018-12-10 19:27:38 -05:00
|
|
|
#define FUNCTION_IREFERSEMASTATUS "iReferSemaStatus"
|
2008-12-01 04:00:36 +00:00
|
|
|
|
2012-06-24 23:10:12 +00:00
|
|
|
CThsema::CThsema(CIopBios& bios, uint8* ram)
|
2018-04-30 21:01:23 +01:00
|
|
|
: m_bios(bios)
|
|
|
|
, m_ram(ram)
|
2008-01-15 20:27:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-24 23:10:12 +00:00
|
|
|
std::string CThsema::GetId() const
|
2008-01-15 20:27:44 +00:00
|
|
|
{
|
2012-06-24 23:10:12 +00:00
|
|
|
return "thsemap";
|
2008-01-15 20:27:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-24 23:10:12 +00:00
|
|
|
std::string CThsema::GetFunctionName(unsigned int functionId) const
|
2008-11-28 23:46:52 +00:00
|
|
|
{
|
2012-06-24 23:10:12 +00:00
|
|
|
switch(functionId)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
return FUNCTION_CREATESEMAPHORE;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
return FUNCTION_DELETESEMAPHORE;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
return FUNCTION_SIGNALSEMAPHORE;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
return FUNCTION_ISIGNALSEMAPHORE;
|
|
|
|
break;
|
|
|
|
case 8:
|
2015-03-08 22:11:36 -04:00
|
|
|
return FUNCTION_WAITSEMAPHORE;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
return FUNCTION_POLLSEMAPHORE;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
return FUNCTION_REFERSEMASTATUS;
|
2012-06-24 23:10:12 +00:00
|
|
|
break;
|
2018-12-10 19:27:38 -05:00
|
|
|
case 12:
|
|
|
|
return FUNCTION_IREFERSEMASTATUS;
|
|
|
|
break;
|
2012-06-24 23:10:12 +00:00
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
break;
|
|
|
|
}
|
2008-11-28 23:46:52 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:27:44 +00:00
|
|
|
void CThsema::Invoke(CMIPS& context, unsigned int functionId)
|
|
|
|
{
|
2012-06-24 23:10:12 +00:00
|
|
|
switch(functionId)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(CreateSemaphore(
|
2018-04-30 21:01:23 +01:00
|
|
|
reinterpret_cast<SEMAPHORE*>(&m_ram[context.m_State.nGPR[CMIPS::A0].nV0])));
|
2012-06-24 23:10:12 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(DeleteSemaphore(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0));
|
2012-06-24 23:10:12 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(SignalSemaphore(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0));
|
2012-06-24 23:10:12 +00:00
|
|
|
break;
|
2008-10-28 21:32:18 +00:00
|
|
|
case 7:
|
2012-06-24 23:10:12 +00:00
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(iSignalSemaphore(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0));
|
2012-06-24 23:10:12 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(WaitSemaphore(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0));
|
2012-06-24 23:10:12 +00:00
|
|
|
break;
|
2015-03-08 22:11:36 -04:00
|
|
|
case 9:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(PollSemaphore(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0));
|
2015-03-08 22:11:36 -04:00
|
|
|
break;
|
|
|
|
case 11:
|
2018-12-10 19:27:38 -05:00
|
|
|
case 12:
|
2015-03-08 22:11:36 -04:00
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(ReferSemaphoreStatus(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0,
|
|
|
|
context.m_State.nGPR[CMIPS::A1].nV0));
|
2015-03-08 22:11:36 -04:00
|
|
|
break;
|
2012-06-24 23:10:12 +00:00
|
|
|
default:
|
2018-05-24 12:59:15 -04:00
|
|
|
CLog::GetInstance().Warn(LOG_NAME, "Unknown function (%d) called at (%08X).\r\n", functionId, context.m_State.nPC);
|
2008-10-28 21:32:18 +00:00
|
|
|
break;
|
2012-06-24 23:10:12 +00:00
|
|
|
}
|
2008-01-15 20:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CThsema::CreateSemaphore(const SEMAPHORE* semaphore)
|
|
|
|
{
|
2021-11-19 17:25:42 -05:00
|
|
|
return m_bios.CreateSemaphore(semaphore->initialCount, semaphore->maxCount, semaphore->options, semaphore->attributes);
|
2008-01-15 20:27:44 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 05:27:03 +00:00
|
|
|
uint32 CThsema::DeleteSemaphore(uint32 semaphoreId)
|
|
|
|
{
|
2012-06-24 23:10:12 +00:00
|
|
|
return m_bios.DeleteSemaphore(semaphoreId);
|
2009-02-09 05:27:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:27:44 +00:00
|
|
|
uint32 CThsema::SignalSemaphore(uint32 semaphoreId)
|
|
|
|
{
|
2012-06-24 23:10:12 +00:00
|
|
|
return m_bios.SignalSemaphore(semaphoreId, false);
|
2008-10-28 21:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CThsema::iSignalSemaphore(uint32 semaphoreId)
|
|
|
|
{
|
|
|
|
return m_bios.SignalSemaphore(semaphoreId, true);
|
2008-01-15 20:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CThsema::WaitSemaphore(uint32 semaphoreId)
|
|
|
|
{
|
2012-06-24 23:10:12 +00:00
|
|
|
return m_bios.WaitSemaphore(semaphoreId);
|
2008-01-15 20:27:44 +00:00
|
|
|
}
|
2015-03-08 22:11:36 -04:00
|
|
|
|
|
|
|
uint32 CThsema::PollSemaphore(uint32 semaphoreId)
|
|
|
|
{
|
|
|
|
return m_bios.PollSemaphore(semaphoreId);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CThsema::ReferSemaphoreStatus(uint32 semaphoreId, uint32 statusPtr)
|
|
|
|
{
|
|
|
|
return m_bios.ReferSemaphoreStatus(semaphoreId, statusPtr);
|
|
|
|
}
|