URL
https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk
Only display areas with differences |
Details |
Blame |
View Log
Rev 207 |
Rev 345 |
#include <_ansi.h>
|
#include <_ansi.h>
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/stat.h>
|
#include <sys/stat.h>
|
|
|
#include "regs.S"
|
#include "regs.S"
|
|
|
extern char _end[];
|
extern char _end[];
|
|
|
/* FIXME: This is not ideal, since we do a get_mem_info() call for
|
/* FIXME: This is not ideal, since we do a get_mem_info() call for
|
every sbrk() call. */
|
every sbrk() call. */
|
char *
|
char *
|
sbrk (nbytes)
|
sbrk (nbytes)
|
int nbytes;
|
int nbytes;
|
{
|
{
|
static char *heap_ptr = _end;
|
static char *heap_ptr = _end;
|
static char *heap_start = _end;
|
static char *heap_start = _end;
|
char *base;
|
char *base;
|
struct s_mem {
|
struct s_mem {
|
unsigned int size;
|
unsigned int size;
|
unsigned int icsize;
|
unsigned int icsize;
|
unsigned int dcsize;
|
unsigned int dcsize;
|
} mem;
|
} mem;
|
unsigned int avail = 0;
|
unsigned int avail = 0;
|
|
|
/* The sizeof (s_mem.size) must be 4 bytes. The compiler should be
|
/* The sizeof (s_mem.size) must be 4 bytes. The compiler should be
|
able to eliminate this check */
|
able to eliminate this check */
|
if (sizeof (unsigned int) != 4)
|
if (sizeof (unsigned int) != 4)
|
return (char *)-1;
|
return (char *)-1;
|
|
|
get_mem_info(&mem);
|
get_mem_info(&mem);
|
/* NOTE: The value returned from the get_mem_info call is the amount
|
/* NOTE: The value returned from the get_mem_info call is the amount
|
of memory, and not the address of the (last byte + 1) */
|
of memory, and not the address of the (last byte + 1) */
|
|
|
if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) {
|
if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) {
|
avail = (heap_start + mem.size) - (size_t)heap_ptr;
|
avail = (heap_start + mem.size) - (size_t)heap_ptr;
|
base = heap_ptr;
|
base = heap_ptr;
|
} /* else will fail since "nbytes" will be greater than zeroed "avail" value */
|
} /* else will fail since "nbytes" will be greater than zeroed "avail" value */
|
|
|
if ((nbytes > avail) || (heap_ptr + nbytes < _end))
|
if ((nbytes > avail) || (heap_ptr + nbytes < _end))
|
base = (char *)-1;
|
base = (char *)-1;
|
else
|
else
|
heap_ptr += nbytes;
|
heap_ptr += nbytes;
|
|
|
return base;
|
return base;
|
}
|
}
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.