Add basic HEAPLIB IOP module implementation.

This commit is contained in:
Jean-Philip Desjardins 2016-12-07 10:14:01 -05:00
parent 4069852ad0
commit 76940c3d11
5 changed files with 132 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include "Iop_Thvpool.h"
#include "Iop_Thmsgbx.h"
#include "Iop_Thevent.h"
#include "Iop_Heaplib.h"
#include "Iop_Timrman.h"
#include "Iop_Intrman.h"
#include "Iop_Vblank.h"
@ -183,6 +184,9 @@ void CIopBios::Reset(const Iop::SifManPtr& sifMan)
{
RegisterModule(std::make_shared<Iop::CThevent>(*this, m_ram));
}
{
RegisterModule(std::make_shared<Iop::CHeaplib>(*m_sysmem));
}
{
RegisterModule(std::make_shared<Iop::CTimrman>(*this));
}

View File

@ -0,0 +1,95 @@
#include "Iop_Heaplib.h"
#include "../Log.h"
using namespace Iop;
#define LOG_NAME ("iop_heaplib")
#define HEAP_PTR 0x12121212
#define FUNCTION_CREATEHEAP "CreateHeap"
#define FUNCTION_ALLOCHEAPMEMORY "AllocHeapMemory"
#define FUNCTION_FREEHEAPMEMORY "FreeHeapMemory"
CHeaplib::CHeaplib(CSysmem& sysMem)
: m_sysMem(sysMem)
{
}
std::string CHeaplib::GetId() const
{
return "heaplib";
}
std::string CHeaplib::GetFunctionName(unsigned int functionId) const
{
switch(functionId)
{
case 4:
return FUNCTION_CREATEHEAP;
break;
case 6:
return FUNCTION_ALLOCHEAPMEMORY;
break;
case 7:
return FUNCTION_FREEHEAPMEMORY;
break;
default:
return "unknown";
break;
}
}
void CHeaplib::Invoke(CMIPS& context, unsigned int functionId)
{
switch(functionId)
{
case 4:
context.m_State.nGPR[CMIPS::V0].nD0 = CreateHeap(
context.m_State.nGPR[CMIPS::A0].nV0,
context.m_State.nGPR[CMIPS::A1].nV0
);
break;
case 6:
context.m_State.nGPR[CMIPS::V0].nD0 = AllocHeapMemory(
context.m_State.nGPR[CMIPS::A0].nV0,
context.m_State.nGPR[CMIPS::A1].nV0
);
break;
case 7:
context.m_State.nGPR[CMIPS::V0].nD0 = FreeHeapMemory(
context.m_State.nGPR[CMIPS::A0].nV0,
context.m_State.nGPR[CMIPS::A1].nV0
);
break;
default:
CLog::GetInstance().Print(LOG_NAME, "Unknown function called (%d).\r\n",
functionId);
break;
}
}
int32 CHeaplib::CreateHeap(uint32 heapSize, uint32 flags)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_CREATEHEAP "(heapSize = 0x%0.8X, flags = %d);\r\n",
heapSize, flags);
return HEAP_PTR;
}
int32 CHeaplib::AllocHeapMemory(uint32 heapPtr, uint32 size)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_ALLOCHEAPMEMORY "(heapPtr = 0x%0.8X, size = 0x%0.8X);\r\n",
heapPtr, size);
assert(heapPtr == HEAP_PTR);
return m_sysMem.AllocateMemory(size, 0, 0);
}
int32 CHeaplib::FreeHeapMemory(uint32 heapPtr, uint32 allocPtr)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_FREEHEAPMEMORY "(heapPtr = 0x%0.8X, allocPtr = 0x%0.8X);\r\n",
heapPtr, allocPtr);
assert(heapPtr == HEAP_PTR);
m_sysMem.FreeMemory(allocPtr);
return 0;
}

25
Source/iop/Iop_Heaplib.h Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include "Iop_Module.h"
#include "Iop_Sysmem.h"
namespace Iop
{
class CHeaplib : public CModule
{
public:
CHeaplib(CSysmem&);
virtual ~CHeaplib() = default;
std::string GetId() const override;
std::string GetFunctionName(unsigned int) const override;
void Invoke(CMIPS&, unsigned int) override;
private:
int32 CreateHeap(uint32, uint32);
int32 AllocHeapMemory(uint32, uint32);
int32 FreeHeapMemory(uint32, uint32);
CSysmem& m_sysMem;
};
}

View File

@ -91,6 +91,7 @@
<ClCompile Include="..\Source\iop\Iop_FileIoHandler1000.cpp" />
<ClCompile Include="..\Source\iop\Iop_FileIoHandler2100.cpp" />
<ClCompile Include="..\Source\iop\Iop_FileIoHandler2300.cpp" />
<ClCompile Include="..\Source\iop\Iop_Heaplib.cpp" />
<ClCompile Include="..\Source\iop\Iop_Intc.cpp" />
<ClCompile Include="..\Source\iop\Iop_Intrman.cpp" />
<ClCompile Include="..\Source\iop\Iop_Ioman.cpp" />
@ -240,6 +241,7 @@
<ClInclude Include="..\Source\iop\Iop_FileIoHandler1000.h" />
<ClInclude Include="..\Source\iop\Iop_FileIoHandler2100.h" />
<ClInclude Include="..\Source\iop\Iop_FileIoHandler2300.h" />
<ClInclude Include="..\Source\iop\Iop_Heaplib.h" />
<ClInclude Include="..\Source\iop\Iop_Intc.h" />
<ClInclude Include="..\Source\iop\Iop_Intrman.h" />
<ClInclude Include="..\Source\iop\Iop_Ioman.h" />

View File

@ -454,6 +454,9 @@
<ClCompile Include="..\Source\iop\Iop_Thvpool.cpp">
<Filter>Source Files\Iop</Filter>
</ClCompile>
<ClCompile Include="..\Source\iop\Iop_Heaplib.cpp">
<Filter>Source Files\Iop</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Source\AppConfig.h">
@ -903,5 +906,8 @@
<ClInclude Include="..\Source\gs\GsTextureCache.h">
<Filter>Source Files\Gs</Filter>
</ClInclude>
<ClInclude Include="..\Source\iop\Iop_Heaplib.h">
<Filter>Source Files\Iop</Filter>
</ClInclude>
</ItemGroup>
</Project>