source: trunk/libs/newlib/src/libgloss/m68k/cf-sbrk.c @ 467

Last change on this file since 467 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.4 KB
Line 
1/*
2 * cf-sbrk.c --
3 *
4 * Copyright (c) 2006 CodeSourcery Inc
5 *
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
14 * they apply.
15 */
16
17#include <errno.h>
18/*
19 * sbrk -- changes heap size size. Get nbytes more
20 *         RAM. We just increment a pointer in what's
21 *         left of memory on the board.
22 */
23
24extern char __end[] __attribute__ ((aligned (4)));
25
26/* End of heap, if non NULL.  */
27extern void *__heap_limit;
28
29void *
30sbrk (int nbytes)
31{
32  static char *heap = __end;
33  char *end = __heap_limit;
34  char *base = heap;
35  char *new_heap = heap + nbytes;
36 
37  if (!end)
38    {
39      /* Use sp - 256 as the heap limit.  */
40      __asm__ __volatile__ ("move.l %/sp,%0" : "=r"(end));
41      end -= 256;
42    }
43  if (nbytes < 0 || (long)(end - new_heap) < 0)
44    {
45      errno = ENOMEM;
46      return (void *)-1;
47    }
48  heap = new_heap;
49  return base;
50}
Note: See TracBrowser for help on using the repository browser.