summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/sparc/shared/startup
diff options
context:
space:
mode:
authorDaniel Hellstrom <daniel@gaisler.com>2012-03-28 10:49:27 +0200
committerGedare Bloom <gedare@rtems.org>2012-03-29 12:33:01 -0400
commit0729e2a7af22fa27defcd1daa90aad32721947b6 (patch)
tree1b499f51298536bcfb929b8b34fd3b225ee1b48a /c/src/lib/libbsp/sparc/shared/startup
parentSMC91111: remove old unused LEON2/LEON3 intialization code (diff)
downloadrtems-0729e2a7af22fa27defcd1daa90aad32721947b6.tar.bz2
SPARC: bsp_early_malloc() routine for startup memory allocation
If bsp_early_malloc() is called early during boot room will be allocated after BSS END. If the function is called after boot is will call malloc() instead. The returned memory is not freeable and always 8-byte aligned. If the bsp_early_malloc() isn't called the function is not dragged in and the workspace will be unmodified in size. Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
Diffstat (limited to 'c/src/lib/libbsp/sparc/shared/startup')
-rw-r--r--c/src/lib/libbsp/sparc/shared/startup/early_malloc.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c b/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c
new file mode 100644
index 0000000000..1f968da206
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c
@@ -0,0 +1,47 @@
+/*
+ * Early dynamic memory allocation (not freeable) for BSP
+ * boot routines. Minimum alignment 8 bytes. Memory is
+ * allocated after _end, it will shrink the workspace.
+ *
+ * COPYRIGHT (c) 2011.
+ * Aeroflex Gaisler AB
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#include <bsp.h>
+#include <stdlib.h>
+
+/* Tells us where to put the workspace in case remote debugger is present. */
+extern uint32_t rdb_start;
+
+/* Must be aligned to 8 */
+extern unsigned int early_mem;
+
+/* must be identical to STACK_SIZE in start.S */
+#define STACK_SIZE (16 * 1024)
+
+/* Allocate 8-byte aligned non-freeable pre-malloc() memory. The function
+ * can be called at any time. The work-area will shrink when called before
+ * bsp_get_work_area(). malloc() is called to get memory when this function
+ * is called after bsp_get_work_area().
+ */
+void *bsp_early_malloc(int size)
+{
+ void *start;
+
+ /* Not early anymore? */
+ if (early_mem == ~0)
+ return malloc(size);
+
+ size = (size + 7) & ~0x7;
+ if (rdb_start - STACK_SIZE - early_mem < size)
+ return NULL;
+
+ start = (void *)early_mem;
+ early_mem += size;
+
+ return start;
+}