summaryrefslogtreecommitdiffstats
path: root/c
diff options
context:
space:
mode:
authorTill Straumann <strauman@slac.stanford.edu>2008-11-03 20:23:29 +0000
committerTill Straumann <strauman@slac.stanford.edu>2008-11-03 20:23:29 +0000
commit0612ad26506097b532bc097472894b342a4e9264 (patch)
treea2c1936db30f0eec41e22e81a72980bdebb4ecb9 /c
parent2008-11-03 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-0612ad26506097b532bc097472894b342a4e9264.tar.bz2
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.
Diffstat (limited to 'c')
-rw-r--r--c/src/lib/libbsp/powerpc/ChangeLog5
-rw-r--r--c/src/lib/libbsp/powerpc/shared/startup/sbrk.c45
2 files changed, 49 insertions, 1 deletions
diff --git a/c/src/lib/libbsp/powerpc/ChangeLog b/c/src/lib/libbsp/powerpc/ChangeLog
index 8ef3c4dd97..aa5f39d570 100644
--- a/c/src/lib/libbsp/powerpc/ChangeLog
+++ b/c/src/lib/libbsp/powerpc/ChangeLog
@@ -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-02 Sebastian Huber <sebastian.huber@embedded-brains.de>
* shared/clock/clock.c: Update for status-checks.h changes.
diff --git a/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c b/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c
index 07168af8b6..1a219cf5f5 100644
--- a/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c
+++ b/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c
@@ -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
uintptr_t _bsp_sbrk_init(
@@ -83,13 +93,42 @@ uintptr_t _bsp_sbrk_init(
uintptr_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;
}
@@ -97,6 +136,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;
@@ -104,5 +144,8 @@ void * sbrk(ptrdiff_t incr)
} else {
errno = ENOMEM;
}
+#ifdef DEBUG
+ printk("************* SBRK 0x%08x (ret 0x%08x) **********\n", incr, rval);
+#endif
return rval;
}