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

4.104.114.84.95
Last change on this file since f774fc06 was f774fc06, checked in by Till Straumann <strauman@…>, on 01/17/07 at 05:45:14

2007-01-16 Till Straumann <strauman@…>

  • ep1a/vme/vmeconfig.c, mvme5500/pci/pcifinddevice.c,
  • mvme5500/startup/pgtbl_activate.c, mvme5500/vectors/bspException.h,
  • mvme5500/vectors/exceptionhandler.c, mvme5500/vme/VME.h,
  • mvme5500/vme/vmeconfig.c, score603e/vme/vmeconfig.c, shared/pci/pcifinddevice.c,
  • shared/startup/pgtbl_activate.c, shared/startup/pgtbl_setup.c,
  • shared/startup/probeMemEnd.c, shared/startup/sbrk.c, shared/vme/VME.h,
  • shared/vme/VMEConfig.h, shared/vme/vme_universe.c, shared/vme/vmeconfig.c: Added SLAC/Stanford Authorship Note / Copyright + Liability Disclaimer.
  • Property mode set to 100644
File size: 3.3 KB
Line 
1/* $Id$ */
2
3/*
4 *  sbrk.c
5 *
6 * Authorship
7 * ----------
8 * This software was created by
9 *     Till Straumann <strauman@slac.stanford.edu>, 2002,
10 *         Stanford Linear Accelerator Center, Stanford University.
11 *
12 * Acknowledgement of sponsorship
13 * ------------------------------
14 * This software was produced by
15 *     the Stanford Linear Accelerator Center, Stanford University,
16 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
17 *
18 * Government disclaimer of liability
19 * ----------------------------------
20 * Neither the United States nor the United States Department of Energy,
21 * nor any of their employees, makes any warranty, express or implied, or
22 * assumes any legal liability or responsibility for the accuracy,
23 * completeness, or usefulness of any data, apparatus, product, or process
24 * disclosed, or represents that its use would not infringe privately owned
25 * rights.
26 *
27 * Stanford disclaimer of liability
28 * --------------------------------
29 * Stanford University makes no representations or warranties, express or
30 * implied, nor assumes any liability for the use of this software.
31 *
32 * Stanford disclaimer of copyright
33 * --------------------------------
34 * Stanford University, owner of the copyright, hereby disclaims its
35 * copyright and all other rights in this software.  Hence, anyone may
36 * freely use it for any purpose without restriction. 
37 *
38 * Maintenance of notices
39 * ----------------------
40 * In the interest of clarity regarding the origin and status of this
41 * SLAC software, this and all the preceding Stanford University notices
42 * are to remain affixed to any copy or derivative of this software made
43 * or distributed by the recipient and are to be affixed to any copy of
44 * software made or distributed by the recipient that contains a copy or
45 * derivative of this software.
46 *
47 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
48 */
49
50/*
51 *  Hack around the 32bit powerpc 32M problem:
52 *
53 *  GCC by default uses relative branches which can not jump
54 *  farther than 32M. Hence all program text is confined to
55 *  a single 32M segment.
56 *  This hack gives the RTEMS malloc region all memory below
57 *  32M at startup. Only when this region is exhausted will sbrk
58 *  add more memory. Loading modules may fail at that point, hence
59 *  the user is expected to load all modules at startup _prior_
60 *  to malloc()ing lots of memory...
61 *
62 *  NOTE: it would probably be better to have a separate region
63 *        for module code.
64 */
65
66#include <rtems.h>
67
68#include <signal.h>
69#include <errno.h>
70#include <sys/types.h>
71#include <unistd.h>
72
73static uint32_t         remaining_start=0;
74static uint32_t         remaining_size=0;
75
76#define LIMIT_32M  0x02000000
77
78uint32_t
79_bsp_sbrk_init(uint32_t         heap_start, uint32_t         *heap_size_p)
80{
81  uint32_t         rval=0;
82
83  remaining_start =  heap_start;
84  remaining_size  =*  heap_size_p;
85  if (remaining_start < LIMIT_32M &&
86      remaining_start + remaining_size > LIMIT_32M) {
87    /* clip at LIMIT_32M */
88    rval = remaining_start + remaining_size - LIMIT_32M;
89    *heap_size_p = LIMIT_32M - remaining_start;
90  }
91  return rval;
92}
93
94void * sbrk(ptrdiff_t incr)
95{
96  void *rval=(void*)-1;
97
98  if (incr <= remaining_size) {
99    remaining_size-=incr;
100    rval = (void*)remaining_start;
101    remaining_start += incr;
102  } else {
103    errno = ENOMEM;
104  }
105  return rval;
106}
Note: See TracBrowser for help on using the repository browser.