You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
554B

  1. #include <errno.h>
  2. extern unsigned long _ebss;
  3. char *__brkval = (char *)&_ebss; // TODO: put heap into OCRAM, not DTCM
  4. #define STACK_MARGIN 8192
  5. void * _sbrk(int incr)
  6. {
  7. char *prev, *stack;
  8. prev = __brkval;
  9. if (incr != 0) {
  10. __asm__ volatile("mov %0, sp" : "=r" (stack) ::);
  11. if (prev + incr >= stack - STACK_MARGIN) {
  12. errno = ENOMEM;
  13. return (void *)-1;
  14. }
  15. __brkval = prev + incr;
  16. }
  17. return prev;
  18. }