From d8eb347247a426919a019b43c7e9c5eebcf25aea Mon Sep 17 00:00:00 2001 From: plutoo Date: Mon, 11 Sep 2017 01:13:01 +0200 Subject: [PATCH] Fixed heap --- crt0/switch_crt0.s | 24 +++++++++--------------- nx/source/heap/heap.c | 5 +++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/crt0/switch_crt0.s b/crt0/switch_crt0.s index ddb7db11..ea16ae9a 100644 --- a/crt0/switch_crt0.s +++ b/crt0/switch_crt0.s @@ -9,7 +9,7 @@ _start: startup: // get aslr base - sub x30, x30, #4 + sub x28, x30, #4 // clear .bss ldr x0, =__bss_start__ @@ -18,7 +18,7 @@ startup: add x1, x1, #7 // round up to 8 bic x1, x1, #7 mov x2, #0 - add x0, x0, x30 // relocate ptr + add x0, x0, x28 // relocate ptr bss_loop: str x2, [x0], #8 @@ -31,30 +31,24 @@ bss_loop: sub x1, x1, x0 // calculate size add x1, x1, #7 // round up to 8 bic x1, x1, #7 - add x0, x0, x30 // relocate ptr + add x0, x0, x28 // relocate ptr got_loop: - ldr x3, [x0] - add x3, x3, x30 - str x3, [x0], #8 + ldr x2, [x0] + add x2, x2, x28 + str x2, [x0], #8 subs x1, x1, #8 bne got_loop - - // setup heap - ldr x1, =HEAP_SIZE - svc 1 // check retval? - mov x0, x1 - ldr x1, =HEAP_SIZE - ldr x3, =heapInit - add x3, x3, x30 + ldr x3, =heapSetup + add x3, x3, x28 blr x3 mov x0, #0 // argc mov x1, #0 // argv ldr x3, =main - add x3, x3, x30 + add x3, x3, x28 blr x3 _sysexit: diff --git a/nx/source/heap/heap.c b/nx/source/heap/heap.c index dc1f0187..48ceee19 100644 --- a/nx/source/heap/heap.c +++ b/nx/source/heap/heap.c @@ -31,6 +31,11 @@ void heapInit(void* base, size_t size) { g_LastFree.Prev = hdr; } +void heapSetup() { + static u8 g_Heap[0x20000]; + heapInit(g_Heap, sizeof(g_Heap)); +} + void* heapAllocPages(size_t size) { void* ptr = heapAlloc(size + 0x1000);