diff --git a/soc/xtensa/intel_s1000/CMakeLists.txt b/soc/xtensa/intel_s1000/CMakeLists.txt index 5c80ba4047a..6d64c0e7b56 100644 --- a/soc/xtensa/intel_s1000/CMakeLists.txt +++ b/soc/xtensa/intel_s1000/CMakeLists.txt @@ -3,3 +3,9 @@ zephyr_library() zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) zephyr_library_sources(soc.c) + +if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xcc") +if(CONFIG_NEWLIB_LIBC) + zephyr_library_sources(xcc_newlib_fix.c) +endif() +endif() diff --git a/soc/xtensa/intel_s1000/xcc_newlib_fix.c b/soc/xtensa/intel_s1000/xcc_newlib_fix.c new file mode 100644 index 00000000000..311b8bbf15c --- /dev/null +++ b/soc/xtensa/intel_s1000/xcc_newlib_fix.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2019, Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include + +/* these externs are from lib/libc/newlib/libc-hooks.c */ +extern int _read(int fd, char *buf, int nbytes); +extern int _write(int fd, const void *buf, int nbytes); +extern int _open(const char *name, int mode); +extern int _close(int file); +extern int _lseek(int file, int ptr, int dir); +extern int _isatty(int file); +extern int _kill(int i, int j); +extern int _getpid(void); +extern int _fstat(int file, struct stat *st); +extern void _exit(int status); +extern void *_sbrk(int count); + +_ssize_t _read_r(struct _reent *r, int fd, void *buf, size_t nbytes) +{ + ARG_UNUSED(r); + + return _read(fd, (char *)buf, nbytes); +} + +_ssize_t _write_r(struct _reent *r, int fd, const void *buf, size_t nbytes) +{ + ARG_UNUSED(r); + + return _write(fd, buf, nbytes); +} + +int _open_r(struct _reent *r, const char *name, int flags, int mode) +{ + ARG_UNUSED(r); + ARG_UNUSED(flags); + + return _open(name, mode); +} + +int _close_r(struct _reent *r, int file) +{ + ARG_UNUSED(r); + + return _close(file); +} + +_off_t _lseek_r(struct _reent *r, int file, _off_t ptr, int dir) +{ + ARG_UNUSED(r); + + return _lseek(file, ptr, dir); +} + +int _isatty_r(struct _reent *r, int file) +{ + ARG_UNUSED(r); + + return _isatty(file); +} + +int _kill_r(struct _reent *r, int i, int j) +{ + ARG_UNUSED(r); + + return _kill(i, j); +} + +int _getpid_r(struct _reent *r) +{ + ARG_UNUSED(r); + + return _getpid(); +} + +int _fstat_r(struct _reent *r, int file, struct stat *st) +{ + ARG_UNUSED(r); + + return _fstat(file, st); +} + +void _exit_r(struct _reent *r, int status) +{ + ARG_UNUSED(r); + + _exit(status); +} + +void *_sbrk_r(struct _reent *r, int count) +{ + ARG_UNUSED(r); + + return _sbrk(count); +}