From 9897c3b0dda296704cd1a8313683f292544c6e3c Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Mon, 3 Feb 2020 05:08:04 -0600 Subject: [PATCH] libc: Move xtensa reentrant syscall impl to common libc-hooks The xcc specific reentrant syscall implementations are actually useful for xtensa in general. So move that code from being specific to intel_s1000 / xcc into generic newlib/libc-hooks.c. This is in prep for the Zephyr SDK dropping -DMISSING_SYSCALL_NAMES which will make its version of newlib on xtensa match behavior with xcc. Signed-off-by: Kumar Gala --- lib/libc/newlib/libc-hooks.c | 85 +++++++++++++++++++++ soc/xtensa/intel_s1000/xcc/newlib_fixes.c | 91 ----------------------- 2 files changed, 85 insertions(+), 91 deletions(-) diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c index 98a11f6547c..0cb4de68e54 100644 --- a/lib/libc/newlib/libc-hooks.c +++ b/lib/libc/newlib/libc-hooks.c @@ -270,3 +270,88 @@ __weak int *__errno(void) { return z_errno(); } + +#if CONFIG_XTENSA +/* The Newlib in xtensa toolchain has a few missing functions for the + * reentrant versions of the syscalls. + */ +#ifndef CONFIG_POSIX_API +_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); +} +#endif + +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); +} +#endif /* CONFIG_XTENSA */ diff --git a/soc/xtensa/intel_s1000/xcc/newlib_fixes.c b/soc/xtensa/intel_s1000/xcc/newlib_fixes.c index d1053b23b40..2c700a76209 100644 --- a/soc/xtensa/intel_s1000/xcc/newlib_fixes.c +++ b/soc/xtensa/intel_s1000/xcc/newlib_fixes.c @@ -12,97 +12,6 @@ #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); -} - int _gettimeofday_r(struct _reent *r, struct timeval *__tp, void *__tzp) { ARG_UNUSED(r);