diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-12-09 08:05:57 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-12-10 08:32:36 +0100 |
commit | 37030e38c61c0d0a8b0742af75f115bda779c46d (patch) | |
tree | d71cd94cf9d534fd606fffd50a0f3256cc822be9 /c/src/lib/libbsp/sparc | |
parent | bsps/sparc: Use default bsp_pretasking_hook() (diff) | |
download | rtems-37030e38c61c0d0a8b0742af75f115bda779c46d.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/sparc')
-rw-r--r-- | c/src/lib/libbsp/sparc/erc32/Makefile.am | 1 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/erc32/include/bsp.h | 7 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon2/Makefile.am | 1 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon2/include/bsp.h | 7 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon3/Makefile.am | 3 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon3/include/bsp.h | 7 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/shared/amba/ambapp.c | 10 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/shared/startup/bspgetworkarea.c | 8 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/shared/startup/early_malloc.c | 47 |
9 files changed, 7 insertions, 84 deletions
diff --git a/c/src/lib/libbsp/sparc/erc32/Makefile.am b/c/src/lib/libbsp/sparc/erc32/Makefile.am index b00853afb1..f0465b0503 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 942a873772..86336349ae 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 7eada5999f..2b5d1956dd 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 09cf7f702a..acc310a6e1 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 d261f9988c..95f10ebe5b 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 5642e14c57..1397716c53 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 dba56c1f48..e4f1aacbd1 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 a68d295826..b05113d9eb 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 911a7b019b..0000000000 --- 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; -} |