Explorar el Código

More syscall functions

teensy4-core
PaulStoffregen hace 6 años
padre
commit
4e51477dbb
Se han modificado 3 ficheros con 91 adiciones y 29 borrados
  1. +2
    -3
      teensy4/imxrt.ld
  2. +1
    -26
      teensy4/libc.c
  3. +88
    -0
      teensy4/startup.c

+ 2
- 3
teensy4/imxrt.ld Ver fichero

@@ -73,9 +73,8 @@ SECTIONS
_sbss = ADDR(.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);
_teensy_model_identifier = 0x23;

+ 1
- 26
teensy4/libc.c Ver fichero

@@ -1,26 +1 @@
#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 Ver fichero

@@ -318,3 +318,91 @@ static void memory_clear(uint32_t *dest, uint32_t *dest_end)
}



// 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) ;
}


Cargando…
Cancelar
Guardar