OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-newlib/] [newlib-1.17.0/] [libgloss/] [mep/] [sbrk.c] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jlechner
/*
2
 * Copyright (c) 2003  Red Hat, Inc. All rights reserved.
3
 *
4
 * This copyrighted material is made available to anyone wishing to use, modify,
5
 * copy, or redistribute it subject to the terms and conditions of the BSD
6
 * License.  This program is distributed in the hope that it will be useful,
7
 * but WITHOUT ANY WARRANTY expressed or implied, including the implied
8
 * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  A copy
9
 * of this license is available at http://www.opensource.org/licenses. Any
10
 * Red Hat trademarks that are incorporated in the source code or documentation
11
 * are not subject to the BSD License and may only be used or replicated with
12
 * the express permission of Red Hat, Inc.
13
 */
14
 
15
#include <errno.h>
16
 
17
extern int __heap __far;      /* beginning of heap */
18
extern int __heap_end __far;  /* if at address 0, use stack pointer as limit */
19
 
20
static char *the_break = (char *)(& __heap);
21
 
22
int
23
is_addr_0 (int address)
24
{
25
  return address ? 0 : 1;
26
}
27
 
28
void *
29
sbrk(int inc)
30
{
31
  char *current_heap_limit = (char *) (& __heap_end);
32
 
33
  /* is_addr_0 avoids optimizing out this block.  */
34
  if (is_addr_0 ((int) current_heap_limit))
35
    {
36
      int something;
37
      int margin = 4096;
38
      current_heap_limit = (char *) (& something) - margin;
39
    }
40
 
41
  if ((the_break + inc) < current_heap_limit)
42
    {
43
      void *rv = (void *) the_break;
44
      the_break += inc;
45
      return rv;
46
    }
47
  else
48
    {
49
      errno = ENOMEM;
50
      return (void *) -1;
51
    }
52
}
53
 
54
int
55
brk (void *ptr)
56
{
57
  the_break = ptr;
58
  return 0;
59
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.