diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-08-09 16:48:00 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-10-25 14:54:06 +0200 |
commit | 47a3cd8f73780bad3eff5135f0eb58e8c98af91d (patch) | |
tree | 8acdfc6ebe5d596f9c6b974e6c460dc69e824e3c /c/src/lib/libbsp/powerpc/shared/startup/sbrk.c | |
parent | score: Append to free list in _Heap_Extend() (diff) | |
download | rtems-47a3cd8f73780bad3eff5135f0eb58e8c98af91d.tar.bz2 |
score: Work area initialization API change
The work areas (RTEMS work space and C program heap) will be initialized
now in a separate step and are no longer part of
rtems_initialize_data_structures(). Initialization is performed with
tables of Heap_Area entries. This allows usage of scattered memory
areas present on various small scale micro-controllers.
The sbrk() support API changes also. The bsp_sbrk_init() must now deal
with a minimum size for the first memory chunk to take the configured
work space size into account.
Diffstat (limited to 'c/src/lib/libbsp/powerpc/shared/startup/sbrk.c')
-rw-r--r-- | c/src/lib/libbsp/powerpc/shared/startup/sbrk.c | 47 |
1 files changed, 23 insertions, 24 deletions
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; |