2013-09-04 03:05:14 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include "Common/ChunkFile.h"
|
2013-09-29 07:07:51 +00:00
|
|
|
#include "Core/Reporting.h"
|
|
|
|
#include "Core/HLE/HLE.h"
|
2013-10-01 15:38:01 +00:00
|
|
|
#include "sceKernelMemory.h"
|
2013-09-04 03:05:14 +00:00
|
|
|
#include "Core/HLE/sceHeap.h"
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
std::map<u32,Heap*> heapList;
|
|
|
|
|
2013-09-04 03:05:14 +00:00
|
|
|
void __HeapDoState(PointerWrap &p) {
|
2013-10-01 15:38:01 +00:00
|
|
|
auto s = p.Section("sceHeap", 1, 2);
|
2013-09-15 03:23:03 +00:00
|
|
|
if (!s)
|
|
|
|
return;
|
2013-10-01 15:38:01 +00:00
|
|
|
|
|
|
|
if (s == 1) {
|
|
|
|
} else {
|
|
|
|
p.Do(heapList);
|
|
|
|
}
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
enum SceHeapAttr
|
|
|
|
{
|
|
|
|
PSP_HEAP_ATTR_HIGHMEM = 0x4000,
|
|
|
|
PSP_HEAP_ATTR_EXT = 0x8000,
|
|
|
|
};
|
|
|
|
|
|
|
|
int sceHeapReallocHeapMemory(u32 heapAddr, u32 memPtr, int memSize) {
|
|
|
|
ERROR_LOG_REPORT(HLE,"UNIMPL sceHeapReallocHeapMemory(%08x, %08x, %08x)", heapAddr, memPtr, memSize);
|
2013-09-04 03:35:16 +00:00
|
|
|
return 0;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sceHeapReallocHeapMemoryWithOption(u32 heapPtr, u32 memPtr, int memSize, u32 paramsPtr) {
|
2013-10-01 15:38:01 +00:00
|
|
|
ERROR_LOG_REPORT(HLE,"UNIMPL sceHeapReallocHeapMemoryWithOption(%08x, %08x, %08x, %08x)", heapPtr, memPtr, memSize, paramsPtr);
|
2013-09-29 07:07:51 +00:00
|
|
|
return 0;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapFreeHeapMemory(u32 heapAddr, u32 memAddr) {
|
|
|
|
if (!Memory::IsValidAddress(memAddr))
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
|
|
|
Heap *heap = heapList[heapAddr];
|
|
|
|
if (!heap)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
|
|
|
if(!heap->alloc.FreeExact(memAddr))
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_POINTER;
|
|
|
|
|
|
|
|
DEBUG_LOG_REPORT(HLE,"sceHeapFreeHeapMemory(%08x, %08x)", heapAddr, memAddr);
|
2013-09-04 03:05:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapGetMallinfo(u32 heapAddr, u32 infoPtr) {
|
|
|
|
ERROR_LOG_REPORT(HLE,"UNIMPL sceHeapGetMallinfo(%08x, %08x)", heapAddr, infoPtr);
|
2013-09-29 07:07:51 +00:00
|
|
|
return 0;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapAllocHeapMemoryWithOption(u32 heapAddr, u32 memSize, u32 paramsPtr) {
|
|
|
|
Heap *heap = heapList[heapAddr];
|
|
|
|
if (!heap)
|
|
|
|
return 0;
|
|
|
|
if (Memory::Read_U32(paramsPtr) == 8)
|
|
|
|
heap->alloc.Setgrain_(Memory::Read_U32(paramsPtr + 4));
|
|
|
|
u32 addr = heap->alloc.Alloc(memSize, heap->fromtop);
|
|
|
|
DEBUG_LOG_REPORT(HLE,"sceHeapAllocHeapMemoryWithOption(%08x, %08x, %08x)", heapAddr, memSize, paramsPtr);
|
|
|
|
return addr;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapGetTotalFreeSize(u32 heapAddr) {
|
|
|
|
Heap *heap = heapList[heapAddr];
|
2013-10-01 16:04:29 +00:00
|
|
|
DEBUG_LOG_REPORT(HLE,"UNIMPL sceHeapGetTotalFreeSize(%08x)", heapAddr);
|
2013-10-01 15:38:01 +00:00
|
|
|
return heap->alloc.GetTotalFreeBytes();
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sceHeapIsAllocatedHeapMemory(u32 heapPtr, u32 memPtr) {
|
2013-10-01 15:38:01 +00:00
|
|
|
ERROR_LOG_REPORT(HLE,"UNIMPL sceHeapIsAllocatedHeapMemory(%08x, %08x)", heapPtr, memPtr);
|
2013-09-29 07:07:51 +00:00
|
|
|
return 0;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapDeleteHeap(u32 heapAddr) {
|
|
|
|
Heap *heap = heapList[heapAddr];
|
|
|
|
if(heapList.erase(heapAddr) != 0)
|
|
|
|
delete heap;
|
|
|
|
ERROR_LOG_REPORT(HLE,"UNIMPL sceHeapDeleteHeap(%08x)", heapAddr);
|
2013-09-29 07:07:51 +00:00
|
|
|
return 0;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapCreateHeap(const char* name, u32 heapSize, int attr, u32 paramsPtr) {
|
|
|
|
if (paramsPtr != 0) {
|
|
|
|
u32 size = Memory::Read_U32(paramsPtr);
|
|
|
|
WARN_LOG_REPORT(SCEKERNEL, "sceHeapCreateHeap(): unsupported options parameter, size = %d", size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int allocSize = (heapSize + 3) & ~3;
|
|
|
|
|
|
|
|
Heap *heap = new Heap;
|
|
|
|
heap->size = allocSize;
|
|
|
|
heap->fromtop = (attr & PSP_HEAP_ATTR_HIGHMEM) != 0;
|
|
|
|
u32 addr = userMemory.Alloc(heap->size, heap->fromtop, "Heap");
|
|
|
|
if (addr == (u32)-1) {
|
|
|
|
ERROR_LOG(SCEKERNEL, "sceHeapCreateHeap(): Failed to allocate %i bytes memory", allocSize);
|
|
|
|
delete heap;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
heap->address = addr;
|
|
|
|
heap->alloc.Init(heap->address,heap->size);
|
|
|
|
heapList[heap->address] = heap;
|
|
|
|
DEBUG_LOG_REPORT(HLE,"sceHeapCreateHeap(%s, %08x, %08x, %08x)", name, heapSize, attr, paramsPtr);
|
|
|
|
return heap->address;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:38:01 +00:00
|
|
|
int sceHeapAllocHeapMemory(u32 heapAddr, u32 memSize) {
|
|
|
|
Heap *heap = heapList[heapAddr];
|
|
|
|
if (!heap)
|
|
|
|
return 0;
|
|
|
|
u32 addr = heap->alloc.Alloc(memSize, heap->fromtop);
|
|
|
|
DEBUG_LOG_REPORT(HLE,"sceHeapAllocHeapMemory(%08x, %08x)", heapAddr, memSize);
|
|
|
|
return addr;
|
2013-09-04 03:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const HLEFunction sceHeap[] =
|
|
|
|
{
|
|
|
|
{0x0E875980,WrapI_UUI<sceHeapReallocHeapMemory>,"sceHeapReallocHeapMemory"},
|
2013-09-29 07:07:51 +00:00
|
|
|
{0x1C84B58D,WrapI_UUIU<sceHeapReallocHeapMemoryWithOption>,"sceHeapReallocHeapMemoryWithOption"},
|
2013-09-04 03:05:14 +00:00
|
|
|
{0x2ABADC63,WrapI_UU<sceHeapFreeHeapMemory>,"sceHeapFreeHeapMemory"},
|
|
|
|
{0x2A0C2009,WrapI_UU<sceHeapGetMallinfo>,"sceHeapGetMallinfo"},
|
2013-10-01 15:38:01 +00:00
|
|
|
{0x2B7299D8,WrapI_UUU<sceHeapAllocHeapMemoryWithOption>,"sceHeapAllocHeapMemoryWithOption"},
|
2013-09-04 03:05:14 +00:00
|
|
|
{0x4929B40D,WrapI_U<sceHeapGetTotalFreeSize>,"sceHeapGetTotalFreeSize"},
|
|
|
|
{0x7012BBDD,WrapI_UU<sceHeapIsAllocatedHeapMemory>,"sceHeapIsAllocatedHeapMemory"},
|
|
|
|
{0x70210B73,WrapI_U<sceHeapDeleteHeap>,"sceHeapDeleteHeap"},
|
2013-10-01 15:38:01 +00:00
|
|
|
{0x7DE281C2,WrapI_CUIU<sceHeapCreateHeap>,"sceHeapCreateHeap"},
|
|
|
|
{0xA8E102A0,WrapI_UU<sceHeapAllocHeapMemory>,"sceHeapAllocHeapMemory"},
|
2013-09-04 03:05:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void Register_sceHeap()
|
|
|
|
{
|
|
|
|
RegisterModule("sceHeap", ARRAY_SIZE(sceHeap), sceHeap);
|
2013-09-04 03:35:16 +00:00
|
|
|
}
|