diff options
Diffstat (limited to 'c')
-rw-r--r-- | c/src/lib/libbsp/arm/gba/startup/bspgetworkarea.c | 20 | ||||
-rw-r--r-- | c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c | 32 | ||||
-rw-r--r-- | c/src/lib/libbsp/powerpc/shared/startup/bspgetworkarea.c | 51 | ||||
-rw-r--r-- | c/src/lib/libbsp/powerpc/shared/startup/sbrk.c | 47 | ||||
-rw-r--r-- | c/src/lib/libbsp/powerpc/tqm8xx/startup/bspgetworkarea.c | 27 | ||||
-rw-r--r-- | c/src/lib/libbsp/shared/bootcard.c | 118 | ||||
-rw-r--r-- | c/src/lib/libbsp/shared/bspgetworkarea.c | 54 | ||||
-rw-r--r-- | c/src/lib/libbsp/shared/bsplibc.c | 8 | ||||
-rw-r--r-- | c/src/lib/libbsp/shared/include/bootcard.h | 175 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/erc32/include/bsp.h | 4 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon2/include/bsp.h | 4 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon3/include/bsp.h | 4 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/shared/bspgetworkarea.c | 27 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/shared/startup/early_malloc.c | 4 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc64/niagara/Makefile.am | 2 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc64/shared/startup/bspgetworkarea.c | 91 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc64/usiii/Makefile.am | 2 |
17 files changed, 185 insertions, 485 deletions
diff --git a/c/src/lib/libbsp/arm/gba/startup/bspgetworkarea.c b/c/src/lib/libbsp/arm/gba/startup/bspgetworkarea.c index abce92f13b..d1c06b14f7 100644 --- a/c/src/lib/libbsp/arm/gba/startup/bspgetworkarea.c +++ b/c/src/lib/libbsp/arm/gba/startup/bspgetworkarea.c @@ -11,21 +11,11 @@ extern void _end; extern void __heap_limit; -/* - * This method returns the base address and size of the area which - * is to be allocated between the RTEMS Workspace and the C Program - * Heap. - */ -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) +void bsp_work_area_initialize(void) { - *work_area_start = (void *)&_end; - *work_area_size = (uintptr_t)&__heap_limit - (uintptr_t)&_end; - *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; - *heap_size = BSP_BOOTCARD_HEAP_SIZE_DEFAULT; + void *area_start = (void *)&_end; + uintptr_t area_size = (uintptr_t)&__heap_limit - (uintptr_t)&_end; + + bsp_work_area_initialize_default( area_start, area_size ); } diff --git a/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c b/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c index 8668d45467..f6ff1391ec 100644 --- a/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c +++ b/c/src/lib/libbsp/i386/pc386/startup/bspgetworkarea.c @@ -1,5 +1,5 @@ /* - * This routine is an implementation of the bsp_get_work_area() + * This routine is an implementation of the bsp_work_area_initialize() * that can be used by all m68k BSPs following linkcmds conventions * regarding heap, stack, and workspace allocation. * @@ -120,30 +120,10 @@ void bsp_size_memory(void) bsp_mem_size = topAddr; } -/* - * This method returns the base address and size of the area which - * is to be allocated between the RTEMS Workspace and the C Program - * Heap. - */ -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) +void bsp_work_area_initialize(void) { - *work_area_start = (void *) rtemsWorkAreaStart; - *work_area_size = (uintptr_t) bsp_mem_size - (uintptr_t) rtemsWorkAreaStart; - *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; - *heap_size = (uintptr_t) HeapSize; - - #ifdef BSP_GET_WORK_AREA_DEBUG - printk( "bsp_mem_size = 0x%08x\n", bsp_mem_size ); - printk( "rtemsWorkAreaStart = 0x%08x\n", rtemsWorkAreaStart ); - printk( "WorkArea Base = %p\n", *work_area_start ); - printk( "WorkArea Size = 0x%08x\n", *work_area_size ); - printk( "C Program Heap Base = %p\n", *heap_start ); - printk( "C Program Heap Size = 0x%08x\n", *heap_size ); - printk( "End of WorkArea = %p\n", *work_area_start + *work_area_size ); - #endif + void *area_start = (void *) rtemsWorkAreaStart; + uintptr_t work_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/powerpc/shared/startup/bspgetworkarea.c b/c/src/lib/libbsp/powerpc/shared/startup/bspgetworkarea.c index 174cf68df1..02d47c8b98 100644 --- a/c/src/lib/libbsp/powerpc/shared/startup/bspgetworkarea.c +++ b/c/src/lib/libbsp/powerpc/shared/startup/bspgetworkarea.c @@ -4,28 +4,12 @@ * http://www.rtems.com/license/LICENSE. */ -/* #define BSP_GET_WORK_AREA_DEBUG */ - #include <bsp.h> #include <bsp/bootcard.h> -#include <stdint.h> -#ifdef BSP_GET_WORK_AREA_DEBUG - #include <rtems/bspIo.h> -#endif extern void *__rtems_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 - * Heap. - */ -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) +void bsp_work_area_initialize(void) { uintptr_t work_size; uintptr_t work_area; @@ -34,36 +18,5 @@ void bsp_get_work_area( rtems_configuration_get_interrupt_stack_size(); work_size = (uintptr_t)BSP_mem_size - work_area; - *work_area_start = (void *)work_area, - *work_area_size = work_size; - *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; - *heap_size = BSP_BOOTCARD_HEAP_SIZE_DEFAULT; - - /* - * The following may be helpful in debugging what goes wrong when - * you are allocating the Work Area in a new BSP. - */ - #ifdef BSP_GET_WORK_AREA_DEBUG - { - void *sp = __builtin_frame_address(0); - void *end = *work_area_start + *work_area_size; - printk( - "work_area_start = 0x%p\n" - "work_area_size = %d 0x%08x\n" - "end = 0x%p\n" - "heap_start = 0x%p\n" - "heap_size = %d\n" - "current stack pointer = 0x%p%s\n", - *work_area_start, - *work_area_size, /* decimal */ - *work_area_size, /* hexadecimal */ - end, - *heap_start, - *heap_size, - sp, - ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "") - ); - } - #endif + bsp_work_area_initialize_default((void *) work_area, work_size); } - diff --git a/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c b/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c index 35ce1f4f06..cd1867d93a 100644 --- a/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c +++ b/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c @@ -61,15 +61,15 @@ * for module code. */ -#include <rtems.h> - -#include <signal.h> #include <errno.h> -#include <sys/types.h> #include <unistd.h> -static void * remaining_start=(void*)-1LL; -static uintptr_t remaining_size=0; +#include <bsp/bootcard.h> + +#define INVALID_REMAINING_START ((uintptr_t) -1) + +static uintptr_t remaining_start = INVALID_REMAINING_START; +static uintptr_t remaining_size = 0; /* App. may provide a value by defining the BSP_sbrk_policy * variable. @@ -81,24 +81,24 @@ static uintptr_t remaining_size=0; */ extern uintptr_t BSP_sbrk_policy __attribute__((weak)); -#define LIMIT_32M ((void*)0x02000000) +#define LIMIT_32M 0x02000000 -uintptr_t bsp_sbrk_init( - void *heap_start, - uintptr_t *heap_size_p -) +ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size) { - uintptr_t rval=0; + uintptr_t rval = 0; uintptr_t policy; + uintptr_t remaining_end; - remaining_start = heap_start; - remaining_size = *heap_size_p; + remaining_start = (uintptr_t) area->begin; + remaining_size = area->size; + remaining_end = remaining_start + remaining_size; if (remaining_start < LIMIT_32M && - remaining_start + remaining_size > LIMIT_32M) { + remaining_end > LIMIT_32M && + min_size <= LIMIT_32M - remaining_start) { /* clip at LIMIT_32M */ - rval = remaining_start + remaining_size - LIMIT_32M; - *heap_size_p = LIMIT_32M - remaining_start; + rval = remaining_end - LIMIT_32M; + area->size = LIMIT_32M - remaining_start; remaining_start = LIMIT_32M; remaining_size = rval; } @@ -106,8 +106,8 @@ uintptr_t bsp_sbrk_init( policy = (0 == &BSP_sbrk_policy ? (uintptr_t)(-1) : BSP_sbrk_policy); switch ( policy ) { case (uintptr_t)(-1): - *heap_size_p += rval; - remaining_start = heap_start + *heap_size_p; + area->size += rval; + remaining_start = (uintptr_t) area->begin + area->size; remaining_size = 0; break; @@ -121,7 +121,7 @@ uintptr_t bsp_sbrk_init( break; } - return rval; + return (ptrdiff_t) (rval <= PTRDIFF_MAX ? rval : rval / 2); } /* @@ -129,14 +129,13 @@ uintptr_t bsp_sbrk_init( * should just use the default implementation in this file. */ void *sbrk(ptrdiff_t incr) __attribute__ (( weak, alias("bsp_sbrk") )); -void *bsp_sbrk(ptrdiff_t incr) +static void *bsp_sbrk(ptrdiff_t incr) { void *rval=(void*)-1; - /* FIXME: BEWARE if size >2G */ - if ( remaining_start != (void*)-1LL && incr <= remaining_size) { + if ( remaining_start != INVALID_REMAINING_START && incr <= remaining_size) { remaining_size-=incr; - rval = remaining_start; + rval = (void *) remaining_start; remaining_start += incr; } else { errno = ENOMEM; diff --git a/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspgetworkarea.c b/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspgetworkarea.c index bd06b70fdd..d9521896f5 100644 --- a/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspgetworkarea.c +++ b/c/src/lib/libbsp/powerpc/tqm8xx/startup/bspgetworkarea.c @@ -7,12 +7,13 @@ */ /* - * Copyright (c) 2008 - * Embedded Brains GmbH - * Obere Lagerstr. 30 - * D-82178 Puchheim - * Germany - * rtems@embedded-brains.de + * Copyright (c) 2008-2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -24,17 +25,11 @@ #include <bsp.h> #include <bsp/bootcard.h> -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) +void bsp_work_area_initialize(void) { char *ram_end = (char *) (TQM_BD_INFO.sdram_size - (uint32_t)TopRamReserved); + void *area_start = bsp_work_area_start; + uintptr_t area_size = (uintptr_t) ram_end - (uintptr_t) bsp_work_area_start; - *work_area_start = bsp_work_area_start; - *work_area_size = ram_end - bsp_work_area_start; - *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; - *heap_size = BSP_BOOTCARD_HEAP_SIZE_DEFAULT; + bsp_work_area_initialize_default( area_start, area_size ); } diff --git a/c/src/lib/libbsp/shared/bootcard.c b/c/src/lib/libbsp/shared/bootcard.c index 189b463cc0..33ad0ee128 100644 --- a/c/src/lib/libbsp/shared/bootcard.c +++ b/c/src/lib/libbsp/shared/bootcard.c @@ -64,41 +64,6 @@ const char *bsp_boot_cmdline; /* - * These are the prototypes and helper routines which are used - * when the BSP lets the framework handle RAM allocation between - * the RTEMS Workspace and C Program Heap. - */ -static void bootcard_bsp_libc_helper( - void *work_area_start, - uintptr_t work_area_size, - void *heap_start, - uintptr_t heap_size, - uintptr_t sbrk_amount -) -{ - if ( heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA ) { - if ( !rtems_configuration_get_unified_work_area() ) { - uintptr_t work_space_size = rtems_configuration_get_work_space_size(); - - heap_start = (char *) work_area_start + work_space_size; - - if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) { - uintptr_t heap_size_default = work_area_size - work_space_size; - - heap_size = heap_size_default; - } - } else { - heap_start = work_area_start; - if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) { - heap_size = work_area_size; - } - } - } - - bsp_libc_init(heap_start, heap_size, sbrk_amount); -} - -/* * This is the initialization framework routine that weaves together * calls to RTEMS and the BSP in the proper sequence to initialize * the system while maximizing shared code and keeping BSP code in C @@ -109,12 +74,6 @@ uint32_t boot_card( ) { rtems_interrupt_level bsp_isr_level; - void *work_area_start = NULL; - uintptr_t work_area_size = 0; - void *heap_start = NULL; - uintptr_t heap_size = 0; - uintptr_t sbrk_amount = 0; - uintptr_t work_space_size = 0; uint32_t status = 0; /* @@ -138,74 +97,9 @@ uint32_t boot_card( bsp_start(); /* - * Find out where the block of memory the BSP will use for - * the RTEMS Workspace and the C Program Heap is. + * Initialize the RTEMS Workspace and the C Program Heap. */ - bsp_get_work_area(&work_area_start, &work_area_size, - &heap_start, &heap_size); - -#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK - /* This routine may reduce the work area size with the - * option to extend it later via sbrk(). If the application - * was configured w/o CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK then - * omit this step. - */ - if ( rtems_malloc_sbrk_helpers ) { - sbrk_amount = bsp_sbrk_init(work_area_start, &work_area_size); - work_space_size = rtems_configuration_get_work_space_size(); - if ( work_area_size < work_space_size && sbrk_amount > 0 ) { - /* Need to use sbrk right now */ - uintptr_t sbrk_now; - - sbrk_now = (work_space_size - work_area_size) / sbrk_amount; - sbrk( sbrk_now * sbrk_amount ); - } - } -#else - if ( rtems_malloc_sbrk_helpers ) { - printk("Configuration error!\n" - "Application was configured with CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK\n" - "but BSP was configured w/o sbrk support\n"); - status = 1; - bsp_cleanup( status ); - return status; - } -#endif - - /* - * If the user has configured a set of objects which will require more - * workspace than is actually available, print a message indicating - * such and return to the invoking initialization code. - * - * NOTE: Output from printk() may not work at this point on some BSPs. - * - * NOTE: Use cast to (void *) and %p since these are uintptr_t types. - */ - work_space_size = rtems_configuration_get_work_space_size(); - if ( work_area_size <= work_space_size ) { - printk( - "bootcard: work space too big for work area: %p >= %p\n", - (void *) work_space_size, - (void *) work_area_size - ); - status = 1; - bsp_cleanup( status ); - return status; - } - - if ( !rtems_configuration_get_unified_work_area() ) { - rtems_configuration_set_work_space_start( work_area_start ); - } else { - rtems_configuration_set_work_space_start( work_area_start ); - rtems_configuration_set_work_space_size( work_area_size ); - if ( !rtems_configuration_get_stack_allocator_avoids_work_space() ) { - rtems_configuration_set_stack_space_size( 0 ); - } - } - - #if (BSP_DIRTY_MEMORY == 1) - memset( work_area_start, 0xCF, work_area_size ); - #endif + bsp_work_area_initialize(); /* * Initialize RTEMS data structures @@ -216,13 +110,7 @@ uint32_t boot_card( * Initialize the C library for those BSPs using the shared * framework. */ - bootcard_bsp_libc_helper( - work_area_start, - work_area_size, - heap_start, - heap_size, - sbrk_amount - ); + bsp_libc_init(); /* * Let the BSP do any required initialization now that RTEMS diff --git a/c/src/lib/libbsp/shared/bspgetworkarea.c b/c/src/lib/libbsp/shared/bspgetworkarea.c index a2ad2e93ce..4122c9b358 100644 --- a/c/src/lib/libbsp/shared/bspgetworkarea.c +++ b/c/src/lib/libbsp/shared/bspgetworkarea.c @@ -1,25 +1,20 @@ /* - * This routine is an implementation of the bsp_get_work_area() + * This routine is an implementation of the bsp_work_area_initialize() * that can be used by all BSPs following linkcmds conventions * regarding heap, stack, and workspace allocation. * * COPYRIGHT (c) 1989-2008. * On-Line Applications Research Corporation (OAR). * - * Copyright (c) 2011 embedded brains GmbH. + * Copyright (c) 2011-2012 embedded brains GmbH. * * 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. */ -/* #define BSP_GET_WORK_AREA_DEBUG */ - #include <bsp.h> #include <bsp/bootcard.h> -#ifdef BSP_GET_WORK_AREA_DEBUG - #include <rtems/bspIo.h> -#endif #ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN #include <rtems/config.h> #endif @@ -32,7 +27,6 @@ * These are provided by the linkcmds for ALL of the BSPs which use this file. */ extern char WorkAreaBase[]; -extern char HeapSize[]; /* * We may get the size information from U-Boot or the linker scripts. @@ -44,17 +38,7 @@ extern char HeapSize[]; extern char RamSize[]; #endif -/* - * This method returns the base address and size of the area which - * is to be allocated between the RTEMS Workspace and the C Program - * Heap. - */ -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) +void bsp_work_area_initialize(void) { uintptr_t work_base = (uintptr_t) WorkAreaBase; uintptr_t ram_end; @@ -70,35 +54,5 @@ void bsp_get_work_area( work_base += Configuration.interrupt_stack_size; #endif - *work_area_start = (void *) work_base; - *work_area_size = ram_end - work_base; - *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; - *heap_size = (uintptr_t) HeapSize; - - /* - * The following may be helpful in debugging what goes wrong when - * you are allocating the Work Area in a new BSP. - */ - #ifdef BSP_GET_WORK_AREA_DEBUG - { - void *sp = __builtin_frame_address(0); - void *end = *work_area_start + *work_area_size; - printk( - "work_area_start = 0x%p\n" - "work_area_size = %d 0x%08x\n" - "end = 0x%p\n" - "heap_start = 0x%p\n" - "heap_size = %d\n" - "current stack pointer = 0x%p%s\n", - *work_area_start, - *work_area_size, /* decimal */ - *work_area_size, /* hexadecimal */ - end, - *heap_start, - *heap_size, - sp, - ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "") - ); - } - #endif + bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base ); } diff --git a/c/src/lib/libbsp/shared/bsplibc.c b/c/src/lib/libbsp/shared/bsplibc.c index 90ba6132b1..181dcff303 100644 --- a/c/src/lib/libbsp/shared/bsplibc.c +++ b/c/src/lib/libbsp/shared/bsplibc.c @@ -9,14 +9,8 @@ #include <bsp/bootcard.h> -void bsp_libc_init( - void *heap_begin, - uintptr_t heap_size, - size_t sbrk_amount -) +void bsp_libc_init(void) { - RTEMS_Malloc_Initialize( heap_begin, heap_size, sbrk_amount ); - /* * Init the RTEMS libio facility to provide UNIX-like system * calls for use by newlib (ie: provide open, close, etc) diff --git a/c/src/lib/libbsp/shared/include/bootcard.h b/c/src/lib/libbsp/shared/include/bootcard.h index 69717b2903..751e77aa77 100644 --- a/c/src/lib/libbsp/shared/include/bootcard.h +++ b/c/src/lib/libbsp/shared/include/bootcard.h @@ -7,12 +7,13 @@ */ /* - * Copyright (c) 2008 - * Embedded Brains GmbH - * Obere Lagerstr. 30 - * D-82178 Puchheim - * Germany - * rtems@embedded-brains.de + * Copyright (c) 2008-2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -25,22 +26,13 @@ * @brief Board support package dependent code. */ -/** - * @defgroup bsp_bootcard Bootcard - * - * @ingroup bsp_kit - * - * @brief Standard system startup. - * - * @{ - */ - #ifndef LIBBSP_SHARED_BOOTCARD_H #define LIBBSP_SHARED_BOOTCARD_H -#include <stddef.h> -#include <stdint.h> -#include <sys/types.h> +#include <unistd.h> + +#include <rtems/malloc.h> +#include <rtems/bspIo.h> #include <bspopts.h> @@ -49,6 +41,16 @@ extern "C" { #endif /* __cplusplus */ /** + * @defgroup bsp_bootcard Bootcard + * + * @ingroup bsp_kit + * + * @brief Standard system startup. + * + * @{ + */ + +/** * @brief Global pointer to the command line of boot_card(). */ extern const char *bsp_boot_cmdline; @@ -66,45 +68,6 @@ void bsp_cleanup(uint32_t status); void bsp_reset(void); /** - * @brief Should be used as the heap begin address in bsp_get_work_area() if - * the heap area is contained in the work area. - */ -#define BSP_BOOTCARD_HEAP_USES_WORK_AREA NULL - -/** - * @brief Should be used to request the default heap size in bsp_get_work_area(). - * - * In case that the heap area is contained in the work area this heap size - * value indicates that the area outside the work space should be used as heap - * space. - */ -#define BSP_BOOTCARD_HEAP_SIZE_DEFAULT 0 - -void bsp_get_work_area( - void **work_area_begin, - uintptr_t *work_area_size, - void **heap_begin, - uintptr_t *heap_size -); - -/** - * @brief Gives the BSP a chance to reduce the work area size with sbrk() adding more later. - * - * bsp_sbrk_init() may reduce the work area size passed in. The routine - * returns the 'sbrk_amount' to be used when extending the heap. - * Note that the return value may be zero. - * - */ - -#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK -uintptr_t bsp_sbrk_init( - void *work_area_begin, - uintptr_t *work_area_size_p -); -#endif - - -/** * @brief Standard system initialization procedure. * * You may pass a command line in @a cmdline. It is later available via the @@ -120,11 +83,10 @@ uintptr_t bsp_sbrk_init( * - disable interrupts, interrupts will be enabled during the first context * switch * - bsp_start() - more advanced initialization - * - obtain information on BSP memory via bsp_get_work_area() and allocate - * RTEMS Workspace + * - bsp_work_area_initialize() - initialize the RTEMS Workspace and the C + * Program Heap * - rtems_initialize_data_structures() - * - allocate memory for C Program Heap - * - initialize C Library and C Program Heap + * - initialize C Library * - bsp_pretasking_hook() * - if defined( RTEMS_DEBUG ) * - rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ) @@ -147,9 +109,94 @@ uintptr_t bsp_sbrk_init( */ uint32_t boot_card(const char *cmdline); -/** @} */ +#ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK + /** + * @brief Gives the BSP a chance to reduce the work area size with sbrk() + * adding more later. + * + * bsp_sbrk_init() may reduce the work area size passed in. The routine + * returns the 'sbrk_amount' to be used when extending the heap. Note that + * the return value may be zero. + * + * In case the @a area size is altered, then the remaining size of the + * @a area must be greater than or equal to @a min_size. + */ + ptrdiff_t bsp_sbrk_init(Heap_Area *area, uintptr_t min_size); +#endif -void bsp_libc_init(void *heap_begin, uintptr_t heap_size, size_t sbrk_amount); +static inline void bsp_work_area_initialize_default( + void *area_begin, + uintptr_t area_size +) +{ + Heap_Area area = { + .begin = area_begin, + .size = area_size + }; + + #if BSP_DIRTY_MEMORY == 1 + memset(area.begin, 0xCF, area.size); + #endif + + #ifdef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK + { + uintptr_t overhead = _Heap_Area_overhead(CPU_HEAP_ALIGNMENT); + uintptr_t work_space_size = rtems_configuration_get_work_space_size(); + ptrdiff_t sbrk_amount = bsp_sbrk_init( + &area, + work_space_size + + overhead + + (rtems_configuration_get_unified_work_area() ? 0 : overhead) + ); + + rtems_heap_set_sbrk_amount(sbrk_amount); + } + #endif + + /* + * The following may be helpful in debugging what goes wrong when + * you are allocating the Work Area in a new BSP. + */ + #ifdef BSP_GET_WORK_AREA_DEBUG + { + void *sp = __builtin_frame_address(0); + void *end = (char *) area.begin + area.size; + printk( + "work_area_start = 0x%p\n" + "work_area_size = %lu 0x%08lx\n" + "end = 0x%p\n" + "current stack pointer = 0x%p%s\n", + area.begin, + (unsigned long) area.size, /* decimal */ + (unsigned long) area.size, /* hexadecimal */ + end, + sp, + (uintptr_t) sp >= (uintptr_t) area.begin + && (uintptr_t) sp <= (uintptr_t) end ? + " OVERLAPS!" : "" + ); + } + #endif + + _Workspace_Handler_initialization(&area, 1, NULL); + + #ifdef BSP_GET_WORK_AREA_DEBUG + printk( + "heap_start = 0x%p\n" + "heap_size = %lu\n", + area.begin, + (unsigned long) area.size + ); + #endif + + RTEMS_Malloc_Initialize(&area, 1, NULL); +} + +void bsp_work_area_initialize(void); + +void bsp_libc_init(void); + +/** @} */ #ifdef __cplusplus } diff --git a/c/src/lib/libbsp/sparc/erc32/include/bsp.h b/c/src/lib/libbsp/sparc/erc32/include/bsp.h index 879e7144e0..26d4d2fc27 100644 --- a/c/src/lib/libbsp/sparc/erc32/include/bsp.h +++ b/c/src/lib/libbsp/sparc/erc32/include/bsp.h @@ -81,8 +81,8 @@ 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_get_work_area(). malloc() is called to get memory when this function - * is called after bsp_get_work_area(). + * 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); diff --git a/c/src/lib/libbsp/sparc/leon2/include/bsp.h b/c/src/lib/libbsp/sparc/leon2/include/bsp.h index e96a63ee90..dbefc347f7 100644 --- a/c/src/lib/libbsp/sparc/leon2/include/bsp.h +++ b/c/src/lib/libbsp/sparc/leon2/include/bsp.h @@ -101,8 +101,8 @@ 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_get_work_area(). malloc() is called to get memory when this function - * is called after bsp_get_work_area(). + * 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); diff --git a/c/src/lib/libbsp/sparc/leon3/include/bsp.h b/c/src/lib/libbsp/sparc/leon3/include/bsp.h index d883064660..31e527eb21 100644 --- a/c/src/lib/libbsp/sparc/leon3/include/bsp.h +++ b/c/src/lib/libbsp/sparc/leon3/include/bsp.h @@ -114,8 +114,8 @@ 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_get_work_area(). malloc() is called to get memory when this function - * is called after bsp_get_work_area(). + * 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); diff --git a/c/src/lib/libbsp/sparc/shared/bspgetworkarea.c b/c/src/lib/libbsp/sparc/shared/bspgetworkarea.c index 45d3d0ed87..d799800d61 100644 --- a/c/src/lib/libbsp/sparc/shared/bspgetworkarea.c +++ b/c/src/lib/libbsp/sparc/shared/bspgetworkarea.c @@ -28,24 +28,17 @@ unsigned int early_mem = (unsigned int)&end; * is to be allocated between the RTEMS Workspace and the C Program * Heap. */ -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) +void bsp_work_area_initialize(void) { /* must be identical to STACK_SIZE in start.S */ #define STACK_SIZE (16 * 1024) /* Early dynamic memory allocator is placed just above _end */ - *work_area_start = (void *)early_mem; - *work_area_size = (void *)rdb_start - (void *)early_mem - STACK_SIZE; + void *work_area_start = (void *)early_mem; + 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 */ - *heap_start = BSP_BOOTCARD_HEAP_USES_WORK_AREA; - *heap_size = BSP_BOOTCARD_HEAP_SIZE_DEFAULT; - /* * The following may be helpful in debugging what goes wrong when * you are allocating the Work Area in a new BSP. @@ -58,19 +51,17 @@ void bsp_get_work_area( "work_area_start = 0x%p\n" "work_area_size = %d 0x%08x\n" "end = 0x%p\n" - "heap_start = 0x%p\n" - "heap_size = %d\n" "current stack pointer = 0x%p%s\n", - *work_area_start, - *work_area_size, /* decimal */ - *work_area_size, /* hexadecimal */ + work_area_start, + work_area_size, /* decimal */ + work_area_size, /* hexadecimal */ end, - *heap_start, - *heap_size, sp, ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "") ); printk( "rdb_start = 0x%08x\n", rdb_start ); } #endif + + bsp_work_area_initialize_default(work_area_start, work_area_size); } diff --git a/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c b/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c index 1f968da206..dc89fad04a 100644 --- a/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c +++ b/c/src/lib/libbsp/sparc/shared/startup/early_malloc.c @@ -25,8 +25,8 @@ extern unsigned int early_mem; /* 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(). + * 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) { diff --git a/c/src/lib/libbsp/sparc64/niagara/Makefile.am b/c/src/lib/libbsp/sparc64/niagara/Makefile.am index 089649d0e6..c251beed44 100644 --- a/c/src/lib/libbsp/sparc64/niagara/Makefile.am +++ b/c/src/lib/libbsp/sparc64/niagara/Makefile.am @@ -42,7 +42,7 @@ startup_SOURCES = ../../shared/bspclean.c ../../shared/bsplibc.c \ ../../shared/bsppredriverhook.c ../../shared/bsppretaskinghook.c \ ../../shared/bsppost.c \ ../../shared/bootcard.c ../../shared/sbrk.c \ - ../shared/startup/bspgetworkarea.c \ + ../../shared/bspgetworkarea.c \ ../shared/startup/bspstart.c \ ../shared/startup/setvec.c \ ../../shared/gnatinstallhandler.c \ diff --git a/c/src/lib/libbsp/sparc64/shared/startup/bspgetworkarea.c b/c/src/lib/libbsp/sparc64/shared/startup/bspgetworkarea.c deleted file mode 100644 index 84f5777573..0000000000 --- a/c/src/lib/libbsp/sparc64/shared/startup/bspgetworkarea.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This routine is an implementation of the bsp_get_work_area() - * that can be used by all BSPs following linkcmds conventions - * regarding heap, stack, and workspace allocation. - * - * COPYRIGHT (c) 1989-2008. - * On-Line Applications Research Corporation (OAR). - * - * 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 <bsp/bootcard.h> -#ifdef BSP_GET_WORK_AREA_DEBUG - #include <rtems/bspIo.h> -#endif - -/* - * These are provided by the linkcmds for ALL of the BSPs which use this file. - */ -extern char WorkAreaBase[]; -extern char HeapSize[]; -extern char HeapBase[]; - - -/* - * We may get the size information from U-Boot or the linker scripts. - */ -#ifdef HAS_UBOOT - extern bd_t bsp_uboot_board_info; -#else - extern char RamBase[]; - extern char RamSize[]; -#endif /* HAS_UBOOT */ - -/* - * This method returns the base address and size of the area which - * is to be allocated between the RTEMS Workspace and the C Program - * Heap. - */ -void bsp_get_work_area( - void **work_area_start, - uintptr_t *work_area_size, - void **heap_start, - uintptr_t *heap_size -) -{ - uintptr_t ram_end; - - #ifdef HAS_UBOOT - ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart + - bsp_uboot_board_info.bi_memsize; - #else - ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize; - #endif - - *work_area_start = WorkAreaBase; - *work_area_size = (uintptr_t) HeapSize; - *heap_start = (void*) HeapBase; - *heap_size = (uintptr_t) HeapSize; - - /* - * The following may be helpful in debugging what goes wrong when - * you are allocating the Work Area in a new BSP. - */ - #ifdef BSP_GET_WORK_AREA_DEBUG - { - void *sp = __builtin_frame_address(0); - void *end = *work_area_start + *work_area_size; - printk( - "bsp_get_work_area\n\r" - "work_area_start = 0x%p\n\r" - "work_area_size = %d 0x%08x\n\r" - "end = 0x%p\n\r" - "heap_start = 0x%p\n\r" - "heap_size = %d\n\r" - "current stack pointer = 0x%p%s\n\r", - *work_area_start, - *work_area_size, /* decimal */ - *work_area_size, /* hexadecimal */ - end, - *heap_start, - *heap_size, - sp, - ((sp >= *work_area_start && sp <= end) ? " OVERLAPS!" : "") - ); - } - #endif -} diff --git a/c/src/lib/libbsp/sparc64/usiii/Makefile.am b/c/src/lib/libbsp/sparc64/usiii/Makefile.am index 6c169e0e64..10c0b35e29 100644 --- a/c/src/lib/libbsp/sparc64/usiii/Makefile.am +++ b/c/src/lib/libbsp/sparc64/usiii/Makefile.am @@ -88,7 +88,7 @@ startup_SOURCES = ../../shared/bspclean.c ../../shared/bsplibc.c \ ../../shared/bspstart.c ../../shared/bsppretaskinghook.c \ ../../shared/bsppost.c \ ../../shared/bootcard.c ../../shared/sbrk.c \ - ../shared/startup/bspgetworkarea.c \ + ../../shared/bspgetworkarea.c \ ../shared/startup/bsppredriverhook.c \ ../shared/startup/setvec.c \ ../../shared/gnatinstallhandler.c \ |