through InitSubHeap

This commit is contained in:
PikalaxALT 2017-12-12 22:09:52 -05:00
parent 48f00a9b91
commit 7d0a8444ff
2 changed files with 46 additions and 83 deletions

View File

@ -5,84 +5,6 @@
.text
thumb_func_start DoInitHeap
DoInitHeap:
push {r4-r6,lr}
mov r6, r9
mov r5, r8
push {r5,r6}
ldr r4, [r1, 0x4]
mov r9, r4
movs r4, 0x4
negs r4, r4
mov r5, r9
ands r5, r4
mov r9, r5
ldr r6, _08002FFC
ldr r4, _08003000
mov r8, r4
ldr r5, [r4]
lsls r4, r5, 2
adds r4, r6
str r0, [r4]
adds r5, 0x1
mov r4, r8
str r5, [r4]
ldr r5, [r1]
str r5, [r0, 0x14]
mov r1, r9
str r1, [r0, 0x18]
movs r1, 0x2
str r1, [r0]
movs r4, 0
str r4, [r0, 0x4]
str r2, [r0, 0x8]
movs r1, 0x1
str r1, [r0, 0xC]
str r3, [r0, 0x10]
str r4, [r2]
str r4, [r2, 0x4]
str r5, [r2, 0xC]
mov r5, r9
str r5, [r2, 0x10]
str r4, [r2, 0x14]
str r4, [r2, 0x8]
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r6}
pop {r0}
bx r0
.align 2, 0
_08002FFC: .4byte gUnknown_2000E88
_08003000: .4byte gUnknown_2000EA8
thumb_func_end DoInitHeap
thumb_func_start InitSubHeap
InitSubHeap:
push {r4,r5,lr}
sub sp, 0x8
adds r3, r2, 0
lsls r4, r3, 1
adds r4, r3
movs r2, 0x4
negs r2, r2
lsls r4, 3
ldr r5, [r1, 0x4]
subs r5, r4
ands r5, r2
ldr r2, [r1]
adds r4, r2, r4
str r4, [sp]
str r5, [sp, 0x4]
mov r1, sp
bl DoInitHeap
add sp, 0x8
pop {r4,r5}
pop {r0}
bx r0
thumb_func_end InitSubHeap
thumb_func_start xxx_memory_attr_related
xxx_memory_attr_related:
push {lr}

View File

@ -6,15 +6,27 @@
// Static type declarations
struct HeapInitArgs {
void *ptr;
u8 *ptr;
u32 size;
};
struct MemoryBlock {
u32 unk_00;
u32 unk_04;
struct MemoryBlock *next;
u32 unk_0c;
size_t unk_10;
u8 *data;
size_t unk_18;
u32 unk_1c;
};
// Static RAM declarations
struct MemoryBlock *gUnknown_2000E88[8] = {};
u32 gUnknown_2000EA8 = 0;
u8 gUnknown_2000EB0[0x20] = {};
u8 gUnknown_2000ED0[0x300] = {};
struct MemoryBlock gUnknown_2000EB0 = {};
struct MemoryBlock gUnknown_2000ED0[24] = {};
u8 gUnknown_20011D0[0x24000] = {};
// Static ROM declarations
@ -24,7 +36,7 @@ u8 gUnknown_20011D0[0x24000] = {};
// .text
void InitHeapInternal(void);
void DoInitHeap(void *a0, struct HeapInitArgs *args, void *a2, size_t a3);
void DoInitHeap(struct MemoryBlock *a0, struct HeapInitArgs *args, struct MemoryBlock *a2, size_t a3);
void InitHeap(void)
{
@ -114,5 +126,34 @@ void InitHeapInternal(void)
args.ptr = gUnknown_20011D0;
args.size = sizeof gUnknown_20011D0;
gUnknown_2000EA8 = 0;
DoInitHeap(gUnknown_2000EB0, &args, gUnknown_2000ED0, sizeof gUnknown_2000EB0);
DoInitHeap(&gUnknown_2000EB0, &args, gUnknown_2000ED0, sizeof gUnknown_2000EB0);
}
void DoInitHeap(struct MemoryBlock *a0, struct HeapInitArgs *args, struct MemoryBlock *a2, size_t a3)
{
size_t size = args->size & ~3; // r9
gUnknown_2000E88[gUnknown_2000EA8] = a0;
gUnknown_2000EA8++;
a0->data = args->ptr;
a0->unk_18 = size;
a0->unk_00 = 2;
a0->unk_04 = 0;
a0->next = a2;
a0->unk_0c = 1;
a0->unk_10 = a3;
a2->unk_00 = 0;
a2->unk_04 = 0;
a2->unk_0c = (intptr_t)args->ptr;
a2->unk_10 = size;
a2->data = NULL;
a2->next = NULL;
}
void InitSubHeap(struct MemoryBlock *a0, struct HeapInitArgs *srcArgs, size_t size)
{
size_t size_ = size * 3;
int r2 = ~3;
size_t size__ = r2 & (srcArgs->size - size_ * 8);
struct HeapInitArgs args = {srcArgs->ptr + size_ * 8, size__};
DoInitHeap(a0, &args, (struct MemoryBlock *)srcArgs->ptr, size);
}