Browse Source

More syscall functions

main
PaulStoffregen 5 years ago
parent
commit
4e51477dbb
3 changed files with 91 additions and 29 deletions
  1. +2
    -3
      teensy4/imxrt.ld
  2. +1
    -26
      teensy4/libc.c
  3. +88
    -0
      teensy4/startup.c

+ 2
- 3
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);
_heap_start = ADDR(.bss.dma) + SIZEOF(.bss.dma);
_heap_end = 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;

+ 1
- 26
teensy4/libc.c View File

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

// from the linker script
extern unsigned long _edmamem;
extern unsigned long _emallocmem;

char *__brkval = (char *)&_edmamem;

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

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

prev = __brkval;
if (incr != 0) {
if (prev + incr > (char *)&_emallocmem) {
errno = ENOMEM;
return (void *)-1;
}
__brkval = prev + incr;
}
return prev;
}

// this file no longer used

+ 88
- 0
teensy4/startup.c View File

} }





// syscall functions need to be in the same C file as the entry point "ResetVector"
// otherwise the linker will discard them in some cases.

#include <errno.h>

// from the linker script
extern unsigned long _heap_start;
extern unsigned long _heap_end;

char *__brkval = (char *)&_heap_start;

void * _sbrk(int incr)
{
char *prev = __brkval;
if (incr != 0) {
if (prev + incr > (char *)&_heap_end) {
errno = ENOMEM;
return (void *)-1;
}
__brkval = prev + incr;
}
return prev;
}

__attribute__((weak))
int _read(int file, char *ptr, int len)
{
return 0;
}

__attribute__((weak))
int _close(int fd)
{
return -1;
}

#include <sys/stat.h>

__attribute__((weak))
int _fstat(int fd, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}

__attribute__((weak))
int _isatty(int fd)
{
return 1;
}

__attribute__((weak))
int _lseek(int fd, long long offset, int whence)
{
return -1;
}

__attribute__((weak))
void _exit(int status)
{
while (1);
}

__attribute__((weak))
void __cxa_pure_virtual()
{
while (1);
}

__attribute__((weak))
int __cxa_guard_acquire (char *g)
{
return !(*g);
}

__attribute__((weak))
void __cxa_guard_release(char *g)
{
*g = 1;
}

__attribute__((weak))
void abort(void)
{
while (1) ;
}


Loading…
Cancel
Save