summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJcw87 <Jcw87@users.noreply.github.com>2023-09-15 16:02:47 -0700
committerGitHub <noreply@github.com>2023-09-15 16:02:47 -0700
commitc2193c41eb2001add35be0faedffad3d611ed53b (patch)
tree8da3f6a07c77e81bd10f11bcc9d962dea0dcfd8a
parent287ae62349ac3e1821b420d8dcad7989148d2a9d (diff)
JKRHeap (#1927)
* JKRHeap * d_a_link
-rw-r--r--asm/JSystem/JKernel/JKRHeap/dispose__7JKRHeapFv.s25
-rw-r--r--asm/JSystem/JKernel/JKRHeap/getMaxAllocatableSize__7JKRHeapFi.s25
-rw-r--r--asm/d/a/d_a_alink/dComIfGp_getEvent__Fv.s5
-rw-r--r--include/JSystem/JUtility/JUTAssert.h14
-rw-r--r--include/JSystem/JUtility/JUTException.h3
-rw-r--r--include/MSL_C/MSL_Common/Src/stddef.h5
-rw-r--r--include/global.h1
-rw-r--r--libs/JSystem/JKernel/JKRHeap.cpp108
8 files changed, 60 insertions, 126 deletions
diff --git a/asm/JSystem/JKernel/JKRHeap/dispose__7JKRHeapFv.s b/asm/JSystem/JKernel/JKRHeap/dispose__7JKRHeapFv.s
deleted file mode 100644
index 6efa015b7d..0000000000
--- a/asm/JSystem/JKernel/JKRHeap/dispose__7JKRHeapFv.s
+++ /dev/null
@@ -1,25 +0,0 @@
-lbl_802CEAC0:
-/* 802CEAC0 94 21 FF E0 */ stwu r1, -0x20(r1)
-/* 802CEAC4 7C 08 02 A6 */ mflr r0
-/* 802CEAC8 90 01 00 24 */ stw r0, 0x24(r1)
-/* 802CEACC 93 E1 00 1C */ stw r31, 0x1c(r1)
-/* 802CEAD0 7C 7F 1B 78 */ mr r31, r3
-/* 802CEAD4 48 00 00 20 */ b lbl_802CEAF4
-lbl_802CEAD8:
-/* 802CEAD8 80 61 00 08 */ lwz r3, 8(r1)
-/* 802CEADC 80 63 00 00 */ lwz r3, 0(r3)
-/* 802CEAE0 38 80 FF FF */ li r4, -1
-/* 802CEAE4 81 83 00 00 */ lwz r12, 0(r3)
-/* 802CEAE8 81 8C 00 08 */ lwz r12, 8(r12)
-/* 802CEAEC 7D 89 03 A6 */ mtctr r12
-/* 802CEAF0 4E 80 04 21 */ bctrl
-lbl_802CEAF4:
-/* 802CEAF4 80 1F 00 5C */ lwz r0, 0x5c(r31)
-/* 802CEAF8 90 01 00 08 */ stw r0, 8(r1)
-/* 802CEAFC 28 00 00 00 */ cmplwi r0, 0
-/* 802CEB00 40 82 FF D8 */ bne lbl_802CEAD8
-/* 802CEB04 83 E1 00 1C */ lwz r31, 0x1c(r1)
-/* 802CEB08 80 01 00 24 */ lwz r0, 0x24(r1)
-/* 802CEB0C 7C 08 03 A6 */ mtlr r0
-/* 802CEB10 38 21 00 20 */ addi r1, r1, 0x20
-/* 802CEB14 4E 80 00 20 */ blr
diff --git a/asm/JSystem/JKernel/JKRHeap/getMaxAllocatableSize__7JKRHeapFi.s b/asm/JSystem/JKernel/JKRHeap/getMaxAllocatableSize__7JKRHeapFi.s
deleted file mode 100644
index fddb50d943..0000000000
--- a/asm/JSystem/JKernel/JKRHeap/getMaxAllocatableSize__7JKRHeapFi.s
+++ /dev/null
@@ -1,25 +0,0 @@
-lbl_802CE7DC:
-/* 802CE7DC 94 21 FF E0 */ stwu r1, -0x20(r1)
-/* 802CE7E0 7C 08 02 A6 */ mflr r0
-/* 802CE7E4 90 01 00 24 */ stw r0, 0x24(r1)
-/* 802CE7E8 39 61 00 20 */ addi r11, r1, 0x20
-/* 802CE7EC 48 09 39 F1 */ bl _savegpr_29
-/* 802CE7F0 7C 7D 1B 78 */ mr r29, r3
-/* 802CE7F4 7C 9E 23 78 */ mr r30, r4
-/* 802CE7F8 4B FF FF 61 */ bl getMaxFreeBlock__7JKRHeapFv
-/* 802CE7FC 7C 7F 1B 78 */ mr r31, r3
-/* 802CE800 7F A3 EB 78 */ mr r3, r29
-/* 802CE804 4B FF FF 29 */ bl getFreeSize__7JKRHeapFv
-/* 802CE808 38 9E FF FF */ addi r4, r30, -1
-/* 802CE80C 57 E0 07 3E */ clrlwi r0, r31, 0x1c
-/* 802CE810 7C 00 F0 50 */ subf r0, r0, r30
-/* 802CE814 7C 80 00 38 */ and r0, r4, r0
-/* 802CE818 7C 60 18 50 */ subf r3, r0, r3
-/* 802CE81C 7C 80 20 F8 */ nor r0, r4, r4
-/* 802CE820 7C 03 18 38 */ and r3, r0, r3
-/* 802CE824 39 61 00 20 */ addi r11, r1, 0x20
-/* 802CE828 48 09 3A 01 */ bl _restgpr_29
-/* 802CE82C 80 01 00 24 */ lwz r0, 0x24(r1)
-/* 802CE830 7C 08 03 A6 */ mtlr r0
-/* 802CE834 38 21 00 20 */ addi r1, r1, 0x20
-/* 802CE838 4E 80 00 20 */ blr
diff --git a/asm/d/a/d_a_alink/dComIfGp_getEvent__Fv.s b/asm/d/a/d_a_alink/dComIfGp_getEvent__Fv.s
deleted file mode 100644
index e932222b35..0000000000
--- a/asm/d/a/d_a_alink/dComIfGp_getEvent__Fv.s
+++ /dev/null
@@ -1,5 +0,0 @@
-lbl_801412F8:
-/* 801412F8 3C 60 80 40 */ lis r3, g_dComIfG_gameInfo@ha /* 0x804061C0@ha */
-/* 801412FC 38 63 61 C0 */ addi r3, r3, g_dComIfG_gameInfo@l /* 0x804061C0@l */
-/* 80141300 38 63 4E C8 */ addi r3, r3, 0x4ec8
-/* 80141304 4E 80 00 20 */ blr
diff --git a/include/JSystem/JUtility/JUTAssert.h b/include/JSystem/JUtility/JUTAssert.h
index 61edbfbee3..219ef76eea 100644
--- a/include/JSystem/JUtility/JUTAssert.h
+++ b/include/JSystem/JUtility/JUTAssert.h
@@ -10,17 +10,21 @@
OSPanic(FILE, LINE, "Halt"); \
}
-#else
-#define JUT_ASSERT(...)
-#endif
-
-#if DEBUG
#define JUT_PANIC(FILE, LINE, TEXT) \
JUTAssertion::showAssert(JUTAssertion::getSDevice(), FILE, LINE, TEXT); \
OSPanic(FILE, LINE, "Halt");
+#define JUT_WARN(FILE, LINE, ...) \
+ JUTAssertion::setWarningMessage_f(JUTAssertion::getSDevice(), FILE, LINE, __VA_ARGS__)
+
+#define JUT_LOG(LINE, ...) \
+ JUTAssertion::setLogMessage_f(JUTAssertion::getSDevice(), __FILE__, LINE, __VA_ARGS__)
+
#else
+#define JUT_ASSERT(...)
#define JUT_PANIC(...)
+#define JUT_WARN(...)
+#define JUT_LOG(...)
#endif
namespace JUTAssertion {
diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h
index 99da12c7c8..05a1661c41 100644
--- a/include/JSystem/JUtility/JUTException.h
+++ b/include/JSystem/JUtility/JUTException.h
@@ -103,6 +103,9 @@ public:
static void setMapFile(const char* map) {
appendMapFile(map);
}
+ static void panic(const char* file, int line, const char* msg) {
+ panic_f(file, line, "%s", msg);
+ }
private:
static OSMessageQueue sMessageQueue;
diff --git a/include/MSL_C/MSL_Common/Src/stddef.h b/include/MSL_C/MSL_Common/Src/stddef.h
index 91086efb33..7d93b65045 100644
--- a/include/MSL_C/MSL_Common/Src/stddef.h
+++ b/include/MSL_C/MSL_Common/Src/stddef.h
@@ -5,8 +5,13 @@
extern "C" {
#endif
+#if defined __INTELLISENSE__
+typedef unsigned int size_t;
+typedef int ptrdiff_t;
+#else
typedef unsigned long size_t;
typedef long ptrdiff_t;
+#endif
#ifndef NULL
#define NULL (0)
diff --git a/include/global.h b/include/global.h
index 8f0e1a3a78..2a255c6070 100644
--- a/include/global.h
+++ b/include/global.h
@@ -14,7 +14,6 @@
#define JUT_EXPECT(...)
#define ASSERT(...)
-#define LOGF(FMT, ...)
#define FLAG_ON(V, F) (((V) & (F)) == 0)
#define FLOAT_LABEL(x) (*(f32*)&x)
diff --git a/libs/JSystem/JKernel/JKRHeap.cpp b/libs/JSystem/JKernel/JKRHeap.cpp
index 0931d53d32..ba90032b3f 100644
--- a/libs/JSystem/JKernel/JKRHeap.cpp
+++ b/libs/JSystem/JKernel/JKRHeap.cpp
@@ -9,20 +9,6 @@
#include "dolphin/os/OS.h"
//
-// Forward References:
-//
-
-extern "C" void getFreeSize__7JKRHeapFv();
-extern "C" void getMaxFreeBlock__7JKRHeapFv();
-
-//
-// External References:
-//
-
-extern "C" void _savegpr_29();
-extern "C" void _restgpr_29();
-
-//
// Declarations:
//
@@ -79,11 +65,13 @@ JKRHeap::~JKRHeap() {
mChildTree.getParent()->removeChild(&mChildTree);
JSUTree<JKRHeap>* nextRootHeap = sRootHeap->mChildTree.getFirstChild();
- if (sCurrentHeap == this)
+ if (sCurrentHeap == this) {
sCurrentHeap = !nextRootHeap ? sRootHeap : nextRootHeap->getObject();
+ }
- if (sSystemHeap == this)
+ if (sSystemHeap == this) {
sSystemHeap = !nextRootHeap ? sRootHeap : nextRootHeap->getObject();
+ }
}
/* ############################################################################################## */
@@ -167,6 +155,9 @@ void* JKRHeap::alloc(u32 size, int alignment, JKRHeap* heap) {
/* 802CE4D4-802CE500 2C8E14 002C+00 1/1 30/30 1/1 .text alloc__7JKRHeapFUli */
void* JKRHeap::alloc(u32 size, int alignment) {
+ if (mInitFlag) {
+ JUT_WARN(__FILE__, 393, "alloc %x byte in heap %x", size, this);
+ }
return do_alloc(size, alignment);
}
@@ -183,6 +174,9 @@ void JKRHeap::free(void* ptr, JKRHeap* heap) {
/* 802CE548-802CE574 2C8E88 002C+00 1/1 29/29 0/0 .text free__7JKRHeapFPv */
void JKRHeap::free(void* ptr) {
+ if (mInitFlag) {
+ JUT_WARN(__FILE__, 441, "free %x in heap %x", ptr, this);
+ }
do_free(ptr);
}
@@ -197,11 +191,17 @@ void JKRHeap::callAllDisposer() {
/* 802CE5CC-802CE5F8 2C8F0C 002C+00 0/0 12/12 0/0 .text freeAll__7JKRHeapFv */
void JKRHeap::freeAll() {
+ if (mInitFlag) {
+ JUT_WARN(__FILE__, 493, "freeAll in heap %x", this);
+ }
do_freeAll();
}
/* 802CE5F8-802CE624 2C8F38 002C+00 0/0 1/1 0/0 .text freeTail__7JKRHeapFv */
void JKRHeap::freeTail() {
+ if (mInitFlag) {
+ JUT_WARN(__FILE__, 507, "freeTail in heap %x", this);
+ }
do_freeTail();
}
@@ -218,6 +218,9 @@ s32 JKRHeap::resize(void* ptr, u32 size, JKRHeap* heap) {
/* 802CE684-802CE6B0 2C8FC4 002C+00 1/1 1/1 0/0 .text resize__7JKRHeapFPvUl */
s32 JKRHeap::resize(void* ptr, u32 size) {
+ if (mInitFlag) {
+ JUT_WARN(__FILE__, 567, "resize block %x into %x in heap %x", ptr, size, this);
+ }
return do_resize(ptr, size);
}
@@ -254,32 +257,19 @@ s32 JKRHeap::getTotalFreeSize() {
/* 802CE7B0-802CE7DC 2C90F0 002C+00 0/0 1/1 0/0 .text changeGroupID__7JKRHeapFUc */
s32 JKRHeap::changeGroupID(u8 groupID) {
+ if (mInitFlag) {
+ JUT_WARN(__FILE__, 646, "change heap ID into %x in heap %x", groupID, this);
+ }
return do_changeGroupID(groupID);
}
/* 802CE7DC-802CE83C 2C911C 0060+00 0/0 2/2 0/0 .text getMaxAllocatableSize__7JKRHeapFi
*/
-// "not/nor" instruction in the wrong place
-#ifdef NONMATCHING
u32 JKRHeap::getMaxAllocatableSize(int alignment) {
u32 maxFreeBlock = (u32)getMaxFreeBlock();
- s32 freeSize = getFreeSize();
-
- u32 mask = alignment - 1U;
- s32 ptrOffset = mask & (alignment - (maxFreeBlock & 0xf));
- s32 alignedSize = (freeSize - ptrOffset) & ~(alignment - 1U);
- return alignedSize;
-}
-#else
-#pragma push
-#pragma optimization_level 0
-#pragma optimizewithasm off
-asm u32 JKRHeap::getMaxAllocatableSize(int param_0) {
- nofralloc
-#include "asm/JSystem/JKernel/JKRHeap/getMaxAllocatableSize__7JKRHeapFi.s"
-}
-#pragma pop
-#endif
+ u32 ptrOffset = (alignment - 1) & alignment - (maxFreeBlock & 0xf);
+ return ~(alignment - 1) & (getFreeSize() - ptrOffset);
+}
/* 802CE83C-802CE894 2C917C 0058+00 3/3 8/8 0/0 .text findFromRoot__7JKRHeapFPv */
JKRHeap* JKRHeap::findFromRoot(void* ptr) {
@@ -366,9 +356,7 @@ void JKRHeap::dispose_subroutine(u32 begin, u32 end) {
/* 802CEA78-802CEAA0 2C93B8 0028+00 0/0 1/1 0/0 .text dispose__7JKRHeapFPvUl */
bool JKRHeap::dispose(void* ptr, u32 size) {
- u32 begin = (u32)ptr;
- u32 end = (u32)ptr + size;
- dispose_subroutine(begin, end);
+ dispose_subroutine((u32)ptr, (u32)ptr + size);
return false;
}
@@ -378,26 +366,12 @@ void JKRHeap::dispose(void* begin, void* end) {
}
/* 802CEAC0-802CEB18 2C9400 0058+00 0/0 3/3 0/0 .text dispose__7JKRHeapFv */
-// missing stack variable?
-#ifdef NONMATCHING
void JKRHeap::dispose() {
- const JSUList<JKRDisposer>& list = mDisposerList;
JSUListIterator<JKRDisposer> iterator;
- while (list.getFirst() != list.getEnd()) {
- iterator = list.getFirst();
+ while ((iterator = mDisposerList.getFirst()) != mDisposerList.getEnd()) {
iterator->~JKRDisposer();
}
}
-#else
-#pragma push
-#pragma optimization_level 0
-#pragma optimizewithasm off
-asm void JKRHeap::dispose() {
- nofralloc
-#include "asm/JSystem/JKernel/JKRHeap/dispose__7JKRHeapFv.s"
-}
-#pragma pop
-#endif
/* 802CEB18-802CEB40 2C9458 0028+00 0/0 4/4 0/0 .text copyMemory__7JKRHeapFPvPvUl */
void JKRHeap::copyMemory(void* dst, void* src, u32 size) {
@@ -415,7 +389,11 @@ void JKRHeap::copyMemory(void* dst, void* src, u32 size) {
/* 802CEB40-802CEB78 2C9480 0038+00 2/2 0/0 0/0 .text JKRDefaultMemoryErrorRoutine__FPvUli */
void JKRDefaultMemoryErrorRoutine(void* heap, u32 size, int alignment) {
- JUTException::panic_f(__FILE__, 831, "%s", "abort\n");
+#if DEBUG
+ OSReport("Error: Cannot allocate memory %d(0x%x)byte in %d byte alignment from %08x\n", size,
+ size, alignment, heap);
+#endif
+ JUTException::panic(__FILE__, 831, "abort\n");
}
/* 802CEB78-802CEB88 2C94B8 0010+00 0/0 2/2 0/0 .text setErrorFlag__7JKRHeapFb */
@@ -462,32 +440,32 @@ bool JKRHeap::isSubHeap(JKRHeap* heap) const {
}
/* 802CEC4C-802CEC74 2C958C 0028+00 0/0 278/278 377/377 .text __nw__FUl */
-void* operator new(u32 size) {
+void* operator new(size_t size) {
return JKRHeap::alloc(size, 4, NULL);
}
/* 802CEC74-802CEC98 2C95B4 0024+00 0/0 15/15 0/0 .text __nw__FUli */
-void* operator new(u32 size, int alignment) {
+void* operator new(size_t size, int alignment) {
return JKRHeap::alloc(size, alignment, NULL);
}
/* 802CEC98-802CECC4 2C95D8 002C+00 0/0 47/47 0/0 .text __nw__FUlP7JKRHeapi */
-void* operator new(u32 size, JKRHeap* heap, int alignment) {
+void* operator new(size_t size, JKRHeap* heap, int alignment) {
return JKRHeap::alloc(size, alignment, heap);
}
/* 802CECC4-802CECEC 2C9604 0028+00 0/0 52/52 15/15 .text __nwa__FUl */
-void* operator new[](u32 size) {
+void* operator new[](size_t size) {
return JKRHeap::alloc(size, 4, NULL);
}
/* 802CECEC-802CED10 2C962C 0024+00 0/0 29/29 0/0 .text __nwa__FUli */
-void* operator new[](u32 size, int alignment) {
+void* operator new[](size_t size, int alignment) {
return JKRHeap::alloc(size, alignment, NULL);
}
/* 802CED10-802CED3C 2C9650 002C+00 0/0 25/25 0/0 .text __nwa__FUlP7JKRHeapi */
-void* operator new[](u32 size, JKRHeap* heap, int alignment) {
+void* operator new[](size_t size, JKRHeap* heap, int alignment) {
return JKRHeap::alloc(size, alignment, heap);
}
@@ -510,16 +488,16 @@ u32 JKRHeap::state_register(JKRHeap::TState* p, u32 id) const {
/* 802CED88-802CEDA0 2C96C8 0018+00 1/0 1/0 0/0 .text
* state_compare__7JKRHeapCFRCQ27JKRHeap6TStateRCQ27JKRHeap6TState */
-bool JKRHeap::state_compare(JKRHeap::TState const& r1, JKRHeap::TState const& r2) const {
+bool JKRHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const {
JUT_ASSERT(__FILE__, 1222, r1.getHeap() == r2.getHeap());
return r1.getCheckCode() == r2.getCheckCode();
}
/* 802CEDA0-802CEDA4 2C96E0 0004+00 1/0 3/0 0/0 .text state_dump__7JKRHeapCFRCQ27JKRHeap6TState */
-void JKRHeap::state_dump(JKRHeap::TState const& p) const {
- LOGF("check-code : 0x%08x", p.getCheckCode());
- LOGF("id : 0x%08x", p.getId());
- LOGF("used size : %u", p.getUsedSize());
+void JKRHeap::state_dump(const JKRHeap::TState& p) const {
+ JUT_LOG(__FILE__, 1246, "check-code : 0x%08x", p.getCheckCode());
+ JUT_LOG(__FILE__, 1247, "id : 0x%08x", p.getId());
+ JUT_LOG(__FILE__, 1248, "used size : %u", p.getUsedSize());
}
/* 802CEDA4-802CEDAC 2C96E4 0008+00 1/0 1/0 0/0 .text do_changeGroupID__7JKRHeapFUc */