Consolidate arch-specific sbrk() implementations
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 4a18562..f3bced4 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1502,7 +1502,23 @@
*p++ += gd->reloc_off;
}
}
-
+
+ulong mem_malloc_start = 0;
+ulong mem_malloc_end = 0;
+ulong mem_malloc_brk = 0;
+
+void *sbrk(ptrdiff_t increment)
+{
+ ulong old = mem_malloc_brk;
+ ulong new = old + increment;
+
+ if ((new < mem_malloc_start) || (new > mem_malloc_end))
+ return NULL;
+
+ mem_malloc_brk = new;
+
+ return (void *)old;
+}
/* field-extraction macros */
diff --git a/include/malloc.h b/include/malloc.h
index a38464e..0382169 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -937,6 +937,12 @@
struct mallinfo mALLINFo();
#endif
+/*
+ * Begin and End of memory area for malloc(), and current "brk"
+ */
+extern ulong mem_malloc_start;
+extern ulong mem_malloc_end;
+extern ulong mem_malloc_brk;
#ifdef __cplusplus
}; /* end of extern "C" */
diff --git a/lib_arm/board.c b/lib_arm/board.c
index fa87d51..62b7874 100644
--- a/lib_arm/board.c
+++ b/lib_arm/board.c
@@ -82,13 +82,6 @@
#include <i2c.h>
#endif
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
static
void mem_malloc_init (ulong dest_addr)
{
@@ -100,19 +93,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
-
- return ((void *) old);
-}
-
/************************************************************************
* Coloured LED functionality
diff --git a/lib_avr32/board.c b/lib_avr32/board.c
index e2b0a2e..03a520c 100644
--- a/lib_avr32/board.c
+++ b/lib_avr32/board.c
@@ -41,13 +41,6 @@
unsigned long monitor_flash_len;
-/*
- * Begin and end of memory area for malloc(), and current "brk"
- */
-static unsigned long mem_malloc_start = 0;
-static unsigned long mem_malloc_end = 0;
-static unsigned long mem_malloc_brk = 0;
-
/* Weak aliases for optional board functions */
static int __do_nothing(void)
{
@@ -73,18 +66,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk(ptrdiff_t increment)
-{
- unsigned long old = mem_malloc_brk;
- unsigned long new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end))
- return NULL;
-
- mem_malloc_brk = new;
- return ((void *)old);
-}
-
#ifdef CONFIG_SYS_DMA_ALLOC_LEN
#include <asm/arch/cacheflush.h>
#include <asm/io.h>
diff --git a/lib_blackfin/board.c b/lib_blackfin/board.c
index 5b9efde..9c405ba 100644
--- a/lib_blackfin/board.c
+++ b/lib_blackfin/board.c
@@ -44,27 +44,13 @@
#endif
}
-static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk;
-
static void mem_malloc_init(void)
{
- mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE;
- mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
+ mem_malloc_start = (ulong)CONFIG_SYS_MALLOC_BASE;
+ mem_malloc_end = (ulong)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
mem_malloc_brk = mem_malloc_start;
- memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
-}
-
-void *sbrk(ptrdiff_t increment)
-{
- void *old = mem_malloc_brk;
- void *new = old + increment;
-
- if (new < mem_malloc_start || new > mem_malloc_end)
- return NULL;
-
- mem_malloc_brk = new;
- return old;
+ memset((void*)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
}
static int display_banner(void)
diff --git a/lib_i386/board.c b/lib_i386/board.c
index 54ef6e7..0262b5e 100644
--- a/lib_i386/board.c
+++ b/lib_i386/board.c
@@ -73,14 +73,6 @@
const char version_string[] =
U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
-
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
static int mem_malloc_init(void)
{
/* start malloc area right after the stack */
@@ -96,19 +88,6 @@
return 0;
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
-
- return ((void *) old);
-}
-
/************************************************************************
* Init Utilities *
************************************************************************
diff --git a/lib_m68k/board.c b/lib_m68k/board.c
index 483c9b6..4392bcc 100644
--- a/lib_m68k/board.c
+++ b/lib_m68k/board.c
@@ -101,13 +101,6 @@
ulong monitor_flash_len;
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
/************************************************************************
* Utilities *
************************************************************************
@@ -129,19 +122,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) ||
- (new > mem_malloc_end) ) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *)old);
-}
-
/*
* All attempts to come up with a "common" initialization sequence
* that works for all boards and architectures failed: some of the
diff --git a/lib_microblaze/board.c b/lib_microblaze/board.c
index cfed5fe..fc25a75 100644
--- a/lib_microblaze/board.c
+++ b/lib_microblaze/board.c
@@ -47,13 +47,6 @@
#endif
/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start;
-static ulong mem_malloc_end;
-static ulong mem_malloc_brk;
-
-/*
* The Malloc area is immediately below the monitor copy in DRAM
* aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
* as our monitory code is run from SDRAM
@@ -66,18 +59,6 @@
memset ((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *)old);
-}
-
/*
* All attempts to come up with a "common" initialization sequence
* that works for all boards and architectures failed: some of the
diff --git a/lib_mips/board.c b/lib_mips/board.c
index aa5b129..68a3697 100644
--- a/lib_mips/board.c
+++ b/lib_mips/board.c
@@ -60,13 +60,6 @@
static char *failed = "*** failed ***\n";
/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start;
-static ulong mem_malloc_end;
-static ulong mem_malloc_brk;
-
-/*
* mips_io_port_base is the begin of the address space to which x86 style
* I/O ports are mapped.
*/
@@ -97,18 +90,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *) old);
-}
-
static int init_func_ram (void)
{
diff --git a/lib_nios/board.c b/lib_nios/board.c
index cd23457..30cdb47 100644
--- a/lib_nios/board.c
+++ b/lib_nios/board.c
@@ -27,6 +27,7 @@
#include <common.h>
#include <stdio_dev.h>
#include <watchdog.h>
+#include <malloc.h>
#include <net.h>
#ifdef CONFIG_STATUS_LED
#include <status_led.h>
@@ -52,13 +53,6 @@
typedef int (init_fnc_t) (void);
/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
-/*
* The Malloc area is immediately below the monitor copy in RAM
*/
static void mem_malloc_init (void)
@@ -71,18 +65,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *) old);
-}
-
/************************************************************************
* Initialization sequence *
diff --git a/lib_nios2/board.c b/lib_nios2/board.c
index b142c59..e5a8d54 100644
--- a/lib_nios2/board.c
+++ b/lib_nios2/board.c
@@ -27,6 +27,7 @@
#include <common.h>
#include <stdio_dev.h>
#include <watchdog.h>
+#include <malloc.h>
#include <net.h>
#ifdef CONFIG_STATUS_LED
#include <status_led.h>
@@ -55,13 +56,6 @@
typedef int (init_fnc_t) (void);
/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
-/*
* The Malloc area is immediately below the monitor copy in RAM
*/
static void mem_malloc_init (void)
@@ -74,18 +68,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *) old);
-}
-
/************************************************************************
* Initialization sequence *
diff --git a/lib_ppc/board.c b/lib_ppc/board.c
index 9faf7f2..f0cc3ce 100644
--- a/lib_ppc/board.c
+++ b/lib_ppc/board.c
@@ -136,13 +136,6 @@
#include <bedbug/type.h>
#endif
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
/************************************************************************
* Utilities *
************************************************************************
@@ -164,18 +157,6 @@
mem_malloc_end - mem_malloc_start);
}
-void *sbrk (ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *) old);
-}
-
/*
* All attempts to come up with a "common" initialization sequence
* that works for all boards and architectures failed: some of the
diff --git a/lib_sh/board.c b/lib_sh/board.c
index 829455d..001e89c 100644
--- a/lib_sh/board.c
+++ b/lib_sh/board.c
@@ -38,10 +38,6 @@
unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
-static unsigned long mem_malloc_start;
-static unsigned long mem_malloc_end;
-static unsigned long mem_malloc_brk;
-
static void mem_malloc_init(void)
{
@@ -52,20 +48,6 @@
(mem_malloc_end - mem_malloc_start));
}
-void *sbrk(ptrdiff_t increment)
-{
- unsigned long old = mem_malloc_brk;
- unsigned long new = old + increment;
-
- if ((new < mem_malloc_start) ||
- (new > mem_malloc_end)) {
- return NULL;
- }
-
- mem_malloc_brk = new;
- return (void *) old;
-}
-
static int sh_flash_init(void)
{
DECLARE_GLOBAL_DATA_PTR;
diff --git a/lib_sparc/board.c b/lib_sparc/board.c
index d40834b..37b7c0a 100644
--- a/lib_sparc/board.c
+++ b/lib_sparc/board.c
@@ -74,13 +74,6 @@
ulong monitor_flash_len;
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
/************************************************************************
* Utilities *
************************************************************************
@@ -97,18 +90,6 @@
memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
}
-void *sbrk(ptrdiff_t increment)
-{
- ulong old = mem_malloc_brk;
- ulong new = old + increment;
-
- if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
- return (NULL);
- }
- mem_malloc_brk = new;
- return ((void *)old);
-}
-
/***********************************************************************/
/************************************************************************