fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libgloss / mips / syscalls.c
blob3ab543674086bedb400d485c9e83d9962a89ff21
1 #include <_ansi.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
5 #include "regs.S"
7 extern char _end[];
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;
15 static char *heap_ptr = _end;
16 static char *heap_start = _end;
17 char *base;
18 struct s_mem {
19 unsigned int size;
20 unsigned int icsize;
21 unsigned int dcsize;
22 } mem;
23 unsigned int avail = 0;
25 /* The sizeof (s_mem.size) must be 4 bytes. The compiler should be
26 able to eliminate this check */
27 if (sizeof (unsigned int) != 4)
28 return (char *)-1;
30 get_mem_info(&mem);
31 /* NOTE: The value returned from the get_mem_info call is the amount
32 of memory, and not the address of the (last byte + 1) */
34 if (((size_t)heap_ptr >= heap_start) && ((size_t)heap_ptr < (heap_start + mem.size))) {
35 avail = (heap_start + mem.size) - (size_t)heap_ptr;
36 base = heap_ptr;
37 } /* else will fail since "nbytes" will be greater than zeroed "avail" value */
39 if ((nbytes > avail) || (heap_ptr + nbytes < _end))
40 base = (char *)-1;
41 else
42 heap_ptr += nbytes;
44 return base;