From b2d3317c6a7954423167316436c949fbcb1ce61d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 23 Feb 2021 03:21:16 +0800 Subject: remove minilibc --- components/libc/compilers/newlib/SConscript | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'components/libc/compilers/newlib/SConscript') diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript index d0868bbdea..b1ad6e4784 100644 --- a/components/libc/compilers/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript @@ -1,21 +1,30 @@ from building import * Import('rtconfig') -src = Glob('*.c') +src = [] cwd = GetCurrentDir() group = [] CPPPATH = [cwd] -CPPDEFINES = ['RT_USING_NEWLIB'] - -# link with libc and libm: -# libm is a frequently used lib. Newlib is compiled with -ffunction-sections in -# recent GCC tool chains. The linker would just link in the functions that have -# been referenced. So setting this won't result in bigger text size. -LIBS = ['c', 'm'] if rtconfig.PLATFORM == 'gcc': - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], - CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + if GetDepend('RT_USING_LIBC'): + CPPDEFINES = ['RT_USING_NEWLIB'] + # link with libc and libm: + # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in + # recent GCC tool chains. The linker would just link in the functions that have + # been referenced. So setting this won't result in bigger text size. + LIBS = ['c', 'm'] + + src += Glob('*.c') + SrcRemove(src, ['minilib.c']) + if GetDepend('RT_USING_MODULE') == False: + SrcRemove(src, ['libc_syms.c']) + else: + src += ['minilib.c'] + CPPDEFINES = [] + LIBS = [] + + group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) Return('group') -- cgit v1.3.1 From 850e1aeb5264818c133a32ff457794ff9bd9364d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 28 Apr 2021 13:03:43 +0800 Subject: [libc][time] 细微调整time.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 10 +++++----- components/libc/compilers/newlib/SConscript | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'components/libc/compilers/newlib/SConscript') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 33d8907165..5f4af8e572 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -16,7 +16,7 @@ * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, * which found by Rob * 2021-02-12 Meco Man move all of the functions located in to this file - * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html + * 2021-03-15 Meco Man fixed a bug of leaking memory in asctime() */ #include @@ -104,7 +104,7 @@ static int get_timeval(struct timeval *tv) } else { - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); return -1; } @@ -112,7 +112,7 @@ static int get_timeval(struct timeval *tv) return (rst < 0) ? -1 : 1; #else - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); return -1; #endif /* RT_USING_RTC */ @@ -273,13 +273,13 @@ RTM_EXPORT(asctime); char *ctime_r (const time_t * tim_p, char * result) { struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); + return asctime_r(localtime_r(tim_p, &tm), result); } RTM_EXPORT(ctime_r); char* ctime(const time_t *tim_p) { - return asctime (localtime (tim_p)); + return asctime(localtime(tim_p)); } RTM_EXPORT(ctime); diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript index b1ad6e4784..542cdecd40 100644 --- a/components/libc/compilers/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript @@ -4,17 +4,18 @@ Import('rtconfig') src = [] cwd = GetCurrentDir() group = [] - +LIBS = [] +CPPDEFINES = [] CPPPATH = [cwd] if rtconfig.PLATFORM == 'gcc': if GetDepend('RT_USING_LIBC'): - CPPDEFINES = ['RT_USING_NEWLIB'] + CPPDEFINES += ['RT_USING_NEWLIB'] # link with libc and libm: # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in # recent GCC tool chains. The linker would just link in the functions that have # been referenced. So setting this won't result in bigger text size. - LIBS = ['c', 'm'] + LIBS += ['c', 'm'] src += Glob('*.c') SrcRemove(src, ['minilib.c']) @@ -22,8 +23,6 @@ if rtconfig.PLATFORM == 'gcc': SrcRemove(src, ['libc_syms.c']) else: src += ['minilib.c'] - CPPDEFINES = [] - LIBS = [] group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) -- cgit v1.3.1 From a0e800617cb9b2e76ec1807a24af189c42ab456f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 25 Sep 2021 14:56:10 -0400 Subject: [libc][newlib] 优化syscall 将minilib.c并入syscalls.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/newlib/SConscript | 3 +- components/libc/compilers/newlib/minilib.c | 72 -------------- components/libc/compilers/newlib/syscalls.c | 143 +++++++++++++++------------- 3 files changed, 76 insertions(+), 142 deletions(-) delete mode 100644 components/libc/compilers/newlib/minilib.c (limited to 'components/libc/compilers/newlib/SConscript') diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript index 542cdecd40..cef546e17c 100644 --- a/components/libc/compilers/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript @@ -18,11 +18,10 @@ if rtconfig.PLATFORM == 'gcc': LIBS += ['c', 'm'] src += Glob('*.c') - SrcRemove(src, ['minilib.c']) if GetDepend('RT_USING_MODULE') == False: SrcRemove(src, ['libc_syms.c']) else: - src += ['minilib.c'] + src += ['syscalls.c'] group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) diff --git a/components/libc/compilers/newlib/minilib.c b/components/libc/compilers/newlib/minilib.c deleted file mode 100644 index 7aed3aa36e..0000000000 --- a/components/libc/compilers/newlib/minilib.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-23 Meco Man first version - */ - -#include -#include - -#ifdef RT_USING_HEAP /* Memory routine */ -#include - -void * _malloc_r (struct _reent *ptr, size_t size) -{ - void* result; - - result = (void*)rt_malloc (size); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void * _realloc_r (struct _reent *ptr, void *old, size_t newlen) -{ - void* result; - - result = (void*)rt_realloc (old, newlen); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_calloc_r (struct _reent *ptr, size_t size, size_t len) -{ - void* result; - - result = (void*)rt_calloc (size, len); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void _free_r (struct _reent *ptr, void *addr) -{ - rt_free (addr); -} - -#else -void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr) -{ - return RT_NULL; -} -#endif /*RT_USING_HEAP*/ - -void __libc_init_array(void) -{ - /* we not use __libc init_aray to initialize C++ objects */ - /* __libc_init_array is ARM code, not Thumb; it will cause hardfault. */ -} diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index b2258c3345..29ffd41ac1 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -11,17 +11,81 @@ * 2020-02-24 Meco Man fix bug of _isatty_r() */ -#include -#include -#include -#include - #include +#include +#include + +#define DBG_TAG "newlib.syscalls" +#define DBG_LVL DBG_INFO +#include + +#ifdef RT_USING_HEAP /* Memory routine */ +void *_malloc_r (struct _reent *ptr, size_t size) +{ + void* result; + result = (void*)rt_malloc (size); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) +{ + void* result; + + result = (void*)rt_realloc (old, newlen); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void *_calloc_r (struct _reent *ptr, size_t size, size_t len) +{ + void* result; + + result = (void*)rt_calloc (size, len); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void _free_r (struct _reent *ptr, void *addr) +{ + rt_free (addr); +} + +#else +void * +_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +{ + LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC"); + RT_ASSERT(0); + return RT_NULL; +} +#endif /*RT_USING_HEAP*/ + +void __libc_init_array(void) +{ + /* we not use __libc init_aray to initialize C++ objects */ + /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */ +} + +#ifdef RT_USING_LIBC +#include +#include #ifdef RT_USING_DFS #include #endif - #ifdef RT_USING_MODULE #include #endif @@ -233,58 +297,11 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) #endif } -#ifdef RT_USING_HEAP /* Memory routine */ -void *_malloc_r (struct _reent *ptr, size_t size) -{ - void* result; - - result = (void*)rt_malloc (size); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) -{ - void* result; - - result = (void*)rt_realloc (old, newlen); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_calloc_r (struct _reent *ptr, size_t size, size_t len) -{ - void* result; - - result = (void*)rt_calloc (size, len); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void _free_r (struct _reent *ptr, void *addr) -{ - rt_free (addr); -} - -#else -void * -_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +void _system(const char *s) { - return RT_NULL; + extern int __rt_libc_system(const char *string); + __rt_libc_system(s); } -#endif /*RT_USING_HEAP*/ /* for exit() and abort() */ __attribute__ ((noreturn)) void _exit (int status) @@ -294,18 +311,6 @@ __attribute__ ((noreturn)) void _exit (int status) while(1); } -void _system(const char *s) -{ - extern int __rt_libc_system(const char *string); - __rt_libc_system(s); -} - -void __libc_init_array(void) -{ - /* we not use __libc init_aray to initialize C++ objects */ - /* __libc_init_array is ARM code, not Thumb; it will cause hardfault. */ -} - mode_t umask(mode_t mask) { return 022; @@ -321,3 +326,5 @@ These functions are implemented and replaced by the 'common/time.c' file int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); _CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); */ + +#endif /* RT_USING_LIBC */ -- cgit v1.3.1 From 8b17d53da73289a368a47f798a9275aea3e50d86 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 27 Sep 2021 14:43:31 -0400 Subject: [libc]新建gcc文件夹,将newlib和partical文件夹并入 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/ls1bdev/Kconfig | 4 - bsp/ls1cdev/Kconfig | 4 - bsp/ls2kdev/Kconfig | 4 - .../libc/compilers/common/partial/SConscript | 15 - .../libc/compilers/common/partial/ls/SConscript | 23 -- .../libc/compilers/common/partial/ls/readme.md | 9 - .../libc/compilers/common/partial/ls/sys/select.h | 52 ---- components/libc/compilers/gcc/SConscript | 15 + components/libc/compilers/gcc/newlib/README.md | 10 + components/libc/compilers/gcc/newlib/SConscript | 28 ++ components/libc/compilers/gcc/newlib/libc.c | 50 +++ components/libc/compilers/gcc/newlib/libc.h | 28 ++ components/libc/compilers/gcc/newlib/libc_syms.c | 52 ++++ .../libc/compilers/gcc/newlib/machine/time.h | 12 + components/libc/compilers/gcc/newlib/stdio.c | 80 +++++ components/libc/compilers/gcc/newlib/syscalls.c | 341 ++++++++++++++++++++ components/libc/compilers/gcc/partial/SConscript | 15 + .../libc/compilers/gcc/partial/mips/SConscript | 20 ++ .../libc/compilers/gcc/partial/mips/readme.md | 4 + .../libc/compilers/gcc/partial/mips/sys/select.h | 52 ++++ components/libc/compilers/gcc/partial/readme.md | 2 + components/libc/compilers/newlib/README.md | 9 - components/libc/compilers/newlib/SConscript | 28 -- components/libc/compilers/newlib/libc.c | 50 --- components/libc/compilers/newlib/libc.h | 28 -- components/libc/compilers/newlib/libc_syms.c | 52 ---- components/libc/compilers/newlib/machine/time.h | 12 - components/libc/compilers/newlib/stdio.c | 80 ----- components/libc/compilers/newlib/syscalls.c | 344 --------------------- 29 files changed, 709 insertions(+), 714 deletions(-) delete mode 100644 components/libc/compilers/common/partial/SConscript delete mode 100644 components/libc/compilers/common/partial/ls/SConscript delete mode 100644 components/libc/compilers/common/partial/ls/readme.md delete mode 100644 components/libc/compilers/common/partial/ls/sys/select.h create mode 100644 components/libc/compilers/gcc/SConscript create mode 100644 components/libc/compilers/gcc/newlib/README.md create mode 100644 components/libc/compilers/gcc/newlib/SConscript create mode 100644 components/libc/compilers/gcc/newlib/libc.c create mode 100644 components/libc/compilers/gcc/newlib/libc.h create mode 100644 components/libc/compilers/gcc/newlib/libc_syms.c create mode 100644 components/libc/compilers/gcc/newlib/machine/time.h create mode 100644 components/libc/compilers/gcc/newlib/stdio.c create mode 100644 components/libc/compilers/gcc/newlib/syscalls.c create mode 100644 components/libc/compilers/gcc/partial/SConscript create mode 100644 components/libc/compilers/gcc/partial/mips/SConscript create mode 100644 components/libc/compilers/gcc/partial/mips/readme.md create mode 100644 components/libc/compilers/gcc/partial/mips/sys/select.h create mode 100644 components/libc/compilers/gcc/partial/readme.md delete mode 100644 components/libc/compilers/newlib/README.md delete mode 100644 components/libc/compilers/newlib/SConscript delete mode 100644 components/libc/compilers/newlib/libc.c delete mode 100644 components/libc/compilers/newlib/libc.h delete mode 100644 components/libc/compilers/newlib/libc_syms.c delete mode 100644 components/libc/compilers/newlib/machine/time.h delete mode 100644 components/libc/compilers/newlib/stdio.c delete mode 100644 components/libc/compilers/newlib/syscalls.c (limited to 'components/libc/compilers/newlib/SConscript') diff --git a/bsp/ls1bdev/Kconfig b/bsp/ls1bdev/Kconfig index c9196af29d..b02aee337a 100644 --- a/bsp/ls1bdev/Kconfig +++ b/bsp/ls1bdev/Kconfig @@ -18,10 +18,6 @@ config PKGS_DIR source "$RTT_DIR/Kconfig" source "$PKGS_DIR/Kconfig" -config SOC_LS - bool - default y - config SOC_LS1B bool select RT_USING_COMPONENTS_INIT diff --git a/bsp/ls1cdev/Kconfig b/bsp/ls1cdev/Kconfig index 59f7c43323..3fb6e3bbdf 100644 --- a/bsp/ls1cdev/Kconfig +++ b/bsp/ls1cdev/Kconfig @@ -19,10 +19,6 @@ source "$RTT_DIR/Kconfig" source "$RTT_DIR/libcpu/mips/common/Kconfig" source "$PKGS_DIR/Kconfig" -config SOC_LS - bool - default y - config SOC_LS1C300 bool select RT_USING_COMPONENTS_INIT diff --git a/bsp/ls2kdev/Kconfig b/bsp/ls2kdev/Kconfig index 57dd99e53a..fc2dfe1328 100644 --- a/bsp/ls2kdev/Kconfig +++ b/bsp/ls2kdev/Kconfig @@ -22,10 +22,6 @@ source "$RTT_DIR/Kconfig" source "$RTT_DIR/libcpu/mips/common/Kconfig" source "$PKGS_DIR/Kconfig" -config SOC_LS - bool - default y - config SOC_LS2K1000 bool select ARCH_MIPS64 diff --git a/components/libc/compilers/common/partial/SConscript b/components/libc/compilers/common/partial/SConscript deleted file mode 100644 index 4c815c49b8..0000000000 --- a/components/libc/compilers/common/partial/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -# RT-Thread building script for bridge - -import os -from building import * - -cwd = GetCurrentDir() -objs = [] -list = os.listdir(cwd) - -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) - -Return('objs') diff --git a/components/libc/compilers/common/partial/ls/SConscript b/components/libc/compilers/common/partial/ls/SConscript deleted file mode 100644 index 2665bee078..0000000000 --- a/components/libc/compilers/common/partial/ls/SConscript +++ /dev/null @@ -1,23 +0,0 @@ -from shutil import copy -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -CPPPATH = [cwd] -group = [] - -if rtconfig.PLATFORM == 'gcc' and GetDepend('SOC_LS'): - try: - # There is no 'sys/select.h' in these bsp's gcc toolchain; thus, we need to copy this file from 'nogcc/sys/select.h' - copy("../../nogcc/sys/select.h", "./sys/select.h") - except: - pass - - if GetDepend('RT_USING_LIBC'): - src += Glob('*.c') - - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH) - -Return('group') diff --git a/components/libc/compilers/common/partial/ls/readme.md b/components/libc/compilers/common/partial/ls/readme.md deleted file mode 100644 index fa68e1e84a..0000000000 --- a/components/libc/compilers/common/partial/ls/readme.md +++ /dev/null @@ -1,9 +0,0 @@ -This folder will be included when compiling the BSPs as follow: - -- ls1bdev -- ls1cdev -- ls2kdev - -These files will be generated by scons automatically , and **DO NOT** change them: - -- sys/select.h \ No newline at end of file diff --git a/components/libc/compilers/common/partial/ls/sys/select.h b/components/libc/compilers/common/partial/ls/sys/select.h deleted file mode 100644 index 575ad3a1b5..0000000000 --- a/components/libc/compilers/common/partial/ls/sys/select.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-07-21 Meco Man The first version - */ - -#ifndef __SYS_SELECT_H__ -#define __SYS_SELECT_H__ - -#include -#include -#include - -#ifndef FD_SETSIZE -#define FD_SETSIZE 32 -#endif - -#ifdef SAL_USING_POSIX -#ifdef FD_SETSIZE -#undef FD_SETSIZE -#endif -#define FD_SETSIZE DFS_FD_MAX -#endif /* SAL_USING_POSIX */ - -#define NBBY 8 /* number of bits in a byte */ - -typedef long fd_mask; - -#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -#ifndef howmany -#define howmany(x,y) (((x)+((y)-1))/(y)) -#endif - -#ifndef _SYS_TYPES_FD_SET /* MIPS */ -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} _types_fd_set; -#define fd_set _types_fd_set - -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) -#endif /* _SYS_TYPES_FD_SET */ - -int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); - -#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/gcc/SConscript b/components/libc/compilers/gcc/SConscript new file mode 100644 index 0000000000..4c815c49b8 --- /dev/null +++ b/components/libc/compilers/gcc/SConscript @@ -0,0 +1,15 @@ +# RT-Thread building script for bridge + +import os +from building import * + +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/components/libc/compilers/gcc/newlib/README.md b/components/libc/compilers/gcc/newlib/README.md new file mode 100644 index 0000000000..62172e6a55 --- /dev/null +++ b/components/libc/compilers/gcc/newlib/README.md @@ -0,0 +1,10 @@ +# NEWLIB (GCC) porting for RT-Thread + +Please define RT_USING_LIBC and compile RT-Thread with GCC compiler. + + + +## More Information + +https://sourceware.org/newlib/libc.html#Reentrancy + diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript new file mode 100644 index 0000000000..cef546e17c --- /dev/null +++ b/components/libc/compilers/gcc/newlib/SConscript @@ -0,0 +1,28 @@ +from building import * +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +group = [] +LIBS = [] +CPPDEFINES = [] +CPPPATH = [cwd] + +if rtconfig.PLATFORM == 'gcc': + if GetDepend('RT_USING_LIBC'): + CPPDEFINES += ['RT_USING_NEWLIB'] + # link with libc and libm: + # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in + # recent GCC tool chains. The linker would just link in the functions that have + # been referenced. So setting this won't result in bigger text size. + LIBS += ['c', 'm'] + + src += Glob('*.c') + if GetDepend('RT_USING_MODULE') == False: + SrcRemove(src, ['libc_syms.c']) + else: + src += ['syscalls.c'] + + group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + +Return('group') diff --git a/components/libc/compilers/gcc/newlib/libc.c b/components/libc/compilers/gcc/newlib/libc.c new file mode 100644 index 0000000000..9834a9a015 --- /dev/null +++ b/components/libc/compilers/gcc/newlib/libc.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ +#include +#include +#include +#include +#include + +#include "libc.h" + +#ifdef RT_USING_PTHREADS +#include +#endif + +int _EXFUN(putenv,(char *__string)); + +int libc_system_init(void) +{ +#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) + rt_device_t dev_console; + + dev_console = rt_console_get_device(); + if (dev_console) + { + #if defined(RT_USING_POSIX) + libc_stdio_set_console(dev_console->parent.name, O_RDWR); + #else + libc_stdio_set_console(dev_console->parent.name, O_WRONLY); + #endif + } + + /* set PATH and HOME */ + putenv("PATH=/bin"); + putenv("HOME=/home"); +#endif + +#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT + pthread_system_init(); +#endif + + return 0; +} +INIT_COMPONENT_EXPORT(libc_system_init); diff --git a/components/libc/compilers/gcc/newlib/libc.h b/components/libc/compilers/gcc/newlib/libc.h new file mode 100644 index 0000000000..c470698aa6 --- /dev/null +++ b/components/libc/compilers/gcc/newlib/libc.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ +#ifndef __RTT_LIBC_H__ +#define __RTT_LIBC_H__ + +#ifndef _EXFUN +#define _EXFUN(name, proto) name proto +#endif + +#ifdef __cplusplus +extern "C" { +#endif +int libc_system_init(void); +int libc_stdio_get_console(void); +int libc_stdio_set_console(const char* device_name, int mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/libc/compilers/gcc/newlib/libc_syms.c b/components/libc/compilers/gcc/newlib/libc_syms.c new file mode 100644 index 0000000000..aaf6980d6b --- /dev/null +++ b/components/libc/compilers/gcc/newlib/libc_syms.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ +#include +#include + +#include +#include +#include + +RTM_EXPORT(strcpy); +RTM_EXPORT(strncpy); +RTM_EXPORT(strlen); +RTM_EXPORT(strcat); +RTM_EXPORT(strstr); +RTM_EXPORT(strchr); +RTM_EXPORT(strcmp); +RTM_EXPORT(strtol); +RTM_EXPORT(strtoul); +RTM_EXPORT(strncmp); + +RTM_EXPORT(memcpy); +RTM_EXPORT(memcmp); +RTM_EXPORT(memmove); +RTM_EXPORT(memset); +RTM_EXPORT(memchr); + +RTM_EXPORT(putchar); +RTM_EXPORT(puts); +RTM_EXPORT(printf); +RTM_EXPORT(sprintf); +RTM_EXPORT(snprintf); + +RTM_EXPORT(fwrite); + +#include +RTM_EXPORT(longjmp); +RTM_EXPORT(setjmp); + +RTM_EXPORT(exit); +RTM_EXPORT(abort); + +RTM_EXPORT(rand); + +#include +RTM_EXPORT(__assert_func); diff --git a/components/libc/compilers/gcc/newlib/machine/time.h b/components/libc/compilers/gcc/newlib/machine/time.h new file mode 100644 index 0000000000..ff754d2473 --- /dev/null +++ b/components/libc/compilers/gcc/newlib/machine/time.h @@ -0,0 +1,12 @@ +#ifndef _MACHTIME_H_ +#define _MACHTIME_H_ + +#include +#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND + +#ifdef __SPU__ +#include +int nanosleep (const struct timespec *, struct timespec *); +#endif + +#endif /* _MACHTIME_H_ */ diff --git a/components/libc/compilers/gcc/newlib/stdio.c b/components/libc/compilers/gcc/newlib/stdio.c new file mode 100644 index 0000000000..baccafad87 --- /dev/null +++ b/components/libc/compilers/gcc/newlib/stdio.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ +#include +#include +#include +#include +#include "libc.h" + +#define STDIO_DEVICE_NAME_MAX 32 + +int _EXFUN(fileno, (FILE *)); + +static FILE* std_console = NULL; + +int libc_stdio_set_console(const char* device_name, int mode) +{ + FILE *fp; + char name[STDIO_DEVICE_NAME_MAX]; + char *file_mode; + + snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); + name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; + + if (mode == O_RDWR) file_mode = "r+"; + else if (mode == O_WRONLY) file_mode = "wb"; + else file_mode = "rb"; + + fp = fopen(name, file_mode); + if (fp) + { + setvbuf(fp, NULL, _IONBF, 0); + + if (std_console) + { + fclose(std_console); + std_console = NULL; + } + std_console = fp; + + if (mode == O_RDWR) + { + _GLOBAL_REENT->_stdin = std_console; + } + else + { + _GLOBAL_REENT->_stdin = NULL; + } + + if (mode == O_RDONLY) + { + _GLOBAL_REENT->_stdout = NULL; + _GLOBAL_REENT->_stderr = NULL; + } + else + { + _GLOBAL_REENT->_stdout = std_console; + _GLOBAL_REENT->_stderr = std_console; + } + + _GLOBAL_REENT->__sdidinit = 1; + } + + if (std_console) return fileno(std_console); + + return -1; +} + +int libc_stdio_get_console(void) { + if (std_console) + return fileno(std_console); + else + return -1; +} diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c new file mode 100644 index 0000000000..8b7ff9efdb --- /dev/null +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r() + * 2020-02-13 Meco Man re-implement exit() and abort() + * 2020-02-21 Meco Man improve and beautify syscalls + * 2020-02-24 Meco Man fix bug of _isatty_r() + */ + +#include +#include +#include +#include +#include + +#define DBG_TAG "newlib.syscalls" +#define DBG_LVL DBG_INFO +#include + +#ifdef RT_USING_HEAP /* Memory routine */ +void *_malloc_r (struct _reent *ptr, size_t size) +{ + void* result; + + result = (void*)rt_malloc (size); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) +{ + void* result; + + result = (void*)rt_realloc (old, newlen); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void *_calloc_r (struct _reent *ptr, size_t size, size_t len) +{ + void* result; + + result = (void*)rt_calloc (size, len); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void _free_r (struct _reent *ptr, void *addr) +{ + rt_free (addr); +} + +#else +void * +_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +{ + LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC"); + RT_ASSERT(0); + return RT_NULL; +} +#endif /*RT_USING_HEAP*/ + +void __libc_init_array(void) +{ + /* we not use __libc init_aray to initialize C++ objects */ + /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */ +} + +#ifdef RT_USING_LIBC +#include +#include +#include "libc.h" +#ifdef RT_USING_DFS +#include +#endif +#ifdef RT_USING_MODULE +#include +#endif + +/* Reentrant versions of system calls. */ + +#ifndef _REENT_ONLY +int *__errno () +{ + return _rt_errno(); +} +#endif + +int _getpid_r(struct _reent *ptr) +{ + return 0; +} + +int _close_r(struct _reent *ptr, int fd) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + return close(fd); +#endif +} + +int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +int _fork_r(struct _reent *ptr) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +int _isatty_r(struct _reent *ptr, int fd) +{ + if (fd >=0 && fd < 3) + { + return 1; + } + else + { + return 0; + } +} + +int _kill_r(struct _reent *ptr, int pid, int sig) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +int _link_r(struct _reent *ptr, const char *old, const char *new) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + _off_t rc; + + rc = lseek(fd, pos, whence); + return rc; +#endif +} + +int _mkdir_r(struct _reent *ptr, const char *name, int mode) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + int rc; + + rc = mkdir(name, mode); + return rc; +#endif +} + +int _open_r(struct _reent *ptr, const char *file, int flags, int mode) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + int rc; + + rc = open(file, flags, mode); + return rc; +#endif +} + +_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + _ssize_t rc; + if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) + { + LOG_W("Do not invoke standard input before initializing libc"); + return 0; + } + rc = read(fd, buf, nbytes); + return rc; +#endif +} + +int _rename_r(struct _reent *ptr, const char *old, const char *new) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + int rc; + + rc = rename(old, new); + return rc; +#endif +} + +int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + int rc; + + rc = stat(file, pstat); + return rc; +#endif +} + +int _unlink_r(struct _reent *ptr, const char *file) +{ +#ifndef RT_USING_DFS + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#else + return unlink(file); +#endif +} + +int _wait_r(struct _reent *ptr, int *status) +{ + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +} + +_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) +{ +#ifndef RT_USING_DFS +#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) + if (STDOUT_FILENO == fd) + { + rt_device_t console; + + console = rt_console_get_device(); + if (console) return rt_device_write(console, -1, buf, nbytes); + } + + return 0; +#else + /* return "not supported" */ + ptr->_errno = ENOTSUP; + return -1; +#endif /*RT_USING_DEVICE*/ +#else + _ssize_t rc; + if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) + { + LOG_W("Do not invoke standard output before initializing libc"); + return 0; + } + rc = write(fd, buf, nbytes); + return rc; +#endif +} + +void _system(const char *s) +{ + extern int __rt_libc_system(const char *string); + __rt_libc_system(s); +} + +/* for exit() and abort() */ +__attribute__ ((noreturn)) void _exit (int status) +{ + extern void __rt_libc_exit(int status); + __rt_libc_exit(status); + while(1); +} + +mode_t umask(mode_t mask) +{ + return 022; +} + +int flock(int fd, int operation) +{ + return 0; +} + +/* +These functions are implemented and replaced by the 'common/time.c' file +int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); +_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); +*/ + +#endif /* RT_USING_LIBC */ diff --git a/components/libc/compilers/gcc/partial/SConscript b/components/libc/compilers/gcc/partial/SConscript new file mode 100644 index 0000000000..4c815c49b8 --- /dev/null +++ b/components/libc/compilers/gcc/partial/SConscript @@ -0,0 +1,15 @@ +# RT-Thread building script for bridge + +import os +from building import * + +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/components/libc/compilers/gcc/partial/mips/SConscript b/components/libc/compilers/gcc/partial/mips/SConscript new file mode 100644 index 0000000000..7651233d46 --- /dev/null +++ b/components/libc/compilers/gcc/partial/mips/SConscript @@ -0,0 +1,20 @@ +from shutil import copy +from building import * + +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] + +if rtconfig.PLATFORM == 'gcc' and ('mips' in rtconfig.PREFIX): # identify mips gcc tool chain + try: + # There is no 'sys/select.h' in tthe mips gcc toolchain; it will be copied from 'nogcc/sys/select.h' + copy("../../../common/nogcc/sys/select.h", "./sys/select.h") + except: + pass + + group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH) + +Return('group') diff --git a/components/libc/compilers/gcc/partial/mips/readme.md b/components/libc/compilers/gcc/partial/mips/readme.md new file mode 100644 index 0000000000..a3eeb06c5d --- /dev/null +++ b/components/libc/compilers/gcc/partial/mips/readme.md @@ -0,0 +1,4 @@ +These files don't exist in the mips gcc toolchain. They will be generated by scons automatically , and **DO NOT** change them: + +- sys/select.h + diff --git a/components/libc/compilers/gcc/partial/mips/sys/select.h b/components/libc/compilers/gcc/partial/mips/sys/select.h new file mode 100644 index 0000000000..575ad3a1b5 --- /dev/null +++ b/components/libc/compilers/gcc/partial/mips/sys/select.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-07-21 Meco Man The first version + */ + +#ifndef __SYS_SELECT_H__ +#define __SYS_SELECT_H__ + +#include +#include +#include + +#ifndef FD_SETSIZE +#define FD_SETSIZE 32 +#endif + +#ifdef SAL_USING_POSIX +#ifdef FD_SETSIZE +#undef FD_SETSIZE +#endif +#define FD_SETSIZE DFS_FD_MAX +#endif /* SAL_USING_POSIX */ + +#define NBBY 8 /* number of bits in a byte */ + +typedef long fd_mask; + +#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ +#ifndef howmany +#define howmany(x,y) (((x)+((y)-1))/(y)) +#endif + +#ifndef _SYS_TYPES_FD_SET /* MIPS */ +typedef struct _types_fd_set { + fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +} _types_fd_set; +#define fd_set _types_fd_set + +#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#endif /* _SYS_TYPES_FD_SET */ + +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); + +#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/gcc/partial/readme.md b/components/libc/compilers/gcc/partial/readme.md new file mode 100644 index 0000000000..959fc29f35 --- /dev/null +++ b/components/libc/compilers/gcc/partial/readme.md @@ -0,0 +1,2 @@ +This folder is for some particular targets. + diff --git a/components/libc/compilers/newlib/README.md b/components/libc/compilers/newlib/README.md deleted file mode 100644 index 385f329a4f..0000000000 --- a/components/libc/compilers/newlib/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# NEWLIB (GCC) porting for RT-Thread - -Please define RT_USING_LIBC and compile RT-Thread with GCC compiler. - - - -## More Information - -https://sourceware.org/newlib/libc.html#Reentrancy \ No newline at end of file diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript deleted file mode 100644 index cef546e17c..0000000000 --- a/components/libc/compilers/newlib/SConscript +++ /dev/null @@ -1,28 +0,0 @@ -from building import * -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -group = [] -LIBS = [] -CPPDEFINES = [] -CPPPATH = [cwd] - -if rtconfig.PLATFORM == 'gcc': - if GetDepend('RT_USING_LIBC'): - CPPDEFINES += ['RT_USING_NEWLIB'] - # link with libc and libm: - # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in - # recent GCC tool chains. The linker would just link in the functions that have - # been referenced. So setting this won't result in bigger text size. - LIBS += ['c', 'm'] - - src += Glob('*.c') - if GetDepend('RT_USING_MODULE') == False: - SrcRemove(src, ['libc_syms.c']) - else: - src += ['syscalls.c'] - - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) - -Return('group') diff --git a/components/libc/compilers/newlib/libc.c b/components/libc/compilers/newlib/libc.c deleted file mode 100644 index 9834a9a015..0000000000 --- a/components/libc/compilers/newlib/libc.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include -#include -#include -#include - -#include "libc.h" - -#ifdef RT_USING_PTHREADS -#include -#endif - -int _EXFUN(putenv,(char *__string)); - -int libc_system_init(void) -{ -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE) - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - #if defined(RT_USING_POSIX) - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - #else - libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif - } - - /* set PATH and HOME */ - putenv("PATH=/bin"); - putenv("HOME=/home"); -#endif - -#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT - pthread_system_init(); -#endif - - return 0; -} -INIT_COMPONENT_EXPORT(libc_system_init); diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h deleted file mode 100644 index c470698aa6..0000000000 --- a/components/libc/compilers/newlib/libc.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#ifndef __RTT_LIBC_H__ -#define __RTT_LIBC_H__ - -#ifndef _EXFUN -#define _EXFUN(name, proto) name proto -#endif - -#ifdef __cplusplus -extern "C" { -#endif -int libc_system_init(void); -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/newlib/libc_syms.c b/components/libc/compilers/newlib/libc_syms.c deleted file mode 100644 index aaf6980d6b..0000000000 --- a/components/libc/compilers/newlib/libc_syms.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include - -#include -#include -#include - -RTM_EXPORT(strcpy); -RTM_EXPORT(strncpy); -RTM_EXPORT(strlen); -RTM_EXPORT(strcat); -RTM_EXPORT(strstr); -RTM_EXPORT(strchr); -RTM_EXPORT(strcmp); -RTM_EXPORT(strtol); -RTM_EXPORT(strtoul); -RTM_EXPORT(strncmp); - -RTM_EXPORT(memcpy); -RTM_EXPORT(memcmp); -RTM_EXPORT(memmove); -RTM_EXPORT(memset); -RTM_EXPORT(memchr); - -RTM_EXPORT(putchar); -RTM_EXPORT(puts); -RTM_EXPORT(printf); -RTM_EXPORT(sprintf); -RTM_EXPORT(snprintf); - -RTM_EXPORT(fwrite); - -#include -RTM_EXPORT(longjmp); -RTM_EXPORT(setjmp); - -RTM_EXPORT(exit); -RTM_EXPORT(abort); - -RTM_EXPORT(rand); - -#include -RTM_EXPORT(__assert_func); diff --git a/components/libc/compilers/newlib/machine/time.h b/components/libc/compilers/newlib/machine/time.h deleted file mode 100644 index ff754d2473..0000000000 --- a/components/libc/compilers/newlib/machine/time.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _MACHTIME_H_ -#define _MACHTIME_H_ - -#include -#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND - -#ifdef __SPU__ -#include -int nanosleep (const struct timespec *, struct timespec *); -#endif - -#endif /* _MACHTIME_H_ */ diff --git a/components/libc/compilers/newlib/stdio.c b/components/libc/compilers/newlib/stdio.c deleted file mode 100644 index baccafad87..0000000000 --- a/components/libc/compilers/newlib/stdio.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include -#include -#include -#include "libc.h" - -#define STDIO_DEVICE_NAME_MAX 32 - -int _EXFUN(fileno, (FILE *)); - -static FILE* std_console = NULL; - -int libc_stdio_set_console(const char* device_name, int mode) -{ - FILE *fp; - char name[STDIO_DEVICE_NAME_MAX]; - char *file_mode; - - snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); - name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; - - if (mode == O_RDWR) file_mode = "r+"; - else if (mode == O_WRONLY) file_mode = "wb"; - else file_mode = "rb"; - - fp = fopen(name, file_mode); - if (fp) - { - setvbuf(fp, NULL, _IONBF, 0); - - if (std_console) - { - fclose(std_console); - std_console = NULL; - } - std_console = fp; - - if (mode == O_RDWR) - { - _GLOBAL_REENT->_stdin = std_console; - } - else - { - _GLOBAL_REENT->_stdin = NULL; - } - - if (mode == O_RDONLY) - { - _GLOBAL_REENT->_stdout = NULL; - _GLOBAL_REENT->_stderr = NULL; - } - else - { - _GLOBAL_REENT->_stdout = std_console; - _GLOBAL_REENT->_stderr = std_console; - } - - _GLOBAL_REENT->__sdidinit = 1; - } - - if (std_console) return fileno(std_console); - - return -1; -} - -int libc_stdio_get_console(void) { - if (std_console) - return fileno(std_console); - else - return -1; -} diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c deleted file mode 100644 index 4c1dc82ad3..0000000000 --- a/components/libc/compilers/newlib/syscalls.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r() - * 2020-02-13 Meco Man re-implement exit() and abort() - * 2020-02-21 Meco Man improve and beautify syscalls - * 2020-02-24 Meco Man fix bug of _isatty_r() - */ - -#include -#include -#include -#include -#include - -#define DBG_TAG "newlib.syscalls" -#define DBG_LVL DBG_INFO -#include - -#ifdef RT_USING_HEAP /* Memory routine */ -void *_malloc_r (struct _reent *ptr, size_t size) -{ - void* result; - - result = (void*)rt_malloc (size); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) -{ - void* result; - - result = (void*)rt_realloc (old, newlen); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_calloc_r (struct _reent *ptr, size_t size, size_t len) -{ - void* result; - - result = (void*)rt_calloc (size, len); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void _free_r (struct _reent *ptr, void *addr) -{ - rt_free (addr); -} - -#else -void * -_sbrk_r(struct _reent *ptr, ptrdiff_t incr) -{ - LOG_E("Please enable RT_USING_HEAP or RT_USING_LIBC"); - RT_ASSERT(0); - return RT_NULL; -} -#endif /*RT_USING_HEAP*/ - -void __libc_init_array(void) -{ - /* we not use __libc init_aray to initialize C++ objects */ - /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */ -} - -#ifdef RT_USING_LIBC -#include -#include -#ifdef RT_USING_DFS -#include -#endif -#ifdef RT_USING_MODULE -#include -#endif - -#define DBG_TAG "newlib.syscalls" -#define DBG_LVL DBG_INFO -#include - -/* Reentrant versions of system calls. */ - -#ifndef _REENT_ONLY -int *__errno () -{ - return _rt_errno(); -} -#endif - -int _getpid_r(struct _reent *ptr) -{ - return 0; -} - -int _close_r(struct _reent *ptr, int fd) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - return close(fd); -#endif -} - -int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -int _fork_r(struct _reent *ptr) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -int _isatty_r(struct _reent *ptr, int fd) -{ - if (fd >=0 && fd < 3) - { - return 1; - } - else - { - return 0; - } -} - -int _kill_r(struct _reent *ptr, int pid, int sig) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -int _link_r(struct _reent *ptr, const char *old, const char *new) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - _off_t rc; - - rc = lseek(fd, pos, whence); - return rc; -#endif -} - -int _mkdir_r(struct _reent *ptr, const char *name, int mode) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - int rc; - - rc = mkdir(name, mode); - return rc; -#endif -} - -int _open_r(struct _reent *ptr, const char *file, int flags, int mode) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - int rc; - - rc = open(file, flags, mode); - return rc; -#endif -} - -_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - _ssize_t rc; - if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) - { - LOG_W("Do not invoke standard input before initializing libc"); - return 0; - } - rc = read(fd, buf, nbytes); - return rc; -#endif -} - -int _rename_r(struct _reent *ptr, const char *old, const char *new) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - int rc; - - rc = rename(old, new); - return rc; -#endif -} - -int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - int rc; - - rc = stat(file, pstat); - return rc; -#endif -} - -int _unlink_r(struct _reent *ptr, const char *file) -{ -#ifndef RT_USING_DFS - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#else - return unlink(file); -#endif -} - -int _wait_r(struct _reent *ptr, int *status) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) -{ -#ifndef RT_USING_DFS -#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) - if (STDOUT_FILENO == fd) - { - rt_device_t console; - - console = rt_console_get_device(); - if (console) return rt_device_write(console, -1, buf, nbytes); - } - - return 0; -#else - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -#endif /*RT_USING_DEVICE*/ -#else - _ssize_t rc; - if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) - { - LOG_W("Do not invoke standard output before initializing libc"); - return 0; - } - rc = write(fd, buf, nbytes); - return rc; -#endif -} - -void _system(const char *s) -{ - extern int __rt_libc_system(const char *string); - __rt_libc_system(s); -} - -/* for exit() and abort() */ -__attribute__ ((noreturn)) void _exit (int status) -{ - extern void __rt_libc_exit(int status); - __rt_libc_exit(status); - while(1); -} - -mode_t umask(mode_t mask) -{ - return 022; -} - -int flock(int fd, int operation) -{ - return 0; -} - -/* -These functions are implemented and replaced by the 'common/time.c' file -int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); -_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); -*/ - -#endif /* RT_USING_LIBC */ -- cgit v1.3.1 From 76cab376adf0cf52a17d11e633be711ba6149c4a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 14 Jan 2022 23:31:59 -0500 Subject: [libc] 调整文件结构 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../libc/compilers/common/extension/SConscript | 14 + components/libc/compilers/common/extension/fcntl.h | 71 +++ .../libc/compilers/common/extension/readme.md | 4 + .../libc/compilers/common/extension/sys/errno.h | 585 +++++++++++++++++++++ .../libc/compilers/common/extension/sys/select.h | 58 ++ .../libc/compilers/common/extension/sys/stat.h | 83 +++ .../libc/compilers/common/extension/sys/types.h | 40 ++ .../libc/compilers/common/extension/sys/unistd.h | 46 ++ .../libc/compilers/common/extension/unistd.h | 10 + components/libc/compilers/common/nogcc/SConscript | 14 - components/libc/compilers/common/nogcc/fcntl.h | 71 --- components/libc/compilers/common/nogcc/readme.md | 3 - components/libc/compilers/common/nogcc/sys/errno.h | 585 --------------------- .../libc/compilers/common/nogcc/sys/select.h | 58 -- components/libc/compilers/common/nogcc/sys/stat.h | 83 --- components/libc/compilers/common/nogcc/sys/types.h | 40 -- .../libc/compilers/common/nogcc/sys/unistd.h | 46 -- components/libc/compilers/common/nogcc/unistd.h | 10 - components/libc/compilers/gcc/SConscript | 15 - components/libc/compilers/gcc/newlib/README.md | 4 - components/libc/compilers/gcc/newlib/SConscript | 31 -- components/libc/compilers/gcc/newlib/fcntl.h | 24 - .../libc/compilers/gcc/newlib/legacy/SConscript | 15 - .../compilers/gcc/newlib/legacy/_select/SConscript | 20 - .../compilers/gcc/newlib/legacy/_select/readme.md | 2 - .../gcc/newlib/legacy/_select/sys/select.h | 58 -- components/libc/compilers/gcc/newlib/libc_syms.c | 53 -- .../libc/compilers/gcc/newlib/machine/time.h | 17 - components/libc/compilers/gcc/newlib/syscalls.c | 339 ------------ components/libc/compilers/newlib/README.md | 4 + components/libc/compilers/newlib/SConscript | 31 ++ components/libc/compilers/newlib/fcntl.h | 24 + components/libc/compilers/newlib/legacy/SConscript | 15 + .../compilers/newlib/legacy/_select/SConscript | 20 + .../libc/compilers/newlib/legacy/_select/readme.md | 2 + .../compilers/newlib/legacy/_select/sys/select.h | 58 ++ components/libc/compilers/newlib/libc_syms.c | 53 ++ components/libc/compilers/newlib/machine/time.h | 17 + components/libc/compilers/newlib/syscalls.c | 339 ++++++++++++ 39 files changed, 1474 insertions(+), 1488 deletions(-) create mode 100644 components/libc/compilers/common/extension/SConscript create mode 100644 components/libc/compilers/common/extension/fcntl.h create mode 100644 components/libc/compilers/common/extension/readme.md create mode 100644 components/libc/compilers/common/extension/sys/errno.h create mode 100644 components/libc/compilers/common/extension/sys/select.h create mode 100644 components/libc/compilers/common/extension/sys/stat.h create mode 100644 components/libc/compilers/common/extension/sys/types.h create mode 100644 components/libc/compilers/common/extension/sys/unistd.h create mode 100644 components/libc/compilers/common/extension/unistd.h delete mode 100644 components/libc/compilers/common/nogcc/SConscript delete mode 100644 components/libc/compilers/common/nogcc/fcntl.h delete mode 100644 components/libc/compilers/common/nogcc/readme.md delete mode 100644 components/libc/compilers/common/nogcc/sys/errno.h delete mode 100644 components/libc/compilers/common/nogcc/sys/select.h delete mode 100644 components/libc/compilers/common/nogcc/sys/stat.h delete mode 100644 components/libc/compilers/common/nogcc/sys/types.h delete mode 100644 components/libc/compilers/common/nogcc/sys/unistd.h delete mode 100644 components/libc/compilers/common/nogcc/unistd.h delete mode 100644 components/libc/compilers/gcc/SConscript delete mode 100644 components/libc/compilers/gcc/newlib/README.md delete mode 100644 components/libc/compilers/gcc/newlib/SConscript delete mode 100644 components/libc/compilers/gcc/newlib/fcntl.h delete mode 100644 components/libc/compilers/gcc/newlib/legacy/SConscript delete mode 100644 components/libc/compilers/gcc/newlib/legacy/_select/SConscript delete mode 100644 components/libc/compilers/gcc/newlib/legacy/_select/readme.md delete mode 100644 components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h delete mode 100644 components/libc/compilers/gcc/newlib/libc_syms.c delete mode 100644 components/libc/compilers/gcc/newlib/machine/time.h delete mode 100644 components/libc/compilers/gcc/newlib/syscalls.c create mode 100644 components/libc/compilers/newlib/README.md create mode 100644 components/libc/compilers/newlib/SConscript create mode 100644 components/libc/compilers/newlib/fcntl.h create mode 100644 components/libc/compilers/newlib/legacy/SConscript create mode 100644 components/libc/compilers/newlib/legacy/_select/SConscript create mode 100644 components/libc/compilers/newlib/legacy/_select/readme.md create mode 100644 components/libc/compilers/newlib/legacy/_select/sys/select.h create mode 100644 components/libc/compilers/newlib/libc_syms.c create mode 100644 components/libc/compilers/newlib/machine/time.h create mode 100644 components/libc/compilers/newlib/syscalls.c (limited to 'components/libc/compilers/newlib/SConscript') diff --git a/components/libc/compilers/common/extension/SConscript b/components/libc/compilers/common/extension/SConscript new file mode 100644 index 0000000000..dbc26ac177 --- /dev/null +++ b/components/libc/compilers/common/extension/SConscript @@ -0,0 +1,14 @@ +from building import * + +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] + +src += Glob('*.c') + +if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) +Return('group') diff --git a/components/libc/compilers/common/extension/fcntl.h b/components/libc/compilers/common/extension/fcntl.h new file mode 100644 index 0000000000..83c3ec0b6b --- /dev/null +++ b/components/libc/compilers/common/extension/fcntl.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-09-02 Meco Man First version + */ + +#ifndef __FCNTL_H__ +#define __FCNTL_H__ + +#include + +#define O_RDONLY 00 +#define O_WRONLY 01 +#define O_RDWR 02 + +#define O_CREAT 0100 +#define O_EXCL 0200 +#define O_NOCTTY 0400 +#define O_TRUNC 01000 +#define O_APPEND 02000 +#define O_NONBLOCK 04000 +#define O_DSYNC 010000 +#define O_SYNC 04010000 +#define O_RSYNC 04010000 +#define O_BINARY 0100000 +#define O_DIRECTORY 0200000 +#define O_NOFOLLOW 0400000 +#define O_CLOEXEC 02000000 + +#define O_ASYNC 020000 +#define O_DIRECT 040000 +#define O_LARGEFILE 0100000 +#define O_NOATIME 01000000 +#define O_PATH 010000000 +#define O_TMPFILE 020200000 +#define O_NDELAY O_NONBLOCK + +#define O_SEARCH O_PATH +#define O_EXEC O_PATH + +#define O_ACCMODE (03|O_SEARCH) + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 + +#define F_SETOWN 8 +#define F_GETOWN 9 +#define F_SETSIG 10 +#define F_GETSIG 11 + +#define F_GETLK 12 +#define F_SETLK 13 +#define F_SETLKW 14 + +#define F_SETOWN_EX 15 +#define F_GETOWN_EX 16 + +#define F_GETOWNER_UIDS 17 + +int open(const char *file, int flags, ...); +int fcntl(int fildes, int cmd, ...); +int creat(const char *, mode_t); + +#endif diff --git a/components/libc/compilers/common/extension/readme.md b/components/libc/compilers/common/extension/readme.md new file mode 100644 index 0000000000..ca0df69246 --- /dev/null +++ b/components/libc/compilers/common/extension/readme.md @@ -0,0 +1,4 @@ +## Attentions + +This folder is "common" for toolchains, which only support ISO C, as an extension part, such as Keil-MDK and IAR. + diff --git a/components/libc/compilers/common/extension/sys/errno.h b/components/libc/compilers/common/extension/sys/errno.h new file mode 100644 index 0000000000..d53ce4b386 --- /dev/null +++ b/components/libc/compilers/common/extension/sys/errno.h @@ -0,0 +1,585 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-05-22 Meco Man The first version. + */ + +#ifndef __SYS_ERRNO_H__ +#define __SYS_ERRNO_H__ + +#if defined(__ARMCC_VERSION) +/* +defined in armcc/errno.h + +#define EDOM 1 +#define ERANGE 2 +#define EILSEQ 4 +#define ESIGNUM 3 +#define EINVAL 5 +#define ENOMEM 6 +*/ + +#define ERROR_BASE_NO 7 + +#elif defined(__IAR_SYSTEMS_ICC__) +/* defined in iar/errno.h +#define EDOM 33 +#define ERANGE 34 +#define EFPOS 35 +#define EILSEQ 36 +*/ +#define ERROR_BASE_NO 36 + +#else +#define ERROR_BASE_NO 0 +#endif + +#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) +#include + +#ifndef EPERM +#define EPERM (ERROR_BASE_NO + 1) +#endif + +#ifndef ENOENT +#define ENOENT (ERROR_BASE_NO + 2) +#endif + +#ifndef ESRCH +#define ESRCH (ERROR_BASE_NO + 3) +#endif + +#ifndef EINTR +#define EINTR (ERROR_BASE_NO + 4) +#endif + +#ifndef EIO +#define EIO (ERROR_BASE_NO + 5) +#endif + +#ifndef ENXIO +#define ENXIO (ERROR_BASE_NO + 6) +#endif + +#ifndef E2BIG +#define E2BIG (ERROR_BASE_NO + 7) +#endif + +#ifndef ENOEXEC +#define ENOEXEC (ERROR_BASE_NO + 8) +#endif + +#ifndef EBADF +#define EBADF (ERROR_BASE_NO + 9) +#endif + +#ifndef ECHILD +#define ECHILD (ERROR_BASE_NO + 10) +#endif + +#ifndef EAGAIN +#define EAGAIN (ERROR_BASE_NO + 11) +#endif + +#ifndef ENOMEM +#define ENOMEM (ERROR_BASE_NO + 12) +#endif + +#ifndef EACCES +#define EACCES (ERROR_BASE_NO + 13) +#endif + +#ifndef EFAULT +#define EFAULT (ERROR_BASE_NO + 14) +#endif + +#ifndef ENOTBLK +#define ENOTBLK (ERROR_BASE_NO + 15) +#endif + +#ifndef EBUSY +#define EBUSY (ERROR_BASE_NO + 16) +#endif + +#ifndef EEXIST +#define EEXIST (ERROR_BASE_NO + 17) +#endif + +#ifndef EXDEV +#define EXDEV (ERROR_BASE_NO + 18) +#endif + +#ifndef ENODEV +#define ENODEV (ERROR_BASE_NO + 19) +#endif + +#ifndef ENOTDIR +#define ENOTDIR (ERROR_BASE_NO + 20) +#endif + +#ifndef EISDIR +#define EISDIR (ERROR_BASE_NO + 21) +#endif + +#ifndef EINVAL +#define EINVAL (ERROR_BASE_NO + 22) +#endif + +#ifndef ENFILE +#define ENFILE (ERROR_BASE_NO + 23) +#endif + +#ifndef EMFILE +#define EMFILE (ERROR_BASE_NO + 24) +#endif + +#ifndef ENOTTY +#define ENOTTY (ERROR_BASE_NO + 25) +#endif + +#ifndef ETXTBSY +#define ETXTBSY (ERROR_BASE_NO + 26) +#endif + +#ifndef EFBIG +#define EFBIG (ERROR_BASE_NO + 27) +#endif + +#ifndef ENOSPC +#define ENOSPC (ERROR_BASE_NO + 28) +#endif + +#ifndef ESPIPE +#define ESPIPE (ERROR_BASE_NO + 29) +#endif + +#ifndef EROFS +#define EROFS (ERROR_BASE_NO + 30) +#endif + +#ifndef EMLINK +#define EMLINK (ERROR_BASE_NO + 31) +#endif + +#ifndef EPIPE +#define EPIPE (ERROR_BASE_NO + 32) +#endif + +#ifndef EDOM +#define EDOM (ERROR_BASE_NO + 33) +#endif + +#ifndef ERANGE +#define ERANGE (ERROR_BASE_NO + 34) +#endif + +#ifndef EDEADLK +#define EDEADLK (ERROR_BASE_NO + 35) +#endif + +#ifndef ENAMETOOLONG +#define ENAMETOOLONG (ERROR_BASE_NO + 36) +#endif + +#ifndef ENOLCK +#define ENOLCK (ERROR_BASE_NO + 37) +#endif + +#ifndef ENOSYS +#define ENOSYS (ERROR_BASE_NO + 38) +#endif + +#ifndef ENOTEMPTY +#define ENOTEMPTY (ERROR_BASE_NO + 39) +#endif + +#ifndef ELOOP +#define ELOOP (ERROR_BASE_NO + 40) +#endif + +#ifndef EWOULDBLOCK +#define EWOULDBLOCK EAGAIN +#endif + +#ifndef ENOMSG +#define ENOMSG (ERROR_BASE_NO + 42) +#endif + +#ifndef EIDRM +#define EIDRM (ERROR_BASE_NO + 43) +#endif + +#ifndef ECHRNG +#define ECHRNG (ERROR_BASE_NO + 44) +#endif + +#ifndef EL2NSYNC +#define EL2NSYNC (ERROR_BASE_NO + 45) +#endif + +#ifndef EL3HLT +#define EL3HLT (ERROR_BASE_NO + 46) +#endif + +#ifndef EL3RST +#define EL3RST (ERROR_BASE_NO + 47) +#endif + +#ifndef ELNRNG +#define ELNRNG (ERROR_BASE_NO + 48) +#endif + +#ifndef EUNATCH +#define EUNATCH (ERROR_BASE_NO + 49) +#endif + +#ifndef ENOCSI +#define ENOCSI (ERROR_BASE_NO + 50) +#endif + +#ifndef EL2HLT +#define EL2HLT (ERROR_BASE_NO + 51) +#endif + +#ifndef EBADE +#define EBADE (ERROR_BASE_NO + 52) +#endif + +#ifndef EBADR +#define EBADR (ERROR_BASE_NO + 53) +#endif + +#ifndef EXFULL +#define EXFULL (ERROR_BASE_NO + 54) +#endif + +#ifndef ENOANO +#define ENOANO (ERROR_BASE_NO + 55) +#endif + +#ifndef EBADRQC +#define EBADRQC (ERROR_BASE_NO + 56) +#endif + +#ifndef EBADSLT +#define EBADSLT (ERROR_BASE_NO + 57) +#endif + +#ifndef EDEADLOCK +#define EDEADLOCK EDEADLK +#endif + +#ifndef EBFONT +#define EBFONT (ERROR_BASE_NO + 59) +#endif + +#ifndef ENOSTR +#define ENOSTR (ERROR_BASE_NO + 60) +#endif + +#ifndef ENODATA +#define ENODATA (ERROR_BASE_NO + 61) +#endif + +#ifndef ETIME +#define ETIME (ERROR_BASE_NO + 62) +#endif + +#ifndef ENOSR +#define ENOSR (ERROR_BASE_NO + 63) +#endif + +#ifndef ENONET +#define ENONET (ERROR_BASE_NO + 64) +#endif + +#ifndef ENOPKG +#define ENOPKG (ERROR_BASE_NO + 65) +#endif + +#ifndef EREMOTE +#define EREMOTE (ERROR_BASE_NO + 66) +#endif + +#ifndef ENOLINK +#define ENOLINK (ERROR_BASE_NO + 67) +#endif + +#ifndef EADV +#define EADV (ERROR_BASE_NO + 68) +#endif + +#ifndef ESRMNT +#define ESRMNT (ERROR_BASE_NO + 69) +#endif + +#ifndef ECOMM +#define ECOMM (ERROR_BASE_NO + 70) +#endif + +#ifndef EPROTO +#define EPROTO (ERROR_BASE_NO + 71) +#endif + +#ifndef EMULTIHOP +#define EMULTIHOP (ERROR_BASE_NO + 72) +#endif + +#ifndef EDOTDOT +#define EDOTDOT (ERROR_BASE_NO + 73) +#endif + +#ifndef EBADMSG +#define EBADMSG (ERROR_BASE_NO + 74) +#endif + +#ifndef EOVERFLOW +#define EOVERFLOW (ERROR_BASE_NO + 75) +#endif + +#ifndef ENOTUNIQ +#define ENOTUNIQ (ERROR_BASE_NO + 76) +#endif + +#ifndef EBADFD +#define EBADFD (ERROR_BASE_NO + 77) +#endif + +#ifndef EREMCHG +#define EREMCHG (ERROR_BASE_NO + 78) +#endif + +#ifndef ELIBACC +#define ELIBACC (ERROR_BASE_NO + 79) +#endif + +#ifndef ELIBBAD +#define ELIBBAD (ERROR_BASE_NO + 80) +#endif + +#ifndef ELIBSCN +#define ELIBSCN (ERROR_BASE_NO + 81) +#endif + +#ifndef ELIBMAX +#define ELIBMAX (ERROR_BASE_NO + 82) +#endif + +#ifndef ELIBEXEC +#define ELIBEXEC (ERROR_BASE_NO + 83) +#endif + +#ifndef EILSEQ +#define EILSEQ (ERROR_BASE_NO + 84) +#endif + +#ifndef ERESTART +#define ERESTART (ERROR_BASE_NO + 85) +#endif + +#ifndef ESTRPIPE +#define ESTRPIPE (ERROR_BASE_NO + 86) +#endif + +#ifndef EUSERS +#define EUSERS (ERROR_BASE_NO + 87) +#endif + +#ifndef ENOTSOCK +#define ENOTSOCK (ERROR_BASE_NO + 88) +#endif + +#ifndef EDESTADDRREQ +#define EDESTADDRREQ (ERROR_BASE_NO + 89) +#endif + +#ifndef EMSGSIZE +#define EMSGSIZE (ERROR_BASE_NO + 90) +#endif + +#ifndef EPROTOTYPE +#define EPROTOTYPE (ERROR_BASE_NO + 91) +#endif + +#ifndef ENOPROTOOPT +#define ENOPROTOOPT (ERROR_BASE_NO + 92) +#endif + +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT (ERROR_BASE_NO + 93) +#endif + +#ifndef ESOCKTNOSUPPORT +#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) +#endif + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP (ERROR_BASE_NO + 95) +#endif + +#ifndef ENOTSUP +#define ENOTSUP EOPNOTSUPP +#endif + +#ifndef EPFNOSUPPORT +#define EPFNOSUPPORT (ERROR_BASE_NO + 96) +#endif + +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT (ERROR_BASE_NO + 97) +#endif + +#ifndef EADDRINUSE +#define EADDRINUSE (ERROR_BASE_NO + 98) +#endif + +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL (ERROR_BASE_NO + 99) +#endif + +#ifndef ENETDOWN +#define ENETDOWN (ERROR_BASE_NO + 100) +#endif + +#ifndef ENETUNREACH +#define ENETUNREACH (ERROR_BASE_NO + 101) +#endif + +#ifndef ENETRESET +#define ENETRESET (ERROR_BASE_NO + 102) +#endif + +#ifndef ECONNABORTED +#define ECONNABORTED (ERROR_BASE_NO + 103) +#endif + +#ifndef ECONNRESET +#define ECONNRESET (ERROR_BASE_NO + 104) +#endif + +#ifndef ENOBUFS +#define ENOBUFS (ERROR_BASE_NO + 105) +#endif + +#ifndef EISCONN +#define EISCONN (ERROR_BASE_NO + 106) +#endif + +#ifndef ENOTCONN +#define ENOTCONN (ERROR_BASE_NO + 107) +#endif + +#ifndef ESHUTDOWN +#define ESHUTDOWN (ERROR_BASE_NO + 108) +#endif + +#ifndef ETOOMANYREFS +#define ETOOMANYREFS (ERROR_BASE_NO + 109) +#endif + +#ifndef ETIMEDOUT +#define ETIMEDOUT (ERROR_BASE_NO + 110) +#endif + +#ifndef ECONNREFUSED +#define ECONNREFUSED (ERROR_BASE_NO + 111) +#endif + +#ifndef EHOSTDOWN +#define EHOSTDOWN (ERROR_BASE_NO + 112) +#endif + +#ifndef EHOSTUNREACH +#define EHOSTUNREACH (ERROR_BASE_NO + 113) +#endif + +#ifndef EALREADY +#define EALREADY (ERROR_BASE_NO + 114) +#endif + +#ifndef EINPROGRESS +#define EINPROGRESS (ERROR_BASE_NO + 115) +#endif + +#ifndef ESTALE +#define ESTALE (ERROR_BASE_NO + 116) +#endif + +#ifndef EUCLEAN +#define EUCLEAN (ERROR_BASE_NO + 117) +#endif + +#ifndef ENOTNAM +#define ENOTNAM (ERROR_BASE_NO + 118) +#endif + +#ifndef ENAVAIL +#define ENAVAIL (ERROR_BASE_NO + 119) +#endif + +#ifndef EISNAM +#define EISNAM (ERROR_BASE_NO + 120) +#endif + +#ifndef EREMOTEIO +#define EREMOTEIO (ERROR_BASE_NO + 121) +#endif + +#ifndef EDQUOT +#define EDQUOT (ERROR_BASE_NO + 122) +#endif + +#ifndef ENOMEDIUM +#define ENOMEDIUM (ERROR_BASE_NO + 123) +#endif + +#ifndef EMEDIUMTYPE +#define EMEDIUMTYPE (ERROR_BASE_NO + 124) +#endif + +#ifndef ECANCELED +#define ECANCELED (ERROR_BASE_NO + 125) +#endif + +#ifndef ENOKEY +#define ENOKEY (ERROR_BASE_NO + 126) +#endif + +#ifndef EKEYEXPIRED +#define EKEYEXPIRED (ERROR_BASE_NO + 127) +#endif + +#ifndef EKEYREVOKED +#define EKEYREVOKED (ERROR_BASE_NO + 128) +#endif + +#ifndef EKEYREJECTED +#define EKEYREJECTED (ERROR_BASE_NO + 129) +#endif + +#ifndef EOWNERDEAD +#define EOWNERDEAD (ERROR_BASE_NO + 130) +#endif + +#ifndef ENOTRECOVERABLE +#define ENOTRECOVERABLE (ERROR_BASE_NO + 131) +#endif + +#ifndef ERFKILL +#define ERFKILL (ERROR_BASE_NO + 132) +#endif + +#ifndef EHWPOISON +#define EHWPOISON (ERROR_BASE_NO + 133) +#endif + +#elif defined(_WIN32) +#include + +#endif /* defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) */ + +#endif /* __SYS_ERRNO_H__ */ diff --git a/components/libc/compilers/common/extension/sys/select.h b/components/libc/compilers/common/extension/sys/select.h new file mode 100644 index 0000000000..44f9b4ed91 --- /dev/null +++ b/components/libc/compilers/common/extension/sys/select.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-07-21 Meco Man The first version + * 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version + */ + +#ifndef __SYS_SELECT_H__ +#define __SYS_SELECT_H__ + +#include +#include +#include + +#ifdef _WIN32 +#include +#endif + +#ifndef FD_SETSIZE +#define FD_SETSIZE 32 +#endif + +#ifdef SAL_USING_POSIX +#ifdef FD_SETSIZE +#undef FD_SETSIZE +#endif +#define FD_SETSIZE DFS_FD_MAX +#endif /* SAL_USING_POSIX */ + +typedef long fd_mask; + +#ifndef _WIN32 +#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */ +#define NBBY 8 /* number of bits in a byte */ +#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ +#ifndef howmany +#define howmany(x,y) (((x)+((y)-1))/(y)) +#endif /* howmany */ + +typedef struct _types_fd_set { + fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +} _types_fd_set; +#define fd_set _types_fd_set + +#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#endif /* _SYS_TYPES_FD_SET */ + +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); +#endif /* _WIN32 */ + +#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/common/extension/sys/stat.h b/components/libc/compilers/common/extension/sys/stat.h new file mode 100644 index 0000000000..107c15decf --- /dev/null +++ b/components/libc/compilers/common/extension/sys/stat.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-09-02 Meco Man First version + */ + +#ifndef __SYS_STAT_H__ +#define __SYS_STAT_H__ + +#include +#include + +#define S_IFMT 00170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 + +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 + +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 + +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 + +struct stat +{ + struct rt_device *st_dev; + uint16_t st_ino; + uint16_t st_mode; + uint16_t st_nlink; + uint16_t st_uid; + uint16_t st_gid; + struct rt_device *st_rdev; + uint32_t st_size; + time_t st_atime; + long st_spare1; + time_t st_mtime; + long st_spare2; + time_t st_ctime; + long st_spare3; + uint32_t st_blksize; + uint32_t st_blocks; + long st_spare4[2]; +}; + +int chmod(const char *, mode_t); +int fchmod(int, mode_t); +int fstat(int, struct stat *); +int lstat(const char *, struct stat *); +int mkdir(const char *, mode_t); +int mkfifo(const char *, mode_t); +int mknod(const char *, mode_t, dev_t); +int stat(const char *, struct stat *); +mode_t umask(mode_t); + +#endif diff --git a/components/libc/compilers/common/extension/sys/types.h b/components/libc/compilers/common/extension/sys/types.h new file mode 100644 index 0000000000..32b2493c95 --- /dev/null +++ b/components/libc/compilers/common/extension/sys/types.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-05 Meco Man fix bugs + * 2020-12-16 Meco Man add useconds_t + */ + +#ifndef __SYS_TYPES_H__ +#define __SYS_TYPES_H__ + +#include +#include +#include + +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int pid_t; /* Used for process IDs and process group IDs. */ +typedef unsigned short uid_t; +typedef unsigned short gid_t; +typedef signed long off_t; +typedef int mode_t; +#ifndef ARCH_CPU_64BIT +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#else +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#endif +typedef long suseconds_t; /* microseconds. */ +typedef unsigned long useconds_t; /* microseconds (unsigned) */ + +typedef unsigned long dev_t; + +typedef unsigned int u_int; +typedef unsigned char u_char; +typedef unsigned long u_long; + +#endif diff --git a/components/libc/compilers/common/extension/sys/unistd.h b/components/libc/compilers/common/extension/sys/unistd.h new file mode 100644 index 0000000000..650c87dc18 --- /dev/null +++ b/components/libc/compilers/common/extension/sys/unistd.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-12-16 Meco Man add usleep + * 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h + */ + +#ifndef __SYS_UNISTD_H__ +#define __SYS_UNISTD_H__ + +#include +#include "types.h" /* */ + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +ssize_t read(int fd, void *buf, size_t len); +ssize_t write(int fd, const void *buf, size_t len); +off_t lseek(int fd, off_t offset, int whence); +int fsync(int fildes); +int unlink(const char *pathname); +int close(int d); +int ftruncate(int fd, off_t length); +int rmdir(const char *path); +int chdir(const char *path); +char *getcwd(char *buf, size_t size); +int access(const char *path, int amode); +int pipe(int fildes[2]); +int isatty(int fd); +char *ttyname(int desc); +unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); +pid_t gettid(void); +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +uid_t geteuid(void); +gid_t getgid(void); +gid_t getegid(void); + +#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/extension/unistd.h b/components/libc/compilers/common/extension/unistd.h new file mode 100644 index 0000000000..4dd71c842e --- /dev/null +++ b/components/libc/compilers/common/extension/unistd.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + +#include "sys/unistd.h" diff --git a/components/libc/compilers/common/nogcc/SConscript b/components/libc/compilers/common/nogcc/SConscript deleted file mode 100644 index dbc26ac177..0000000000 --- a/components/libc/compilers/common/nogcc/SConscript +++ /dev/null @@ -1,14 +0,0 @@ -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -CPPPATH = [cwd] -group = [] - -src += Glob('*.c') - -if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': - group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) -Return('group') diff --git a/components/libc/compilers/common/nogcc/fcntl.h b/components/libc/compilers/common/nogcc/fcntl.h deleted file mode 100644 index 83c3ec0b6b..0000000000 --- a/components/libc/compilers/common/nogcc/fcntl.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-09-02 Meco Man First version - */ - -#ifndef __FCNTL_H__ -#define __FCNTL_H__ - -#include - -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_DSYNC 010000 -#define O_SYNC 04010000 -#define O_RSYNC 04010000 -#define O_BINARY 0100000 -#define O_DIRECTORY 0200000 -#define O_NOFOLLOW 0400000 -#define O_CLOEXEC 02000000 - -#define O_ASYNC 020000 -#define O_DIRECT 040000 -#define O_LARGEFILE 0100000 -#define O_NOATIME 01000000 -#define O_PATH 010000000 -#define O_TMPFILE 020200000 -#define O_NDELAY O_NONBLOCK - -#define O_SEARCH O_PATH -#define O_EXEC O_PATH - -#define O_ACCMODE (03|O_SEARCH) - -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 - -#define F_SETOWN 8 -#define F_GETOWN 9 -#define F_SETSIG 10 -#define F_GETSIG 11 - -#define F_GETLK 12 -#define F_SETLK 13 -#define F_SETLKW 14 - -#define F_SETOWN_EX 15 -#define F_GETOWN_EX 16 - -#define F_GETOWNER_UIDS 17 - -int open(const char *file, int flags, ...); -int fcntl(int fildes, int cmd, ...); -int creat(const char *, mode_t); - -#endif diff --git a/components/libc/compilers/common/nogcc/readme.md b/components/libc/compilers/common/nogcc/readme.md deleted file mode 100644 index b10940d003..0000000000 --- a/components/libc/compilers/common/nogcc/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -## Attentions - -This folder is "common" for toolchains excluding gcc. \ No newline at end of file diff --git a/components/libc/compilers/common/nogcc/sys/errno.h b/components/libc/compilers/common/nogcc/sys/errno.h deleted file mode 100644 index d53ce4b386..0000000000 --- a/components/libc/compilers/common/nogcc/sys/errno.h +++ /dev/null @@ -1,585 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-05-22 Meco Man The first version. - */ - -#ifndef __SYS_ERRNO_H__ -#define __SYS_ERRNO_H__ - -#if defined(__ARMCC_VERSION) -/* -defined in armcc/errno.h - -#define EDOM 1 -#define ERANGE 2 -#define EILSEQ 4 -#define ESIGNUM 3 -#define EINVAL 5 -#define ENOMEM 6 -*/ - -#define ERROR_BASE_NO 7 - -#elif defined(__IAR_SYSTEMS_ICC__) -/* defined in iar/errno.h -#define EDOM 33 -#define ERANGE 34 -#define EFPOS 35 -#define EILSEQ 36 -*/ -#define ERROR_BASE_NO 36 - -#else -#define ERROR_BASE_NO 0 -#endif - -#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) -#include - -#ifndef EPERM -#define EPERM (ERROR_BASE_NO + 1) -#endif - -#ifndef ENOENT -#define ENOENT (ERROR_BASE_NO + 2) -#endif - -#ifndef ESRCH -#define ESRCH (ERROR_BASE_NO + 3) -#endif - -#ifndef EINTR -#define EINTR (ERROR_BASE_NO + 4) -#endif - -#ifndef EIO -#define EIO (ERROR_BASE_NO + 5) -#endif - -#ifndef ENXIO -#define ENXIO (ERROR_BASE_NO + 6) -#endif - -#ifndef E2BIG -#define E2BIG (ERROR_BASE_NO + 7) -#endif - -#ifndef ENOEXEC -#define ENOEXEC (ERROR_BASE_NO + 8) -#endif - -#ifndef EBADF -#define EBADF (ERROR_BASE_NO + 9) -#endif - -#ifndef ECHILD -#define ECHILD (ERROR_BASE_NO + 10) -#endif - -#ifndef EAGAIN -#define EAGAIN (ERROR_BASE_NO + 11) -#endif - -#ifndef ENOMEM -#define ENOMEM (ERROR_BASE_NO + 12) -#endif - -#ifndef EACCES -#define EACCES (ERROR_BASE_NO + 13) -#endif - -#ifndef EFAULT -#define EFAULT (ERROR_BASE_NO + 14) -#endif - -#ifndef ENOTBLK -#define ENOTBLK (ERROR_BASE_NO + 15) -#endif - -#ifndef EBUSY -#define EBUSY (ERROR_BASE_NO + 16) -#endif - -#ifndef EEXIST -#define EEXIST (ERROR_BASE_NO + 17) -#endif - -#ifndef EXDEV -#define EXDEV (ERROR_BASE_NO + 18) -#endif - -#ifndef ENODEV -#define ENODEV (ERROR_BASE_NO + 19) -#endif - -#ifndef ENOTDIR -#define ENOTDIR (ERROR_BASE_NO + 20) -#endif - -#ifndef EISDIR -#define EISDIR (ERROR_BASE_NO + 21) -#endif - -#ifndef EINVAL -#define EINVAL (ERROR_BASE_NO + 22) -#endif - -#ifndef ENFILE -#define ENFILE (ERROR_BASE_NO + 23) -#endif - -#ifndef EMFILE -#define EMFILE (ERROR_BASE_NO + 24) -#endif - -#ifndef ENOTTY -#define ENOTTY (ERROR_BASE_NO + 25) -#endif - -#ifndef ETXTBSY -#define ETXTBSY (ERROR_BASE_NO + 26) -#endif - -#ifndef EFBIG -#define EFBIG (ERROR_BASE_NO + 27) -#endif - -#ifndef ENOSPC -#define ENOSPC (ERROR_BASE_NO + 28) -#endif - -#ifndef ESPIPE -#define ESPIPE (ERROR_BASE_NO + 29) -#endif - -#ifndef EROFS -#define EROFS (ERROR_BASE_NO + 30) -#endif - -#ifndef EMLINK -#define EMLINK (ERROR_BASE_NO + 31) -#endif - -#ifndef EPIPE -#define EPIPE (ERROR_BASE_NO + 32) -#endif - -#ifndef EDOM -#define EDOM (ERROR_BASE_NO + 33) -#endif - -#ifndef ERANGE -#define ERANGE (ERROR_BASE_NO + 34) -#endif - -#ifndef EDEADLK -#define EDEADLK (ERROR_BASE_NO + 35) -#endif - -#ifndef ENAMETOOLONG -#define ENAMETOOLONG (ERROR_BASE_NO + 36) -#endif - -#ifndef ENOLCK -#define ENOLCK (ERROR_BASE_NO + 37) -#endif - -#ifndef ENOSYS -#define ENOSYS (ERROR_BASE_NO + 38) -#endif - -#ifndef ENOTEMPTY -#define ENOTEMPTY (ERROR_BASE_NO + 39) -#endif - -#ifndef ELOOP -#define ELOOP (ERROR_BASE_NO + 40) -#endif - -#ifndef EWOULDBLOCK -#define EWOULDBLOCK EAGAIN -#endif - -#ifndef ENOMSG -#define ENOMSG (ERROR_BASE_NO + 42) -#endif - -#ifndef EIDRM -#define EIDRM (ERROR_BASE_NO + 43) -#endif - -#ifndef ECHRNG -#define ECHRNG (ERROR_BASE_NO + 44) -#endif - -#ifndef EL2NSYNC -#define EL2NSYNC (ERROR_BASE_NO + 45) -#endif - -#ifndef EL3HLT -#define EL3HLT (ERROR_BASE_NO + 46) -#endif - -#ifndef EL3RST -#define EL3RST (ERROR_BASE_NO + 47) -#endif - -#ifndef ELNRNG -#define ELNRNG (ERROR_BASE_NO + 48) -#endif - -#ifndef EUNATCH -#define EUNATCH (ERROR_BASE_NO + 49) -#endif - -#ifndef ENOCSI -#define ENOCSI (ERROR_BASE_NO + 50) -#endif - -#ifndef EL2HLT -#define EL2HLT (ERROR_BASE_NO + 51) -#endif - -#ifndef EBADE -#define EBADE (ERROR_BASE_NO + 52) -#endif - -#ifndef EBADR -#define EBADR (ERROR_BASE_NO + 53) -#endif - -#ifndef EXFULL -#define EXFULL (ERROR_BASE_NO + 54) -#endif - -#ifndef ENOANO -#define ENOANO (ERROR_BASE_NO + 55) -#endif - -#ifndef EBADRQC -#define EBADRQC (ERROR_BASE_NO + 56) -#endif - -#ifndef EBADSLT -#define EBADSLT (ERROR_BASE_NO + 57) -#endif - -#ifndef EDEADLOCK -#define EDEADLOCK EDEADLK -#endif - -#ifndef EBFONT -#define EBFONT (ERROR_BASE_NO + 59) -#endif - -#ifndef ENOSTR -#define ENOSTR (ERROR_BASE_NO + 60) -#endif - -#ifndef ENODATA -#define ENODATA (ERROR_BASE_NO + 61) -#endif - -#ifndef ETIME -#define ETIME (ERROR_BASE_NO + 62) -#endif - -#ifndef ENOSR -#define ENOSR (ERROR_BASE_NO + 63) -#endif - -#ifndef ENONET -#define ENONET (ERROR_BASE_NO + 64) -#endif - -#ifndef ENOPKG -#define ENOPKG (ERROR_BASE_NO + 65) -#endif - -#ifndef EREMOTE -#define EREMOTE (ERROR_BASE_NO + 66) -#endif - -#ifndef ENOLINK -#define ENOLINK (ERROR_BASE_NO + 67) -#endif - -#ifndef EADV -#define EADV (ERROR_BASE_NO + 68) -#endif - -#ifndef ESRMNT -#define ESRMNT (ERROR_BASE_NO + 69) -#endif - -#ifndef ECOMM -#define ECOMM (ERROR_BASE_NO + 70) -#endif - -#ifndef EPROTO -#define EPROTO (ERROR_BASE_NO + 71) -#endif - -#ifndef EMULTIHOP -#define EMULTIHOP (ERROR_BASE_NO + 72) -#endif - -#ifndef EDOTDOT -#define EDOTDOT (ERROR_BASE_NO + 73) -#endif - -#ifndef EBADMSG -#define EBADMSG (ERROR_BASE_NO + 74) -#endif - -#ifndef EOVERFLOW -#define EOVERFLOW (ERROR_BASE_NO + 75) -#endif - -#ifndef ENOTUNIQ -#define ENOTUNIQ (ERROR_BASE_NO + 76) -#endif - -#ifndef EBADFD -#define EBADFD (ERROR_BASE_NO + 77) -#endif - -#ifndef EREMCHG -#define EREMCHG (ERROR_BASE_NO + 78) -#endif - -#ifndef ELIBACC -#define ELIBACC (ERROR_BASE_NO + 79) -#endif - -#ifndef ELIBBAD -#define ELIBBAD (ERROR_BASE_NO + 80) -#endif - -#ifndef ELIBSCN -#define ELIBSCN (ERROR_BASE_NO + 81) -#endif - -#ifndef ELIBMAX -#define ELIBMAX (ERROR_BASE_NO + 82) -#endif - -#ifndef ELIBEXEC -#define ELIBEXEC (ERROR_BASE_NO + 83) -#endif - -#ifndef EILSEQ -#define EILSEQ (ERROR_BASE_NO + 84) -#endif - -#ifndef ERESTART -#define ERESTART (ERROR_BASE_NO + 85) -#endif - -#ifndef ESTRPIPE -#define ESTRPIPE (ERROR_BASE_NO + 86) -#endif - -#ifndef EUSERS -#define EUSERS (ERROR_BASE_NO + 87) -#endif - -#ifndef ENOTSOCK -#define ENOTSOCK (ERROR_BASE_NO + 88) -#endif - -#ifndef EDESTADDRREQ -#define EDESTADDRREQ (ERROR_BASE_NO + 89) -#endif - -#ifndef EMSGSIZE -#define EMSGSIZE (ERROR_BASE_NO + 90) -#endif - -#ifndef EPROTOTYPE -#define EPROTOTYPE (ERROR_BASE_NO + 91) -#endif - -#ifndef ENOPROTOOPT -#define ENOPROTOOPT (ERROR_BASE_NO + 92) -#endif - -#ifndef EPROTONOSUPPORT -#define EPROTONOSUPPORT (ERROR_BASE_NO + 93) -#endif - -#ifndef ESOCKTNOSUPPORT -#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) -#endif - -#ifndef EOPNOTSUPP -#define EOPNOTSUPP (ERROR_BASE_NO + 95) -#endif - -#ifndef ENOTSUP -#define ENOTSUP EOPNOTSUPP -#endif - -#ifndef EPFNOSUPPORT -#define EPFNOSUPPORT (ERROR_BASE_NO + 96) -#endif - -#ifndef EAFNOSUPPORT -#define EAFNOSUPPORT (ERROR_BASE_NO + 97) -#endif - -#ifndef EADDRINUSE -#define EADDRINUSE (ERROR_BASE_NO + 98) -#endif - -#ifndef EADDRNOTAVAIL -#define EADDRNOTAVAIL (ERROR_BASE_NO + 99) -#endif - -#ifndef ENETDOWN -#define ENETDOWN (ERROR_BASE_NO + 100) -#endif - -#ifndef ENETUNREACH -#define ENETUNREACH (ERROR_BASE_NO + 101) -#endif - -#ifndef ENETRESET -#define ENETRESET (ERROR_BASE_NO + 102) -#endif - -#ifndef ECONNABORTED -#define ECONNABORTED (ERROR_BASE_NO + 103) -#endif - -#ifndef ECONNRESET -#define ECONNRESET (ERROR_BASE_NO + 104) -#endif - -#ifndef ENOBUFS -#define ENOBUFS (ERROR_BASE_NO + 105) -#endif - -#ifndef EISCONN -#define EISCONN (ERROR_BASE_NO + 106) -#endif - -#ifndef ENOTCONN -#define ENOTCONN (ERROR_BASE_NO + 107) -#endif - -#ifndef ESHUTDOWN -#define ESHUTDOWN (ERROR_BASE_NO + 108) -#endif - -#ifndef ETOOMANYREFS -#define ETOOMANYREFS (ERROR_BASE_NO + 109) -#endif - -#ifndef ETIMEDOUT -#define ETIMEDOUT (ERROR_BASE_NO + 110) -#endif - -#ifndef ECONNREFUSED -#define ECONNREFUSED (ERROR_BASE_NO + 111) -#endif - -#ifndef EHOSTDOWN -#define EHOSTDOWN (ERROR_BASE_NO + 112) -#endif - -#ifndef EHOSTUNREACH -#define EHOSTUNREACH (ERROR_BASE_NO + 113) -#endif - -#ifndef EALREADY -#define EALREADY (ERROR_BASE_NO + 114) -#endif - -#ifndef EINPROGRESS -#define EINPROGRESS (ERROR_BASE_NO + 115) -#endif - -#ifndef ESTALE -#define ESTALE (ERROR_BASE_NO + 116) -#endif - -#ifndef EUCLEAN -#define EUCLEAN (ERROR_BASE_NO + 117) -#endif - -#ifndef ENOTNAM -#define ENOTNAM (ERROR_BASE_NO + 118) -#endif - -#ifndef ENAVAIL -#define ENAVAIL (ERROR_BASE_NO + 119) -#endif - -#ifndef EISNAM -#define EISNAM (ERROR_BASE_NO + 120) -#endif - -#ifndef EREMOTEIO -#define EREMOTEIO (ERROR_BASE_NO + 121) -#endif - -#ifndef EDQUOT -#define EDQUOT (ERROR_BASE_NO + 122) -#endif - -#ifndef ENOMEDIUM -#define ENOMEDIUM (ERROR_BASE_NO + 123) -#endif - -#ifndef EMEDIUMTYPE -#define EMEDIUMTYPE (ERROR_BASE_NO + 124) -#endif - -#ifndef ECANCELED -#define ECANCELED (ERROR_BASE_NO + 125) -#endif - -#ifndef ENOKEY -#define ENOKEY (ERROR_BASE_NO + 126) -#endif - -#ifndef EKEYEXPIRED -#define EKEYEXPIRED (ERROR_BASE_NO + 127) -#endif - -#ifndef EKEYREVOKED -#define EKEYREVOKED (ERROR_BASE_NO + 128) -#endif - -#ifndef EKEYREJECTED -#define EKEYREJECTED (ERROR_BASE_NO + 129) -#endif - -#ifndef EOWNERDEAD -#define EOWNERDEAD (ERROR_BASE_NO + 130) -#endif - -#ifndef ENOTRECOVERABLE -#define ENOTRECOVERABLE (ERROR_BASE_NO + 131) -#endif - -#ifndef ERFKILL -#define ERFKILL (ERROR_BASE_NO + 132) -#endif - -#ifndef EHWPOISON -#define EHWPOISON (ERROR_BASE_NO + 133) -#endif - -#elif defined(_WIN32) -#include - -#endif /* defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) */ - -#endif /* __SYS_ERRNO_H__ */ diff --git a/components/libc/compilers/common/nogcc/sys/select.h b/components/libc/compilers/common/nogcc/sys/select.h deleted file mode 100644 index 44f9b4ed91..0000000000 --- a/components/libc/compilers/common/nogcc/sys/select.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-07-21 Meco Man The first version - * 2021-12-25 Meco Man Handle newlib 2.2.0 or lower version - */ - -#ifndef __SYS_SELECT_H__ -#define __SYS_SELECT_H__ - -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -#ifndef FD_SETSIZE -#define FD_SETSIZE 32 -#endif - -#ifdef SAL_USING_POSIX -#ifdef FD_SETSIZE -#undef FD_SETSIZE -#endif -#define FD_SETSIZE DFS_FD_MAX -#endif /* SAL_USING_POSIX */ - -typedef long fd_mask; - -#ifndef _WIN32 -#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */ -#define NBBY 8 /* number of bits in a byte */ -#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -#ifndef howmany -#define howmany(x,y) (((x)+((y)-1))/(y)) -#endif /* howmany */ - -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} _types_fd_set; -#define fd_set _types_fd_set - -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) -#endif /* _SYS_TYPES_FD_SET */ - -int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -#endif /* _WIN32 */ - -#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/common/nogcc/sys/stat.h b/components/libc/compilers/common/nogcc/sys/stat.h deleted file mode 100644 index 107c15decf..0000000000 --- a/components/libc/compilers/common/nogcc/sys/stat.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-09-02 Meco Man First version - */ - -#ifndef __SYS_STAT_H__ -#define __SYS_STAT_H__ - -#include -#include - -#define S_IFMT 00170000 -#define S_IFSOCK 0140000 -#define S_IFLNK 0120000 -#define S_IFREG 0100000 -#define S_IFBLK 0060000 -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFIFO 0010000 -#define S_ISUID 0004000 -#define S_ISGID 0002000 -#define S_ISVTX 0001000 - -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) - -#define S_IRWXU 00700 -#define S_IRUSR 00400 -#define S_IWUSR 00200 -#define S_IXUSR 00100 - -#define S_IRWXG 00070 -#define S_IRGRP 00040 -#define S_IWGRP 00020 -#define S_IXGRP 00010 - -#define S_IRWXO 00007 -#define S_IROTH 00004 -#define S_IWOTH 00002 -#define S_IXOTH 00001 - -struct stat -{ - struct rt_device *st_dev; - uint16_t st_ino; - uint16_t st_mode; - uint16_t st_nlink; - uint16_t st_uid; - uint16_t st_gid; - struct rt_device *st_rdev; - uint32_t st_size; - time_t st_atime; - long st_spare1; - time_t st_mtime; - long st_spare2; - time_t st_ctime; - long st_spare3; - uint32_t st_blksize; - uint32_t st_blocks; - long st_spare4[2]; -}; - -int chmod(const char *, mode_t); -int fchmod(int, mode_t); -int fstat(int, struct stat *); -int lstat(const char *, struct stat *); -int mkdir(const char *, mode_t); -int mkfifo(const char *, mode_t); -int mknod(const char *, mode_t, dev_t); -int stat(const char *, struct stat *); -mode_t umask(mode_t); - -#endif diff --git a/components/libc/compilers/common/nogcc/sys/types.h b/components/libc/compilers/common/nogcc/sys/types.h deleted file mode 100644 index 32b2493c95..0000000000 --- a/components/libc/compilers/common/nogcc/sys/types.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-05 Meco Man fix bugs - * 2020-12-16 Meco Man add useconds_t - */ - -#ifndef __SYS_TYPES_H__ -#define __SYS_TYPES_H__ - -#include -#include -#include - -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int pid_t; /* Used for process IDs and process group IDs. */ -typedef unsigned short uid_t; -typedef unsigned short gid_t; -typedef signed long off_t; -typedef int mode_t; -#ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#endif -typedef long suseconds_t; /* microseconds. */ -typedef unsigned long useconds_t; /* microseconds (unsigned) */ - -typedef unsigned long dev_t; - -typedef unsigned int u_int; -typedef unsigned char u_char; -typedef unsigned long u_long; - -#endif diff --git a/components/libc/compilers/common/nogcc/sys/unistd.h b/components/libc/compilers/common/nogcc/sys/unistd.h deleted file mode 100644 index 650c87dc18..0000000000 --- a/components/libc/compilers/common/nogcc/sys/unistd.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add usleep - * 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h - */ - -#ifndef __SYS_UNISTD_H__ -#define __SYS_UNISTD_H__ - -#include -#include "types.h" /* */ - -#define STDIN_FILENO 0 /* standard input file descriptor */ -#define STDOUT_FILENO 1 /* standard output file descriptor */ -#define STDERR_FILENO 2 /* standard error file descriptor */ - -ssize_t read(int fd, void *buf, size_t len); -ssize_t write(int fd, const void *buf, size_t len); -off_t lseek(int fd, off_t offset, int whence); -int fsync(int fildes); -int unlink(const char *pathname); -int close(int d); -int ftruncate(int fd, off_t length); -int rmdir(const char *path); -int chdir(const char *path); -char *getcwd(char *buf, size_t size); -int access(const char *path, int amode); -int pipe(int fildes[2]); -int isatty(int fd); -char *ttyname(int desc); -unsigned int sleep(unsigned int seconds); -int usleep(useconds_t usec); -pid_t gettid(void); -pid_t getpid(void); -pid_t getppid(void); -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); - -#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/nogcc/unistd.h b/components/libc/compilers/common/nogcc/unistd.h deleted file mode 100644 index 4dd71c842e..0000000000 --- a/components/libc/compilers/common/nogcc/unistd.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ - -#include "sys/unistd.h" diff --git a/components/libc/compilers/gcc/SConscript b/components/libc/compilers/gcc/SConscript deleted file mode 100644 index 4c815c49b8..0000000000 --- a/components/libc/compilers/gcc/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -# RT-Thread building script for bridge - -import os -from building import * - -cwd = GetCurrentDir() -objs = [] -list = os.listdir(cwd) - -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) - -Return('objs') diff --git a/components/libc/compilers/gcc/newlib/README.md b/components/libc/compilers/gcc/newlib/README.md deleted file mode 100644 index 4614375b45..0000000000 --- a/components/libc/compilers/gcc/newlib/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# NEWLIB (GCC) porting for RT-Thread - -https://sourceware.org/newlib/libc.html#Reentrancy - diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript deleted file mode 100644 index 8076a73727..0000000000 --- a/components/libc/compilers/gcc/newlib/SConscript +++ /dev/null @@ -1,31 +0,0 @@ -import os -from building import * -from gcc import * -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -group = [] -LIBS = ['m'] # link libm -CPPPATH = [cwd] - -if rtconfig.PLATFORM == 'gcc': - LIBS += ['c'] # link libc - src += Glob('*.c') - - #report newlib version - print('Newlib version:' + GetNewLibVersion(rtconfig)) - - # identify this is Newlib, and only enable POSIX.1-1990 - CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1'] - - group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) - - -list = os.listdir(cwd) -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - group = group + SConscript(os.path.join(d, 'SConscript')) - -Return('group') diff --git a/components/libc/compilers/gcc/newlib/fcntl.h b/components/libc/compilers/gcc/newlib/fcntl.h deleted file mode 100644 index 847ae3d35b..0000000000 --- a/components/libc/compilers/gcc/newlib/fcntl.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-09-02 Meco Man First version - */ - -#ifndef __FCNTL_H__ -#define __FCNTL_H__ - -#include - -#ifndef O_DIRECTORY -#define O_DIRECTORY 0x200000 -#endif - -#ifndef O_BINARY -#define O_BINARY 0x10000 -#endif - -#endif diff --git a/components/libc/compilers/gcc/newlib/legacy/SConscript b/components/libc/compilers/gcc/newlib/legacy/SConscript deleted file mode 100644 index 4c815c49b8..0000000000 --- a/components/libc/compilers/gcc/newlib/legacy/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -# RT-Thread building script for bridge - -import os -from building import * - -cwd = GetCurrentDir() -objs = [] -list = os.listdir(cwd) - -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) - -Return('objs') diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript b/components/libc/compilers/gcc/newlib/legacy/_select/SConscript deleted file mode 100644 index b7bd86a36c..0000000000 --- a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript +++ /dev/null @@ -1,20 +0,0 @@ -from shutil import copy -from building import * -from gcc import * -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -CPPPATH = [cwd] -group = [] - -# sys/select.h does not exist in newlib 2.1.0 or lower version -if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == False): - try: - copy("../../../../common/nogcc/sys/select.h", "./sys/select.h") # copy from 'nogcc/sys/select.h' - except: - pass - - group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) - -Return('group') diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md b/components/libc/compilers/gcc/newlib/legacy/_select/readme.md deleted file mode 100644 index 4ad9f21923..0000000000 --- a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md +++ /dev/null @@ -1,2 +0,0 @@ -Newlib 2.2.0 or lower version does not provide `sys/select.h`, and `fd_set` is defined in `sys/types.h`. It will be generated by scons automatically, and **DO NOT** change it. - diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h b/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h deleted file mode 100644 index 02fb77dd89..0000000000 --- a/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-07-21 Meco Man The first version - */ - -#ifndef __SYS_SELECT_H__ -#define __SYS_SELECT_H__ - -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -#ifndef FD_SETSIZE -#define FD_SETSIZE 32 -#endif - -#ifdef SAL_USING_POSIX -#ifdef FD_SETSIZE -#undef FD_SETSIZE -#endif -#define FD_SETSIZE DFS_FD_MAX -#endif /* SAL_USING_POSIX */ - -typedef long fd_mask; - -#ifndef _WIN32 -#ifndef _SYS_TYPES_FD_SET /* MIPS */ - -#define NBBY 8 /* number of bits in a byte */ -#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -#ifndef howmany -#define howmany(x,y) (((x)+((y)-1))/(y)) -#endif - -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} _types_fd_set; -#define fd_set _types_fd_set - -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) -#endif /* _SYS_TYPES_FD_SET */ - -int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -#endif /* _WIN32 */ - -#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/gcc/newlib/libc_syms.c b/components/libc/compilers/gcc/newlib/libc_syms.c deleted file mode 100644 index e6ca23b393..0000000000 --- a/components/libc/compilers/gcc/newlib/libc_syms.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ - -#include -#include - -#include -#include -#include - -RTM_EXPORT(strcpy); -RTM_EXPORT(strncpy); -RTM_EXPORT(strlen); -RTM_EXPORT(strcat); -RTM_EXPORT(strstr); -RTM_EXPORT(strchr); -RTM_EXPORT(strcmp); -RTM_EXPORT(strtol); -RTM_EXPORT(strtoul); -RTM_EXPORT(strncmp); - -RTM_EXPORT(memcpy); -RTM_EXPORT(memcmp); -RTM_EXPORT(memmove); -RTM_EXPORT(memset); -RTM_EXPORT(memchr); - -RTM_EXPORT(putchar); -RTM_EXPORT(puts); -RTM_EXPORT(printf); -RTM_EXPORT(sprintf); -RTM_EXPORT(snprintf); - -RTM_EXPORT(fwrite); - -#include -RTM_EXPORT(longjmp); -RTM_EXPORT(setjmp); - -RTM_EXPORT(exit); -RTM_EXPORT(abort); - -RTM_EXPORT(rand); - -#include -RTM_EXPORT(__assert_func); diff --git a/components/libc/compilers/gcc/newlib/machine/time.h b/components/libc/compilers/gcc/newlib/machine/time.h deleted file mode 100644 index 805b061aea..0000000000 --- a/components/libc/compilers/gcc/newlib/machine/time.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-16 Meco Man The first version - */ - -#ifndef _MACHTIME_H_ -#define _MACHTIME_H_ - -#include -#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND - -#endif /* _MACHTIME_H_ */ diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c deleted file mode 100644 index dcf26ccfb7..0000000000 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r() - * 2020-02-13 Meco Man re-implement exit() and abort() - * 2020-02-21 Meco Man improve and beautify syscalls - * 2020-02-24 Meco Man fix bug of _isatty_r() - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef RT_USING_POSIX_STDIO -#include "libc.h" -#endif /* RT_USING_POSIX_STDIO */ -#ifdef RT_USING_MODULE -#include -#endif /* RT_USING_MODULE */ -#include -#define DBG_TAG "newlib.syscalls" -#define DBG_LVL DBG_INFO -#include - -#ifdef RT_USING_HEAP /* Memory routine */ -void *_malloc_r (struct _reent *ptr, size_t size) -{ - void* result; - - result = (void*)rt_malloc (size); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) -{ - void* result; - - result = (void*)rt_realloc (old, newlen); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void *_calloc_r (struct _reent *ptr, size_t size, size_t len) -{ - void* result; - - result = (void*)rt_calloc (size, len); - if (result == RT_NULL) - { - ptr->_errno = ENOMEM; - } - - return result; -} - -void _free_r (struct _reent *ptr, void *addr) -{ - rt_free (addr); -} - -#else -void * -_sbrk_r(struct _reent *ptr, ptrdiff_t incr) -{ - LOG_E("Please enable RT_USING_HEAP"); - RT_ASSERT(0); - return RT_NULL; -} -#endif /*RT_USING_HEAP*/ - -void __libc_init_array(void) -{ - /* we not use __libc init_aray to initialize C++ objects */ - /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */ -} - -/* Reentrant versions of system calls. */ -#ifndef _REENT_ONLY -int *__errno () -{ - return _rt_errno(); -} -#endif - -int _getpid_r(struct _reent *ptr) -{ - return 0; -} - -int _close_r(struct _reent *ptr, int fd) -{ -#ifdef DFS_USING_POSIX - return close(fd); -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -int _fork_r(struct _reent *ptr) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -int _isatty_r(struct _reent *ptr, int fd) -{ - if (fd >=0 && fd < 3) - { - return 1; - } - else - { - return 0; - } -} - -int _kill_r(struct _reent *ptr, int pid, int sig) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -int _link_r(struct _reent *ptr, const char *old, const char *new) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -int _wait_r(struct _reent *ptr, int *status) -{ - ptr->_errno = ENOTSUP; - return -1; -} - -mode_t umask(mode_t mask) -{ - return 022; -} - -int flock(int fd, int operation) -{ - return 0; -} - -_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) -{ -#ifdef DFS_USING_POSIX - _off_t rc; - rc = lseek(fd, pos, whence); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -int _mkdir_r(struct _reent *ptr, const char *name, int mode) -{ -#ifdef DFS_USING_POSIX - int rc; - rc = mkdir(name, mode); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -int _open_r(struct _reent *ptr, const char *file, int flags, int mode) -{ -#ifdef DFS_USING_POSIX - int rc; - rc = open(file, flags, mode); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) -{ -#ifdef DFS_USING_POSIX - _ssize_t rc; - if (fd == STDIN_FILENO) - { -#ifdef RT_USING_POSIX_STDIO - if (libc_stdio_get_console() < 0) - { - LOG_W("Do not invoke standard input before initializing Compiler"); - return 0; - } -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO); - ptr->_errno = ENOTSUP; - return -1; -#endif /* RT_USING_POSIX_STDIO */ - } - else if (fd == STDOUT_FILENO || fd == STDERR_FILENO) - { - ptr->_errno = ENOTSUP; - return -1; - } - - rc = read(fd, buf, nbytes); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -int _rename_r(struct _reent *ptr, const char *old, const char *new) -{ -#ifdef DFS_USING_POSIX - int rc; - rc = rename(old, new); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) -{ -#ifdef DFS_USING_POSIX - int rc; - rc = stat(file, pstat); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -int _unlink_r(struct _reent *ptr, const char *file) -{ -#ifdef DFS_USING_POSIX - return unlink(file); -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) -{ -#ifdef DFS_USING_POSIX - _ssize_t rc; -#endif /* DFS_USING_POSIX */ - - if (fd == STDOUT_FILENO || fd == STDERR_FILENO) - { -#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) - rt_device_t console; - - console = rt_console_get_device(); - if (console) - return rt_device_write(console, -1, buf, nbytes); -#else - ptr->_errno = ENOTSUP; - return -1; -#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */ - } - else if (fd == STDIN_FILENO) - { - ptr->_errno = ENOTSUP; - return -1; - } - -#ifdef DFS_USING_POSIX - rc = write(fd, buf, nbytes); - return rc; -#else - LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); - ptr->_errno = ENOTSUP; - return -1; -#endif /* DFS_USING_POSIX */ -} - -/* for exit() and abort() */ -__attribute__ ((noreturn)) void _exit (int status) -{ - extern void __rt_libc_exit(int status); - __rt_libc_exit(status); - while(1); -} - -/* -These functions are implemented and replaced by the 'common/time.c' file -int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); -_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); -*/ diff --git a/components/libc/compilers/newlib/README.md b/components/libc/compilers/newlib/README.md new file mode 100644 index 0000000000..4614375b45 --- /dev/null +++ b/components/libc/compilers/newlib/README.md @@ -0,0 +1,4 @@ +# NEWLIB (GCC) porting for RT-Thread + +https://sourceware.org/newlib/libc.html#Reentrancy + diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript new file mode 100644 index 0000000000..8076a73727 --- /dev/null +++ b/components/libc/compilers/newlib/SConscript @@ -0,0 +1,31 @@ +import os +from building import * +from gcc import * +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +group = [] +LIBS = ['m'] # link libm +CPPPATH = [cwd] + +if rtconfig.PLATFORM == 'gcc': + LIBS += ['c'] # link libc + src += Glob('*.c') + + #report newlib version + print('Newlib version:' + GetNewLibVersion(rtconfig)) + + # identify this is Newlib, and only enable POSIX.1-1990 + CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1'] + + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + + +list = os.listdir(cwd) +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + group = group + SConscript(os.path.join(d, 'SConscript')) + +Return('group') diff --git a/components/libc/compilers/newlib/fcntl.h b/components/libc/compilers/newlib/fcntl.h new file mode 100644 index 0000000000..847ae3d35b --- /dev/null +++ b/components/libc/compilers/newlib/fcntl.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-09-02 Meco Man First version + */ + +#ifndef __FCNTL_H__ +#define __FCNTL_H__ + +#include + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0x200000 +#endif + +#ifndef O_BINARY +#define O_BINARY 0x10000 +#endif + +#endif diff --git a/components/libc/compilers/newlib/legacy/SConscript b/components/libc/compilers/newlib/legacy/SConscript new file mode 100644 index 0000000000..4c815c49b8 --- /dev/null +++ b/components/libc/compilers/newlib/legacy/SConscript @@ -0,0 +1,15 @@ +# RT-Thread building script for bridge + +import os +from building import * + +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/components/libc/compilers/newlib/legacy/_select/SConscript b/components/libc/compilers/newlib/legacy/_select/SConscript new file mode 100644 index 0000000000..b7bd86a36c --- /dev/null +++ b/components/libc/compilers/newlib/legacy/_select/SConscript @@ -0,0 +1,20 @@ +from shutil import copy +from building import * +from gcc import * +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] + +# sys/select.h does not exist in newlib 2.1.0 or lower version +if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == False): + try: + copy("../../../../common/nogcc/sys/select.h", "./sys/select.h") # copy from 'nogcc/sys/select.h' + except: + pass + + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/components/libc/compilers/newlib/legacy/_select/readme.md b/components/libc/compilers/newlib/legacy/_select/readme.md new file mode 100644 index 0000000000..4ad9f21923 --- /dev/null +++ b/components/libc/compilers/newlib/legacy/_select/readme.md @@ -0,0 +1,2 @@ +Newlib 2.2.0 or lower version does not provide `sys/select.h`, and `fd_set` is defined in `sys/types.h`. It will be generated by scons automatically, and **DO NOT** change it. + diff --git a/components/libc/compilers/newlib/legacy/_select/sys/select.h b/components/libc/compilers/newlib/legacy/_select/sys/select.h new file mode 100644 index 0000000000..02fb77dd89 --- /dev/null +++ b/components/libc/compilers/newlib/legacy/_select/sys/select.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-07-21 Meco Man The first version + */ + +#ifndef __SYS_SELECT_H__ +#define __SYS_SELECT_H__ + +#include +#include +#include + +#ifdef _WIN32 +#include +#endif + +#ifndef FD_SETSIZE +#define FD_SETSIZE 32 +#endif + +#ifdef SAL_USING_POSIX +#ifdef FD_SETSIZE +#undef FD_SETSIZE +#endif +#define FD_SETSIZE DFS_FD_MAX +#endif /* SAL_USING_POSIX */ + +typedef long fd_mask; + +#ifndef _WIN32 +#ifndef _SYS_TYPES_FD_SET /* MIPS */ + +#define NBBY 8 /* number of bits in a byte */ +#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ +#ifndef howmany +#define howmany(x,y) (((x)+((y)-1))/(y)) +#endif + +typedef struct _types_fd_set { + fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +} _types_fd_set; +#define fd_set _types_fd_set + +#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#endif /* _SYS_TYPES_FD_SET */ + +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); +#endif /* _WIN32 */ + +#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/newlib/libc_syms.c b/components/libc/compilers/newlib/libc_syms.c new file mode 100644 index 0000000000..e6ca23b393 --- /dev/null +++ b/components/libc/compilers/newlib/libc_syms.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/10/15 bernard the first version + */ + +#include +#include + +#include +#include +#include + +RTM_EXPORT(strcpy); +RTM_EXPORT(strncpy); +RTM_EXPORT(strlen); +RTM_EXPORT(strcat); +RTM_EXPORT(strstr); +RTM_EXPORT(strchr); +RTM_EXPORT(strcmp); +RTM_EXPORT(strtol); +RTM_EXPORT(strtoul); +RTM_EXPORT(strncmp); + +RTM_EXPORT(memcpy); +RTM_EXPORT(memcmp); +RTM_EXPORT(memmove); +RTM_EXPORT(memset); +RTM_EXPORT(memchr); + +RTM_EXPORT(putchar); +RTM_EXPORT(puts); +RTM_EXPORT(printf); +RTM_EXPORT(sprintf); +RTM_EXPORT(snprintf); + +RTM_EXPORT(fwrite); + +#include +RTM_EXPORT(longjmp); +RTM_EXPORT(setjmp); + +RTM_EXPORT(exit); +RTM_EXPORT(abort); + +RTM_EXPORT(rand); + +#include +RTM_EXPORT(__assert_func); diff --git a/components/libc/compilers/newlib/machine/time.h b/components/libc/compilers/newlib/machine/time.h new file mode 100644 index 0000000000..805b061aea --- /dev/null +++ b/components/libc/compilers/newlib/machine/time.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-02-16 Meco Man The first version + */ + +#ifndef _MACHTIME_H_ +#define _MACHTIME_H_ + +#include +#define _CLOCKS_PER_SEC_ RT_TICK_PER_SECOND + +#endif /* _MACHTIME_H_ */ diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c new file mode 100644 index 0000000000..dcf26ccfb7 --- /dev/null +++ b/components/libc/compilers/newlib/syscalls.c @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r() + * 2020-02-13 Meco Man re-implement exit() and abort() + * 2020-02-21 Meco Man improve and beautify syscalls + * 2020-02-24 Meco Man fix bug of _isatty_r() + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef RT_USING_POSIX_STDIO +#include "libc.h" +#endif /* RT_USING_POSIX_STDIO */ +#ifdef RT_USING_MODULE +#include +#endif /* RT_USING_MODULE */ +#include +#define DBG_TAG "newlib.syscalls" +#define DBG_LVL DBG_INFO +#include + +#ifdef RT_USING_HEAP /* Memory routine */ +void *_malloc_r (struct _reent *ptr, size_t size) +{ + void* result; + + result = (void*)rt_malloc (size); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) +{ + void* result; + + result = (void*)rt_realloc (old, newlen); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void *_calloc_r (struct _reent *ptr, size_t size, size_t len) +{ + void* result; + + result = (void*)rt_calloc (size, len); + if (result == RT_NULL) + { + ptr->_errno = ENOMEM; + } + + return result; +} + +void _free_r (struct _reent *ptr, void *addr) +{ + rt_free (addr); +} + +#else +void * +_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +{ + LOG_E("Please enable RT_USING_HEAP"); + RT_ASSERT(0); + return RT_NULL; +} +#endif /*RT_USING_HEAP*/ + +void __libc_init_array(void) +{ + /* we not use __libc init_aray to initialize C++ objects */ + /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */ +} + +/* Reentrant versions of system calls. */ +#ifndef _REENT_ONLY +int *__errno () +{ + return _rt_errno(); +} +#endif + +int _getpid_r(struct _reent *ptr) +{ + return 0; +} + +int _close_r(struct _reent *ptr, int fd) +{ +#ifdef DFS_USING_POSIX + return close(fd); +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +int _fork_r(struct _reent *ptr) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +int _isatty_r(struct _reent *ptr, int fd) +{ + if (fd >=0 && fd < 3) + { + return 1; + } + else + { + return 0; + } +} + +int _kill_r(struct _reent *ptr, int pid, int sig) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +int _link_r(struct _reent *ptr, const char *old, const char *new) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +int _wait_r(struct _reent *ptr, int *status) +{ + ptr->_errno = ENOTSUP; + return -1; +} + +mode_t umask(mode_t mask) +{ + return 022; +} + +int flock(int fd, int operation) +{ + return 0; +} + +_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) +{ +#ifdef DFS_USING_POSIX + _off_t rc; + rc = lseek(fd, pos, whence); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +int _mkdir_r(struct _reent *ptr, const char *name, int mode) +{ +#ifdef DFS_USING_POSIX + int rc; + rc = mkdir(name, mode); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +int _open_r(struct _reent *ptr, const char *file, int flags, int mode) +{ +#ifdef DFS_USING_POSIX + int rc; + rc = open(file, flags, mode); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) +{ +#ifdef DFS_USING_POSIX + _ssize_t rc; + if (fd == STDIN_FILENO) + { +#ifdef RT_USING_POSIX_STDIO + if (libc_stdio_get_console() < 0) + { + LOG_W("Do not invoke standard input before initializing Compiler"); + return 0; + } +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_STDIO); + ptr->_errno = ENOTSUP; + return -1; +#endif /* RT_USING_POSIX_STDIO */ + } + else if (fd == STDOUT_FILENO || fd == STDERR_FILENO) + { + ptr->_errno = ENOTSUP; + return -1; + } + + rc = read(fd, buf, nbytes); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +int _rename_r(struct _reent *ptr, const char *old, const char *new) +{ +#ifdef DFS_USING_POSIX + int rc; + rc = rename(old, new); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) +{ +#ifdef DFS_USING_POSIX + int rc; + rc = stat(file, pstat); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +int _unlink_r(struct _reent *ptr, const char *file) +{ +#ifdef DFS_USING_POSIX + return unlink(file); +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) +{ +#ifdef DFS_USING_POSIX + _ssize_t rc; +#endif /* DFS_USING_POSIX */ + + if (fd == STDOUT_FILENO || fd == STDERR_FILENO) + { +#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) + rt_device_t console; + + console = rt_console_get_device(); + if (console) + return rt_device_write(console, -1, buf, nbytes); +#else + ptr->_errno = ENOTSUP; + return -1; +#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */ + } + else if (fd == STDIN_FILENO) + { + ptr->_errno = ENOTSUP; + return -1; + } + +#ifdef DFS_USING_POSIX + rc = write(fd, buf, nbytes); + return rc; +#else + LOG_W("%s: %s", __func__, _WARNING_WITHOUT_FS); + ptr->_errno = ENOTSUP; + return -1; +#endif /* DFS_USING_POSIX */ +} + +/* for exit() and abort() */ +__attribute__ ((noreturn)) void _exit (int status) +{ + extern void __rt_libc_exit(int status); + __rt_libc_exit(status); + while(1); +} + +/* +These functions are implemented and replaced by the 'common/time.c' file +int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); +_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); +*/ -- cgit v1.3.1