diff options
Diffstat (limited to 'src/leeds')
-rw-r--r-- | src/leeds/base/memoryManager.cpp | 75 | ||||
-rw-r--r-- | src/leeds/base/memoryManager.h | 39 | ||||
-rw-r--r-- | src/leeds/base/relocatableChunk.cpp | 36 | ||||
-rw-r--r-- | src/leeds/base/relocatableChunk.h | 53 | ||||
-rw-r--r-- | src/leeds/base/sList.h | 35 | ||||
-rw-r--r-- | src/leeds/smallHeap.cpp | 20 | ||||
-rw-r--r-- | src/leeds/smallHeap.h | 17 |
7 files changed, 275 insertions, 0 deletions
diff --git a/src/leeds/base/memoryManager.cpp b/src/leeds/base/memoryManager.cpp new file mode 100644 index 00000000..57e7d954 --- /dev/null +++ b/src/leeds/base/memoryManager.cpp @@ -0,0 +1,75 @@ +#include "common.h" +#include "memoryManager.h" + +namespace base +{ + cMemoryManager::cMemoryManager() + { + + } + + void* cMemoryManager::Allocate(uint32 size) + { + void* buf = malloc(size); + memset(buf, 0, size); + return buf; + } + + void* cMemoryManager::AllocateAligned(uint32 size) + { + void* buf = malloc(size); + memset(buf, 0, size); + return buf; + } + + void* cMemoryManager::Realloc(void* buf, uint32 newSize, bool unk) + { + return realloc(buf, newSize); + } + + void cMemoryManager::Free(void* buf) + { + if (buf) + free(buf); + } + + bool cMemoryManager::IsFree(void* buf) + { + return buf == nil; + } + + + cMainMemoryManager* cMainMemoryManager::m_pInstance = nil; + + cMainMemoryManager::cMainMemoryManager() + { + assert(m_pInstance == nil); + m_pInstance = this; + Init(nil, 0); + } + + void cMainMemoryManager::Init(void*, uint32) + { + + } +}; + +void* operator new(size_t size) +{ + return base::cMainMemoryManager::Instance()->Allocate(size); +} + +void* operator new[](size_t size) +{ + return base::cMainMemoryManager::Instance()->Allocate(size); +} + +void operator delete(void* buf) noexcept +{ + base::cMainMemoryManager::Instance()->Free(buf); +} + +void operator delete[](void* buf) noexcept +{ + base::cMainMemoryManager::Instance()->Free(buf); +}
\ No newline at end of file diff --git a/src/leeds/base/memoryManager.h b/src/leeds/base/memoryManager.h new file mode 100644 index 00000000..91124cd1 --- /dev/null +++ b/src/leeds/base/memoryManager.h @@ -0,0 +1,39 @@ +#pragma once + +namespace base +{ + class cMemoryManager + { + public: + cMemoryManager(); + void* Allocate(uint32 size); + void* AllocateAligned(uint32 size); + void* Realloc(void* buf, uint32 newSize, bool unk); + void Free(void* buf); + bool IsFree(void* buf); + }; + + class cMainMemoryManager : public cMemoryManager + { + static cMainMemoryManager* m_pInstance; + static void Init(void*, uint32); + + public: + cMainMemoryManager(); + static cMainMemoryManager *Instance() + { + static cMainMemoryManager instance; + return &instance; + } + }; + + class cMemoryBlock + { + // TODO + }; +} + +void* operator new(size_t size); +void* operator new[](size_t size); +void operator delete(void* buf) noexcept; +void operator delete[](void* buf) noexcept;
\ No newline at end of file diff --git a/src/leeds/base/relocatableChunk.cpp b/src/leeds/base/relocatableChunk.cpp new file mode 100644 index 00000000..5cb5a426 --- /dev/null +++ b/src/leeds/base/relocatableChunk.cpp @@ -0,0 +1,36 @@ +#include "common.h" +#include "relocatableChunk.h" + +namespace base +{ + // TODO(LCS): add actual code (all of these are stubs) + + void* cRelocatableChunk::Load(void* data, bool bShrink) { return nil; } + void* cRelocatableChunk::Load(const char* name, bool bShrink) { return nil; } + void cRelocatableChunk::Fixup(const sChunkHeader& header, void* data) {} + void cRelocatableChunk::Fixup(void* data) {} + void* cRelocatableChunk::Shrink(const sChunkHeader& header, void* data) { return nil; } + void* cRelocatableChunk::Shrink(void* data) { return nil; } + + cRelocatableChunkClassInfo::cRelocatableChunkClassInfo(const char* class_name, const void* pVmt, int size) {} + + cRelocatableChunkWriter::cRelocatableChunkWriter() {} + cRelocatableChunkWriter::~cRelocatableChunkWriter() {} + + void cRelocatableChunkWriter::AddPatch(void* addr) {} + void cRelocatableChunkWriter::AddPatchWithInfo(const char* str, int unk, void* addr) {} + void cRelocatableChunkWriter::AllocateRaw(void* addr, uint32 size, uint32 align, bool a5, bool a6) {} + + void cRelocatableChunkWriter::Clear() {} + void cRelocatableChunkWriter::Class(void* ptr, const cRelocatableChunkClassInfo& classInfo) {} + void cRelocatableChunkWriter::DebugFileLine(void*) {} + + void cRelocatableChunkWriter::PatchFunc(void* ptr) {} + + bool cRelocatableChunkWriter::IsAllocated(void* addr) { return false; } + + void cRelocatableChunkWriter::Reserve(int, int) {} + + void cRelocatableChunkWriter::Save(const char* filename, uint32 a3, uint32 a4, bool a5) {} + void cRelocatableChunkWriter::Save(void* file, uint32 a3, uint32 a4, bool a5, sChunkHeader* pHeader) {} +};
\ No newline at end of file diff --git a/src/leeds/base/relocatableChunk.h b/src/leeds/base/relocatableChunk.h new file mode 100644 index 00000000..2658aa21 --- /dev/null +++ b/src/leeds/base/relocatableChunk.h @@ -0,0 +1,53 @@ +#pragma once + +namespace base +{ + // TODO(LCS): add actual struct fields + + struct sChunkHeader; + struct sDataBlock; + struct sFileLine; + + class cRelocatableChunk + { + public: + void* Load(void* data, bool bShrink); + void* Load(const char* name, bool bShrink); + void Fixup(const sChunkHeader& header, void* data); + void Fixup(void* data); + void* Shrink(const sChunkHeader& header, void* data); + void* Shrink(void* data); + }; + +#define VTABLE_ADDR(obj) ((void*)obj) // TODO: make this portable + + class cRelocatableChunkClassInfo + { + public: + cRelocatableChunkClassInfo(const char* class_name, const void* pVmt, int size); + }; + + class cRelocatableChunkWriter + { + public: + cRelocatableChunkWriter(); + ~cRelocatableChunkWriter(); + + void AddPatch(void* addr); + void AddPatchWithInfo(const char* str, int unk, void* addr); + void AllocateRaw(void* addr, uint32 size, uint32 align, bool a5 = false, bool a6 = false); + + void Clear(); + void Class(void* ptr, const cRelocatableChunkClassInfo& classInfo); + void DebugFileLine(void*); + + void PatchFunc(void* ptr); + + bool IsAllocated(void* addr); + + void Reserve(int, int); + + void Save(const char* filename, uint32 a3, uint32 a4, bool a5); + void Save(void* file, uint32 a3, uint32 a4, bool a5, sChunkHeader* pHeader); + }; +};
\ No newline at end of file diff --git a/src/leeds/base/sList.h b/src/leeds/base/sList.h new file mode 100644 index 00000000..378d8e31 --- /dev/null +++ b/src/leeds/base/sList.h @@ -0,0 +1,35 @@ +#pragma once + +namespace base +{ + +template<typename T> +class cSList +{ +public: + struct tSItem + { + tSItem* next; + T item; + }; + // extra field on PS2 + tSItem* first; + + cSList() { first = nil; } + void Insert(tSItem* item) { tSItem* n = first; first = item; item->next = n; } + void Remove(tSItem* item) { + if (first == item) { + first = item->next; + return; + } + tSItem* i = first; + while (i && i->next != item) + i = i->next; + assert(i); + i->next = item->next; + + } + +}; + +}
\ No newline at end of file diff --git a/src/leeds/smallHeap.cpp b/src/leeds/smallHeap.cpp new file mode 100644 index 00000000..262113af --- /dev/null +++ b/src/leeds/smallHeap.cpp @@ -0,0 +1,20 @@ +#include "common.h" +#include "smallHeap.h" + +cSmallHeap cSmallHeap::msInstance; + +cSmallHeap::cSmallHeap() +{ + bLocked = false; + bUnk = false; +} + +void cSmallHeap::Lock() +{ + // TODO: PS2 code +} + +void cSmallHeap::Unlock() +{ + // TODO: PS2 code +}
\ No newline at end of file diff --git a/src/leeds/smallHeap.h b/src/leeds/smallHeap.h new file mode 100644 index 00000000..f2897688 --- /dev/null +++ b/src/leeds/smallHeap.h @@ -0,0 +1,17 @@ +#pragma once + +#include "memoryManager.h" + +class cSmallHeap : public base::cMemoryManager +{ + bool bLocked; + bool bUnk; +public: + cSmallHeap(); + void Lock(); + void Unlock(); + + bool IsLocked() const { return bLocked; } + + static cSmallHeap msInstance; +};
\ No newline at end of file |