2008-09-23 Joel Sherrill <joel.sherrill@oarcorp.com>

* bootcard.c, include/bootcard.h: Make letting boot_card() handle work
	area allocation mandatory. Rename
	RTEMS_BSP_BOOTCARD_HANDLES_RAM_ALLOCATION to BSP_BOOTCARD_OPTIONS.
This commit is contained in:
Joel Sherrill
2008-09-23 19:53:41 +00:00
parent 95aa5e134e
commit 0de9fdfb2e
3 changed files with 92 additions and 104 deletions

View File

@@ -1,3 +1,9 @@
2008-09-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* bootcard.c, include/bootcard.h: Make letting boot_card() handle work
area allocation mandatory. Rename
RTEMS_BSP_BOOTCARD_HANDLES_RAM_ALLOCATION to BSP_BOOTCARD_OPTIONS.
2008-09-23 Sebastian Huber <sebastian.huber@embedded-brains.de> 2008-09-23 Sebastian Huber <sebastian.huber@embedded-brains.de>
* include/utility.h: New file. * include/utility.h: New file.

View File

@@ -62,53 +62,51 @@ extern bool rtems_unified_work_area;
* when the BSP lets the framework handle RAM allocation between * when the BSP lets the framework handle RAM allocation between
* the RTEMS Workspace and C Program Heap. * the RTEMS Workspace and C Program Heap.
*/ */
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION) static rtems_status_code bootcard_bsp_libc_helper(
static rtems_status_code bootcard_bsp_libc_helper( void *work_area_start,
void *work_area_start, size_t work_area_size,
size_t work_area_size, void *heap_start,
void *heap_start, size_t heap_size
size_t heap_size )
) {
{ size_t heap_size_default = 0;
size_t heap_size_default = 0;
if ( !rtems_unified_work_area && if ( !rtems_unified_work_area &&
heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA) { heap_start == BSP_BOOTCARD_HEAP_USES_WORK_AREA) {
/* Use the work area start as heap start */ /* Use the work area start as heap start */
heap_start = work_area_start; heap_start = work_area_start;
/* Ensure proper alignement */ /* Ensure proper alignement */
if ((uintptr_t) heap_start & (CPU_ALIGNMENT - 1)) { if ((uintptr_t) heap_start & (CPU_ALIGNMENT - 1)) {
heap_start = (void *) (((uintptr_t) heap_start + CPU_ALIGNMENT) heap_start = (void *) (((uintptr_t) heap_start + CPU_ALIGNMENT)
& ~(CPU_ALIGNMENT - 1)); & ~(CPU_ALIGNMENT - 1));
}
/*
* For the default heap size use the free space from the start of the
* work area up to the work space start as heap area.
*/
heap_size_default = (size_t) ((char *) Configuration.work_space_start
- (char *) work_area_start);
/* Keep it as a multiple of 16 bytes */
heap_size_default &= ~((size_t) 0xf);
/* Use default heap size if requested */
if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
heap_size = heap_size_default;
}
/* Check heap size */
if (heap_size > heap_size_default) {
return RTEMS_INVALID_SIZE;
}
} }
bsp_libc_init(heap_start, heap_size, 0); /*
* For the default heap size use the free space from the start of the
* work area up to the work space start as heap area.
*/
heap_size_default = (size_t) ((char *) Configuration.work_space_start
- (char *) work_area_start);
return RTEMS_SUCCESSFUL; /* Keep it as a multiple of 16 bytes */
heap_size_default &= ~((size_t) 0xf);
/* Use default heap size if requested */
if (heap_size == BSP_BOOTCARD_HEAP_SIZE_DEFAULT) {
heap_size = heap_size_default;
}
/* Check heap size */
if (heap_size > heap_size_default) {
return RTEMS_INVALID_SIZE;
}
} }
#endif
bsp_libc_init(heap_start, heap_size, 0);
return RTEMS_SUCCESSFUL;
}
/* /*
* This is the initialization framework routine that weaves together * This is the initialization framework routine that weaves together
@@ -122,18 +120,16 @@ int boot_card(
char **envp char **envp
) )
{ {
static char *argv_pointer = NULL; static char *argv_pointer = NULL;
static char *envp_pointer = NULL; static char *envp_pointer = NULL;
char **argv_p = &argv_pointer; char **argv_p = &argv_pointer;
char **envp_p = &envp_pointer; char **envp_p = &envp_pointer;
rtems_interrupt_level bsp_isr_level; rtems_interrupt_level bsp_isr_level;
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION) rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_status_code sc = RTEMS_SUCCESSFUL; void *work_area_start = NULL;
void *work_area_start = NULL; size_t work_area_size = 0;
size_t work_area_size = 0; void *heap_start = NULL;
void *heap_start = NULL; size_t heap_size = 0;
size_t heap_size = 0;
#endif
/* /*
* Special case for PowerPC: The interrupt disable mask is stored in SPRG0. * Special case for PowerPC: The interrupt disable mask is stored in SPRG0.
@@ -174,33 +170,24 @@ int boot_card(
* Find out where the block of memory the BSP will use for * Find out where the block of memory the BSP will use for
* the RTEMS Workspace and the C Program Heap is. * the RTEMS Workspace and the C Program Heap is.
*/ */
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION) bsp_get_work_area(&work_area_start, &work_area_size, &heap_start, &heap_size);
{
bsp_get_work_area(
&work_area_start,
&work_area_size,
&heap_start,
&heap_size
);
if ( work_area_size <= Configuration.work_space_size ) { if ( work_area_size <= Configuration.work_space_size ) {
printk( "bootcard: Work space too big for work area!\n"); printk( "bootcard: Work space too big for work area!\n");
bsp_cleanup(); bsp_cleanup();
return -1; return -1;
} }
if ( rtems_unified_work_area ) { if ( rtems_unified_work_area ) {
Configuration.work_space_start = work_area_start; Configuration.work_space_start = work_area_start;
Configuration.work_space_size = work_area_size; Configuration.work_space_size = work_area_size;
} else { } else {
Configuration.work_space_start = (char *) work_area_start + Configuration.work_space_start = (char *) work_area_start +
work_area_size - rtems_configuration_get_work_space_size(); work_area_size - rtems_configuration_get_work_space_size();
} }
#if (BSP_DIRTY_MEMORY == 1) #if (BSP_DIRTY_MEMORY == 1)
memset( work_area_start, 0xCF, work_area_size); memset( work_area_start, 0xCF, work_area_size );
#endif
}
#endif #endif
/* /*
@@ -212,19 +199,17 @@ int boot_card(
* Initialize the C library for those BSPs using the shared * Initialize the C library for those BSPs using the shared
* framework. * framework.
*/ */
#if defined(BSP_BOOTCARD_HANDLES_RAM_ALLOCATION) sc = bootcard_bsp_libc_helper(
sc = bootcard_bsp_libc_helper( work_area_start,
work_area_start, work_area_size,
work_area_size, heap_start,
heap_start, heap_size
heap_size );
); if ( sc != RTEMS_SUCCESSFUL ) {
if (sc != RTEMS_SUCCESSFUL) { printk( "bootcard: Cannot initialize C library!\n");
printk( "bootcard: Cannot initialize C library!\n"); bsp_cleanup();
bsp_cleanup(); return -1;
return -1; }
}
#endif
/* /*
* All BSP to do any required initialization now that RTEMS * All BSP to do any required initialization now that RTEMS
@@ -295,6 +280,5 @@ int boot_card(
/* /*
* Now return to the start code. * Now return to the start code.
*/ */
return 0; return 0;
} }

View File

@@ -30,7 +30,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <bspopts.h> /* for BSP_BOOTCARD_HANDLES_RAM_ALLOCATION */ #include <bspopts.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -48,18 +48,16 @@ void bsp_cleanup(void);
void bsp_reset(void); void bsp_reset(void);
#ifdef BSP_BOOTCARD_HANDLES_RAM_ALLOCATION #define BSP_BOOTCARD_HEAP_USES_WORK_AREA NULL
#define BSP_BOOTCARD_HEAP_USES_WORK_AREA NULL
#define BSP_BOOTCARD_HEAP_SIZE_DEFAULT 0 #define BSP_BOOTCARD_HEAP_SIZE_DEFAULT 0
void bsp_get_work_area( void bsp_get_work_area(
void **work_area_start, void **work_area_start,
size_t *work_area_size, size_t *work_area_size,
void **heap_start, void **heap_start,
size_t *heap_size size_t *heap_size
); );
#endif
int boot_card( int argc, char **argv, char **envp); int boot_card( int argc, char **argv, char **envp);