aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-09-12 16:24:43 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-09-12 17:25:01 -0400
commitf52af4876b0ffc98055fba237fb01852f1bfaaae (patch)
tree7c3571113c9b4b59beb1fefe4993418124cbb6ff
parentc3e769c44e072faebd5dc87582ff832bc13ee184 (diff)
downloadlibrambutan-f52af4876b0ffc98055fba237fb01852f1bfaaae.tar.gz
librambutan-f52af4876b0ffc98055fba237fb01852f1bfaaae.zip
[support/ld] Add linker support for reconfigurable heap.
- common_header.inc: Declare EXTERN symbols _lm_heap_start and _lm_heap_end. - common_rom.inc: Check for _lm_heap_start and _lm_heap_end. If they are defined, preserve their values. Otherwise, _lm_heap_start is starts after .bss, and _lm_heap_end is the end of SRAM. This allows existing linker scripts to continue using the old heap scheme, but allows for customizability elsewhere. - syscalls.c: Respect the addresses of _lm_heap_start and _lm_heap_end as the boundaries of the heap in _sbrk().
-rw-r--r--libmaple/syscalls.c18
-rw-r--r--support/ld/common_header.inc5
-rw-r--r--support/ld/common_rom.inc13
3 files changed, 21 insertions, 15 deletions
diff --git a/libmaple/syscalls.c b/libmaple/syscalls.c
index f28202c..a3f12f1 100644
--- a/libmaple/syscalls.c
+++ b/libmaple/syscalls.c
@@ -29,20 +29,12 @@
#include <sys/stat.h>
#include <errno.h>
-/* Set by the linker script */
-extern int _end;
+/* Set by the linker */
+extern char _lm_heap_start;
+extern char _lm_heap_end;
-/* FIXME these should be determined by the linker script.
- *
- * Doing so will allow the heap to be configured on a per-board basis.
- * Current values are just stopgaps for a heap in built-in SRAM.
- *
- * STACK_RESERVED_BYTES is just a hack to ensure a minimum stack size.
- * It should probably go away as well. */
-#define STACK_RESERVED_BYTES 1024
-#define HEAP_START ((caddr_t)&_end)
-#define HEAP_END ((caddr_t)((uint32)STM32_SRAM_END - \
- STACK_RESERVED_BYTES))
+#define HEAP_START ((caddr_t)&_lm_heap_start)
+#define HEAP_END ((caddr_t)&_lm_heap_end)
/*
* _sbrk -- Increment the program break.
diff --git a/support/ld/common_header.inc b/support/ld/common_header.inc
index 36ed2b1..1d11ba0 100644
--- a/support/ld/common_header.inc
+++ b/support/ld/common_header.inc
@@ -32,5 +32,6 @@ PROVIDE(__cs3_stack = __cs3_region_start_ram + LENGTH(ram));
EXTERN(_start)
PROVIDE(__cs3_reset = _start);
-/* Beginning of the heap */
-PROVIDE(__cs3_heap_start = _end);
+/* Heap boundaries, for libmaple */
+EXTERN(_lm_heap_start);
+EXTERN(_lm_heap_end);
diff --git a/support/ld/common_rom.inc b/support/ld/common_rom.inc
index 7284492..7182a4d 100644
--- a/support/ld/common_rom.inc
+++ b/support/ld/common_rom.inc
@@ -112,6 +112,19 @@ SECTIONS
*(.got.plt) *(.got)
*(.data .data.* .gnu.linkonce.d.*)
+
+
+ /*
+ * Heap: Linker scripts may choose a custom heap by overriding
+ * _lm_heap_start and _lm_heap_end. Otherwise, the heap is in
+ * internal SRAM, beginning after .bss, and growing towards
+ * the stack.
+ *
+ * I'm shoving these here naively; there's probably a cleaner way
+ * to go about this. [mbolivar]
+ */
+ _lm_heap_start = DEFINED(_lm_heap_start) ? _lm_heap_start : _end;
+ _lm_heap_end = DEFINED(_lm_heap_end) ? _lm_heap_end : __cs3_stack;
. = ALIGN (8);
_edata = .;
} > REGION_DATA AT> REGION_TEXT