Browse Source

Fix malloc, using OCRAM rather than DTCM

teensy4-core
PaulStoffregen 6 years ago
parent
commit
1989b49cf3
2 changed files with 21 additions and 15 deletions
  1. +4
    -0
      teensy4/imxrt.ld
  2. +17
    -15
      teensy4/libc.c

+ 4
- 0
teensy4/imxrt.ld View File

_sbss = ADDR(.bss); _sbss = ADDR(.bss);
_ebss = ADDR(.bss) + SIZEOF(.bss); _ebss = ADDR(.bss) + SIZEOF(.bss);


_sdmamem = ADDR(.bss.dma);
_edmamem = ADDR(.bss.dma) + SIZEOF(.bss.dma);
_emallocmem = ORIGIN(RAM) + LENGTH(RAM);

_flashimagelen = SIZEOF(.text.progmem) + SIZEOF(.text) + SIZEOF(.data); _flashimagelen = SIZEOF(.text.progmem) + SIZEOF(.text) + SIZEOF(.data);
_teensy_model_identifier = 0x23; _teensy_model_identifier = 0x23;



+ 17
- 15
teensy4/libc.c View File

#include <errno.h> #include <errno.h>
#include "debug/printf.h"


extern unsigned long _ebss;

char *__brkval = (char *)&_ebss; // TODO: put heap into OCRAM, not DTCM
#define STACK_MARGIN 8192
// from the linker script
extern unsigned long _edmamem;
extern unsigned long _emallocmem;


char *__brkval = (char *)&_edmamem;


void * _sbrk(int incr) void * _sbrk(int incr)
{ {
char *prev, *stack;
char *prev;

printf("sbrk incr = %d\n", incr);


prev = __brkval;
if (incr != 0) {
__asm__ volatile("mov %0, sp" : "=r" (stack) ::);
if (prev + incr >= stack - STACK_MARGIN) {
errno = ENOMEM;
return (void *)-1;
}
__brkval = prev + incr;
}
return prev;
prev = __brkval;
if (incr != 0) {
if (prev + incr > (char *)&_emallocmem) {
errno = ENOMEM;
return (void *)-1;
}
__brkval = prev + incr;
}
return prev;
} }



Loading…
Cancel
Save