source: rtems/c/src/lib/libbsp/powerpc/shared/startup/sbrk.c @ e79a1947

4.104.114.84.95
Last change on this file since e79a1947 was 6128a4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 21, 2004 at 10:43:04 AM

Remove stray white spaces.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/* $Id$ */
2
3/*
4 *  sbrk.c
5 *
6 *  Author: Till Straumann <strauman@slac.stanford.edu>, 2002
7 *
8 *  Hack around the 32bit powerpc 32M problem:
9 *
10 *  GCC by default uses relative branches which can not jump
11 *  farther than 32M. Hence all program text is confined to
12 *  a single 32M segment.
13 *  This hack gives the RTEMS malloc region all memory below
14 *  32M at startup. Only when this region is exhausted will sbrk
15 *  add more memory. Loading modules may fail at that point, hence
16 *  the user is expected to load all modules at startup _prior_
17 *  to malloc()ing lots of memory...
18 *
19 *  NOTE: it would probably be better to have a separate region
20 *        for module code.
21 */
22
23#include <rtems.h>
24
25#include <signal.h>
26#include <errno.h>
27#include <sys/types.h>
28#include <unistd.h>
29
30static uint32_t         remaining_start=0;
31static uint32_t         remaining_size=0;
32
33#define LIMIT_32M  0x02000000
34
35uint32_t
36_bsp_sbrk_init(uint32_t         heap_start, uint32_t         *heap_size_p)
37{
38  uint32_t         rval=0;
39
40  remaining_start =  heap_start;
41  remaining_size  =*  heap_size_p;
42  if (remaining_start < LIMIT_32M &&
43      remaining_start + remaining_size > LIMIT_32M) {
44    /* clip at LIMIT_32M */
45    rval = remaining_start + remaining_size - LIMIT_32M;
46    *heap_size_p = LIMIT_32M - remaining_start;
47  }
48  return rval;
49}
50
51void * sbrk(ptrdiff_t incr)
52{
53  void *rval=(void*)-1;
54
55  if (incr <= remaining_size) {
56    remaining_size-=incr;
57    rval = (void*)remaining_start;
58    remaining_start += incr;
59  } else {
60    errno = ENOMEM;
61  }
62  return rval;
63}
Note: See TracBrowser for help on using the repository browser.