u32 __heapBase;
extern u32 __heap_size, __linear_heap_size;
+u32 __attribute__((weak)) __stacksize__ = 32 * 1024;
void __attribute__((weak)) __system_allocateHeaps() {
u32 tmp=0;
// Allocate the linear heap
svcControlMemory(&__linear_heap, 0x0, 0x0, __linear_heap_size, MEMOP_ALLOC_LINEAR, 0x3);
// Set up newlib heap
- fake_heap_start = (char*)__heapBase;
- fake_heap_end = fake_heap_start + __heap_size;
+ fake_heap_start = (char*)__heapBase + __stacksize__;
+ fake_heap_end = fake_heap_start + __heap_size - __stacksize__;
-}
\ No newline at end of file
+}
void __libc_fini_array(void);
-void __attribute__((weak)) __attribute__((noreturn)) __ctru_exit(int rc)
+void __attribute__((weak)) __attribute__((noreturn)) __libctru_exit(int rc)
{
u32 tmp=0;
void __ctru_exit(int rc);
-void __attribute__((weak)) initSystem(void (*retAddr)(void))
+void __attribute__((weak)) __ctru_initSystem(void (*retAddr)(void))
{
// Register newlib exit() syscall
--- /dev/null
+ .text
+ .arm
+ .cpu mpcore
+
+ .global initSystem
+ .type initSystem STT_FUNC
+@---------------------------------------------------------------------------------
+initSystem:
+@---------------------------------------------------------------------------------
+ adr r0, saved_lr
+ str lr, [r0]
+ str sp, [r0,#4]
+ bl __ctru_initSystem
+ ldr r0,=fake_heap_start
+ ldr sp, [r0]
+ ldr pc, saved_lr
+
+saved_lr:
+ .word 0
+saved_stack:
+ .word 0
+
+
+ .global __ctru_exit
+ .type __ctru_exit STT_FUNC
+@---------------------------------------------------------------------------------
+__ctru_exit:
+@---------------------------------------------------------------------------------
+ ldr sp, saved_stack
+ b __libctru_exit