diff options
author | Ranjith Kumaran <ranjith@cygnus.com> | 2000-03-17 22:48:54 +0000 |
---|---|---|
committer | Ranjith Kumaran <ranjith@cygnus.com> | 2000-03-17 22:48:54 +0000 |
commit | 03261851a10dd2d6900a0a00a7515a0a46fb5d76 (patch) | |
tree | 7c22ac6cbbc99fd5cd1b5426853be8d4fd7bfcf1 /libgloss/mips/syscalls.c | |
parent | fae4c299f14fc23e2829c8656992eba21f79242a (diff) | |
download | cygnal-03261851a10dd2d6900a0a00a7515a0a46fb5d76.tar.gz cygnal-03261851a10dd2d6900a0a00a7515a0a46fb5d76.tar.bz2 cygnal-03261851a10dd2d6900a0a00a7515a0a46fb5d76.zip |
20000317 sourceware import
Diffstat (limited to 'libgloss/mips/syscalls.c')
-rw-r--r-- | libgloss/mips/syscalls.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libgloss/mips/syscalls.c b/libgloss/mips/syscalls.c new file mode 100644 index 000000000..3ab543674 --- /dev/null +++ b/libgloss/mips/syscalls.c @@ -0,0 +1,45 @@ +#include <_ansi.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include "regs.S" + +extern char _end[]; + +/* FIXME: This is not ideal, since we do a get_mem_info() call for + every sbrk() call. */ +char * +sbrk (nbytes) + int nbytes; +{ + static char *heap_ptr = _end; + static char *heap_start = _end; + char *base; + struct s_mem { + unsigned int size; + unsigned int icsize; + unsigned int dcsize; + } mem; + unsigned int avail = 0; + + /* The sizeof (s_mem.size) must be 4 bytes. The compiler should be + able to eliminate this check */ + if (sizeof (unsigned int) != 4) + return (char *)-1; + + get_mem_info(&mem); + /* NOTE: The value returned from the get_mem_info call is the amount + 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))) { + avail = (heap_start + mem.size) - (size_t)heap_ptr; + base = heap_ptr; + } /* else will fail since "nbytes" will be greater than zeroed "avail" value */ + + if ((nbytes > avail) || (heap_ptr + nbytes < _end)) + base = (char *)-1; + else + heap_ptr += nbytes; + + return base; +} |