Get rid of 1.3.2, fix JKRHeap for debug

This commit is contained in:
SwareJonge 2024-05-27 21:22:52 +02:00
parent d506290f69
commit a49da0b2a1
6 changed files with 110 additions and 81 deletions

View File

@ -211,9 +211,6 @@ SDK_CC = os.path.join(SDK_CW, "mwcceppc.exe")
SDK_PACTHED_CW = os.path.join(TOOLS, "1.2.5n")
SDK_PACTHED_CC = os.path.join(SDK_PACTHED_CW, "mwcceppc.exe")
MW_1_3_2 = os.path.join(TOOLS, "1.3.2")
CC_1_3_2 = os.path.join(MW_1_3_2, "mwcceppc.exe")
JSYSTEM_O0_MW = os.path.join(TOOLS, "3.0a5.2")
JSYSTEM_O0_CC = os.path.join(JSYSTEM_O0_MW, "mwcceppc.exe")

View File

@ -325,14 +325,13 @@ libs/JSystem/JKernel/JKRFileLoader.cpp:
.sbss: [0x804159a0, 0x804159a8]
.sdata2: [0x80417af0, 0x80417af8]
# The hacks in JKRHeap cause issues for RaceMgr(and so will it for other files), disable for now
#libs/JSystem/JKernel/JKRHeap.cpp:
#.text: [0x80083e20, 0x800853bc]
#.rodata: [0x803670e8, 0x803673a8]
#.data: [0x8038b418, 0x8038b478]
#.sdata: [0x80414098, 0x804140a0]
#.sbss: [0x804159a8, 0x804159d0]
#.sdata2: [0x80417af8, 0x80417b18]
libs/JSystem/JKernel/JKRHeap.cpp:
.text: [0x80083e20, 0x800853bc]
.rodata: [0x803670e8, 0x803673a8]
.data: [0x8038b418, 0x8038b478]
.sdata: [0x80414098, 0x804140a0]
.sbss: [0x804159a8, 0x804159d0]
.sdata2: [0x80417af8, 0x80417b18]
libs/JSystem/JKernel/JKRMemArchive.cpp:
.text: [0x800853bc, 0x80085cf4]

View File

@ -43,7 +43,6 @@ import common as c
# Check CW was added
assert os.path.exists("tools/2.6/mwcceppc.exe") and \
os.path.exists("tools/1.3.2/mwcceppc.exe") and \
os.path.exists("tools/1.2.5n/mwcceppc.exe") and \
os.path.exists("tools/1.2.5/mwcceppc.exe") and \
os.path.exists("tools/2.6/mwldeppc.exe"), \
@ -588,8 +587,6 @@ class CSource(Source):
self.cflags = c.JAUDIO_DSP_CFLAGS
elif path.startswith("libs/JSystem/"):
self.cflags = c.JSYSTEM_RELEASE_CFLAGS
if path.endswith("JKRSolidHeap.cpp"):
self.cc = c.CC_1_3_2
else:
if path.startswith("libs/JSystem/JUtility/") or path.startswith("libs/JSystem/JKernel/") or path.startswith("libs/JSystem/J2DGraph/"):
self.cflags = c.DOL_CFLAGS

View File

@ -23,7 +23,7 @@ public:
{
}
void *_00; // _00
char *_00; // _00
int _04; // _04
};
@ -242,7 +242,7 @@ protected:
u8 mFillCheckFlag; // _3D
u8 mAllocMode; // _3E, see EAllocMode enum
u8 mGroupID; // _3F
JSUTree<JKRHeap> mHeapTree; // _40
mutable JSUTree<JKRHeap> mHeapTree; // _40
JSUList<JKRDisposer> mDisposerList; // _5C
bool mErrorFlag; // _68
bool mInitFlag; // _69

View File

@ -87,7 +87,7 @@ namespace JUTAssertion
#define JUT_MINMAX_ASSERT(...)
#define JUT_MAX_ASSERT(...)
#define JUT_LOG_F(...)
#define JUT_REPORT_MSG(...)
#define JUT_REPORT_MSG(...) (void)0
#endif
#endif

View File

@ -21,17 +21,19 @@ JKRHeap::JKRHeap(void *data, u32 size, JKRHeap *heap, bool errorFlag) : JKRDispo
{
OSInitMutex(&mMutex);
mHeapSize = size;
mStartAddress = (u8*)data;
mEndAddress = ((u8*)data + size);
if(heap == nullptr) {
mStartAddress = (u8 *)data;
mEndAddress = ((u8 *)data + size);
if (heap == nullptr)
{
becomeSystemHeap();
becomeCurrentHeap();
}
else {
else
{
heap->mHeapTree.appendChild(&mHeapTree);
if(sSystemHeap == sRootHeap)
if (sSystemHeap == sRootHeap)
becomeSystemHeap();
if(sCurrentHeap == sRootHeap)
if (sCurrentHeap == sRootHeap)
becomeCurrentHeap();
}
mErrorFlag = errorFlag;
@ -92,7 +94,8 @@ JKRHeap *JKRHeap::becomeCurrentHeap()
return old;
}
void JKRHeap::destroy(JKRHeap * heap) {
void JKRHeap::destroy(JKRHeap *heap)
{
#line 200
JUT_ASSERT(heap != 0);
heap->destroy();
@ -114,7 +117,8 @@ void *JKRHeap::alloc(u32 byteCount, int padding, JKRHeap *heap)
return nullptr;
}
void *JKRHeap::alloc(u32 byteCount, int padding) {
void *JKRHeap::alloc(u32 byteCount, int padding)
{
#line 317
JUT_WARNING_F(!mInitFlag, "alloc %x byte in heap %x", byteCount, this);
return do_alloc(byteCount, padding);
@ -128,7 +132,8 @@ void JKRHeap::free(void *memory, JKRHeap *heap)
}
}
void JKRHeap::free(void *memory) {
void JKRHeap::free(void *memory)
{
#line 365
JUT_WARNING_F(!mInitFlag, "free %x in heap %x", memory, this);
do_free(memory);
@ -143,26 +148,30 @@ void JKRHeap::callAllDisposer()
}
}
void JKRHeap::freeAll() {
void JKRHeap::freeAll()
{
#line 417
JUT_WARNING_F(!mInitFlag, "freeAll in heap %x", this);
do_freeAll();
}
void JKRHeap::freeTail() {
void JKRHeap::freeTail()
{
#line 431
JUT_WARNING_F(!mInitFlag, "freeTail in heap %x", this);
do_freeTail();
}
// fabricated
void JKRHeap::fillFreeArea() {
void JKRHeap::fillFreeArea()
{
#line 461
JUT_WARNING_F(!mInitFlag, "fillFreeArea in heap %x", this);
do_fillFreeArea();
}
int JKRHeap::resize(void *memoryBlock, u32 newSize) {
int JKRHeap::resize(void *memoryBlock, u32 newSize)
{
#line 491
JUT_WARNING_F(!mInitFlag, "resize block %x into %x in heap %x", memoryBlock, newSize, this);
return do_resize(memoryBlock, newSize);
@ -170,7 +179,8 @@ int JKRHeap::resize(void *memoryBlock, u32 newSize) {
s32 JKRHeap::getFreeSize() { return do_getFreeSize(); }
u32 JKRHeap::getTotalFreeSize() { return do_getTotalFreeSize(); }
u8 JKRHeap::changeGroupID(u8 newGroupID) {
u8 JKRHeap::changeGroupID(u8 newGroupID)
{
#line 570
JUT_WARNING_F(!mInitFlag, "change heap ID into %x in heap %x", newGroupID, this);
return do_changeGroupID(newGroupID);
@ -200,19 +210,22 @@ JKRHeap *JKRHeap::findFromRoot(void *ptr)
return sRootHeap->findAllHeap(ptr);
}
JKRHeap* JKRHeap::find(void* memory) const
JKRHeap *JKRHeap::find(void *memory) const
{
if ((mStartAddress <= memory) && (memory < mEndAddress)) {
if (mHeapTree.getNumChildren() != 0) {
if ((mStartAddress <= memory) && (memory < mEndAddress))
{
if (mHeapTree.getNumChildren() != 0)
{
for (JSUTreeIterator<JKRHeap> iterator(mHeapTree.getFirstChild()); iterator != mHeapTree.getEndChild(); ++iterator)
{
JKRHeap* result = iterator->find(memory);
if (result) {
JKRHeap *result = iterator->find(memory);
if (result)
{
return result;
}
}
}
return const_cast<JKRHeap*>(this);
return const_cast<JKRHeap *>(this);
}
return nullptr;
}
@ -309,18 +322,20 @@ void JKRHeap::copyMemory(void *dst, void *src, u32 size)
}
}
void JKRDefaultMemoryErrorRoutine(void * heap, u32 size, int alignment) {
void JKRDefaultMemoryErrorRoutine(void *heap, u32 size, int alignment)
{
#line 830
JUT_REPORT_MSG("Error: Cannot allocate memory %d(0x%x)byte in %d byte alignment from %08x\n", size, size, alignment, heap);
JUT_PANIC("abort\n");
}
// attempt to reconstruct function but lazy
void JKRHeap::checkMemoryFilled(u8 * address, u32 size, u8 p3)
void JKRHeap::checkMemoryFilled(u8 *address, u32 size, u8 p3)
{
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
{
#line 999
JUT_WARNING_F( p3 == address[i], "**** checkMemoryFilled:\n address %08x size %x:\n (%08x = %02x)\n", address, size, address[i], address[i]);
JUT_WARNING_F(p3 == address[i], "**** checkMemoryFilled:\n address %08x size %x:\n (%08x = %02x)\n", address, size, address[i], address[i]);
}
}
@ -360,20 +375,25 @@ bool JKRHeap::isSubHeap(JKRHeap *heap) const
return false;
}
void *operator new(u32 byteCount) {
void *operator new(u32 byteCount)
{
return JKRHeap::alloc(byteCount, 4, nullptr);
}
void *operator new(u32 byteCount, int alignment) {
void *operator new(u32 byteCount, int alignment)
{
return JKRHeap::alloc(byteCount, alignment, nullptr);
}
void *operator new(u32 byteCount, JKRHeap *heap, int alignment){
void *operator new(u32 byteCount, JKRHeap *heap, int alignment)
{
return JKRHeap::alloc(byteCount, alignment, heap);
}
void *operator new[](u32 byteCount) {
void *operator new[](u32 byteCount)
{
return JKRHeap::alloc(byteCount, 4, nullptr);
}
void *operator new[](u32 byteCount, int alignment) {
void *operator new[](u32 byteCount, int alignment)
{
return JKRHeap::alloc(byteCount, alignment, nullptr);
}
void *operator new[](u32 byteCount, JKRHeap *heap, int alignment)
@ -381,7 +401,6 @@ void *operator new[](u32 byteCount, JKRHeap *heap, int alignment)
return JKRHeap::alloc(byteCount, alignment, heap);
}
// this is not needed without the other pragma and asm bs
void operator delete(void *memory) { JKRHeap::free(memory, nullptr); }
void operator delete[](void *memory) { JKRHeap::free(memory, nullptr); }
@ -400,46 +419,63 @@ JKRHeap::TState::TState(const JKRHeap::TState &other, const JKRHeap::TState::TLo
// UNUSED FUNCTION
}*/
// not sure where these lines originally were, i think in the destructor of TState but not many games have that
#if DEBUG
static void genData()
{
#line 1000
JUT_LOG_F("heap unchanged");
JUT_LOG_F("**** heap changed ****");
JUT_LOG_F("location : [%s:%d]");
JUT_LOG_F("**** heap changed : old ****");
JUT_LOG_F("**** heap changed : new ****");
}
#endif
JKRHeap::TState::~TState()
{
// Unused, however might need it
// Unused
if (isCompareOnDestructed())
{
TState state(getHeap(), getId(), false);
if (mArgument.mHeap->state_compare(*this, state))
{
if (isVerbose())
{
JUT_REPORT_MSG("heap unchanged");
}
}
else
{
state_dumpDifference(*this, state);
if (isVerbose())
{
char *str = mLocation._00;
u32 addr = mLocation._04;
JUT_REPORT_MSG("**** heap changed ****");
JUT_REPORT_MSG("location : [%s:%d]", str, addr);
JUT_REPORT_MSG("**** heap changed : old ****");
dump();
JUT_REPORT_MSG("**** heap changed : new ****");
state.dump();
}
}
}
}
void JKRHeap::state_register(JKRHeap::TState * p, u32) const {
void JKRHeap::state_register(JKRHeap::TState *p, u32) const
{
#line 1132
JUT_ASSERT(p != 0);
JUT_ASSERT(p->getHeap() == this);
}
bool JKRHeap::state_compare(const JKRHeap::TState &r1, const JKRHeap::TState &r2) const {
bool JKRHeap::state_compare(const JKRHeap::TState &r1, const JKRHeap::TState &r2) const
{
#line 1141
JUT_ASSERT(r1.getHeap() == r2.getHeap());
return (r1.getCheckCode() == r2.getCheckCode());
}
// fabricated, but probably matches(except for line numbers)
void JKRHeap::state_dumpDifference(const JKRHeap::TState & r1, const JKRHeap::TState & r2) {
#line 1157
void JKRHeap::state_dumpDifference(const JKRHeap::TState &r1, const JKRHeap::TState &r2)
{
JUT_LOG_F("heap : %p / %p", r1.getHeap(), r2.getHeap());
JUT_LOG_F("check-code : 0x%08x / 0x%08x", r1.getCheckCode(), r2.getCheckCode());
JUT_LOG_F("id : 0x%08x / 0x%08x", r1.getId(), r2.getId());
JUT_LOG_F("used size : %10u / %10u", r1.getUsedSize(), r2.getUsedSize());
}
void JKRHeap::state_dump(const TState & state) const {
void JKRHeap::state_dump(const TState &state) const
{
#line 1165
JUT_LOG_F("check-code : 0x%08x", state.getCheckCode());
JUT_LOG_F("id : 0x%08x", state.getId());