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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [libgloss/] [mips/] [syscalls.c] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
#include <_ansi.h>
2
#include <sys/types.h>
3
#include <sys/stat.h>
4
 
5
#include "regs.S"
6
 
7
extern char _end[];
8
 
9
/* FIXME: This is not ideal, since we do a get_mem_info() call for
10
   every sbrk() call. */
11
char *
12
sbrk (nbytes)
13
     int nbytes;
14
{
15
  static char *heap_ptr = _end;
16
  char        *base;
17
  struct s_mem {
18
    unsigned int size;
19
    unsigned int icsize;
20
    unsigned int dcsize;
21
  } mem;
22
  unsigned int avail = 0;
23
 
24
  /* The sizeof (s_mem.size) must be 4 bytes.  The compiler should be
25
     able to eliminate this check */
26
  if (sizeof (unsigned int) != 4)
27
    return (char *)-1;
28
 
29
  get_mem_info(&mem);
30
  /* NOTE: The value returned from the get_mem_info call is the amount
31
     of memory, and not the address of the (last byte + 1) */
32
 
33
  if (((size_t)heap_ptr >= K1BASE) && ((size_t)heap_ptr < (K1BASE + mem.size))) {
34
    avail = (K1BASE + mem.size) - (size_t)heap_ptr;
35
    base = heap_ptr;
36
  } /* else will fail since "nbytes" will be greater than zeroed "avail" value */
37
 
38
  if ((nbytes > avail) || (heap_ptr + nbytes < _end))
39
   base = (char *)-1;
40
  else
41
   heap_ptr += nbytes;
42
 
43
  return base;
44
}

powered by: WebSVN 2.1.0

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