summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-12-09 07:05:57 (UTC)
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-12-10 07:32:36 (UTC)
commit37030e38c61c0d0a8b0742af75f115bda779c46d (patch)
treed71cd94cf9d534fd606fffd50a0f3256cc822be9 /c/src/lib/libbsp
parent938ef78cc4c6fa2afe55426b603a3767de3262b5 (diff)
downloadrtems-37030e38.tar.bz2
bsps: Call bsp_work_area_initialize() early
Call bsp_work_area_initialize() before bsp_start(). This allows bsp_start() to use malloc() etc. which is beneficial for systems with a plug-and-play hardware enumeration. Update #2408.
Diffstat (limited to 'c/src/lib/libbsp')
-rw-r--r--c/src/lib/libbsp/arm/lpc176x/Makefile.am1
-rw-r--r--c/src/lib/libbsp/arm/lpc176x/startup/bspstart.c6
-rw-r--r--c/src/lib/libbsp/arm/lpc24xx/Makefile.am1
-rw-r--r--c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c4
-rw-r--r--c/src/lib/libbsp/i386/pc386/include/bsp.h2
-rw-r--r--c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c13
-rw-r--r--c/src/lib/libbsp/i386/pc386/startup/bspstart.c5
-rw-r--r--c/src/lib/libbsp/shared/bootcard.c8
-rw-r--r--c/src/lib/libbsp/shared/include/bootcard.h2
-rw-r--r--c/src/lib/libbsp/sparc/erc32/Makefile.am1
-rw-r--r--c/src/lib/libbsp/sparc/erc32/include/bsp.h7
-rw-r--r--c/src/lib/libbsp/sparc/leon2/Makefile.am1
-rw-r--r--c/src/lib/libbsp/sparc/leon2/include/bsp.h7
-rw-r--r--c/src/lib/libbsp/sparc/leon3/Makefile.am3
-rw-r--r--c/src/lib/libbsp/sparc/leon3/include/bsp.h7
-rw-r--r--c/src/lib/libbsp/sparc/shared/amba/ambapp.c10
-rw-r--r--c/src/lib/libbsp/sparc/shared/startup/bspgetworkarea.c8
-rw-r--r--c/src/lib/libbsp/sparc/shared/startup/early_malloc.c47
18 files changed, 31 insertions, 102 deletions
diff --git a/c/src/lib/libbsp/arm/lpc176x/Makefile.am b/c/src/lib/libbsp/arm/lpc176x/Makefile.am
index 352b2d9..54eae6e 100644
--- a/c/src/lib/libbsp/arm/lpc176x/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc176x/Makefile.am
@@ -94,6 +94,7 @@ libbsp_a_SOURCES += ../../shared/bspclean.c
libbsp_a_SOURCES += ../../shared/bspgetworkarea.c
libbsp_a_SOURCES += ../../shared/bsplibc.c
libbsp_a_SOURCES += ../../shared/bsppost.c
+libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c
libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
libbsp_a_SOURCES += ../../shared/sbrk.c
diff --git a/c/src/lib/libbsp/arm/lpc176x/startup/bspstart.c b/c/src/lib/libbsp/arm/lpc176x/startup/bspstart.c
index 1aa8e0f..f1aba44 100644
--- a/c/src/lib/libbsp/arm/lpc176x/startup/bspstart.c
+++ b/c/src/lib/libbsp/arm/lpc176x/startup/bspstart.c
@@ -42,7 +42,7 @@ LINKER_SYMBOL( lpc176x_region_heap_1_end );
extern Heap_Control *RTEMS_Malloc_Heap;
#endif
-void bsp_pretasking_hook( void )
+static void heap_extend( void )
{
#ifdef LPC176X_HEAP_EXTEND
_Heap_Extend( RTEMS_Malloc_Heap,
@@ -86,4 +86,6 @@ void bsp_start( void )
/* DMA */
lpc176x_dma_initialize();
-} \ No newline at end of file
+
+ heap_extend();
+}
diff --git a/c/src/lib/libbsp/arm/lpc24xx/Makefile.am b/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
index c7fcb86..bc5772b 100644
--- a/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc24xx/Makefile.am
@@ -96,6 +96,7 @@ libbsp_a_SOURCES += ../../shared/bootcard.c \
../../shared/bspgetworkarea.c \
../../shared/bsplibc.c \
../../shared/bsppost.c \
+ ../../shared/bsppretaskinghook.c \
../../shared/bsppredriverhook.c \
../../shared/gnatinstallhandler.c \
../../shared/sbrk.c \
diff --git a/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c b/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c
index dbceb01..6f00f35 100644
--- a/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c
+++ b/c/src/lib/libbsp/arm/lpc24xx/startup/bspstart.c
@@ -43,7 +43,7 @@
extern Heap_Control *RTEMS_Malloc_Heap;
#endif
-void bsp_pretasking_hook(void)
+static void heap_extend(void)
{
#ifdef LPC24XX_HEAP_EXTEND
_Heap_Extend(
@@ -91,4 +91,6 @@ void bsp_start(void)
/* DMA */
lpc24xx_dma_initialize();
+
+ heap_extend();
}
diff --git a/c/src/lib/libbsp/i386/pc386/include/bsp.h b/c/src/lib/libbsp/i386/pc386/include/bsp.h
index 5a82ac2..d9f24e4 100644
--- a/c/src/lib/libbsp/i386/pc386/include/bsp.h
+++ b/c/src/lib/libbsp/i386/pc386/include/bsp.h
@@ -187,8 +187,6 @@ void Calibrate_loop_1ms(void); /* from 'timer.c' */
void rtems_irq_mngt_init(void); /* from 'irq_init.c' */
-void bsp_size_memory(void); /* from 'bspstart.c' */
-
#if (BSP_IS_EDISON == 0)
void Clock_driver_install_handler(void); /* from 'ckinit.c' */
void Clock_driver_support_initialize_hardware(void); /* from 'ckinit.c' */
diff --git a/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c b/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c
index 2e4bf5c..5207bac 100644
--- a/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c
+++ b/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c
@@ -52,7 +52,7 @@ uint32_t bsp_mem_size = 0;
/* Size of stack used during initialization. Defined in 'start.s'. */
extern uint32_t _stack_size;
-void bsp_size_memory(void)
+static void bsp_size_memory(void)
{
uintptr_t topAddr;
@@ -126,8 +126,15 @@ void bsp_size_memory(void)
void bsp_work_area_initialize(void)
{
- void *area_start = (void *) rtemsWorkAreaStart;
- uintptr_t area_size = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
+ void *area_start;
+ uintptr_t area_size;
+ /*
+ * We need to determine how much memory there is in the system.
+ */
+ bsp_size_memory();
+
+ area_start = (void *) rtemsWorkAreaStart;
+ area_size = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart;
bsp_work_area_initialize_default( area_start, area_size );
}
diff --git a/c/src/lib/libbsp/i386/pc386/startup/bspstart.c b/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
index 9b1be64..ac871f0 100644
--- a/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
+++ b/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
@@ -58,11 +58,6 @@ static void bsp_pci_initialize_helper(void)
static void bsp_start_default( void )
{
/*
- * We need to determine how much memory there is in the system.
- */
- bsp_size_memory();
-
- /*
* Turn off watchdog
*/
#if (BSP_IS_EDISON == 1)
diff --git a/c/src/lib/libbsp/shared/bootcard.c b/c/src/lib/libbsp/shared/bootcard.c
index eeb5746..cbeb7b2 100644
--- a/c/src/lib/libbsp/shared/bootcard.c
+++ b/c/src/lib/libbsp/shared/bootcard.c
@@ -75,14 +75,14 @@ void boot_card(
bsp_boot_cmdline = cmdline;
/*
- * Invoke Board Support Package initialization routine written in C.
+ * Initialize the RTEMS Workspace and the C Program Heap.
*/
- bsp_start();
+ bsp_work_area_initialize();
/*
- * Initialize the RTEMS Workspace and the C Program Heap.
+ * Invoke Board Support Package initialization routine written in C.
*/
- bsp_work_area_initialize();
+ bsp_start();
/*
* Initialize RTEMS data structures
diff --git a/c/src/lib/libbsp/shared/include/bootcard.h b/c/src/lib/libbsp/shared/include/bootcard.h
index 93d5041..7c0d3f1 100644
--- a/c/src/lib/libbsp/shared/include/bootcard.h
+++ b/c/src/lib/libbsp/shared/include/bootcard.h
@@ -78,9 +78,9 @@ void bsp_reset(void);
*
* - disable interrupts, interrupts will be enabled during the first context
* switch
- * - bsp_start() - more advanced initialization
* - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C
* Program Heap
+ * - bsp_start() - more advanced initialization
* - rtems_initialize_data_structures()
* - initialize C Library
* - bsp_pretasking_hook()
diff --git a/c/src/lib/libbsp/sparc/erc32/Makefile.am b/c/src/lib/libbsp/sparc/erc32/Makefile.am
index b00853a..f0465b0 100644
--- a/c/src/lib/libbsp/sparc/erc32/Makefile.am
+++ b/c/src/lib/libbsp/sparc/erc32/Makefile.am
@@ -43,7 +43,6 @@ libbsp_a_SOURCES += startup/erc32mec.c
libbsp_a_SOURCES += startup/boardinit.S
libbsp_a_SOURCES += startup/bspidle.c
libbsp_a_SOURCES += startup/bspdelay.c
-libbsp_a_SOURCES += ../../sparc/shared/startup/early_malloc.c
libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_exit.c
libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_halt.c
# ISR Handler
diff --git a/c/src/lib/libbsp/sparc/erc32/include/bsp.h b/c/src/lib/libbsp/sparc/erc32/include/bsp.h
index 942a873..8633634 100644
--- a/c/src/lib/libbsp/sparc/erc32/include/bsp.h
+++ b/c/src/lib/libbsp/sparc/erc32/include/bsp.h
@@ -93,13 +93,6 @@ void BSP_fatal_exit(uint32_t error);
void bsp_spurious_initialize( void );
-/* 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_work_area_initialize(). malloc() is called to get memory when this
- * function is called after bsp_work_area_initialize().
- */
-void *bsp_early_malloc(int size);
-
/* Interrupt Service Routine (ISR) pointer */
typedef void (*bsp_shared_isr)(void *arg);
diff --git a/c/src/lib/libbsp/sparc/leon2/Makefile.am b/c/src/lib/libbsp/sparc/leon2/Makefile.am
index 7eada59..2b5d195 100644
--- a/c/src/lib/libbsp/sparc/leon2/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon2/Makefile.am
@@ -42,7 +42,6 @@ libbsp_a_SOURCES += startup/setvec.c
libbsp_a_SOURCES += startup/spurious.c
libbsp_a_SOURCES += startup/bspidle.c
libbsp_a_SOURCES += startup/bspdelay.c
-libbsp_a_SOURCES += ../../sparc/shared/startup/early_malloc.c
libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_exit.c
libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_halt.c
diff --git a/c/src/lib/libbsp/sparc/leon2/include/bsp.h b/c/src/lib/libbsp/sparc/leon2/include/bsp.h
index 09cf7f7..acc310a 100644
--- a/c/src/lib/libbsp/sparc/leon2/include/bsp.h
+++ b/c/src/lib/libbsp/sparc/leon2/include/bsp.h
@@ -117,13 +117,6 @@ void BSP_fatal_exit(uint32_t error);
void bsp_spurious_initialize( void );
-/* 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_work_area_initialize(). malloc() is called to get memory when this
- * function is called after bsp_work_area_initialize().
- */
-void *bsp_early_malloc(int size);
-
/* Interrupt Service Routine (ISR) pointer */
typedef void (*bsp_shared_isr)(void *arg);
diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am b/c/src/lib/libbsp/sparc/leon3/Makefile.am
index d261f99..95f10eb 100644
--- a/c/src/lib/libbsp/sparc/leon3/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am
@@ -38,8 +38,7 @@ libbsp_a_SOURCES += ../../shared/bsplibc.c \
../../shared/bsppretaskinghook.c startup/bsppredriver.c \
../../sparc/shared/startup/bspgetworkarea.c ../../shared/sbrk.c \
startup/setvec.c \
- startup/spurious.c startup/bspidle.S startup/bspdelay.c \
- ../../sparc/shared/startup/early_malloc.c
+ startup/spurious.c startup/bspidle.S startup/bspdelay.c
libbsp_a_SOURCES += startup/cpucounter.c
libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_exit.c
libbsp_a_SOURCES += startup/bsp_fatal_halt.c
diff --git a/c/src/lib/libbsp/sparc/leon3/include/bsp.h b/c/src/lib/libbsp/sparc/leon3/include/bsp.h
index 5642e14..1397716 100644
--- a/c/src/lib/libbsp/sparc/leon3/include/bsp.h
+++ b/c/src/lib/libbsp/sparc/leon3/include/bsp.h
@@ -140,13 +140,6 @@ void bsp_spurious_initialize( void );
*/
void rtems_bsp_delay(int usecs);
-/* 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_work_area_initialize(). malloc() is called to get memory when this
- * function is called after bsp_work_area_initialize().
- */
-void *bsp_early_malloc(int size);
-
/* Interrupt Service Routine (ISR) pointer */
typedef void (*bsp_shared_isr)(void *arg);
diff --git a/c/src/lib/libbsp/sparc/shared/amba/ambapp.c b/c/src/lib/libbsp/sparc/shared/amba/ambapp.c
index dba56c1..e4f1aac 100644
--- a/c/src/lib/libbsp/sparc/shared/amba/ambapp.c
+++ b/c/src/lib/libbsp/sparc/shared/amba/ambapp.c
@@ -23,18 +23,16 @@
/* Allocate one AMBA device */
static struct ambapp_dev *ambapp_alloc_dev_struct(int dev_type)
{
- int size = sizeof(struct ambapp_dev);
struct ambapp_dev *dev;
+ size_t size = sizeof(*dev);
if (dev_type == DEV_APB_SLV)
size += sizeof(struct ambapp_apb_info);
else
size += sizeof(struct ambapp_ahb_info); /* AHB */
- dev = (struct ambapp_dev *)bsp_early_malloc(size);
- if (dev == NULL)
- return NULL;
- memset(dev, 0 , size);
- dev->dev_type = dev_type;
+ dev = (struct ambapp_dev *)calloc(1, size);
+ if (dev != NULL)
+ dev->dev_type = dev_type;
return dev;
}
diff --git a/c/src/lib/libbsp/sparc/shared/startup/bspgetworkarea.c b/c/src/lib/libbsp/sparc/shared/startup/bspgetworkarea.c
index a68d295..b05113d 100644
--- a/c/src/lib/libbsp/sparc/shared/startup/bspgetworkarea.c
+++ b/c/src/lib/libbsp/sparc/shared/startup/bspgetworkarea.c
@@ -20,9 +20,6 @@
/* Tells us where to put the workspace in case remote debugger is present. */
extern uint32_t rdb_start;
-/* Must be aligned to 8, _end is aligned to 8 */
-unsigned int early_mem = (unsigned int)&end;
-
/*
* This method returns the base address and size of the area which
* is to be allocated between the RTEMS Workspace and the C Program
@@ -34,10 +31,9 @@ void bsp_work_area_initialize(void)
#define STACK_SIZE (16 * 1024)
/* Early dynamic memory allocator is placed just above _end */
- void *work_area_start = (void *)early_mem;
+ void *work_area_start = (void *)&end;
uintptr_t work_area_size =
- (uintptr_t)rdb_start - (uintptr_t)early_mem - STACK_SIZE;
- early_mem = ~0; /* Signal bsp_early_malloc not to be used anymore */
+ (uintptr_t)rdb_start - (uintptr_t)&end - STACK_SIZE;
/*
* The following may be helpful in debugging what goes wrong when
diff --git a/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c b/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c
deleted file mode 100644
index 911a7b0..0000000
--- a/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.org/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_work_area_initialize(). malloc() is called to get memory when this function
- * is called after bsp_work_area_initialize().
- */
-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;
-}