mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-29 16:00:17 +00:00
2008-11-03 Till Straumann <strauman@slac.stanford.edu>
* shared/startup/pretaskinghook.c, shared/startup/sbrk.c: Fixed PR#1335. Pass initial starting address to heap initialization to avoid 1st 'sbrk'. User may now define 'BSP_sbrk_policy' variable (see sbrk.c) to tune behavior.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2008-11-03 Till Straumann <strauman@slac.stanford.edu>
|
||||
|
||||
* shared/startup/pretaskinghook.c, shared/startup/sbrk.c:
|
||||
Fixed PR#1335.
|
||||
|
||||
2008-10-23 Eric Norum <norume@aps.anl.gov>
|
||||
|
||||
* ep1a/include/bsp.h, motorola_powerpc/Makefile.am,
|
||||
|
||||
@@ -61,13 +61,9 @@ void bsp_pretasking_hook(void)
|
||||
BSP_heap_start, heap_size, heap_sbrk_spared);
|
||||
#endif
|
||||
|
||||
/* Must install sbrk helpers since we rely on sbrk for giving
|
||||
* us even the first chunk of memory (bsp_libc_init(heap start==NULL))
|
||||
*/
|
||||
|
||||
rtems_malloc_sbrk_helpers = &rtems_malloc_sbrk_helpers_table;
|
||||
|
||||
bsp_libc_init((void *) 0, heap_size, heap_sbrk_spared);
|
||||
bsp_libc_init((void *)BSP_heap_start, heap_size, heap_sbrk_spared);
|
||||
|
||||
/* Note that VME support may be omitted also by
|
||||
* providing a no-op BSP_vme_config routine
|
||||
|
||||
@@ -73,6 +73,16 @@
|
||||
static uint32_t remaining_start=0;
|
||||
static uint32_t remaining_size=0;
|
||||
|
||||
/* App. may provide a value by defining the BSP_sbrk_policy
|
||||
* variable.
|
||||
*
|
||||
* (-1) -> give all memory to the heap at initialization time
|
||||
* > 0 -> value used as sbrk amount; initially give 32M
|
||||
* 0 -> limit memory effectively to 32M.
|
||||
*
|
||||
*/
|
||||
extern uint32_t BSP_sbrk_policy __attribute__((weak));
|
||||
|
||||
#define LIMIT_32M 0x02000000
|
||||
|
||||
uint32_t
|
||||
@@ -81,13 +91,42 @@ _bsp_sbrk_init(uint32_t heap_start, uint32_t *heap_size_p)
|
||||
uint32_t rval=0;
|
||||
|
||||
remaining_start = heap_start;
|
||||
remaining_size =* heap_size_p;
|
||||
remaining_size = *heap_size_p;
|
||||
|
||||
if (remaining_start < LIMIT_32M &&
|
||||
remaining_start + remaining_size > LIMIT_32M) {
|
||||
/* clip at LIMIT_32M */
|
||||
rval = remaining_start + remaining_size - LIMIT_32M;
|
||||
*heap_size_p = LIMIT_32M - remaining_start;
|
||||
remaining_start = LIMIT_32M;
|
||||
remaining_size = rval;
|
||||
}
|
||||
|
||||
if ( 0 != &BSP_sbrk_policy ) {
|
||||
switch ( BSP_sbrk_policy ) {
|
||||
case (uint32_t)(-1):
|
||||
remaining_start = heap_start + *heap_size_p;
|
||||
remaining_size = 0;
|
||||
/* return a nonzero sbrk_amount because the libsupport code
|
||||
* at some point divides by this number prior to trying an
|
||||
* sbrk() which will fail.
|
||||
*/
|
||||
rval = 1;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
remaining_size = 0;
|
||||
/* see above for why we return 1 */
|
||||
rval = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( rval > BSP_sbrk_policy )
|
||||
rval = BSP_sbrk_policy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
@@ -95,6 +134,7 @@ void * sbrk(ptrdiff_t incr)
|
||||
{
|
||||
void *rval=(void*)-1;
|
||||
|
||||
/* FIXME: BEWARE if size >2G */
|
||||
if (incr <= remaining_size) {
|
||||
remaining_size-=incr;
|
||||
rval = (void*)remaining_start;
|
||||
@@ -102,5 +142,8 @@ void * sbrk(ptrdiff_t incr)
|
||||
} else {
|
||||
errno = ENOMEM;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printk("************* SBRK 0x%08x (ret 0x%08x) **********\n", incr, rval);
|
||||
#endif
|
||||
return rval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user