]> Chaos Git - corbenik/ctrulib.git/commitdiff
Set default stack to 32K, allow user adjustment
authorDave Murphy <davem@devkitpro.org>
Mon, 29 Dec 2014 23:52:08 +0000 (23:52 +0000)
committerDave Murphy <davem@devkitpro.org>
Mon, 29 Dec 2014 23:52:51 +0000 (23:52 +0000)
libctru/source/system/allocateHeaps.c
libctru/source/system/ctru_exit.c
libctru/source/system/initSystem.c
libctru/source/system/init_exit_Wrappers.s [new file with mode: 0644]

index 4009f8ec6d9bef80b33f628d9c63db42da028992..d53625c3e42e1bd041f9b3f51e2c218e997b22d5 100644 (file)
@@ -7,6 +7,7 @@ u32 __linear_heap;
 u32 __heapBase;
 extern u32 __heap_size, __linear_heap_size;
 
+u32 __attribute__((weak)) __stacksize__ = 32 * 1024;
 
 void __attribute__((weak)) __system_allocateHeaps() {
        u32 tmp=0;
@@ -18,7 +19,7 @@ void __attribute__((weak)) __system_allocateHeaps() {
        // 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
+}
index 058ea7caa263e31ce1ebaccb4eb355cdfd5b692d..f4c99f1dc78fbe38d7bcee6cdb3f71e5be9f3766 100644 (file)
@@ -11,7 +11,7 @@ void __appExit();
 
 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;
 
index 080d1258c7fdf7a81f08d5ef6b342f9adacde5f2..47b1067976e17cb7794400263cfd6f1acc7a8955 100644 (file)
@@ -18,7 +18,7 @@ void __libc_init_array(void);
 
 void __ctru_exit(int rc);
 
-void __attribute__((weak)) initSystem(void (*retAddr)(void))
+void __attribute__((weak)) __ctru_initSystem(void (*retAddr)(void))
 {
 
        // Register newlib exit() syscall
diff --git a/libctru/source/system/init_exit_Wrappers.s b/libctru/source/system/init_exit_Wrappers.s
new file mode 100644 (file)
index 0000000..6155b64
--- /dev/null
@@ -0,0 +1,30 @@
+       .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