From 37a9231e6219b94f7cde8bdea9251e260c4bed18 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 19 Mar 2021 13:26:12 +0800 Subject: [kernel][devices] add security devices --- include/rtdef.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index f5a09f815b..66893ffe1a 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -34,6 +34,7 @@ * 2019-12-20 Bernard change version number to v4.0.3 * 2020-08-10 Meco Man add macro for struct rt_device_ops * 2020-10-23 Meco Man define maximum value of ipc type + * 2021-03-19 Meco Man add security devices */ #ifndef __RT_DEF_H__ @@ -887,6 +888,7 @@ enum rt_device_class_type RT_Device_Class_Sensor, /**< Sensor device */ RT_Device_Class_Touch, /**< Touch device */ RT_Device_Class_PHY, /**< PHY device */ + RT_Device_Class_Security, /**< Security device */ RT_Device_Class_Unknown /**< unknown device */ }; -- cgit v1.3.1 From a5f7635f31b237ad8ce09610ee76a75f4072e7d4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 22 May 2021 02:50:35 +0800 Subject: remove libc_errno.h & libc_limits.h --- components/dfs/include/dfs_fs.h | 2 +- .../libc/compilers/common/none-gcc/sys/errno.h | 199 ++++++++++++++++++++ components/libc/compilers/common/time.c | 1 + components/libc/getline/posix_getline.c | 6 +- components/libc/pthreads/posix_types.h | 2 +- components/libc/termios/posix_termios.c | 2 +- .../net/lwip-1.4.1/src/arch/include/arch/cc.h | 2 +- .../net/lwip-2.0.2/src/arch/include/arch/cc.h | 2 +- components/net/lwip-2.0.2/src/lwipopts.h | 2 + .../net/lwip-2.1.2/src/arch/include/arch/cc.h | 2 +- components/net/lwip-2.1.2/src/include/lwip/errno.h | 2 +- components/net/lwip-2.1.2/src/lwipopts.h | 1 + components/net/sal_socket/socket/net_sockets.c | 2 +- examples/libc/ex3.c | 2 +- examples/libc/ex6.c | 2 +- examples/libc/ex7.c | 2 +- examples/libc/file.c | 2 +- examples/libc/memory.c | 2 +- include/libc/libc_errno.h | 206 --------------------- include/libc/libc_limits.h | 25 --- include/rtlibc.h | 2 - 21 files changed, 219 insertions(+), 249 deletions(-) create mode 100644 components/libc/compilers/common/none-gcc/sys/errno.h delete mode 100644 include/libc/libc_errno.h delete mode 100644 include/libc/libc_limits.h (limited to 'include') diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 828f15a0f5..3d194515df 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -15,7 +15,7 @@ #ifdef RT_USING_LIBC #include #endif - +#include #ifdef __cplusplus extern "C" { #endif diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h new file mode 100644 index 0000000000..bdc3a3c9da --- /dev/null +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -0,0 +1,199 @@ +/* + * 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(__CC_ARM) +/* +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(_WIN32) + +#include + +#define EPERM (ERROR_BASE_NO + 1) +#define ENOENT (ERROR_BASE_NO + 2) +#define ESRCH (ERROR_BASE_NO + 3) +#define EINTR (ERROR_BASE_NO + 4) +#define EIO (ERROR_BASE_NO + 5) +#define ENXIO (ERROR_BASE_NO + 6) +#define E2BIG (ERROR_BASE_NO + 7) +#define ENOEXEC (ERROR_BASE_NO + 8) +#define EBADF (ERROR_BASE_NO + 9) +#define ECHILD (ERROR_BASE_NO + 10) +#define EAGAIN (ERROR_BASE_NO + 11) + +#ifndef ENOMEM +#define ENOMEM (ERROR_BASE_NO + 12) +#endif + +#define EACCES (ERROR_BASE_NO + 13) +#define EFAULT (ERROR_BASE_NO + 14) +#define ENOTBLK (ERROR_BASE_NO + 15) +#define EBUSY (ERROR_BASE_NO + 16) +#define EEXIST (ERROR_BASE_NO + 17) +#define EXDEV (ERROR_BASE_NO + 18) +#define ENODEV (ERROR_BASE_NO + 19) +#define ENOTDIR (ERROR_BASE_NO + 20) +#define EISDIR (ERROR_BASE_NO + 21) + +#ifndef EINVAL +#define EINVAL (ERROR_BASE_NO + 22) +#endif + +#define ENFILE (ERROR_BASE_NO + 23) +#define EMFILE (ERROR_BASE_NO + 24) +#define ENOTTY (ERROR_BASE_NO + 25) +#define ETXTBSY (ERROR_BASE_NO + 26) +#define EFBIG (ERROR_BASE_NO + 27) +#define ENOSPC (ERROR_BASE_NO + 28) +#define ESPIPE (ERROR_BASE_NO + 29) +#define EROFS (ERROR_BASE_NO + 30) +#define EMLINK (ERROR_BASE_NO + 31) +#define EPIPE (ERROR_BASE_NO + 32) + +#ifndef EDOM +#define EDOM (ERROR_BASE_NO + 33) +#endif + +#ifndef ERANGE +#define ERANGE (ERROR_BASE_NO + 34) +#endif + +#define EDEADLK (ERROR_BASE_NO + 35) +#define ENAMETOOLONG (ERROR_BASE_NO + 36) +#define ENOLCK (ERROR_BASE_NO + 37) +#define ENOSYS (ERROR_BASE_NO + 38) +#define ENOTEMPTY (ERROR_BASE_NO + 39) +#define ELOOP (ERROR_BASE_NO + 40) +#define EWOULDBLOCK EAGAIN +#define ENOMSG (ERROR_BASE_NO + 42) +#define EIDRM (ERROR_BASE_NO + 43) +#define ECHRNG (ERROR_BASE_NO + 44) +#define EL2NSYNC (ERROR_BASE_NO + 45) +#define EL3HLT (ERROR_BASE_NO + 46) +#define EL3RST (ERROR_BASE_NO + 47) +#define ELNRNG (ERROR_BASE_NO + 48) +#define EUNATCH (ERROR_BASE_NO + 49) +#define ENOCSI (ERROR_BASE_NO + 50) +#define EL2HLT (ERROR_BASE_NO + 51) +#define EBADE (ERROR_BASE_NO + 52) +#define EBADR (ERROR_BASE_NO + 53) +#define EXFULL (ERROR_BASE_NO + 54) +#define ENOANO (ERROR_BASE_NO + 55) +#define EBADRQC (ERROR_BASE_NO + 56) +#define EBADSLT (ERROR_BASE_NO + 57) +#define EDEADLOCK EDEADLK +#define EBFONT (ERROR_BASE_NO + 59) +#define ENOSTR (ERROR_BASE_NO + 60) +#define ENODATA (ERROR_BASE_NO + 61) +#define ETIME (ERROR_BASE_NO + 62) +#define ENOSR (ERROR_BASE_NO + 63) +#define ENONET (ERROR_BASE_NO + 64) +#define ENOPKG (ERROR_BASE_NO + 65) +#define EREMOTE (ERROR_BASE_NO + 66) +#define ENOLINK (ERROR_BASE_NO + 67) +#define EADV (ERROR_BASE_NO + 68) +#define ESRMNT (ERROR_BASE_NO + 69) +#define ECOMM (ERROR_BASE_NO + 70) +#define EPROTO (ERROR_BASE_NO + 71) +#define EMULTIHOP (ERROR_BASE_NO + 72) +#define EDOTDOT (ERROR_BASE_NO + 73) +#define EBADMSG (ERROR_BASE_NO + 74) +#define EOVERFLOW (ERROR_BASE_NO + 75) +#define ENOTUNIQ (ERROR_BASE_NO + 76) +#define EBADFD (ERROR_BASE_NO + 77) +#define EREMCHG (ERROR_BASE_NO + 78) +#define ELIBACC (ERROR_BASE_NO + 79) +#define ELIBBAD (ERROR_BASE_NO + 80) +#define ELIBSCN (ERROR_BASE_NO + 81) +#define ELIBMAX (ERROR_BASE_NO + 82) +#define ELIBEXEC (ERROR_BASE_NO + 83) + +#ifndef EILSEQ +#define EILSEQ (ERROR_BASE_NO + 84) +#endif + +#define ERESTART (ERROR_BASE_NO + 85) +#define ESTRPIPE (ERROR_BASE_NO + 86) +#define EUSERS (ERROR_BASE_NO + 87) +#define ENOTSOCK (ERROR_BASE_NO + 88) +#define EDESTADDRREQ (ERROR_BASE_NO + 89) +#define EMSGSIZE (ERROR_BASE_NO + 90) +#define EPROTOTYPE (ERROR_BASE_NO + 91) +#define ENOPROTOOPT (ERROR_BASE_NO + 92) +#define EPROTONOSUPPORT (ERROR_BASE_NO + 93) +#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) +#define EOPNOTSUPP (ERROR_BASE_NO + 95) +#define ENOTSUP EOPNOTSUPP +#define EPFNOSUPPORT (ERROR_BASE_NO + 96) +#define EAFNOSUPPORT (ERROR_BASE_NO + 97) +#define EADDRINUSE (ERROR_BASE_NO + 98) +#define EADDRNOTAVAIL (ERROR_BASE_NO + 99) +#define ENETDOWN (ERROR_BASE_NO + 100) +#define ENETUNREACH (ERROR_BASE_NO + 101) +#define ENETRESET (ERROR_BASE_NO + 102) +#define ECONNABORTED (ERROR_BASE_NO + 103) +#define ECONNRESET (ERROR_BASE_NO + 104) +#define ENOBUFS (ERROR_BASE_NO + 105) +#define EISCONN (ERROR_BASE_NO + 106) +#define ENOTCONN (ERROR_BASE_NO + 107) +#define ESHUTDOWN (ERROR_BASE_NO + 108) +#define ETOOMANYREFS (ERROR_BASE_NO + 109) +#define ETIMEDOUT (ERROR_BASE_NO + 110) +#define ECONNREFUSED (ERROR_BASE_NO + 111) +#define EHOSTDOWN (ERROR_BASE_NO + 112) +#define EHOSTUNREACH (ERROR_BASE_NO + 113) +#define EALREADY (ERROR_BASE_NO + 114) +#define EINPROGRESS (ERROR_BASE_NO + 115) +#define ESTALE (ERROR_BASE_NO + 116) +#define EUCLEAN (ERROR_BASE_NO + 117) +#define ENOTNAM (ERROR_BASE_NO + 118) +#define ENAVAIL (ERROR_BASE_NO + 119) +#define EISNAM (ERROR_BASE_NO + 120) +#define EREMOTEIO (ERROR_BASE_NO + 121) +#define EDQUOT (ERROR_BASE_NO + 122) +#define ENOMEDIUM (ERROR_BASE_NO + 123) +#define EMEDIUMTYPE (ERROR_BASE_NO + 124) +#define ECANCELED (ERROR_BASE_NO + 125) +#define ENOKEY (ERROR_BASE_NO + 126) +#define EKEYEXPIRED (ERROR_BASE_NO + 127) +#define EKEYREVOKED (ERROR_BASE_NO + 128) +#define EKEYREJECTED (ERROR_BASE_NO + 129) +#define EOWNERDEAD (ERROR_BASE_NO + 130) +#define ENOTRECOVERABLE (ERROR_BASE_NO + 131) +#define ERFKILL (ERROR_BASE_NO + 132) +#define EHWPOISON (ERROR_BASE_NO + 133) +#endif + +#endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 9996212444..4cdfe77343 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -21,6 +21,7 @@ */ #include "sys/time.h" +#include #include #ifdef RT_USING_DEVICE diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c index 794ac3a07d..da80242ecc 100644 --- a/components/libc/getline/posix_getline.c +++ b/components/libc/getline/posix_getline.c @@ -11,8 +11,8 @@ #include "posix_getline.h" #include -#include -#include +#include +#include ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { char *cur_pos, *new_lineptr; @@ -43,7 +43,7 @@ ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { break; if ((*lineptr + *n - cur_pos) < 2) { - if (SSIZE_MAX / 2 < *n) { + if (LONG_MAX / 2 < *n) { #ifdef EOVERFLOW errno = EOVERFLOW; #else diff --git a/components/libc/pthreads/posix_types.h b/components/libc/pthreads/posix_types.h index 942657ef39..5838e8b370 100644 --- a/components/libc/pthreads/posix_types.h +++ b/components/libc/pthreads/posix_types.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #endif diff --git a/components/libc/termios/posix_termios.c b/components/libc/termios/posix_termios.c index 01ba010c86..10a1f466d6 100644 --- a/components/libc/termios/posix_termios.c +++ b/components/libc/termios/posix_termios.c @@ -11,7 +11,7 @@ #include #include #include - +#include #include int tcgetattr(int fd, struct termios *tio) diff --git a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h index 8dd59e8dee..880366d1f8 100644 --- a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h +++ b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h @@ -105,7 +105,7 @@ void sys_arch_assert(const char* file, int line); #define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0) #define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0) -#include "string.h" +#include #define SYS_ARCH_DECL_PROTECT(level) #define SYS_ARCH_PROTECT(level) rt_enter_critical() diff --git a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h index e3014f552c..a17b162805 100644 --- a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h @@ -84,7 +84,7 @@ void sys_arch_assert(const char* file, int line); #define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0) #define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0) -#include "string.h" +#include #define SYS_ARCH_DECL_PROTECT(level) #define SYS_ARCH_PROTECT(level) rt_enter_critical() diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h index 09bd223aa4..b334c5ac17 100644 --- a/components/net/lwip-2.0.2/src/lwipopts.h +++ b/components/net/lwip-2.0.2/src/lwipopts.h @@ -5,6 +5,8 @@ #define ERRNO 1 +#define LWIP_ERRNO_STDINCLUDE + #define LWIP_IPV4 1 #ifdef RT_USING_LWIP_IPV6 diff --git a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h index 413fef65df..e85ca1d085 100644 --- a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h @@ -46,7 +46,7 @@ #define X32_F "lx" #ifdef RT_USING_LIBC -#include +#include #ifndef ENSRNOTFOUND #define ENSRNOTFOUND 163 /* Domain name not found */ #endif diff --git a/components/net/lwip-2.1.2/src/include/lwip/errno.h b/components/net/lwip-2.1.2/src/include/lwip/errno.h index 48d6b539d8..9fd88fc91a 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/errno.h +++ b/components/net/lwip-2.1.2/src/include/lwip/errno.h @@ -181,7 +181,7 @@ extern int errno; /* Define LWIP_ERRNO_STDINCLUDE if you want to include here */ #ifdef LWIP_ERRNO_STDINCLUDE -#include +#include #else /* LWIP_ERRNO_STDINCLUDE */ /* Define LWIP_ERRNO_INCLUDE to an equivalent of to include the error defines here */ #ifdef LWIP_ERRNO_INCLUDE diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h index 220bb6fa41..8c2bfbdd76 100644 --- a/components/net/lwip-2.1.2/src/lwipopts.h +++ b/components/net/lwip-2.1.2/src/lwipopts.h @@ -5,6 +5,7 @@ #define ERRNO 1 +#define LWIP_ERRNO_STDINCLUDE #define LWIP_SOCKET_SELECT 1 #define LWIP_SOCKET_POLL 1 diff --git a/components/net/sal_socket/socket/net_sockets.c b/components/net/sal_socket/socket/net_sockets.c index 3637635d50..7d4db34327 100644 --- a/components/net/sal_socket/socket/net_sockets.c +++ b/components/net/sal_socket/socket/net_sockets.c @@ -13,7 +13,7 @@ #include #include #include - +#include #include int accept(int s, struct sockaddr *addr, socklen_t *addrlen) diff --git a/examples/libc/ex3.c b/examples/libc/ex3.c index 1697e7145b..615ed8f35c 100644 --- a/examples/libc/ex3.c +++ b/examples/libc/ex3.c @@ -9,7 +9,7 @@ /* Multi-thread searching. Illustrates: thread cancellation, cleanup handlers. */ -#include +#include #include #include #include diff --git a/examples/libc/ex6.c b/examples/libc/ex6.c index ac6319d74c..ba687aa46f 100644 --- a/examples/libc/ex6.c +++ b/examples/libc/ex6.c @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes */ -#include +#include #include #include #include diff --git a/examples/libc/ex7.c b/examples/libc/ex7.c index e885f79c57..d1f05dbdcd 100644 --- a/examples/libc/ex7.c +++ b/examples/libc/ex7.c @@ -11,7 +11,7 @@ * Test case that illustrates a timed wait on a condition variable. */ -#include +#include #include #include #include diff --git a/examples/libc/file.c b/examples/libc/file.c index 79cdce3092..878d3a98d7 100644 --- a/examples/libc/file.c +++ b/examples/libc/file.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/examples/libc/memory.c b/examples/libc/memory.c index 063d90cfdc..4a31b69017 100644 --- a/examples/libc/memory.c +++ b/examples/libc/memory.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include static int errors = 0; static void merror(const char *msg) diff --git a/include/libc/libc_errno.h b/include/libc/libc_errno.h deleted file mode 100644 index 30d6092e33..0000000000 --- a/include/libc/libc_errno.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2016-11-12 Bernard The first version - */ - -#ifndef LIBC_ERRNO_H__ -#define LIBC_ERRNO_H__ - -#include - -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -/* use errno.h file in toolchains */ -#include -#endif - -#if defined(__CC_ARM) -/* -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(RT_USING_NEWLIB) && !defined(_WIN32) && !(defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) - -#define EPERM (ERROR_BASE_NO + 1) -#define ENOENT (ERROR_BASE_NO + 2) -#define ESRCH (ERROR_BASE_NO + 3) -#define EINTR (ERROR_BASE_NO + 4) -#define EIO (ERROR_BASE_NO + 5) -#define ENXIO (ERROR_BASE_NO + 6) -#define E2BIG (ERROR_BASE_NO + 7) -#define ENOEXEC (ERROR_BASE_NO + 8) -#define EBADF (ERROR_BASE_NO + 9) -#define ECHILD (ERROR_BASE_NO + 10) -#define EAGAIN (ERROR_BASE_NO + 11) - -#ifndef ENOMEM -#define ENOMEM (ERROR_BASE_NO + 12) -#endif - -#define EACCES (ERROR_BASE_NO + 13) -#define EFAULT (ERROR_BASE_NO + 14) -#define ENOTBLK (ERROR_BASE_NO + 15) -#define EBUSY (ERROR_BASE_NO + 16) -#define EEXIST (ERROR_BASE_NO + 17) -#define EXDEV (ERROR_BASE_NO + 18) -#define ENODEV (ERROR_BASE_NO + 19) -#define ENOTDIR (ERROR_BASE_NO + 20) -#define EISDIR (ERROR_BASE_NO + 21) - -#ifndef EINVAL -#define EINVAL (ERROR_BASE_NO + 22) -#endif - -#define ENFILE (ERROR_BASE_NO + 23) -#define EMFILE (ERROR_BASE_NO + 24) -#define ENOTTY (ERROR_BASE_NO + 25) -#define ETXTBSY (ERROR_BASE_NO + 26) -#define EFBIG (ERROR_BASE_NO + 27) -#define ENOSPC (ERROR_BASE_NO + 28) -#define ESPIPE (ERROR_BASE_NO + 29) -#define EROFS (ERROR_BASE_NO + 30) -#define EMLINK (ERROR_BASE_NO + 31) -#define EPIPE (ERROR_BASE_NO + 32) - -#ifndef EDOM -#define EDOM (ERROR_BASE_NO + 33) -#endif - -#ifndef ERANGE -#define ERANGE (ERROR_BASE_NO + 34) -#endif - -#define EDEADLK (ERROR_BASE_NO + 35) -#define ENAMETOOLONG (ERROR_BASE_NO + 36) -#define ENOLCK (ERROR_BASE_NO + 37) -#define ENOSYS (ERROR_BASE_NO + 38) -#define ENOTEMPTY (ERROR_BASE_NO + 39) -#define ELOOP (ERROR_BASE_NO + 40) -#define EWOULDBLOCK EAGAIN -#define ENOMSG (ERROR_BASE_NO + 42) -#define EIDRM (ERROR_BASE_NO + 43) -#define ECHRNG (ERROR_BASE_NO + 44) -#define EL2NSYNC (ERROR_BASE_NO + 45) -#define EL3HLT (ERROR_BASE_NO + 46) -#define EL3RST (ERROR_BASE_NO + 47) -#define ELNRNG (ERROR_BASE_NO + 48) -#define EUNATCH (ERROR_BASE_NO + 49) -#define ENOCSI (ERROR_BASE_NO + 50) -#define EL2HLT (ERROR_BASE_NO + 51) -#define EBADE (ERROR_BASE_NO + 52) -#define EBADR (ERROR_BASE_NO + 53) -#define EXFULL (ERROR_BASE_NO + 54) -#define ENOANO (ERROR_BASE_NO + 55) -#define EBADRQC (ERROR_BASE_NO + 56) -#define EBADSLT (ERROR_BASE_NO + 57) -#define EDEADLOCK EDEADLK -#define EBFONT (ERROR_BASE_NO + 59) -#define ENOSTR (ERROR_BASE_NO + 60) -#define ENODATA (ERROR_BASE_NO + 61) -#define ETIME (ERROR_BASE_NO + 62) -#define ENOSR (ERROR_BASE_NO + 63) -#define ENONET (ERROR_BASE_NO + 64) -#define ENOPKG (ERROR_BASE_NO + 65) -#define EREMOTE (ERROR_BASE_NO + 66) -#define ENOLINK (ERROR_BASE_NO + 67) -#define EADV (ERROR_BASE_NO + 68) -#define ESRMNT (ERROR_BASE_NO + 69) -#define ECOMM (ERROR_BASE_NO + 70) -#define EPROTO (ERROR_BASE_NO + 71) -#define EMULTIHOP (ERROR_BASE_NO + 72) -#define EDOTDOT (ERROR_BASE_NO + 73) -#define EBADMSG (ERROR_BASE_NO + 74) -#define EOVERFLOW (ERROR_BASE_NO + 75) -#define ENOTUNIQ (ERROR_BASE_NO + 76) -#define EBADFD (ERROR_BASE_NO + 77) -#define EREMCHG (ERROR_BASE_NO + 78) -#define ELIBACC (ERROR_BASE_NO + 79) -#define ELIBBAD (ERROR_BASE_NO + 80) -#define ELIBSCN (ERROR_BASE_NO + 81) -#define ELIBMAX (ERROR_BASE_NO + 82) -#define ELIBEXEC (ERROR_BASE_NO + 83) - -#ifndef EILSEQ -#define EILSEQ (ERROR_BASE_NO + 84) -#endif - -#define ERESTART (ERROR_BASE_NO + 85) -#define ESTRPIPE (ERROR_BASE_NO + 86) -#define EUSERS (ERROR_BASE_NO + 87) -#define ENOTSOCK (ERROR_BASE_NO + 88) -#define EDESTADDRREQ (ERROR_BASE_NO + 89) -#define EMSGSIZE (ERROR_BASE_NO + 90) -#define EPROTOTYPE (ERROR_BASE_NO + 91) -#define ENOPROTOOPT (ERROR_BASE_NO + 92) -#define EPROTONOSUPPORT (ERROR_BASE_NO + 93) -#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) -#define EOPNOTSUPP (ERROR_BASE_NO + 95) -#define ENOTSUP EOPNOTSUPP -#define EPFNOSUPPORT (ERROR_BASE_NO + 96) -#define EAFNOSUPPORT (ERROR_BASE_NO + 97) -#define EADDRINUSE (ERROR_BASE_NO + 98) -#define EADDRNOTAVAIL (ERROR_BASE_NO + 99) -#define ENETDOWN (ERROR_BASE_NO + 100) -#define ENETUNREACH (ERROR_BASE_NO + 101) -#define ENETRESET (ERROR_BASE_NO + 102) -#define ECONNABORTED (ERROR_BASE_NO + 103) -#define ECONNRESET (ERROR_BASE_NO + 104) -#define ENOBUFS (ERROR_BASE_NO + 105) -#define EISCONN (ERROR_BASE_NO + 106) -#define ENOTCONN (ERROR_BASE_NO + 107) -#define ESHUTDOWN (ERROR_BASE_NO + 108) -#define ETOOMANYREFS (ERROR_BASE_NO + 109) -#define ETIMEDOUT (ERROR_BASE_NO + 110) -#define ECONNREFUSED (ERROR_BASE_NO + 111) -#define EHOSTDOWN (ERROR_BASE_NO + 112) -#define EHOSTUNREACH (ERROR_BASE_NO + 113) -#define EALREADY (ERROR_BASE_NO + 114) -#define EINPROGRESS (ERROR_BASE_NO + 115) -#define ESTALE (ERROR_BASE_NO + 116) -#define EUCLEAN (ERROR_BASE_NO + 117) -#define ENOTNAM (ERROR_BASE_NO + 118) -#define ENAVAIL (ERROR_BASE_NO + 119) -#define EISNAM (ERROR_BASE_NO + 120) -#define EREMOTEIO (ERROR_BASE_NO + 121) -#define EDQUOT (ERROR_BASE_NO + 122) -#define ENOMEDIUM (ERROR_BASE_NO + 123) -#define EMEDIUMTYPE (ERROR_BASE_NO + 124) -#define ECANCELED (ERROR_BASE_NO + 125) -#define ENOKEY (ERROR_BASE_NO + 126) -#define EKEYEXPIRED (ERROR_BASE_NO + 127) -#define EKEYREVOKED (ERROR_BASE_NO + 128) -#define EKEYREJECTED (ERROR_BASE_NO + 129) -#define EOWNERDEAD (ERROR_BASE_NO + 130) -#define ENOTRECOVERABLE (ERROR_BASE_NO + 131) -#define ERFKILL (ERROR_BASE_NO + 132) -#define EHWPOISON (ERROR_BASE_NO + 133) - -#endif - -#endif diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h deleted file mode 100644 index 36b8dbb202..0000000000 --- a/include/libc/libc_limits.h +++ /dev/null @@ -1,25 +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 the first version - */ - -#ifndef LIBC_LIMITS_H__ -#define LIBC_LIMITS_H__ - -#include -#include - -#ifdef RT_USING_POSIX - -#ifndef SSIZE_MAX -# define SSIZE_MAX LONG_MAX -#endif - -#endif - -#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 50bddc6ee8..a62051e157 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -13,14 +13,12 @@ /* definitions for libc if toolchain has no these definitions */ #include "libc/libc_stat.h" -#include "libc/libc_errno.h" #include "libc/libc_fcntl.h" #include "libc/libc_ioctl.h" #include "libc/libc_dirent.h" #include "libc/libc_signal.h" #include "libc/libc_fdset.h" -#include "libc/libc_limits.h" #include "libc/libc_stdio.h" #ifndef RT_USING_LIBC -- cgit v1.3.1 From 0e32728a5d688c51bc844617de7d89d7fdbe34d0 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 23 May 2021 00:14:22 +0800 Subject: [libc][rtlibc] remove libc_ioctl.h --- components/libc/compilers/common/sys/ioctl.h | 220 +++++++++++++++++++++++++ include/libc/libc_ioctl.h | 229 --------------------------- include/rtlibc.h | 1 - 3 files changed, 220 insertions(+), 230 deletions(-) delete mode 100644 include/libc/libc_ioctl.h (limited to 'include') diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index 648d90230d..51f51f2ea4 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -15,4 +15,224 @@ #include #endif +struct winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) +#define _IOC_NONE 0U +#define _IOC_WRITE 1U +#define _IOC_READ 2U + +#if !defined (_WIN32) && !defined (__TASKING__) +#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) + +#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ +#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ +#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */ +#endif + +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TCGETA 0x5405 +#define TCSETA 0x5406 +#define TCSETAW 0x5407 +#define TCSETAF 0x5408 +#define TCSBRK 0x5409 +#define TCXONC 0x540A +#define TCFLSH 0x540B +#define TIOCEXCL 0x540C +#define TIOCNXCL 0x540D +#define TIOCSCTTY 0x540E +#define TIOCGPGRP 0x540F +#define TIOCSPGRP 0x5410 +#define TIOCOUTQ 0x5411 +#define TIOCSTI 0x5412 +#define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 +#define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 +#define TIOCMSET 0x5418 +#define TIOCGSOFTCAR 0x5419 +#define TIOCSSOFTCAR 0x541A +#ifndef FIONREAD +#define FIONREAD 0x541B +#endif +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +#ifndef FIONBIO +#define FIONBIO 0x5421 +#endif +#define TIOCNOTTY 0x5422 +#define TIOCSETD 0x5423 +#define TIOCGETD 0x5424 +#define TCSBRKP 0x5425 +#define TIOCSBRK 0x5427 +#define TIOCCBRK 0x5428 +#define TIOCGSID 0x5429 +#define TIOCGRS485 0x542E +#define TIOCSRS485 0x542F +#define TIOCGPTN 0x80045430 +#define TIOCSPTLCK 0x40045431 +#define TIOCGDEV 0x80045432 +#define TCGETX 0x5432 +#define TCSETX 0x5433 +#define TCSETXF 0x5434 +#define TCSETXW 0x5435 +#define TIOCSIG 0x40045436 +#define TIOCVHANGUP 0x5437 +#define TIOCGPKT 0x80045438 +#define TIOCGPTLCK 0x80045439 +#define TIOCGEXCL 0x80045440 + +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 + +#ifndef _WIN32 +#define FIOASYNC 0x5452 +#endif + +#define TIOCSERCONFIG 0x5453 +#define TIOCSERGWILD 0x5454 +#define TIOCSERSWILD 0x5455 +#define TIOCGLCKTRMIOS 0x5456 +#define TIOCSLCKTRMIOS 0x5457 +#define TIOCSERGSTRUCT 0x5458 +#define TIOCSERGETLSR 0x5459 +#define TIOCSERGETMULTI 0x545A +#define TIOCSERSETMULTI 0x545B + +#define TIOCMIWAIT 0x545C +#define TIOCGICOUNT 0x545D +#define FIOQSIZE 0x5460 + +#define TIOCPKT_DATA 0 +#define TIOCPKT_FLUSHREAD 1 +#define TIOCPKT_FLUSHWRITE 2 +#define TIOCPKT_STOP 4 +#define TIOCPKT_START 8 +#define TIOCPKT_NOSTOP 16 +#define TIOCPKT_DOSTOP 32 +#define TIOCPKT_IOCTL 64 + +#define TIOCSER_TEMT 0x01 + +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG +#define TIOCM_OUT1 0x2000 +#define TIOCM_OUT2 0x4000 +#define TIOCM_LOOP 0x8000 + +#define N_TTY 0 +#define N_SLIP 1 +#define N_MOUSE 2 +#define N_PPP 3 +#define N_STRIP 4 +#define N_AX25 5 +#define N_X25 6 +#define N_6PACK 7 +#define N_MASC 8 +#define N_R3964 9 +#define N_PROFIBUS_FDL 10 +#define N_IRDA 11 +#define N_SMSBLOCK 12 +#define N_HDLC 13 +#define N_SYNC_PPP 14 +#define N_HCI 15 + +#define FIOSETOWN 0x8901 +#define SIOCSPGRP 0x8902 +#define FIOGETOWN 0x8903 +#define SIOCGPGRP 0x8904 +#ifndef SIOCATMARK +#define SIOCATMARK 0x8905 +#endif +#define SIOCGSTAMP 0x8906 +#define SIOCGSTAMPNS 0x8907 + +#define SIOCADDRT 0x890B +#define SIOCDELRT 0x890C +#define SIOCRTMSG 0x890D + +#define SIOCGIFNAME 0x8910 +#define SIOCSIFLINK 0x8911 +#define SIOCGIFCONF 0x8912 +#define SIOCGIFFLAGS 0x8913 +#define SIOCSIFFLAGS 0x8914 +#define SIOCGIFADDR 0x8915 +#define SIOCSIFADDR 0x8916 +#define SIOCGIFDSTADDR 0x8917 +#define SIOCSIFDSTADDR 0x8918 +#define SIOCGIFBRDADDR 0x8919 +#define SIOCSIFBRDADDR 0x891a +#define SIOCGIFNETMASK 0x891b +#define SIOCSIFNETMASK 0x891c +#define SIOCGIFMETRIC 0x891d +#define SIOCSIFMETRIC 0x891e +#define SIOCGIFMEM 0x891f +#define SIOCSIFMEM 0x8920 +#define SIOCGIFMTU 0x8921 +#define SIOCSIFMTU 0x8922 +#define SIOCSIFNAME 0x8923 +#define SIOCSIFHWADDR 0x8924 +#define SIOCGIFENCAP 0x8925 +#define SIOCSIFENCAP 0x8926 +#define SIOCGIFHWADDR 0x8927 +#define SIOCGIFSLAVE 0x8929 +#define SIOCSIFSLAVE 0x8930 +#define SIOCADDMULTI 0x8931 +#define SIOCDELMULTI 0x8932 +#define SIOCGIFINDEX 0x8933 +#define SIOGIFINDEX SIOCGIFINDEX +#define SIOCSIFPFLAGS 0x8934 +#define SIOCGIFPFLAGS 0x8935 +#define SIOCDIFADDR 0x8936 +#define SIOCSIFHWBROADCAST 0x8937 +#define SIOCGIFCOUNT 0x8938 + +#define SIOCGIFBR 0x8940 +#define SIOCSIFBR 0x8941 + +#define SIOCGIFTXQLEN 0x8942 +#define SIOCSIFTXQLEN 0x8943 + +#define SIOCDARP 0x8953 +#define SIOCGARP 0x8954 +#define SIOCSARP 0x8955 + +#define SIOCDRARP 0x8960 +#define SIOCGRARP 0x8961 +#define SIOCSRARP 0x8962 + +#define SIOCGIFMAP 0x8970 +#define SIOCSIFMAP 0x8971 + +#define SIOCADDDLCI 0x8980 +#define SIOCDELDLCI 0x8981 + +#define SIOCDEVPRIVATE 0x89F0 +#define SIOCPROTOPRIVATE 0x89E0 + #endif diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h deleted file mode 100644 index 05f0daa238..0000000000 --- a/include/libc/libc_ioctl.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-01-21 Bernard the first version - */ - -#ifndef LIBC_IOCTL_H__ -#define LIBC_IOCTL_H__ - -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U - -#if !defined (_WIN32) && !defined (__TASKING__) -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) - -#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ -#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ -#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding - * in send queue. */ -#endif - -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -// #define FIONREAD 0x541B -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -// #define FIONBIO 0x5421 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGRS485 0x542E -#define TIOCSRS485 0x542F -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TIOCGDEV 0x80045432 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 -#define TIOCSIG 0x40045436 -#define TIOCVHANGUP 0x5437 -#define TIOCGPKT 0x80045438 -#define TIOCGPTLCK 0x80045439 -#define TIOCGEXCL 0x80045440 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 - -#ifndef _WIN32 -#define FIOASYNC 0x5452 -#endif - -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 - -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; - -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -// #define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 -#define SIOCGSTAMPNS 0x8907 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 - -#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 50bddc6ee8..d69f3ca185 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -16,7 +16,6 @@ #include "libc/libc_errno.h" #include "libc/libc_fcntl.h" -#include "libc/libc_ioctl.h" #include "libc/libc_dirent.h" #include "libc/libc_signal.h" #include "libc/libc_fdset.h" -- cgit v1.3.1 From 8b82b834826249dff299353da44188429d18dde2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 30 May 2021 11:43:44 +0800 Subject: [kernel] 增加rt_mutex_trytake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 1 + src/ipc.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/rtthread.h b/include/rtthread.h index 784b208a76..ccd2d147a8 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -322,6 +322,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag); rt_err_t rt_mutex_delete(rt_mutex_t mutex); rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time); +rt_err_t rt_mutex_trytake(rt_mutex_t mutex); rt_err_t rt_mutex_release(rt_mutex_t mutex); rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg); #endif diff --git a/src/ipc.c b/src/ipc.c index 22e0f06bc6..6cd38b74ab 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -37,7 +37,8 @@ * 2020-07-29 Meco Man fix thread->event_set/event_info when received an * event without pending * 2020-10-11 Meco Man add value overflow-check code - * 2021-01-03 Meco Man add rt_mb_urgent() + * 2021-01-03 Meco Man implement rt_mb_urgent() + * 2021-05-30 Meco Man implement rt_mutex_trytake() * 2021-01-20 hupu fix priority inversion bug of mutex */ @@ -452,7 +453,7 @@ RTM_EXPORT(rt_sem_take); */ rt_err_t rt_sem_trytake(rt_sem_t sem) { - return rt_sem_take(sem, 0); + return rt_sem_take(sem, RT_WAITING_NO); } RTM_EXPORT(rt_sem_trytake); @@ -843,6 +844,19 @@ __again: } RTM_EXPORT(rt_mutex_take); +/** + * This function will try to take a mutex and immediately return + * + * @param mutex the mutex object + * + * @return the error code + */ +rt_err_t rt_mutex_trytake(rt_mutex_t mutex) +{ + return rt_mutex_take(mutex, RT_WAITING_NO); +} +RTM_EXPORT(rt_mutex_trytake); + /** * This function will release a mutex, if there are threads suspended on mutex, * it will be waked up. -- cgit v1.3.1 From 921e6064260f7afa80f3d10424bd49526241a3ee Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 13 Jun 2021 17:36:42 +0800 Subject: 将defined(__CC_ARM) || defined(__CLANG_ARM) 改为 ifdef __ARMCC_VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/shell.c | 2 +- include/libc/libc_signal.h | 2 +- include/rtlibc.h | 2 +- include/rtthread.h | 2 +- src/components.c | 4 ++-- src/kservice.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/components/finsh/shell.c b/components/finsh/shell.c index a749660629..c89139c0ed 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -817,7 +817,7 @@ int finsh_system_init(void) rt_thread_t tid; #ifdef FINSH_USING_SYMTAB -#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ +#ifdef __ARMCC_VERSION /* ARM C Compiler */ extern const int FSymTab$$Base; extern const int FSymTab$$Limit; extern const int VSymTab$$Base; diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index 8a4cc0d738..1fb8194643 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -71,7 +71,7 @@ typedef unsigned long sigset_t; #include -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION #define SIGHUP 1 /* #define SIGINT 2 */ diff --git a/include/rtlibc.h b/include/rtlibc.h index a62051e157..4e7caa81fc 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -22,7 +22,7 @@ #include "libc/libc_stdio.h" #ifndef RT_USING_LIBC -#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) +#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) typedef signed long off_t; typedef int mode_t; #endif diff --git a/include/rtthread.h b/include/rtthread.h index ccd2d147a8..cf897b0e5e 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -567,7 +567,7 @@ rt_size_t rt_strlen(const char *src); #endif /*RT_KSERVICE_USING_STDLIB*/ char *rt_strdup(const char *s); -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION /* lack strdup interface */ char* strdup(const char* str); #endif diff --git a/src/components.c b/src/components.c index d684d5e6fd..e156b783e4 100644 --- a/src/components.c +++ b/src/components.c @@ -134,7 +134,7 @@ void rt_application_init(void); void rt_hw_board_init(void); int rtthread_startup(void); -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION extern int $Super$$main(void); /* re-define main function */ int $Sub$$main(void) @@ -183,7 +183,7 @@ void main_thread_entry(void *parameter) rt_hw_secondary_cpu_up(); #endif /* RT_USING_SMP */ /* invoke system main function */ -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION { extern int $Super$$main(void); $Super$$main(); /* for ARMCC. */ diff --git a/src/kservice.c b/src/kservice.c index 448b2d717d..49e1486078 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -532,7 +532,7 @@ char *rt_strdup(const char *s) return tmp; } RTM_EXPORT(rt_strdup); -#if defined(__CC_ARM) || defined(__CLANG_ARM) +#ifdef __ARMCC_VERSION char *strdup(const char *s) __attribute__((alias("rt_strdup"))); #endif #endif /* RT_USING_HEAP */ -- cgit v1.3.1 From 41875c17ff3ec878f18920f67cbebb73a0447f7a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 17 Jun 2021 23:20:44 +0800 Subject: [rtthread.h] 移除rt_sscanf声明 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/rtthread.h b/include/rtthread.h index ccd2d147a8..980c4771b3 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -522,7 +522,6 @@ rt_int32_t rt_vsprintf(char *dest, const char *format, va_list arg_ptr); rt_int32_t rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args); rt_int32_t rt_sprintf(char *buf, const char *format, ...); rt_int32_t rt_snprintf(char *buf, rt_size_t size, const char *format, ...); -rt_int32_t rt_sscanf(const char *buf, const char *fmt, ...); #if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE) rt_device_t rt_console_set_device(const char *name); -- cgit v1.3.1 From 43a80193c4d959c8dd150bfc0a52650a357244bf Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 21 Jun 2021 21:55:25 +0800 Subject: [rtlibc] remove libc_stdio.h --- include/libc/libc_stdio.h | 22 ---------------------- include/rtlibc.h | 1 - 2 files changed, 23 deletions(-) delete mode 100644 include/libc/libc_stdio.h (limited to 'include') diff --git a/include/libc/libc_stdio.h b/include/libc/libc_stdio.h deleted file mode 100644 index 565e1bfd32..0000000000 --- a/include/libc/libc_stdio.h +++ /dev/null @@ -1,22 +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 the first version - */ - -#ifndef LIBC_STDIO_H__ -#define LIBC_STDIO_H__ - -#include - -#ifdef RT_USING_POSIX_GETLINE - -#include - -#endif - -#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 1fd6053deb..d78ec8046f 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -18,7 +18,6 @@ #include "libc/libc_dirent.h" #include "libc/libc_signal.h" #include "libc/libc_fdset.h" -#include "libc/libc_stdio.h" #ifndef RT_USING_LIBC #if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) -- cgit v1.3.1 From 05bb1a50b0d26b7c60c82ccb4ff8a66a501feac3 Mon Sep 17 00:00:00 2001 From: fenghuijie Date: Sat, 3 Jul 2021 17:54:58 +0800 Subject: 添加idle回收资源的修改 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtthread.h | 6 ++- src/Kconfig | 5 ++ src/idle.c | 154 +++++++++++++++++++++++++++++++++++++++++++++-------- src/scheduler.c | 5 -- src/thread.c | 40 ++++++++------ 5 files changed, 168 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/include/rtthread.h b/include/rtthread.h index 0583ce6434..f9d0b45e86 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -168,7 +168,6 @@ void rt_thread_idle_init(void); rt_err_t rt_thread_idle_sethook(void (*hook)(void)); rt_err_t rt_thread_idle_delhook(void (*hook)(void)); #endif -void rt_thread_idle_excute(void); rt_thread_t rt_thread_idle_gethandler(void); /* @@ -187,6 +186,7 @@ rt_uint16_t rt_critical_level(void); #ifdef RT_USING_HOOK void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to)); +void rt_scheduler_switchto_sethook(void (*hook)(struct rt_thread *tid)); #endif #ifdef RT_USING_SMP @@ -396,6 +396,10 @@ rt_err_t rt_mq_recv(rt_mq_t mq, rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg); #endif +/* defunct */ +void rt_thread_defunct_enqueue(rt_thread_t thread); +rt_thread_t rt_thread_defunct_dequeue(void); + /* * spinlock */ diff --git a/src/Kconfig b/src/Kconfig index 9a49146dff..e0582f5663 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -98,6 +98,11 @@ config IDLE_THREAD_STACK_SIZE int "The stack size of idle thread" default 256 +config SYSTEM_THREAD_STACK_SIZE + int "The stack size of system thread (for defunct etc.)" + depends on RT_USING_SMP + default IDLE_THREAD_STACK_SIZE + config RT_USING_TIMER_SOFT bool "Enable software timer with a timer thread" default y diff --git a/src/idle.c b/src/idle.c index db256a6010..a571e487cf 100644 --- a/src/idle.c +++ b/src/idle.c @@ -44,12 +44,22 @@ #define _CPUS_NR 1 #endif /* RT_USING_SMP */ -extern rt_list_t rt_thread_defunct; +static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);; static struct rt_thread idle[_CPUS_NR]; ALIGN(RT_ALIGN_SIZE) static rt_uint8_t rt_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE]; +#ifdef RT_USING_SMP +#ifndef SYSTEM_THREAD_STACK_SIZE +#define SYSTEM_THREAD_STACK_SIZE IDLE_THREAD_STACK_SIZE +#endif +static struct rt_thread rt_system_thread; +ALIGN(RT_ALIGN_SIZE) +static rt_uint8_t rt_system_stack[SYSTEM_THREAD_STACK_SIZE]; +static struct rt_semaphore system_sem; +#endif + #ifdef RT_USING_IDLE_HOOK #ifndef RT_IDLE_HOOK_LIST_SIZE #define RT_IDLE_HOOK_LIST_SIZE 4 @@ -127,43 +137,75 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void)) #endif /* RT_USING_IDLE_HOOK */ -#ifdef RT_USING_HEAP +#ifdef RT_USING_MODULE /* Return whether there is defunctional thread to be deleted. */ rt_inline int _has_defunct_thread(void) { /* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)". - * So the compiler has a good reason that the rt_thread_defunct list does - * not change within rt_thread_idle_excute thus optimize the "while" loop + * So the compiler has a good reason that the _rt_thread_defunct list does + * not change within rt_thread_defunct_exceute thus optimize the "while" loop * into a "if". * * So add the volatile qualifier here. */ - const volatile rt_list_t *l = (const volatile rt_list_t *)&rt_thread_defunct; + const volatile rt_list_t *l = (const volatile rt_list_t *)&_rt_thread_defunct; return l->next != l; } -#endif /* RT_USING_HEAP */ +#endif /* RT_USING_MODULE */ + +/* enqueue a thread to defunct queue + * it must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable + */ +void rt_thread_defunct_enqueue(rt_thread_t thread) +{ + rt_list_insert_after(&_rt_thread_defunct, &thread->tlist); +#ifdef RT_USING_SMP + rt_sem_release(&system_sem); +#endif +} + +/* dequeue a thread from defunct queue + * it must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable + */ +rt_thread_t rt_thread_defunct_dequeue(void) +{ + rt_thread_t thread = RT_NULL; + rt_list_t *l = &_rt_thread_defunct; + + if (l->next != l) + { + thread = rt_list_entry(l->next, + struct rt_thread, + tlist); + rt_list_remove(&(thread->tlist)); + } + return thread; +} /** * @ingroup Thread * * This function will perform system background job when system idle. */ -void rt_thread_idle_excute(void) +static void rt_defunct_execute(void) { - /* Loop until there is no dead thread. So one call to rt_thread_idle_excute + /* Loop until there is no dead thread. So one call to rt_defunct_execute * will do all the cleanups. */ - /* disable interrupt */ - - RT_DEBUG_NOT_IN_INTERRUPT; - -#ifdef RT_USING_HEAP while (1) { rt_base_t lock; rt_thread_t thread; + void (*cleanup)(struct rt_thread *tid); +#ifdef RT_USING_MODULE + struct rt_dlmodule *module = RT_NULL; +#endif + RT_DEBUG_NOT_IN_INTERRUPT; + + /* disable interrupt */ lock = rt_hw_interrupt_disable(); +#ifdef RT_USING_MODULE /* check whether list is empty */ if (!_has_defunct_thread()) { @@ -171,18 +213,56 @@ void rt_thread_idle_excute(void) break; } /* get defunct thread */ - thread = rt_list_entry(rt_thread_defunct.next, + thread = rt_list_entry(_rt_thread_defunct.next, struct rt_thread, tlist); + module = (struct rt_dlmodule*)thread->module_id; + if (module) + { + dlmodule_destroy(module); + } /* remove defunct thread */ rt_list_remove(&(thread->tlist)); - /* release thread's stack */ - RT_KERNEL_FREE(thread->stack_addr); - /* delete thread object */ - rt_object_delete((rt_object_t)thread); - rt_hw_interrupt_enable(lock); +#else + thread = rt_thread_defunct_dequeue(); + if (!thread) + { + rt_hw_interrupt_enable(lock); + break; + } +#endif + /* invoke thread cleanup */ + cleanup = thread->cleanup; + if (cleanup != RT_NULL) + { + rt_hw_interrupt_enable(lock); + cleanup(thread); + lock = rt_hw_interrupt_disable(); + } + +#ifdef RT_USING_SIGNALS + rt_thread_free_sig(thread); +#endif + + /* if it's a system object, not delete it */ + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + /* detach this object */ + rt_object_detach((rt_object_t)thread); + /* enable interrupt */ + rt_hw_interrupt_enable(lock); + } + else + { + rt_hw_interrupt_enable(lock); +#ifdef RT_USING_HEAP + /* release thread's stack */ + RT_KERNEL_FREE(thread->stack_addr); + /* delete thread object */ + rt_object_delete((rt_object_t)thread); +#endif + } } -#endif /* RT_USING_HEAP */ } extern void rt_system_power_manager(void); @@ -214,13 +294,27 @@ static void rt_thread_idle_entry(void *parameter) } #endif /* RT_USING_IDLE_HOOK */ - rt_thread_idle_excute(); +#ifndef RT_USING_SMP + rt_defunct_execute(); +#endif /* RT_USING_SMP */ + #ifdef RT_USING_PM rt_system_power_manager(); #endif /* RT_USING_PM */ } } +#ifdef RT_USING_SMP +static void rt_thread_system_entry(void *parameter) +{ + while (1) + { + rt_sem_take(&system_sem, RT_WAITING_FOREVER); + rt_defunct_execute(); + } +} +#endif + /** * @ingroup SystemInit * @@ -250,6 +344,24 @@ void rt_thread_idle_init(void) /* startup */ rt_thread_startup(&idle[i]); } + +#ifdef RT_USING_SMP + RT_ASSERT(RT_THREAD_PRIORITY_MAX > 2); + + rt_sem_init(&system_sem, "defunct", 1, RT_IPC_FLAG_FIFO); + + /* create defunct thread */ + rt_thread_init(&rt_system_thread, + "tsystem", + rt_thread_system_entry, + RT_NULL, + rt_system_stack, + sizeof(rt_system_stack), + RT_THREAD_PRIORITY_MAX - 2, + 32); + /* startup */ + rt_thread_startup(&rt_system_thread); +#endif } /** diff --git a/src/scheduler.c b/src/scheduler.c index eec660a8aa..956d95d7cc 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -47,8 +47,6 @@ struct rt_thread *rt_current_thread = RT_NULL; rt_uint8_t rt_current_priority; #endif /* RT_USING_SMP */ -rt_list_t rt_thread_defunct; - #ifdef RT_USING_HOOK static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); @@ -224,9 +222,6 @@ void rt_system_scheduler_init(void) /* initialize ready table */ rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table)); #endif /* RT_THREAD_PRIORITY_MAX > 32 */ - - /* initialize thread defunct */ - rt_list_init(&rt_thread_defunct); } /** diff --git a/src/thread.c b/src/thread.c index c0a8f0ee74..88cc7b61ba 100644 --- a/src/thread.c +++ b/src/thread.c @@ -32,8 +32,6 @@ #include #include -extern rt_list_t rt_thread_defunct; - #ifdef RT_USING_HOOK static void (*rt_thread_suspend_hook)(rt_thread_t thread); static void (*rt_thread_resume_hook) (rt_thread_t thread); @@ -131,7 +129,7 @@ static void _rt_thread_exit(void) else { /* insert to defunct thread list */ - rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); + rt_thread_defunct_enqueue(thread); } /* switch to next task */ @@ -379,17 +377,22 @@ rt_err_t rt_thread_detach(rt_thread_t thread) /* release thread timer */ rt_timer_detach(&(thread->thread_timer)); - /* disable interrupt */ - lock = rt_hw_interrupt_disable(); - /* change stat */ thread->stat = RT_THREAD_CLOSE; - /* detach thread object */ - rt_object_detach((rt_object_t)thread); - - /* enable interrupt */ - rt_hw_interrupt_enable(lock); + if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE) + { + rt_object_detach((rt_object_t)thread); + } + else + { + /* disable interrupt */ + lock = rt_hw_interrupt_disable(); + /* insert to defunct thread list */ + rt_thread_defunct_enqueue(thread); + /* enable interrupt */ + rt_hw_interrupt_enable(lock); + } return RT_EOK; } @@ -484,7 +487,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread) thread->stat = RT_THREAD_CLOSE; /* insert to defunct thread list */ - rt_list_insert_after(&rt_thread_defunct, &(thread->tlist)); + rt_thread_defunct_enqueue(thread); /* enable interrupt */ rt_hw_interrupt_enable(lock); @@ -847,12 +850,12 @@ rt_err_t rt_thread_resume(rt_thread_t thread) rt_timer_stop(&thread->thread_timer); - /* enable interrupt */ - rt_hw_interrupt_enable(temp); - /* insert to schedule ready list */ rt_schedule_insert_thread(thread); + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + RT_OBJECT_HOOK_CALL(rt_thread_resume_hook, (thread)); return RT_EOK; } @@ -867,6 +870,7 @@ RTM_EXPORT(rt_thread_resume); void rt_thread_timeout(void *parameter) { struct rt_thread *thread; + register rt_base_t temp; thread = (struct rt_thread *)parameter; @@ -875,6 +879,9 @@ void rt_thread_timeout(void *parameter) RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND); RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread); + /* disable interrupt */ + temp = rt_hw_interrupt_disable(); + /* set error number */ thread->error = -RT_ETIMEOUT; @@ -884,6 +891,9 @@ void rt_thread_timeout(void *parameter) /* insert to schedule ready list */ rt_schedule_insert_thread(thread); + /* enable interrupt */ + rt_hw_interrupt_enable(temp); + /* do schedule */ rt_schedule(); } -- cgit v1.3.1 From 3dfebe337ab996eeaea651c3a87f06af114e9326 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 3 Jul 2021 18:48:15 +0800 Subject: [kernel] remove switchto_sethook --- include/rtthread.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/rtthread.h b/include/rtthread.h index f9d0b45e86..f2f4091b8a 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -186,7 +186,6 @@ rt_uint16_t rt_critical_level(void); #ifdef RT_USING_HOOK void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to)); -void rt_scheduler_switchto_sethook(void (*hook)(struct rt_thread *tid)); #endif #ifdef RT_USING_SMP -- cgit v1.3.1 From e933c1f6105caf4e68bd57bc5521767b32063a5f Mon Sep 17 00:00:00 2001 From: fenghuijie Date: Mon, 5 Jul 2021 14:43:33 +0800 Subject: 调整异常处理代码结构,以支持backtrace功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 4 ++ libcpu/arm/cortex-a/start_gcc.S | 13 +++++- libcpu/arm/cortex-a/trap.c | 88 +++++++++++++++++++++++++++++++---------- 3 files changed, 84 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index d125c970c9..2eb2cc1963 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -567,6 +567,10 @@ typedef siginfo_t rt_siginfo_t; #define RT_SCHEDULE_IPI 0 #endif +#ifndef RT_STOP_IPI +#define RT_STOP_IPI 1 +#endif + /** * CPUs definitions * diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 8fcf6abd2a..6c5dd81785 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -373,9 +373,18 @@ rt_hw_context_switch_interrupt_do: mrs r6, spsr @/* Save CPSR */ str lr, [r0, #15*4] @/* Push PC */ str r6, [r0, #16*4] @/* Push CPSR */ - cps #Mode_SVC + mrs r5, cpsr @/* Save CPSR */ + + and r4, r6, #0x1F + cmp r4, #Mode_USR + moveq r6, #Mode_SYS + + orr r6, r6, #0x80 @/* Switch to previous mode, then save SP & PC */ + msr cpsr_c, r6 str sp, [r0, #13*4] @/* Save calling SP */ str lr, [r0, #14*4] @/* Save calling PC */ + + msr cpsr_c, r5 @/* Switch back to current mode */ .endm .align 5 @@ -482,6 +491,8 @@ secondary_cpu_start: .bss .align 2 //align to 2~2=4 +.global sub_stack_top /* used for backtrace to calculate stack top of irq mode */ + sub_stack_start: .space (SUB_ISR_Stack_Size * (RT_CPUS_NR-1)) sub_stack_top: diff --git a/libcpu/arm/cortex-a/trap.c b/libcpu/arm/cortex-a/trap.c index f61b89871d..b3efe31a64 100644 --- a/libcpu/arm/cortex-a/trap.c +++ b/libcpu/arm/cortex-a/trap.c @@ -35,6 +35,18 @@ void rt_hw_show_register(struct rt_hw_exp_stack *regs) rt_kprintf("cpsr:0x%08x\n", regs->cpsr); } +void (*rt_trap_hook)(struct rt_hw_exp_stack *regs, const char *ex, unsigned int exception_type); + +/** + * This function will set a hook function to trap handler. + * + * @param hook the hook function + */ +void rt_hw_trap_set_hook(void (*hook)(struct rt_hw_exp_stack *regs, const char *ex, unsigned int exception_type)) +{ + rt_trap_hook = hook; +} + /** * When comes across an instruction which it cannot handle, * it takes the undefined instruction trap. @@ -72,12 +84,20 @@ void rt_hw_trap_undef(struct rt_hw_exp_stack *regs) } } #endif - rt_kprintf("undefined instruction:\n"); - rt_hw_show_register(regs); + + if (rt_trap_hook == RT_NULL) + { + rt_kprintf("undefined instruction:\n"); + rt_hw_show_register(regs); #ifdef RT_USING_FINSH - list_thread(); + list_thread(); #endif - rt_hw_cpu_shutdown(); + rt_hw_cpu_shutdown(); + } + else + { + rt_trap_hook(regs, "undefined instruction", UND_EXCEPTION); + } } /** @@ -91,12 +111,19 @@ void rt_hw_trap_undef(struct rt_hw_exp_stack *regs) */ void rt_hw_trap_swi(struct rt_hw_exp_stack *regs) { - rt_kprintf("software interrupt:\n"); - rt_hw_show_register(regs); + if (rt_trap_hook == RT_NULL) + { + rt_kprintf("software interrupt:\n"); + rt_hw_show_register(regs); #ifdef RT_USING_FINSH - list_thread(); + list_thread(); #endif - rt_hw_cpu_shutdown(); + rt_hw_cpu_shutdown(); + } + else + { + rt_trap_hook(regs, "software instruction", SWI_EXCEPTION); + } } /** @@ -109,12 +136,19 @@ void rt_hw_trap_swi(struct rt_hw_exp_stack *regs) */ void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs) { - rt_kprintf("prefetch abort:\n"); - rt_hw_show_register(regs); + if (rt_trap_hook == RT_NULL) + { + rt_kprintf("prefetch abort:\n"); + rt_hw_show_register(regs); #ifdef RT_USING_FINSH - list_thread(); + list_thread(); #endif - rt_hw_cpu_shutdown(); + rt_hw_cpu_shutdown(); + } + else + { + rt_trap_hook(regs, "prefetch abort", PABT_EXCEPTION); + } } /** @@ -127,12 +161,19 @@ void rt_hw_trap_pabt(struct rt_hw_exp_stack *regs) */ void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs) { - rt_kprintf("data abort:"); - rt_hw_show_register(regs); + if (rt_trap_hook == RT_NULL) + { + rt_kprintf("data abort:"); + rt_hw_show_register(regs); #ifdef RT_USING_FINSH - list_thread(); + list_thread(); #endif - rt_hw_cpu_shutdown(); + rt_hw_cpu_shutdown(); + } + else + { + rt_trap_hook(regs, "data abort", DABT_EXCEPTION); + } } /** @@ -144,12 +185,19 @@ void rt_hw_trap_dabt(struct rt_hw_exp_stack *regs) */ void rt_hw_trap_resv(struct rt_hw_exp_stack *regs) { - rt_kprintf("reserved trap:\n"); - rt_hw_show_register(regs); + if (rt_trap_hook == RT_NULL) + { + rt_kprintf("reserved trap:\n"); + rt_hw_show_register(regs); #ifdef RT_USING_FINSH - list_thread(); + list_thread(); #endif - rt_hw_cpu_shutdown(); + rt_hw_cpu_shutdown(); + } + else + { + rt_trap_hook(regs, "reserved trap", RESV_EXCEPTION); + } } void rt_hw_trap_irq(void) -- cgit v1.3.1 From 0015af02e4f08ab47f2d2fefcb7c1aca1682bfda Mon Sep 17 00:00:00 2001 From: fenghuijie Date: Mon, 5 Jul 2021 18:33:22 +0800 Subject: 调整代码,以支持cpu usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtdef.h | 4 ++++ include/rtthread.h | 1 + libcpu/arm/cortex-a/interrupt.c | 14 ++++++++++++++ libcpu/arm/cortex-a/start_gcc.S | 2 ++ src/irq.c | 2 +- src/scheduler.c | 13 +++++++++++++ src/thread.c | 4 ++++ 7 files changed, 39 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index 2eb2cc1963..e1a64a433a 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -663,6 +663,10 @@ struct rt_thread rt_ubase_t init_tick; /**< thread's initialized tick */ rt_ubase_t remaining_tick; /**< remaining tick */ +#ifdef RT_USING_CPU_USAGE + rt_uint64_t duration_tick; /**< cpu usage tick */ +#endif + struct rt_timer thread_timer; /**< built-in thread timer */ void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */ diff --git a/include/rtthread.h b/include/rtthread.h index f2f4091b8a..cf47a48efe 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -186,6 +186,7 @@ rt_uint16_t rt_critical_level(void); #ifdef RT_USING_HOOK void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to)); +void rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid)); #endif #ifdef RT_USING_SMP diff --git a/libcpu/arm/cortex-a/interrupt.c b/libcpu/arm/cortex-a/interrupt.c index 474a23fee1..f90f1c0094 100644 --- a/libcpu/arm/cortex-a/interrupt.c +++ b/libcpu/arm/cortex-a/interrupt.c @@ -27,6 +27,20 @@ struct rt_irq_desc isr_table[MAX_HANDLERS]; rt_uint32_t rt_interrupt_from_thread = 0; rt_uint32_t rt_interrupt_to_thread = 0; rt_uint32_t rt_thread_switch_interrupt_flag = 0; + +#ifdef RT_USING_HOOK +static void (*rt_interrupt_switch_hook)(void); + +void rt_interrupt_switch_sethook(void (*hook)(void)) +{ + rt_interrupt_switch_hook = hook; +} +#endif + +void rt_interrupt_hook(void) +{ + RT_OBJECT_HOOK_CALL(rt_interrupt_switch_hook, ()); +} #endif const unsigned int VECTOR_BASE = 0x00; diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 6c5dd81785..908468476e 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -341,6 +341,8 @@ rt_hw_context_switch_interrupt_do: ldr r6, [r6] ldr sp, [r6] @ get new task's stack pointer + bl rt_interrupt_hook + #ifdef RT_USING_FPU /* fpu context */ ldmfd sp!, {r6} diff --git a/src/irq.c b/src/irq.c index e89b8504dc..6ddcb3dd4a 100644 --- a/src/irq.c +++ b/src/irq.c @@ -89,8 +89,8 @@ void rt_interrupt_leave(void) rt_interrupt_nest)); level = rt_hw_interrupt_disable(); - rt_interrupt_nest --; RT_OBJECT_HOOK_CALL(rt_interrupt_leave_hook,()); + rt_interrupt_nest --; rt_hw_interrupt_enable(level); } RTM_EXPORT(rt_interrupt_leave); diff --git a/src/scheduler.c b/src/scheduler.c index 956d95d7cc..353fdad5cb 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -49,6 +49,7 @@ rt_uint8_t rt_current_priority; #ifdef RT_USING_HOOK static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to); +static void (*rt_scheduler_switch_hook)(struct rt_thread *tid); /** * @addtogroup Hook @@ -68,6 +69,12 @@ rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to)) rt_scheduler_hook = hook; } +void +rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid)) +{ + rt_scheduler_switch_hook = hook; +} + /**@}*/ #endif /* RT_USING_HOOK */ @@ -364,6 +371,8 @@ void rt_schedule(void) _rt_scheduler_stack_check(to_thread); #endif /* RT_USING_OVERFLOW_CHECK */ + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (current_thread)); + rt_hw_context_switch((rt_ubase_t)¤t_thread->sp, (rt_ubase_t)&to_thread->sp, to_thread); } @@ -473,6 +482,8 @@ void rt_schedule(void) { extern void rt_thread_handle_sig(rt_bool_t clean_state); + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (from_thread)); + rt_hw_context_switch((rt_ubase_t)&from_thread->sp, (rt_ubase_t)&to_thread->sp); @@ -609,6 +620,8 @@ void rt_scheduler_do_irq_switch(void *context) current_thread->cpus_lock_nest--; current_thread->scheduler_lock_nest--; + RT_OBJECT_HOOK_CALL(rt_scheduler_switch_hook, (current_thread)); + rt_hw_context_switch_interrupt(context, (rt_ubase_t)¤t_thread->sp, (rt_ubase_t)&to_thread->sp, to_thread); } diff --git a/src/thread.c b/src/thread.c index 88cc7b61ba..60e6ab91d1 100644 --- a/src/thread.c +++ b/src/thread.c @@ -228,6 +228,10 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, thread->lwp = RT_NULL; #endif /* RT_USING_LWP */ +#ifdef RT_USING_CPU_USAGE + thread->duration_tick = 0; +#endif + RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread)); return RT_EOK; -- cgit v1.3.1 From a2a7f3c2d926388c71d0be5fca0309bfef81e523 Mon Sep 17 00:00:00 2001 From: iysheng Date: Mon, 5 Jul 2021 11:34:11 +0800 Subject: [components][rtc] Add RTC framework V2.0 to simplify RTC registration process --- components/drivers/include/drivers/rtc.h | 3 + components/drivers/include/drivers/rtc_core.h | 43 ++++++++++ components/drivers/rtc/SConscript | 4 +- components/drivers/rtc/rtc.c | 1 + components/drivers/rtc/rtc_core.c | 117 ++++++++++++++++++++++++++ components/libc/compilers/common/time.c | 9 ++ include/rtdef.h | 6 -- 7 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 components/drivers/include/drivers/rtc_core.h create mode 100644 components/drivers/rtc/rtc_core.c (limited to 'include') diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index 4845937113..3a318357da 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/components/drivers/include/drivers/rtc.h @@ -11,6 +11,9 @@ #ifndef __RTC_H__ #define __RTC_H__ +#include +#include + rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day); rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second); diff --git a/components/drivers/include/drivers/rtc_core.h b/components/drivers/include/drivers/rtc_core.h new file mode 100644 index 0000000000..c093a1d749 --- /dev/null +++ b/components/drivers/include/drivers/rtc_core.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-06-11 iysheng first version. + */ + +#ifndef __RTC_CORE_H__ +#define __RTC_CORE_H__ + +#include + +#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */ +#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */ +#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */ +#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */ +#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */ +#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */ + +struct rt_rtc_ops +{ + rt_err_t (*init)(void); + rt_err_t (*get_secs)(void *arg); + rt_err_t (*set_secs)(void *arg); + rt_err_t (*get_alarm)(void *arg); + rt_err_t (*set_alarm)(void *arg); +}; + +typedef struct rt_rtc_device +{ + struct rt_device parent; + const struct rt_rtc_ops *ops; +} rt_rtc_dev_t; + +rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc, + const char *name, + rt_uint32_t flag, + void *data); + +#endif /* __RTC_CORE_H__ */ diff --git a/components/drivers/rtc/SConscript b/components/drivers/rtc/SConscript index e1f8f433c1..b922db70c2 100644 --- a/components/drivers/rtc/SConscript +++ b/components/drivers/rtc/SConscript @@ -13,7 +13,7 @@ CPPPATH = [cwd + '/../include'] group = [] if GetDepend(['RT_USING_RTC']): - src = src + rtc + src = src + ['rtc.c', 'rtc_core.c'] if GetDepend(['RT_USING_ALARM']): src = src + rtc_alarm if GetDepend(['RT_USING_SOFT_RTC']): @@ -21,4 +21,4 @@ if GetDepend(['RT_USING_RTC']): group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_RTC'], CPPPATH = CPPPATH) -Return('group') \ No newline at end of file +Return('group') diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index 98b60f9f95..2b9397da90 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef RT_USING_RTC diff --git a/components/drivers/rtc/rtc_core.c b/components/drivers/rtc/rtc_core.c new file mode 100644 index 0000000000..ada0ed283b --- /dev/null +++ b/components/drivers/rtc/rtc_core.c @@ -0,0 +1,117 @@ +/* + * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-06-11 iysheng first version. + */ + +#include + +#define TRY_DO_RTC_FUNC(rt_rtc_dev, func_name, args) \ + rt_rtc_dev->ops->func_name ? rt_rtc_dev->ops->func_name(args) : -RT_EINVAL; + +/* + * This function initializes rtc_core + */ +static rt_err_t rt_rtc_core_init(struct rt_device *dev) +{ + rt_rtc_dev_t *rtc_core; + + RT_ASSERT(dev != RT_NULL); + rtc_core = (rt_rtc_dev_t *)dev; + if (rtc_core->ops->init) + { + return (rtc_core->ops->init()); + } + + return (-RT_ENOSYS); +} + +static rt_err_t rt_rtc_core_open(struct rt_device *dev, rt_uint16_t oflag) +{ + return (RT_EOK); +} + +static rt_err_t rt_rtc_core_close(struct rt_device *dev) +{ + /* Add close member function in rt_rtc_ops when need, + * then call that function here. + * */ + return (RT_EOK); +} + +static rt_err_t rt_rtc_core_control(struct rt_device *dev, + int cmd, + void *args) +{ + rt_rtc_dev_t *rtc_core; + rt_err_t ret = -RT_EINVAL; + + RT_ASSERT(dev != RT_NULL); + rtc_core = (rt_rtc_dev_t *)dev; + + switch (cmd) + { + case RT_DEVICE_CTRL_RTC_GET_TIME: + ret = TRY_DO_RTC_FUNC(rtc_core, get_secs, args); + break; + case RT_DEVICE_CTRL_RTC_SET_TIME: + ret = TRY_DO_RTC_FUNC(rtc_core, set_secs, args); + break; + case RT_DEVICE_CTRL_RTC_GET_ALARM: + ret = TRY_DO_RTC_FUNC(rtc_core, get_alarm, args); + break; + case RT_DEVICE_CTRL_RTC_SET_ALARM: + ret = TRY_DO_RTC_FUNC(rtc_core, set_alarm, args); + break; + default: + break; + } + + return ret; +} +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops rtc_core_ops = +{ + rt_rtc_core_init, + rt_rtc_core_open, + rt_rtc_core_close, + RT_NULL, + RT_NULL, + rt_rtc_core_control, +}; +#endif + +rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc, + const char *name, + rt_uint32_t flag, + void *data) +{ + struct rt_device *device; + RT_ASSERT(rtc != RT_NULL); + + device = &(rtc->parent); + + device->type = RT_Device_Class_RTC; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + +#ifdef RT_USING_DEVICE_OPS + device->ops = &rtc_core_ops; +#else + device->init = rt_rtc_core_init; + device->open = rt_rtc_core_open; + device->close = rt_rtc_core_close; + device->read = RT_NULL; + device->write = RT_NULL; + device->control = rt_rtc_core_control; +#endif + device->user_data = data; + + /* register a character device */ + return rt_device_register(device, name, flag); +} + diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index deda18a560..e13f81c2f7 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -473,12 +473,17 @@ static int clock_time_system_init() rt_device_t device; time = 0; + +#ifdef RT_USING_RTC device = rt_device_find("rtc"); if (device != RT_NULL) { /* get realtime seconds */ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); } +#else + LOG_W("Cannot find a RTC device to provide time!"); +#endif /* get tick */ tick = rt_tick_get(); @@ -591,6 +596,7 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; +#ifdef RT_USING_RTC /* update for RTC device */ device = rt_device_find("rtc"); if (device != RT_NULL) @@ -599,6 +605,9 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); } else +#else + LOG_W("Cannot find a RTC device to save time!"); +#endif return -1; return 0; diff --git a/include/rtdef.h b/include/rtdef.h index 111ac4a12c..2b4750330f 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -962,12 +962,6 @@ enum rt_device_class_type #define RT_DEVICE_CTRL_BLK_AUTOREFRESH 0x13 /**< block device : enter/exit auto refresh mode */ #define RT_DEVICE_CTRL_NETIF_GETMAC 0x10 /**< get mac address */ #define RT_DEVICE_CTRL_MTD_FORMAT 0x10 /**< format a MTD device */ -#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */ -#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */ -#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */ -#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */ -#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */ -#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */ typedef struct rt_device *rt_device_t; -- cgit v1.3.1 From fc094e921103f9a37fa1c4cbf1301900419d2801 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 21 Jul 2021 01:43:48 +0800 Subject: [rtlibc] remove libc_signal.h and libc_fdset.h --- components/dfs/include/dfs_select.h | 2 +- components/libc/aio/posix_aio.c | 6 - components/libc/aio/posix_aio.h | 4 + .../libc/compilers/common/none-gcc/sys/errno.h | 4 +- .../libc/compilers/common/none-gcc/sys/stat.h | 5 + .../libc/compilers/common/none-gcc/sys/types.h | 4 +- .../libc/compilers/common/none-gcc/sys/unistd.h | 4 +- components/libc/compilers/common/sys/select.h | 49 ++++++ components/libc/compilers/common/sys/signal.h | 194 +++++++++++++++++++++ components/libc/pthreads/mqueue.c | 1 + components/libc/signal/posix_signal.c | 5 +- components/libc/signal/posix_signal.h | 1 - include/libc/libc_fdset.h | 60 ------- include/libc/libc_signal.h | 184 ------------------- include/rtdef.h | 2 +- include/rtlibc.h | 3 - 16 files changed, 263 insertions(+), 265 deletions(-) create mode 100644 components/libc/compilers/common/sys/select.h create mode 100644 components/libc/compilers/common/sys/signal.h delete mode 100644 include/libc/libc_fdset.h delete mode 100644 include/libc/libc_signal.h (limited to 'include') diff --git a/components/dfs/include/dfs_select.h b/components/dfs/include/dfs_select.h index 458691df20..e0572c5059 100644 --- a/components/dfs/include/dfs_select.h +++ b/components/dfs/include/dfs_select.h @@ -10,7 +10,7 @@ #ifndef DFS_SELECT_H__ #define DFS_SELECT_H__ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/components/libc/aio/posix_aio.c b/components/libc/aio/posix_aio.c index 66f15e4c57..66cced8687 100644 --- a/components/libc/aio/posix_aio.c +++ b/components/libc/aio/posix_aio.c @@ -9,14 +9,8 @@ */ #include -#include - #include -#include -#include - #include - #include "posix_aio.h" struct rt_workqueue* aio_queue = NULL; diff --git a/components/libc/aio/posix_aio.h b/components/libc/aio/posix_aio.h index de11738515..4e25e1d15b 100644 --- a/components/libc/aio/posix_aio.h +++ b/components/libc/aio/posix_aio.h @@ -11,6 +11,10 @@ #ifndef POSIX_AIO_H__ #define POSIX_AIO_H__ +#include +#include +#include + struct aiocb { int aio_fildes; /* File descriptor. */ diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h index ad3614024d..ff1abca387 100644 --- a/components/libc/compilers/common/none-gcc/sys/errno.h +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -7,8 +7,8 @@ * Date Author Notes * 2021-05-22 Meco Man The first version. */ -#ifndef _SYS_ERRNO_H -#define _SYS_ERRNO_H +#ifndef __SYS_ERRNO_H__ +#define __SYS_ERRNO_H__ #if defined(__ARMCC_VERSION) /* diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h index c4b42083c4..c8f65df435 100644 --- a/components/libc/compilers/common/none-gcc/sys/stat.h +++ b/components/libc/compilers/common/none-gcc/sys/stat.h @@ -6,3 +6,8 @@ * Change Logs: * Date Author Notes */ + + #ifndef __SYS_STAT_H__ + #define __SYS_STAT_H__ + + #endif diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h index 7222326a2a..e9f44f7762 100644 --- a/components/libc/compilers/common/none-gcc/sys/types.h +++ b/components/libc/compilers/common/none-gcc/sys/types.h @@ -8,8 +8,8 @@ * 2020-09-05 Meco Man fix bugs * 2020-12-16 Meco Man add useconds_t */ -#ifndef __TYPES_H__ -#define __TYPES_H__ +#ifndef __SYS_TYPES_H__ +#define __SYS_TYPES_H__ #include diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index 2f01f660b3..ea2d674b0f 100644 --- a/components/libc/compilers/common/none-gcc/sys/unistd.h +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -7,8 +7,8 @@ * Date Author Notes * 2020-12-16 Meco Man add usleep */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H +#ifndef __SYS_UNISTD_H__ +#define __SYS_UNISTD_H__ #include #include "types.h" diff --git a/components/libc/compilers/common/sys/select.h b/components/libc/compilers/common/sys/select.h new file mode 100644 index 0000000000..db42b6ebcc --- /dev/null +++ b/components/libc/compilers/common/sys/select.h @@ -0,0 +1,49 @@ +/* + * 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 + +#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 */ + +#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h new file mode 100644 index 0000000000..9787958a37 --- /dev/null +++ b/components/libc/compilers/common/sys/signal.h @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017-09-12 Bernard The first version + * 2021-07-21 Meco Man move to libc/common + */ + +#ifndef __SYS_SIGNAL_H__ +#define __SYS_SIGNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Signal Generation and Delivery, P1003.1b-1993, p. 63 + NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and + sigev_notify_attributes to the sigevent structure. */ +union sigval +{ + int sival_int; /* Integer signal value */ + void *sival_ptr; /* Pointer signal value */ +}; + +struct sigevent +{ + int sigev_notify; /* Notification type */ + int sigev_signo; /* Signal number */ + union sigval sigev_value; /* Signal value */ + void (*sigev_notify_function)( union sigval ); + /* Notification function */ + void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ +}; + +struct siginfo +{ + uint16_t si_signo; + uint16_t si_code; + + union sigval si_value; +}; +typedef struct siginfo siginfo_t; + +#define SI_USER 0x01 /* Signal sent by kill(). */ +#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ +#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */ +#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */ +#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */ + +typedef void (*_sig_func_ptr)(int); +typedef unsigned long sigset_t; + +struct sigaction +{ + _sig_func_ptr sa_handler; + sigset_t sa_mask; + int sa_flags; +}; + +#define SIG_SETMASK 0 /* set mask with sigprocmask() */ +#define SIG_BLOCK 1 /* set of signals to block */ +#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ + +#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) +#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) +#define sigemptyset(what) (*(what) = 0, 0) +#define sigfillset(what) (*(what) = ~(0), 0) +#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) + +int sigprocmask (int how, const sigset_t *set, sigset_t *oset); +int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); + +#ifdef __ARMCC_VERSION +#define SIGHUP 1 +/* #define SIGINT 2 */ +#define SIGQUIT 3 +/* #define SIGILL 4 */ +#define SIGTRAP 5 +/* #define SIGABRT 6 */ +#define SIGEMT 7 +/* #define SIGFPE 8 */ +#define SIGKILL 9 +#define SIGBUS 10 +/* #define SIGSEGV 11 */ +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +/* #define SIGTERM 15 */ +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 +/* #define SIGUSR1 25 */ +/* #define SIGUSR2 26 */ +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 + +#include + +#elif defined(__IAR_SYSTEMS_ICC__) +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +/* #define SIGABRT 6 */ +#define SIGEMT 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGBUS 10 +#define SIGSEGV 11 +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 +#define SIGUSR1 25 +#define SIGUSR2 26 +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 + +#include + +#elif defined(__GNUC__) +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt */ +#define SIGQUIT 3 /* quit */ +#define SIGILL 4 /* illegal instruction (not reset when caught) */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGIOT 6 /* IOT instruction */ +#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ +#define SIGEMT 7 /* EMT instruction */ +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGBUS 10 /* bus error */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGSYS 12 /* bad argument to system call */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ +#define SIGURG 16 /* urgent condition on IO channel */ +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGCLD 20 /* System V name for SIGCHLD */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ +#define SIGIO 23 /* input/output possible signal */ +#define SIGPOLL SIGIO /* System V name for SIGIO */ +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#define SIGWINCH 28 /* window changed */ +#define SIGLOST 29 /* resource lost (eg, record-lock lost) */ +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ +#define NSIG 32 /* signal 0 implied */ + +#ifndef _SIGNAL_H_ +/* Some applications take advantage of the fact that + * and are equivalent in glibc. Allow for that here. */ +#include +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c index 1af0ab2919..a59c7a445b 100644 --- a/components/libc/pthreads/mqueue.c +++ b/components/libc/pthreads/mqueue.c @@ -8,6 +8,7 @@ */ #include +#include #include "mqueue.h" #include "pthread_internal.h" diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c index 1cb561d428..45646f63ea 100644 --- a/components/libc/signal/posix_signal.c +++ b/components/libc/signal/posix_signal.c @@ -7,6 +7,7 @@ * Date Author Notes * 2017/10/1 Bernard The first version */ + #include #include @@ -14,6 +15,7 @@ #include #include "posix_signal.h" + #define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX) void (*signal(int sig, void (*func)(int))) (int) @@ -79,13 +81,10 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, int ret = 0; int tick = RT_WAITING_FOREVER; -#ifdef RT_USING_PTHREADS if (timeout) { - extern int clock_time_to_tick(const struct timespec *time); tick = clock_time_to_tick(timeout); } -#endif ret = rt_signal_wait(set, info, tick); if (ret == 0) return 0; diff --git a/components/libc/signal/posix_signal.h b/components/libc/signal/posix_signal.h index fa8ad38fa6..f04b54c5f8 100644 --- a/components/libc/signal/posix_signal.h +++ b/components/libc/signal/posix_signal.h @@ -15,7 +15,6 @@ extern "C" { #endif -#include #include enum rt_signal_value{ diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h deleted file mode 100644 index c542e6855c..0000000000 --- a/include/libc/libc_fdset.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-10-30 Bernard The first version - */ - -#ifndef LIBC_FDSET_H__ -#define LIBC_FDSET_H__ - -#include - -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -#include -#if defined(HAVE_SYS_SELECT_H) -#include -#endif - -#else - -#ifdef SAL_USING_POSIX - -#ifdef FD_SETSIZE -#undef FD_SETSIZE -#endif - -#define FD_SETSIZE DFS_FD_MAX -#endif - -# ifndef FD_SETSIZE -# define FD_SETSIZE 32 -# endif - -# 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 - -/* We use a macro for fd_set so that including Sockets.h afterwards - can work. */ -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 - -#endif diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h deleted file mode 100644 index 1fb8194643..0000000000 --- a/include/libc/libc_signal.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-09-12 Bernard The first version - */ - -#ifndef LIBC_SIGNAL_H__ -#define LIBC_SIGNAL_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#ifdef HAVE_CCONFIG_H -#include -#endif - -#ifndef HAVE_SIGVAL -/* Signal Generation and Delivery, P1003.1b-1993, p. 63 - NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and - sigev_notify_attributes to the sigevent structure. */ - -union sigval -{ - int sival_int; /* Integer signal value */ - void *sival_ptr; /* Pointer signal value */ -}; -#endif - -#ifndef HAVE_SIGEVENT -struct sigevent -{ - int sigev_notify; /* Notification type */ - int sigev_signo; /* Signal number */ - union sigval sigev_value; /* Signal value */ - void (*sigev_notify_function)( union sigval ); - /* Notification function */ - void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ -}; -#endif - -#ifndef HAVE_SIGINFO -struct siginfo -{ - uint16_t si_signo; - uint16_t si_code; - - union sigval si_value; -}; -typedef struct siginfo siginfo_t; -#endif - -#define SI_USER 0x01 /* Signal sent by kill(). */ -#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ -#define SI_TIMER 0x03 /* Signal generated by expiration of a - timer set by timer_settime(). */ -#define SI_ASYNCIO 0x04 /* Signal generated by completion of an - asynchronous I/O request. */ -#define SI_MESGQ 0x05 /* Signal generated by arrival of a - message on an empty message queue. */ - -#if !defined(RT_USING_NEWLIB) -typedef void (*_sig_func_ptr)(int); -typedef unsigned long sigset_t; -#endif - -#include - -#ifdef __ARMCC_VERSION - -#define SIGHUP 1 -/* #define SIGINT 2 */ -#define SIGQUIT 3 -/* #define SIGILL 4 */ -#define SIGTRAP 5 -/* #define SIGABRT 6 */ -#define SIGEMT 7 -/* #define SIGFPE 8 */ -#define SIGKILL 9 -#define SIGBUS 10 -/* #define SIGSEGV 11 */ -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -/* #define SIGTERM 15 */ -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGPOLL 23 -#define SIGWINCH 24 -/* #define SIGUSR1 25 */ -/* #define SIGUSR2 26 */ -#define SIGRTMIN 27 -#define SIGRTMAX 31 -#define NSIG 32 - -#define SIG_SETMASK 0 /* set mask with sigprocmask() */ -#define SIG_BLOCK 1 /* set of signals to block */ -#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ - -struct sigaction -{ - _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; -}; - -#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) - -int sigprocmask (int how, const sigset_t *set, sigset_t *oset); -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); - -#elif defined(__IAR_SYSTEMS_ICC__) - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -/* #define SIGABRT 6 */ -#define SIGEMT 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGBUS 10 -#define SIGSEGV 11 -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGPOLL 23 -#define SIGWINCH 24 -#define SIGUSR1 25 -#define SIGUSR2 26 -#define SIGRTMIN 27 -#define SIGRTMAX 31 -#define NSIG 32 - -#define SIG_SETMASK 0 /* set mask with sigprocmask() */ -#define SIG_BLOCK 1 /* set of signals to block */ -#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ - -struct sigaction -{ - _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; -}; - -#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) - -int sigprocmask (int how, const sigset_t *set, sigset_t *oset); -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/include/rtdef.h b/include/rtdef.h index 394bbca5d2..62d0a53685 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -510,7 +510,7 @@ typedef struct rt_timer *rt_timer_t; * @addtogroup Signal */ #ifdef RT_USING_SIGNALS -#include +#include typedef unsigned long rt_sigset_t; typedef void (*rt_sighandler_t)(int signo); typedef siginfo_t rt_siginfo_t; diff --git a/include/rtlibc.h b/include/rtlibc.h index ac44a97831..4b145b1b1b 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -13,11 +13,8 @@ /* definitions for libc if toolchain has no these definitions */ #include "libc/libc_stat.h" - #include "libc/libc_fcntl.h" #include "libc/libc_dirent.h" -#include "libc/libc_signal.h" -#include "libc/libc_fdset.h" #ifndef RT_USING_LIBC #if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) -- cgit v1.3.1 From 1e51b40d57164e021eace0f162f0c46fd63e1f37 Mon Sep 17 00:00:00 2001 From: lymzzyh Date: Fri, 13 Aug 2021 16:29:37 +0800 Subject: Add device type USBOTG to redef.h --- include/rtdef.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index 62d0a53685..dac345f26d 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -908,6 +908,7 @@ enum rt_device_class_type RT_Device_Class_I2CBUS, /**< I2C bus device */ RT_Device_Class_USBDevice, /**< USB slave device */ RT_Device_Class_USBHost, /**< USB host bus */ + RT_Device_Class_USBOTG, /**< USB OTG bus */ RT_Device_Class_SPIBUS, /**< SPI bus device */ RT_Device_Class_SPIDevice, /**< SPI device */ RT_Device_Class_SDIO, /**< SDIO bus device */ -- cgit v1.3.1 From 221da7f464d811955acce96280332d95348fb24f Mon Sep 17 00:00:00 2001 From: 马志远 <1468728718@qq.com> Date: Mon, 23 Aug 2021 17:30:05 +0800 Subject: Remove C Style Command Shell --- bsp/lm3s8962/applications/startup.c | 100 +-- bsp/lm3s9b9x/applications/startup.c | 94 +- bsp/lm4f232/applications/startup.c | 94 +- components/drivers/misc/adc.c | 4 +- components/drivers/misc/dac.c | 4 +- components/drivers/misc/rt_drv_pwm.c | 4 +- components/drivers/mtd/mtd_nand.c | 8 +- components/drivers/rtc/rtc.c | 4 +- components/drivers/sensors/sensor_cmd.c | 8 +- components/drivers/spi/spi_flash_sfud.c | 5 +- components/drivers/wlan/wlan_cmd.c | 2 +- components/finsh/Kconfig | 31 +- components/finsh/SConscript | 28 +- components/finsh/cmd.c | 544 ++++-------- components/finsh/finsh.h | 334 +++---- components/finsh/finsh_api.h | 218 ----- components/finsh/finsh_compiler.c | 918 ------------------- components/finsh/finsh_error.c | 55 -- components/finsh/finsh_error.h | 23 - components/finsh/finsh_heap.c | 279 ------ components/finsh/finsh_heap.h | 19 - components/finsh/finsh_init.c | 57 -- components/finsh/finsh_node.c | 183 ---- components/finsh/finsh_node.h | 69 -- components/finsh/finsh_ops.c | 603 ------------- components/finsh/finsh_ops.h | 116 --- components/finsh/finsh_parser.c | 986 --------------------- components/finsh/finsh_parser.h | 18 - components/finsh/finsh_token.c | 598 ------------- components/finsh/finsh_token.h | 63 -- components/finsh/finsh_var.c | 142 --- components/finsh/finsh_var.h | 41 - components/finsh/finsh_vm.c | 363 -------- components/finsh/finsh_vm.h | 35 - components/finsh/msh.c | 93 +- components/finsh/msh.h | 1 - components/finsh/msh_file.c | 20 +- components/finsh/shell.c | 189 +--- components/finsh/shell.h | 26 +- components/finsh/symbol.c | 66 -- components/libc/compilers/armlibc/syscalls.c | 2 +- components/net/at/Kconfig | 2 +- .../net/lwip-2.0.2/src/apps/tftp/tftp_port.c | 2 - .../net/lwip-2.0.3/src/apps/tftp/tftp_port.c | 2 - .../net/lwip-2.1.2/src/apps/tftp/tftp_port.c | 2 - components/utilities/ulog/ulog.c | 4 +- examples/file/listdir.c | 2 - examples/file/readspeed.c | 2 - examples/file/readwrite.c | 2 - examples/file/writespeed.c | 2 - examples/kernel/tc_comm.c | 1 - examples/libc/termios_test.c | 4 +- examples/test/hwtimer_test.c | 2 +- include/rtdef.h | 1 - include/rtthread.h | 2 +- 55 files changed, 550 insertions(+), 5927 deletions(-) delete mode 100644 components/finsh/finsh_api.h delete mode 100644 components/finsh/finsh_compiler.c delete mode 100644 components/finsh/finsh_error.c delete mode 100644 components/finsh/finsh_error.h delete mode 100644 components/finsh/finsh_heap.c delete mode 100644 components/finsh/finsh_heap.h delete mode 100644 components/finsh/finsh_init.c delete mode 100644 components/finsh/finsh_node.c delete mode 100644 components/finsh/finsh_node.h delete mode 100644 components/finsh/finsh_ops.c delete mode 100644 components/finsh/finsh_ops.h delete mode 100644 components/finsh/finsh_parser.c delete mode 100644 components/finsh/finsh_parser.h delete mode 100644 components/finsh/finsh_token.c delete mode 100644 components/finsh/finsh_token.h delete mode 100644 components/finsh/finsh_var.c delete mode 100644 components/finsh/finsh_var.h delete mode 100644 components/finsh/finsh_vm.c delete mode 100644 components/finsh/finsh_vm.h delete mode 100644 components/finsh/symbol.c (limited to 'include') diff --git a/bsp/lm3s8962/applications/startup.c b/bsp/lm3s8962/applications/startup.c index e78cfa7eca..87df6e8788 100644 --- a/bsp/lm3s8962/applications/startup.c +++ b/bsp/lm3s8962/applications/startup.c @@ -18,8 +18,8 @@ #include "board.h" #ifdef RT_USING_LWIP -#include -#include + #include + #include #endif /** @@ -30,8 +30,8 @@ extern void rt_hw_serial_init(void); /*@{*/ #ifdef RT_USING_FINSH -extern int finsh_system_init(void); -extern void finsh_set_device(char* device); + extern int finsh_system_init(void); + extern void finsh_set_device(const char *device); #endif extern int rt_application_init(void); @@ -39,11 +39,11 @@ extern void rt_hw_sdcard_init(void); extern int rt_hw_luminaryif_init(void); #ifdef __CC_ARM -extern int Image$$RW_IRAM1$$ZI$$Limit; + extern int Image$$RW_IRAM1$$ZI$$Limit; #elif __ICCARM__ -#pragma section="HEAP" + #pragma section="HEAP" #else -extern int __bss_end; + extern int __bss_end; #endif #ifdef DEBUG @@ -56,13 +56,13 @@ extern int __bss_end; * Output : None * Return : None *******************************************************************************/ -void assert_failed(u8* file, u32 line) +void assert_failed(u8 *file, u32 line) { - rt_kprintf("\n\r Wrong parameter value detected on\r\n"); - rt_kprintf(" file %s\r\n", file); - rt_kprintf(" line %d\r\n", line); + rt_kprintf("\n\r Wrong parameter value detected on\r\n"); + rt_kprintf(" file %s\r\n", file); + rt_kprintf(" line %d\r\n", line); - while (1) ; + while (1) ; } #endif @@ -71,76 +71,76 @@ void assert_failed(u8* file, u32 line) */ void rtthread_startup(void) { - /* init board */ - rt_hw_board_init(); + /* init board */ + rt_hw_board_init(); - /* show version */ - rt_show_version(); + /* show version */ + rt_show_version(); - /* init timer system */ - rt_system_timer_init(); + /* init timer system */ + rt_system_timer_init(); #ifdef RT_USING_HEAP #ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)LM3S_SRAM_END); + rt_system_heap_init((void *)&Image$$RW_IRAM1$$ZI$$Limit, (void *)LM3S_SRAM_END); #elif __ICCARM__ - rt_system_heap_init(__segment_end("HEAP"), (void*)LM3S_SRAM_END); + rt_system_heap_init(__segment_end("HEAP"), (void *)LM3S_SRAM_END); #else - /* init memory system */ - rt_system_heap_init((void*)&__bss_end, (void*)LM3S_SRAM_END); + /* init memory system */ + rt_system_heap_init((void *)&__bss_end, (void *)LM3S_SRAM_END); #endif #endif -#ifdef RT_USING_MODULE - /* init module system */ - rt_system_module_init(); +#ifdef RT_USING_MODULE + /* init module system */ + rt_system_module_init(); #endif - /* init scheduler system */ - rt_system_scheduler_init(); + /* init scheduler system */ + rt_system_scheduler_init(); #ifdef RT_USING_LWIP - eth_system_device_init(); + eth_system_device_init(); - /* register ethernetif device */ - rt_hw_luminaryif_init(); + /* register ethernetif device */ + rt_hw_luminaryif_init(); #endif - /* init hardware serial device */ - rt_hw_serial_init(); + /* init hardware serial device */ + rt_hw_serial_init(); #ifdef RT_USING_DFS - /* init sd card device */ - rt_hw_sdcard_init(); + /* init sd card device */ + rt_hw_sdcard_init(); #endif - /* init application */ - rt_application_init(); + /* init application */ + rt_application_init(); #ifdef RT_USING_FINSH - /* init finsh */ - finsh_system_init(); + /* init finsh */ + finsh_system_init(); #ifdef RT_USING_DEVICE - finsh_set_device("uart1"); + finsh_set_device("uart1"); #endif #endif - /* init idle thread */ - rt_thread_idle_init(); + /* init idle thread */ + rt_thread_idle_init(); - /* start scheduler */ - rt_system_scheduler_start(); + /* start scheduler */ + rt_system_scheduler_start(); - /* never reach here */ - return ; + /* never reach here */ + return ; } int main(void) { - /* disable interrupt first */ - rt_hw_interrupt_disable(); - rtthread_startup(); - - return 0; + /* disable interrupt first */ + rt_hw_interrupt_disable(); + rtthread_startup(); + + return 0; } /*@}*/ diff --git a/bsp/lm3s9b9x/applications/startup.c b/bsp/lm3s9b9x/applications/startup.c index 4d374824e7..8d261d0036 100644 --- a/bsp/lm3s9b9x/applications/startup.c +++ b/bsp/lm3s9b9x/applications/startup.c @@ -18,8 +18,8 @@ #include "board.h" #ifdef RT_USING_LWIP -#include -#include + #include + #include #endif /** @@ -30,8 +30,8 @@ extern void rt_hw_serial_init(void); /*@{*/ #ifdef RT_USING_FINSH -extern int finsh_system_init(void); -extern void finsh_set_device(char* device); + extern int finsh_system_init(void); + extern void finsh_set_device(const char *device); #endif extern int rt_application_init(void); @@ -39,11 +39,11 @@ extern void rt_hw_sdcard_init(void); extern int rt_hw_luminaryif_init(void); #ifdef __CC_ARM -extern int Image$$RW_IRAM1$$ZI$$Limit; + extern int Image$$RW_IRAM1$$ZI$$Limit; #elif __ICCARM__ -#pragma section="HEAP" + #pragma section="HEAP" #else -extern int __bss_end; + extern int __bss_end; #endif #ifdef DEBUG @@ -56,13 +56,13 @@ extern int __bss_end; * Output : None * Return : None *******************************************************************************/ -void __error__(char* file, unsigned long line) +void __error__(char *file, unsigned long line) { - rt_kprintf("\n\r Wrong parameter value detected on\r\n"); - rt_kprintf(" file %s\r\n", file); - rt_kprintf(" line %d\r\n", line); + rt_kprintf("\n\r Wrong parameter value detected on\r\n"); + rt_kprintf(" file %s\r\n", file); + rt_kprintf(" line %d\r\n", line); - while (1) ; + while (1) ; } #endif @@ -71,77 +71,77 @@ void __error__(char* file, unsigned long line) */ void rtthread_startup(void) { - /* init board */ - rt_hw_board_init(); + /* init board */ + rt_hw_board_init(); - /* show version */ - rt_show_version(); + /* show version */ + rt_show_version(); - /* init timer system */ - rt_system_timer_init(); + /* init timer system */ + rt_system_timer_init(); #ifdef RT_USING_HEAP #if LM3S_EXT_SRAM == 1 - /* init sdram */ - rt_system_heap_init((void*)LM3S_EXT_SRAM_BEGIN, (void*)LM3S_EXT_SRAM_END); + /* init sdram */ + rt_system_heap_init((void *)LM3S_EXT_SRAM_BEGIN, (void *)LM3S_EXT_SRAM_END); #else #ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)LM3S_SRAM_END); + rt_system_heap_init((void *)&Image$$RW_IRAM1$$ZI$$Limit, (void *)LM3S_SRAM_END); #elif __ICCARM__ - rt_system_heap_init(__segment_end("HEAP"), (void*)LM3S_SRAM_END); + rt_system_heap_init(__segment_end("HEAP"), (void *)LM3S_SRAM_END); #else - /* init memory system */ - rt_system_heap_init((void*)&__bss_end, (void*)LM3S_SRAM_END); + /* init memory system */ + rt_system_heap_init((void *)&__bss_end, (void *)LM3S_SRAM_END); #endif #endif #endif - /* init scheduler system */ - rt_system_scheduler_init(); + /* init scheduler system */ + rt_system_scheduler_init(); #ifdef RT_USING_LWIP - eth_system_device_init(); + eth_system_device_init(); - /* register ethernetif device */ - rt_hw_luminaryif_init(); + /* register ethernetif device */ + rt_hw_luminaryif_init(); #endif - /* init hardware serial device */ - rt_hw_serial_init(); + /* init hardware serial device */ + rt_hw_serial_init(); #ifdef RT_USING_DFS - /* init sd card device */ - rt_hw_sdcard_init(); + /* init sd card device */ + rt_hw_sdcard_init(); #endif - /* init application */ - rt_application_init(); + /* init application */ + rt_application_init(); #ifdef RT_USING_FINSH - /* init finsh */ - finsh_system_init(); + /* init finsh */ + finsh_system_init(); #ifdef RT_USING_DEVICE - finsh_set_device("uart1"); + finsh_set_device("uart1"); #endif #endif - /* init idle thread */ - rt_thread_idle_init(); + /* init idle thread */ + rt_thread_idle_init(); - /* start scheduler */ - rt_system_scheduler_start(); + /* start scheduler */ + rt_system_scheduler_start(); - /* never reach here */ - return ; + /* never reach here */ + return ; } int main(void) { - /* disable interrupt first */ + /* disable interrupt first */ rt_hw_interrupt_disable(); - rtthread_startup(); + rtthread_startup(); - return 0; + return 0; } /*@}*/ diff --git a/bsp/lm4f232/applications/startup.c b/bsp/lm4f232/applications/startup.c index 8d9eb54611..ed16b60a50 100644 --- a/bsp/lm4f232/applications/startup.c +++ b/bsp/lm4f232/applications/startup.c @@ -18,8 +18,8 @@ #include "board.h" #ifdef RT_USING_LWIP -#include -#include + #include + #include #endif /** @@ -30,8 +30,8 @@ extern void rt_hw_serial_init(void); /*@{*/ #ifdef RT_USING_FINSH -extern int finsh_system_init(void); -extern void finsh_set_device(char* device); + extern int finsh_system_init(void); + extern void finsh_set_device(const char *device); #endif extern int rt_application_init(void); @@ -39,11 +39,11 @@ extern void rt_hw_sdcard_init(void); extern int rt_hw_luminaryif_init(void); #ifdef __CC_ARM -extern int Image$$ER_ZI$$ZI$$Limit; + extern int Image$$ER_ZI$$ZI$$Limit; #elif __ICCARM__ -#pragma section="HEAP" + #pragma section="HEAP" #else -extern int __bss_end; + extern int __bss_end; #endif #ifdef DEBUG @@ -56,13 +56,13 @@ extern int __bss_end; * Output : None * Return : None *******************************************************************************/ -void __error__(char* file, unsigned long line) +void __error__(char *file, unsigned long line) { - rt_kprintf("\n\r Wrong parameter value detected on\r\n"); - rt_kprintf(" file %s\r\n", file); - rt_kprintf(" line %d\r\n", line); + rt_kprintf("\n\r Wrong parameter value detected on\r\n"); + rt_kprintf(" file %s\r\n", file); + rt_kprintf(" line %d\r\n", line); - while (1) ; + while (1) ; } #endif @@ -71,77 +71,77 @@ void __error__(char* file, unsigned long line) */ void rtthread_startup(void) { - /* init board */ - rt_hw_board_init(); + /* init board */ + rt_hw_board_init(); - /* show version */ - rt_show_version(); + /* show version */ + rt_show_version(); - /* init timer system */ - rt_system_timer_init(); + /* init timer system */ + rt_system_timer_init(); #ifdef RT_USING_HEAP #if LM3S_EXT_SRAM == 1 - /* init sdram */ - rt_system_heap_init((void*)LM3S_EXT_SRAM_BEGIN, (void*)LM3S_EXT_SRAM_END); + /* init sdram */ + rt_system_heap_init((void *)LM3S_EXT_SRAM_BEGIN, (void *)LM3S_EXT_SRAM_END); #else #ifdef __CC_ARM - rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)LM3S_SRAM_END); + rt_system_heap_init((void *)&Image$$ER_ZI$$ZI$$Limit, (void *)LM3S_SRAM_END); #elif __ICCARM__ - rt_system_heap_init(__segment_end("HEAP"), (void*)LM3S_SRAM_END); + rt_system_heap_init(__segment_end("HEAP"), (void *)LM3S_SRAM_END); #else - /* init memory system */ - rt_system_heap_init((void*)&__bss_end, (void*)LM3S_SRAM_END); + /* init memory system */ + rt_system_heap_init((void *)&__bss_end, (void *)LM3S_SRAM_END); #endif #endif #endif - /* init scheduler system */ - rt_system_scheduler_init(); + /* init scheduler system */ + rt_system_scheduler_init(); #ifdef RT_USING_LWIP - eth_system_device_init(); + eth_system_device_init(); - /* register ethernetif device */ - rt_hw_luminaryif_init(); + /* register ethernetif device */ + rt_hw_luminaryif_init(); #endif - /* init hardware serial device */ - rt_hw_serial_init(); + /* init hardware serial device */ + rt_hw_serial_init(); #ifdef RT_USING_DFS - /* init sd card device */ - rt_hw_sdcard_init(); + /* init sd card device */ + rt_hw_sdcard_init(); #endif - /* init application */ - rt_application_init(); + /* init application */ + rt_application_init(); #ifdef RT_USING_FINSH - /* init finsh */ - finsh_system_init(); + /* init finsh */ + finsh_system_init(); #ifdef RT_USING_DEVICE - finsh_set_device("uart1"); + finsh_set_device("uart1"); #endif #endif - /* init idle thread */ - rt_thread_idle_init(); + /* init idle thread */ + rt_thread_idle_init(); - /* start scheduler */ - rt_system_scheduler_start(); + /* start scheduler */ + rt_system_scheduler_start(); - /* never reach here */ - return ; + /* never reach here */ + return ; } int main(void) { - /* disable interrupt first */ + /* disable interrupt first */ rt_hw_interrupt_disable(); - rtthread_startup(); + rtthread_startup(); - return 0; + return 0; } /*@}*/ diff --git a/components/drivers/misc/adc.c b/components/drivers/misc/adc.c index d8f79e058b..a73fcc54e3 100644 --- a/components/drivers/misc/adc.c +++ b/components/drivers/misc/adc.c @@ -144,7 +144,7 @@ rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel) return result; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static int adc(int argc, char **argv) { @@ -232,4 +232,4 @@ static int adc(int argc, char **argv) } MSH_CMD_EXPORT(adc, adc function); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ diff --git a/components/drivers/misc/dac.c b/components/drivers/misc/dac.c index 784a503888..45b90d2106 100644 --- a/components/drivers/misc/dac.c +++ b/components/drivers/misc/dac.c @@ -141,7 +141,7 @@ rt_err_t rt_dac_disabled(rt_dac_device_t dev, rt_uint32_t channel) return result; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static int dac(int argc, char **argv) { @@ -228,4 +228,4 @@ static int dac(int argc, char **argv) } MSH_CMD_EXPORT(dac, dac function); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c index f274f509e2..04895868e2 100644 --- a/components/drivers/misc/rt_drv_pwm.c +++ b/components/drivers/misc/rt_drv_pwm.c @@ -198,7 +198,7 @@ rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *c FINSH_FUNCTION_EXPORT_ALIAS(rt_pwm_enable, pwm_enable, enable pwm by channel.); FINSH_FUNCTION_EXPORT_ALIAS(rt_pwm_set, pwm_set, set pwm.); -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static int pwm_enable(int argc, char **argv) { int result = 0; @@ -323,5 +323,5 @@ _exit: } MSH_CMD_EXPORT(pwm_get, pwm_get ); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */ diff --git a/components/drivers/mtd/mtd_nand.c b/components/drivers/mtd/mtd_nand.c index 646625ade5..f516f9b147 100644 --- a/components/drivers/mtd/mtd_nand.c +++ b/components/drivers/mtd/mtd_nand.c @@ -278,7 +278,7 @@ int mtd_nand_erase_all(const char *name) return 0; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH static void mtd_nand(int argc, char **argv) { /* If the number of arguments less than 2 */ @@ -346,16 +346,16 @@ help: } } MSH_CMD_EXPORT(mtd_nand, MTD nand device test function); -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ -#ifndef FINSH_USING_MSH_ONLY +#ifndef RT_USING_FINSH_ONLY FINSH_FUNCTION_EXPORT_ALIAS(mtd_nandid, nand_id, read ID - nandid(name)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_read, nand_read, read page in nand - nand_read(name, block, page)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_readoob, nand_readoob, read spare data in nand - nand_readoob(name, block, page)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_write, nand_write, write dump data to nand - nand_write(name, block, page)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_erase, nand_erase, nand_erase(name, block)); FINSH_FUNCTION_EXPORT_ALIAS(mtd_nand_erase_all, nand_erase_all, erase all of nand device - nand_erase_all(name, block)); -#endif /* FINSH_USING_MSH_ONLY */ +#endif /* RT_USING_FINSH_ONLY */ #endif /* defined(RT_MTD_NAND_DEBUG) && defined(RT_USING_FINSH) */ diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index 5eabeed2dd..35e7ddc3c4 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -218,7 +218,7 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) return ret; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH #include /** * get date and time or set (local timezone) [year month day hour min sec] @@ -283,6 +283,6 @@ static void date(uint8_t argc, char **argv) } } MSH_CMD_EXPORT(date, get date and time or set (local timezone) [year month day hour min sec]) -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ #endif /* RT_USING_RTC */ diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index 0f0ab66d63..14e53b1c22 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -155,7 +155,7 @@ static void sensor_fifo(int argc, char **argv) rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20); } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); #endif @@ -219,7 +219,7 @@ static void sensor_int(int argc, char **argv) } rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20); } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor_int, Sensor interrupt mode test function); #endif @@ -268,7 +268,7 @@ static void sensor_polling(int argc, char **argv) } rt_device_close(dev); } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor_polling, Sensor polling mode test function); #endif @@ -496,6 +496,6 @@ static void sensor(int argc, char **argv) LOG_W("Unknown command, please enter 'sensor' get help information!"); } } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(sensor, sensor test function); #endif diff --git a/components/drivers/spi/spi_flash_sfud.c b/components/drivers/spi/spi_flash_sfud.c index ba673edf62..bcc49e8df4 100644 --- a/components/drivers/spi/spi_flash_sfud.c +++ b/components/drivers/spi/spi_flash_sfud.c @@ -9,6 +9,7 @@ */ #include +#include #include #include "spi_flash.h" #include "spi_flash_sfud.h" @@ -508,7 +509,7 @@ __error: return RT_NULL; } -#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) +#if defined(RT_USING_FINSH) #include @@ -773,6 +774,6 @@ static void sf(uint8_t argc, char **argv) { } } MSH_CMD_EXPORT(sf, SPI Flash operate.); -#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */ +#endif /* defined(RT_USING_FINSH) */ #endif /* RT_USING_SFUD */ diff --git a/components/drivers/wlan/wlan_cmd.c b/components/drivers/wlan/wlan_cmd.c index fde9065428..3b8a119784 100644 --- a/components/drivers/wlan/wlan_cmd.c +++ b/components/drivers/wlan/wlan_cmd.c @@ -586,7 +586,7 @@ static int wifi_msh(int argc, char *argv[]) return 0; } -#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) +#if defined(RT_USING_FINSH) FINSH_FUNCTION_EXPORT_ALIAS(wifi_msh, __cmd_wifi, wifi command.); #endif diff --git a/components/finsh/Kconfig b/components/finsh/Kconfig index 8722fcd79a..637b1a30c1 100644 --- a/components/finsh/Kconfig +++ b/components/finsh/Kconfig @@ -1,13 +1,18 @@ menu "Command shell" config RT_USING_FINSH - bool "finsh shell" + bool + default n + +config RT_USING_MSH + bool "msh shell" + select RT_USING_FINSH default y -if RT_USING_FINSH +if RT_USING_MSH config FINSH_THREAD_NAME - string "The finsh thread name" + string "The msh thread name" default "tshell" config FINSH_USING_HISTORY bool "Enable command history feature" @@ -31,11 +36,11 @@ config FINSH_ECHO_DISABLE_DEFAULT default n config FINSH_THREAD_PRIORITY - int "The priority level value of finsh thread" + int "The priority level value of thread" default 20 config FINSH_THREAD_STACK_SIZE - int "The stack size for finsh thread" + int "The stack size for thread" default 4096 config FINSH_CMD_SIZE @@ -58,23 +63,9 @@ config FINSH_PASSWORD_MAX default RT_NAME_MAX endif -config FINSH_USING_MSH - bool "Using module shell" - default y - -if FINSH_USING_MSH -config FINSH_USING_MSH_DEFAULT - bool "Using module shell in default" - default y - -config FINSH_USING_MSH_ONLY - bool "Only using module shell" - default n - config FINSH_ARG_MAX - int "The command arg num for shell" + int "The number of arguments for a shell command" default 10 -endif endif diff --git a/components/finsh/SConscript b/components/finsh/SConscript index be04c56616..1a6d7c8fc7 100644 --- a/components/finsh/SConscript +++ b/components/finsh/SConscript @@ -1,39 +1,17 @@ -Import('rtconfig') from building import * cwd = GetCurrentDir() src = Split(''' shell.c cmd.c +msh.c ''') -fsh_src = Split(''' -finsh_compiler.c -finsh_error.c -finsh_heap.c -finsh_init.c -finsh_node.c -finsh_ops.c -finsh_parser.c -finsh_var.c -finsh_vm.c -finsh_token.c -''') - -msh_src = Glob('msh.c') - if GetDepend('RT_USING_DFS'): - msh_src += ['msh_file.c'] - -if not GetDepend('FINSH_USING_SYMTAB'): - src += ['symbol.c'] -if GetDepend('FINSH_USING_MSH'): - src = src + msh_src -if not GetDepend('FINSH_USING_MSH_ONLY'): - src = src + fsh_src + src += ['msh_file.c'] CPPPATH = [cwd] -group = DefineGroup('finsh', src, depend = ['RT_USING_FINSH'], CPPPATH = CPPPATH) +group = DefineGroup('msh', src, depend = ['RT_USING_FINSH'], CPPPATH = CPPPATH) Return('group') diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index fd08246fa5..ad68c49b35 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -33,10 +33,10 @@ #include #include +#include #ifdef RT_USING_FINSH - -#include "finsh.h" +#include #define LIST_FIND_OBJ_NR 8 @@ -46,7 +46,7 @@ long hello(void) return 0; } -FINSH_FUNCTION_EXPORT(hello, say hello world); +MSH_CMD_EXPORT(hello, say hello world); static long clear(void) { @@ -54,8 +54,7 @@ static long clear(void) return 0; } -FINSH_FUNCTION_EXPORT(clear,clear the terminal screen); -MSH_CMD_EXPORT(clear,clear the terminal screen); +MSH_CMD_EXPORT(clear, clear the terminal screen); extern void rt_show_version(void); long version(void) @@ -64,8 +63,7 @@ long version(void) return 0; } -FINSH_FUNCTION_EXPORT(version, show RT-Thread version information); -MSH_CMD_EXPORT(version, show RT-Thread version information); +MSH_CMD_EXPORT(version, show RT - Thread version information); rt_inline void object_split(int len) { @@ -166,20 +164,22 @@ long list_thread(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; const char *item_title = "thread"; int maxlen; - list_find_init(&find_arg, RT_Object_Class_Thread, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_Thread, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; #ifdef RT_USING_SMP - rt_kprintf("%-*.s cpu bind pri status sp stack size max used left tick error\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " --- ---- --- ------- ---------- ---------- ------ ---------- ---\n"); + rt_kprintf("%-*.s cpu bind pri status sp stack size max used left tick error\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" --- ---- --- ------- ---------- ---------- ------ ---------- ---\n"); #else - rt_kprintf("%-*.s pri status sp stack size max used left tick error\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " --- ------- ---------- ---------- ------ ---------- ---\n"); + rt_kprintf("%-*.s pri status sp stack size max used left tick error\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" --- ------- ---------- ---------- ------ ---------- ---\n"); #endif /*RT_USING_SMP*/ do @@ -201,10 +201,10 @@ long list_thread(void) continue; } /* copy info */ - memcpy(&thread_info, obj, sizeof thread_info); + rt_memcpy(&thread_info, obj, sizeof thread_info); rt_hw_interrupt_enable(level); - thread = (struct rt_thread*)obj; + thread = (struct rt_thread *)obj; { rt_uint8_t stat; rt_uint8_t *ptr; @@ -230,32 +230,31 @@ long list_thread(void) while (*ptr == '#')ptr --; rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", - ((rt_ubase_t)thread->sp - (rt_ubase_t)thread->stack_addr), - thread->stack_size, - ((rt_ubase_t)ptr - (rt_ubase_t)thread->stack_addr) * 100 / thread->stack_size, - thread->remaining_tick, - thread->error); + ((rt_ubase_t)thread->sp - (rt_ubase_t)thread->stack_addr), + thread->stack_size, + ((rt_ubase_t)ptr - (rt_ubase_t)thread->stack_addr) * 100 / thread->stack_size, + thread->remaining_tick, + thread->error); #else ptr = (rt_uint8_t *)thread->stack_addr; while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", - thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp), - thread->stack_size, - (thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100 - / thread->stack_size, - thread->remaining_tick, - thread->error); + thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp), + thread->stack_size, + (thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100 + / thread->stack_size, + thread->remaining_tick, + thread->error); #endif } } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_thread, list thread); MSH_CMD_EXPORT(list_thread, list thread); static void show_wait_queue(struct rt_list_node *list) @@ -266,7 +265,7 @@ static void show_wait_queue(struct rt_list_node *list) for (node = list->next; node != list; node = node->next) { thread = rt_list_entry(node, struct rt_thread, tlist); - rt_kprintf("%s", thread->name); + rt_kprintf("%.*s", RT_NAME_MAX, thread->name); if (node->next != list) rt_kprintf("/"); @@ -279,17 +278,18 @@ long list_sem(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "semaphore"; - list_find_init(&find_arg, RT_Object_Class_Semaphore, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_Semaphore, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s v suspend thread\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " --- --------------\n"); + rt_kprintf("%-*.s v suspend thread\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" --- --------------\n"); do { @@ -310,33 +310,32 @@ long list_sem(void) } rt_hw_interrupt_enable(level); - sem = (struct rt_semaphore*)obj; + sem = (struct rt_semaphore *)obj; if (!rt_list_isempty(&sem->parent.suspend_thread)) { rt_kprintf("%-*.*s %03d %d:", - maxlen, RT_NAME_MAX, - sem->parent.parent.name, - sem->value, - rt_list_len(&sem->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + sem->parent.parent.name, + sem->value, + rt_list_len(&sem->parent.suspend_thread)); show_wait_queue(&(sem->parent.suspend_thread)); rt_kprintf("\n"); } else { rt_kprintf("%-*.*s %03d %d\n", - maxlen, RT_NAME_MAX, - sem->parent.parent.name, - sem->value, - rt_list_len(&sem->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + sem->parent.parent.name, + sem->value, + rt_list_len(&sem->parent.suspend_thread)); } } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_sem, list semaphore in system); MSH_CMD_EXPORT(list_sem, list semaphore in system); #endif @@ -346,17 +345,18 @@ long list_event(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "event"; - list_find_init(&find_arg, RT_Object_Class_Event, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_Event, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s set suspend thread\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " ---------- --------------\n"); + rt_kprintf("%-*.s set suspend thread\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" ---------- --------------\n"); do { @@ -382,26 +382,25 @@ long list_event(void) if (!rt_list_isempty(&e->parent.suspend_thread)) { rt_kprintf("%-*.*s 0x%08x %03d:", - maxlen, RT_NAME_MAX, - e->parent.parent.name, - e->set, - rt_list_len(&e->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + e->parent.parent.name, + e->set, + rt_list_len(&e->parent.suspend_thread)); show_wait_queue(&(e->parent.suspend_thread)); rt_kprintf("\n"); } else { rt_kprintf("%-*.*s 0x%08x 0\n", - maxlen, RT_NAME_MAX, e->parent.parent.name, e->set); + maxlen, RT_NAME_MAX, e->parent.parent.name, e->set); } } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_event, list event in system); MSH_CMD_EXPORT(list_event, list event in system); #endif @@ -411,17 +410,18 @@ long list_mutex(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "mutex"; - list_find_init(&find_arg, RT_Object_Class_Mutex, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_Mutex, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s owner hold suspend thread\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " -------- ---- --------------\n"); + rt_kprintf("%-*.s owner hold suspend thread\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" -------- ---- --------------\n"); do { @@ -445,21 +445,20 @@ long list_mutex(void) m = (struct rt_mutex *)obj; rt_kprintf("%-*.*s %-8.*s %04d %d\n", - maxlen, RT_NAME_MAX, - m->parent.parent.name, - RT_NAME_MAX, - m->owner->name, - m->hold, - rt_list_len(&m->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + m->parent.parent.name, + RT_NAME_MAX, + m->owner->name, + m->hold, + rt_list_len(&m->parent.suspend_thread)); } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_mutex, list mutex in system); MSH_CMD_EXPORT(list_mutex, list mutex in system); #endif @@ -469,17 +468,18 @@ long list_mailbox(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "mailbox"; - list_find_init(&find_arg, RT_Object_Class_MailBox, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_MailBox, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s entry size suspend thread\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " ---- ---- --------------\n"); + rt_kprintf("%-*.s entry size suspend thread\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" ---- ---- --------------\n"); do { @@ -505,32 +505,31 @@ long list_mailbox(void) if (!rt_list_isempty(&m->parent.suspend_thread)) { rt_kprintf("%-*.*s %04d %04d %d:", - maxlen, RT_NAME_MAX, - m->parent.parent.name, - m->entry, - m->size, - rt_list_len(&m->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + m->parent.parent.name, + m->entry, + m->size, + rt_list_len(&m->parent.suspend_thread)); show_wait_queue(&(m->parent.suspend_thread)); rt_kprintf("\n"); } else { rt_kprintf("%-*.*s %04d %04d %d\n", - maxlen, RT_NAME_MAX, - m->parent.parent.name, - m->entry, - m->size, - rt_list_len(&m->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + m->parent.parent.name, + m->entry, + m->size, + rt_list_len(&m->parent.suspend_thread)); } } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_mailbox, list mail box in system); MSH_CMD_EXPORT(list_mailbox, list mail box in system); #endif @@ -540,17 +539,18 @@ long list_msgqueue(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "msgqueue"; - list_find_init(&find_arg, RT_Object_Class_MessageQueue, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_MessageQueue, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s entry suspend thread\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " ---- --------------\n"); + rt_kprintf("%-*.s entry suspend thread\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" ---- --------------\n"); do { next = list_get_next(next, &find_arg); @@ -575,29 +575,28 @@ long list_msgqueue(void) if (!rt_list_isempty(&m->parent.suspend_thread)) { rt_kprintf("%-*.*s %04d %d:", - maxlen, RT_NAME_MAX, - m->parent.parent.name, - m->entry, - rt_list_len(&m->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + m->parent.parent.name, + m->entry, + rt_list_len(&m->parent.suspend_thread)); show_wait_queue(&(m->parent.suspend_thread)); rt_kprintf("\n"); } else { rt_kprintf("%-*.*s %04d %d\n", - maxlen, RT_NAME_MAX, - m->parent.parent.name, - m->entry, - rt_list_len(&m->parent.suspend_thread)); + maxlen, RT_NAME_MAX, + m->parent.parent.name, + m->entry, + rt_list_len(&m->parent.suspend_thread)); } } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_msgqueue, list message queue in system); MSH_CMD_EXPORT(list_msgqueue, list message queue in system); #endif @@ -607,17 +606,18 @@ long list_memheap(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "memheap"; - list_find_init(&find_arg, RT_Object_Class_MemHeap, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_MemHeap, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s pool size max used size available size\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " ---------- ------------- --------------\n"); + rt_kprintf("%-*.s pool size max used size available size\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" ---------- ------------- --------------\n"); do { next = list_get_next(next, &find_arg); @@ -641,20 +641,19 @@ long list_memheap(void) mh = (struct rt_memheap *)obj; rt_kprintf("%-*.*s %-010d %-013d %-05d\n", - maxlen, RT_NAME_MAX, - mh->parent.name, - mh->pool_size, - mh->max_used_size, - mh->available_size); + maxlen, RT_NAME_MAX, + mh->parent.name, + mh->pool_size, + mh->max_used_size, + mh->available_size); } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_memheap, list memory heap in system); MSH_CMD_EXPORT(list_memheap, list memory heap in system); #endif @@ -664,17 +663,18 @@ long list_mempool(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "mempool"; - list_find_init(&find_arg, RT_Object_Class_MemPool, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_MemPool, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s block total free suspend thread\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " ---- ---- ---- --------------\n"); + rt_kprintf("%-*.s block total free suspend thread\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" ---- ---- ---- --------------\n"); do { next = list_get_next(next, &find_arg); @@ -708,33 +708,32 @@ long list_mempool(void) if (suspend_thread_count > 0) { rt_kprintf("%-*.*s %04d %04d %04d %d:", - maxlen, RT_NAME_MAX, - mp->parent.name, - mp->block_size, - mp->block_total_count, - mp->block_free_count, - suspend_thread_count); + maxlen, RT_NAME_MAX, + mp->parent.name, + mp->block_size, + mp->block_total_count, + mp->block_free_count, + suspend_thread_count); show_wait_queue(&(mp->suspend_thread)); rt_kprintf("\n"); } else { rt_kprintf("%-*.*s %04d %04d %04d %d\n", - maxlen, RT_NAME_MAX, - mp->parent.name, - mp->block_size, - mp->block_total_count, - mp->block_free_count, - suspend_thread_count); + maxlen, RT_NAME_MAX, + mp->parent.name, + mp->block_size, + mp->block_total_count, + mp->block_free_count, + suspend_thread_count); } } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_mempool, list memory pool in system) MSH_CMD_EXPORT(list_mempool, list memory pool in system); #endif @@ -743,18 +742,20 @@ long list_timer(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "timer"; - list_find_init(&find_arg, RT_Object_Class_Timer, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_Timer, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s periodic timeout flag\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " ---------- ---------- -----------\n"); - do { + rt_kprintf("%-*.s periodic timeout flag\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" ---------- ---------- -----------\n"); + do + { next = list_get_next(next, &find_arg); { int i; @@ -775,10 +776,10 @@ long list_timer(void) timer = (struct rt_timer *)obj; rt_kprintf("%-*.*s 0x%08x 0x%08x ", - maxlen, RT_NAME_MAX, - timer->parent.name, - timer->init_tick, - timer->timeout_tick); + maxlen, RT_NAME_MAX, + timer->parent.name, + timer->init_tick, + timer->timeout_tick); if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) rt_kprintf("activated\n"); else @@ -787,13 +788,12 @@ long list_timer(void) } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); rt_kprintf("current tick:0x%08x\n", rt_tick_get()); return 0; } -FINSH_FUNCTION_EXPORT(list_timer, list timer in system); MSH_CMD_EXPORT(list_timer, list timer in system); #ifdef RT_USING_DEVICE @@ -831,17 +831,18 @@ long list_device(void) rt_ubase_t level; list_get_next_t find_arg; rt_list_t *obj_list[LIST_FIND_OBJ_NR]; - rt_list_t *next = (rt_list_t*)RT_NULL; + rt_list_t *next = (rt_list_t *)RT_NULL; int maxlen; const char *item_title = "device"; - list_find_init(&find_arg, RT_Object_Class_Device, obj_list, sizeof(obj_list)/sizeof(obj_list[0])); + list_find_init(&find_arg, RT_Object_Class_Device, obj_list, sizeof(obj_list) / sizeof(obj_list[0])); maxlen = RT_NAME_MAX; - rt_kprintf("%-*.s type ref count\n", maxlen, item_title); object_split(maxlen); - rt_kprintf( " -------------------- ----------\n"); + rt_kprintf("%-*.s type ref count\n", maxlen, item_title); + object_split(maxlen); + rt_kprintf(" -------------------- ----------\n"); do { next = list_get_next(next, &find_arg); @@ -864,31 +865,25 @@ long list_device(void) device = (struct rt_device *)obj; rt_kprintf("%-*.*s %-20s %-8d\n", - maxlen, RT_NAME_MAX, - device->parent.name, - (device->type <= RT_Device_Class_Unknown) ? - device_type_str[device->type] : - device_type_str[RT_Device_Class_Unknown], - device->ref_count); + maxlen, RT_NAME_MAX, + device->parent.name, + (device->type <= RT_Device_Class_Unknown) ? + device_type_str[device->type] : + device_type_str[RT_Device_Class_Unknown], + device->ref_count); } } } - while (next != (rt_list_t*)RT_NULL); + while (next != (rt_list_t *)RT_NULL); return 0; } -FINSH_FUNCTION_EXPORT(list_device, list device in system); MSH_CMD_EXPORT(list_device, list device in system); #endif long list(void) { -#ifndef FINSH_USING_MSH_ONLY - struct finsh_syscall_item *syscall_item; - struct finsh_sysvar_item *sysvar_item; -#endif - rt_kprintf("--Function List:\n"); { struct finsh_syscall *index; @@ -907,247 +902,8 @@ long list(void) } } -#ifndef FINSH_USING_MSH_ONLY - /* list syscall list */ - syscall_item = global_syscall_list; - while (syscall_item != NULL) - { - rt_kprintf("[l] %s\n", syscall_item->syscall.name); - syscall_item = syscall_item->next; - } - - rt_kprintf("--Variable List:\n"); - { - struct finsh_sysvar *index; - for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) - { -#ifdef FINSH_USING_DESCRIPTION - rt_kprintf("%-16s -- %s\n", index->name, index->desc); -#else - rt_kprintf("%s\n", index->name); -#endif - } - } - - sysvar_item = global_sysvar_list; - while (sysvar_item != NULL) - { - rt_kprintf("[l] %s\n", sysvar_item->sysvar.name); - sysvar_item = sysvar_item->next; - } -#endif - return 0; } -FINSH_FUNCTION_EXPORT(list, list all symbol in system) - -#ifndef FINSH_USING_MSH_ONLY -static int str_is_prefix(const char *prefix, const char *str) -{ - while ((*prefix) && (*prefix == *str)) - { - prefix ++; - str ++; - } - - if (*prefix == 0) - return 0; - - return -1; -} - -static int str_common(const char *str1, const char *str2) -{ - const char *str = str1; - - while ((*str != 0) && (*str2 != 0) && (*str == *str2)) - { - str ++; - str2 ++; - } - - return (str - str1); -} - -void list_prefix(char *prefix) -{ - struct finsh_syscall_item *syscall_item; - struct finsh_sysvar_item *sysvar_item; - rt_uint16_t func_cnt, var_cnt; - int length, min_length; - const char *name_ptr; - - func_cnt = 0; - var_cnt = 0; - min_length = 0; - name_ptr = RT_NULL; - - /* checks in system function call */ - { - struct finsh_syscall *index; - for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) - { - /* skip internal command */ - if (str_is_prefix("__", index->name) == 0) continue; - - if (str_is_prefix(prefix, index->name) == 0) - { - if (func_cnt == 0) - { - rt_kprintf("--function:\n"); - - if (*prefix != 0) - { - /* set name_ptr */ - name_ptr = index->name; - - /* set initial length */ - min_length = strlen(name_ptr); - } - } - - func_cnt ++; - - if (*prefix != 0) - { - length = str_common(name_ptr, index->name); - if (length < min_length) - min_length = length; - } - -#ifdef FINSH_USING_DESCRIPTION - rt_kprintf("%-16s -- %s\n", index->name, index->desc); -#else - rt_kprintf("%s\n", index->name); -#endif - } - } - } - - /* checks in dynamic system function call */ - syscall_item = global_syscall_list; - while (syscall_item != NULL) - { - if (str_is_prefix(prefix, syscall_item->syscall.name) == 0) - { - if (func_cnt == 0) - { - rt_kprintf("--function:\n"); - if (*prefix != 0 && name_ptr == NULL) - { - /* set name_ptr */ - name_ptr = syscall_item->syscall.name; - - /* set initial length */ - min_length = strlen(name_ptr); - } - } - - func_cnt ++; - - if (*prefix != 0) - { - length = str_common(name_ptr, syscall_item->syscall.name); - if (length < min_length) - min_length = length; - } - - rt_kprintf("[l] %s\n", syscall_item->syscall.name); - } - syscall_item = syscall_item->next; - } - - /* checks in system variable */ - { - struct finsh_sysvar *index; - for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) - { - if (str_is_prefix(prefix, index->name) == 0) - { - if (var_cnt == 0) - { - rt_kprintf("--variable:\n"); - - if (*prefix != 0 && name_ptr == NULL) - { - /* set name_ptr */ - name_ptr = index->name; - - /* set initial length */ - min_length = strlen(name_ptr); - - } - } - - var_cnt ++; - - if (*prefix != 0) - { - length = str_common(name_ptr, index->name); - if (length < min_length) - min_length = length; - } - -#ifdef FINSH_USING_DESCRIPTION - rt_kprintf("%-16s -- %s\n", index->name, index->desc); -#else - rt_kprintf("%s\n", index->name); -#endif - } - } - } - - /* checks in dynamic system variable */ - sysvar_item = global_sysvar_list; - while (sysvar_item != NULL) - { - if (str_is_prefix(prefix, sysvar_item->sysvar.name) == 0) - { - if (var_cnt == 0) - { - rt_kprintf("--variable:\n"); - if (*prefix != 0 && name_ptr == NULL) - { - /* set name_ptr */ - name_ptr = sysvar_item->sysvar.name; - - /* set initial length */ - min_length = strlen(name_ptr); - } - } - - var_cnt ++; - - if (*prefix != 0) - { - length = str_common(name_ptr, sysvar_item->sysvar.name); - if (length < min_length) - min_length = length; - } - - rt_kprintf("[v] %s\n", sysvar_item->sysvar.name); - } - sysvar_item = sysvar_item->next; - } - - /* only one matched */ - if (name_ptr != NULL) - { - rt_strncpy(prefix, name_ptr, min_length); - } -} -#endif - -#if defined(FINSH_USING_SYMTAB) && !defined(FINSH_USING_MSH_ONLY) -static int dummy = 0; -FINSH_VAR_EXPORT(dummy, finsh_type_int, dummy variable for finsh) -#endif +MSH_CMD_EXPORT(list, list all symbol in system) #endif /* RT_USING_FINSH */ - diff --git a/components/finsh/finsh.h b/components/finsh/finsh.h index dd5e27dea5..74fef60fc0 100644 --- a/components/finsh/finsh.h +++ b/components/finsh/finsh.h @@ -11,239 +11,157 @@ #define __FINSH_H__ #include -#include "finsh_api.h" -/* -- the beginning of option -- */ -#define FINSH_NAME_MAX 16 /* max length of identifier */ -#define FINSH_NODE_MAX 16 /* max number of node */ - -#define FINSH_HEAP_MAX 128 /* max length of heap */ -#define FINSH_STRING_MAX 128 /* max length of string */ -#define FINSH_VARIABLE_MAX 8 /* max number of variable */ - -#define FINSH_STACK_MAX 64 /* max stack size */ -#define FINSH_TEXT_MAX 128 /* max text segment size */ +#if defined(_MSC_VER) + #pragma section("FSymTab$f",read) +#endif -#define HEAP_ALIGNMENT 4 /* heap alignment */ +typedef long (*syscall_func)(void); +#ifdef FINSH_USING_SYMTAB +#ifdef __TI_COMPILER_VERSION__ + #define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab")) +#endif +#ifdef FINSH_USING_DESCRIPTION +#ifdef _MSC_VER +#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ + const char __fsym_##cmd##_name[] = #cmd; \ + const char __fsym_##cmd##_desc[] = #desc; \ + __declspec(allocate("FSymTab$f")) \ + const struct finsh_syscall __fsym_##cmd = \ + { \ + __fsym_##cmd##_name, \ + __fsym_##cmd##_desc, \ + (syscall_func)&name \ + }; +#pragma comment(linker, "/merge:FSymTab=mytext") + +#elif defined(__TI_COMPILER_VERSION__) +#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ + __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \ + const char __fsym_##cmd##_name[] = #cmd; \ + const char __fsym_##cmd##_desc[] = #desc; \ + const struct finsh_syscall __fsym_##cmd = \ + { \ + __fsym_##cmd##_name, \ + __fsym_##cmd##_desc, \ + (syscall_func)&name \ + }; -#define FINSH_GET16(x) (*(x)) | (*((x)+1) << 8) -#define FINSH_GET32(x) (rt_ubase_t)(*(x)) | ((rt_ubase_t)*((x)+1) << 8) | \ - ((rt_ubase_t)*((x)+2) << 16) | ((rt_ubase_t)*((x)+3) << 24) +#else +#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ + const char __fsym_##cmd##_name[] RT_SECTION(".rodata.name") = #cmd; \ + const char __fsym_##cmd##_desc[] RT_SECTION(".rodata.name") = #desc; \ + RT_USED const struct finsh_syscall __fsym_##cmd RT_SECTION("FSymTab")= \ + { \ + __fsym_##cmd##_name, \ + __fsym_##cmd##_desc, \ + (syscall_func)&name \ + }; -#define FINSH_SET16(x, v) \ - do \ - { \ - *(x) = (v) & 0x00ff; \ - (*((x)+1)) = (v) >> 8; \ - } while ( 0 ) +#endif +#else +#ifdef _MSC_VER +#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ + const char __fsym_##cmd##_name[] = #cmd; \ + __declspec(allocate("FSymTab$f")) \ + const struct finsh_syscall __fsym_##cmd = \ + { \ + __fsym_##cmd##_name, \ + (syscall_func)&name \ + }; +#pragma comment(linker, "/merge:FSymTab=mytext") + +#elif defined(__TI_COMPILER_VERSION__) +#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ + __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \ + const char __fsym_##cmd##_name[] = #cmd; \ + const struct finsh_syscall __fsym_##cmd = \ + { \ + __fsym_##cmd##_name, \ + (syscall_func)&name \ + }; -#define FINSH_SET32(x, v) \ - do \ - { \ - *(x) = (rt_uint32_t)(v) & 0x000000ff; \ - (*((x)+1)) = ((rt_uint32_t)(v) >> 8) & 0x000000ff; \ - (*((x)+2)) = ((rt_uint32_t)(v) >> 16) & 0x000000ff; \ - (*((x)+3)) = ((rt_uint32_t)(v) >> 24); \ - } while ( 0 ) +#else +#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ + const char __fsym_##cmd##_name[] = #cmd; \ + RT_USED const struct finsh_syscall __fsym_##cmd RT_SECTION("FSymTab")= \ + { \ + __fsym_##cmd##_name, \ + (syscall_func)&name \ + }; -/* -- the end of option -- */ +#endif +#endif /* end of FINSH_USING_DESCRIPTION */ +#endif /* end of FINSH_USING_SYMTAB */ -/* std header file */ -#include -#include -#include -#include -#include +/** + * @ingroup finsh + * + * This macro exports a system function to finsh shell. + * + * @param name the name of function. + * @param desc the description of function, which will show in help. + */ +#define FINSH_FUNCTION_EXPORT(name, desc) \ + FINSH_FUNCTION_EXPORT_CMD(name, name, desc) -#define FINSH_VERSION_MAJOR 1 -#define FINSH_VERSION_MINOR 0 +/** + * @ingroup finsh + * + * This macro exports a system function with an alias name to finsh shell. + * + * @param name the name of function. + * @param alias the alias name of function. + * @param desc the description of function, which will show in help. + */ +#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc) \ + FINSH_FUNCTION_EXPORT_CMD(name, alias, desc) /** - * @addtogroup finsh + * @ingroup finsh + * + * This macro exports a command to module shell. + * + * @param command the name of command. + * @param desc the description of command, which will show in help. */ -/*@{*/ -#define FINSH_ERROR_OK 0 /**< No error */ -#define FINSH_ERROR_INVALID_TOKEN 1 /**< Invalid token */ -#define FINSH_ERROR_EXPECT_TYPE 2 /**< Expect a type */ -#define FINSH_ERROR_UNKNOWN_TYPE 3 /**< Unknown type */ -#define FINSH_ERROR_VARIABLE_EXIST 4 /**< Variable exist */ -#define FINSH_ERROR_EXPECT_OPERATOR 5 /**< Expect a operator */ -#define FINSH_ERROR_MEMORY_FULL 6 /**< Memory full */ -#define FINSH_ERROR_UNKNOWN_OP 7 /**< Unknown operator */ -#define FINSH_ERROR_UNKNOWN_NODE 8 /**< Unknown node */ -#define FINSH_ERROR_EXPECT_CHAR 9 /**< Expect a character */ -#define FINSH_ERROR_UNEXPECT_END 10 /**< Unexpect end */ -#define FINSH_ERROR_UNKNOWN_TOKEN 11 /**< Unknown token */ -#define FINSH_ERROR_NO_FLOAT 12 /**< Float not supported */ -#define FINSH_ERROR_UNKNOWN_SYMBOL 13 /**< Unknown symbol */ -#define FINSH_ERROR_NULL_NODE 14 /**< Null node */ -/*@}*/ +#define MSH_CMD_EXPORT(command, desc) \ + FINSH_FUNCTION_EXPORT_CMD(command, __cmd_##command, desc) +#define MSH_CMD_EXPORT_ALIAS(command, alias, desc) \ + FINSH_FUNCTION_EXPORT_ALIAS(command, __cmd_##alias, desc) + +/* system call table */ +struct finsh_syscall +{ + const char *name; /* the name of system call */ +#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB) + const char *desc; /* description of system call */ +#endif + syscall_func func; /* the function address of system call */ +}; /* system call item */ struct finsh_syscall_item { - struct finsh_syscall_item* next; /* next item */ + struct finsh_syscall_item *next; /* next item */ struct finsh_syscall syscall; /* syscall */ }; -extern struct finsh_syscall_item *global_syscall_list; -/* system variable table */ -struct finsh_sysvar -{ - const char* name; /* the name of variable */ -#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB) - const char* desc; /* description of system variable */ -#endif - uint8_t type; /* the type of variable */ - void* var ; /* the address of variable */ -}; +extern struct finsh_syscall_item *global_syscall_list; +extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end; #if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) -struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call); -struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call); -#define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index) -#define FINSH_NEXT_SYSVAR(index) index=finsh_sysvar_next(index) + struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call); + #define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index) #else -#define FINSH_NEXT_SYSCALL(index) index++ -#define FINSH_NEXT_SYSVAR(index) index++ + #define FINSH_NEXT_SYSCALL(index) index++ #endif -/* system variable item */ -struct finsh_sysvar_item -{ - struct finsh_sysvar_item *next; /* next item */ - struct finsh_sysvar sysvar; /* system variable */ -}; -extern struct finsh_sysvar *_sysvar_table_begin, *_sysvar_table_end; -extern struct finsh_sysvar_item* global_sysvar_list; +/* find out system call, which should be implemented in user program */ +struct finsh_syscall *finsh_syscall_lookup(const char *name); -/* find out system variable, which should be implemented in user program */ -struct finsh_sysvar* finsh_sysvar_lookup(const char* name); - - -struct finsh_token -{ - char eof; - char replay; - - int position; - uint8_t current_token; - - union { - char char_value; - int int_value; - long long_value; - } value; - uint8_t string[FINSH_STRING_MAX]; - - uint8_t* line; -}; - -#define FINSH_IDTYPE_VAR 0x01 -#define FINSH_IDTYPE_SYSVAR 0x02 -#define FINSH_IDTYPE_SYSCALL 0x04 -#define FINSH_IDTYPE_ADDRESS 0x08 -struct finsh_node -{ - uint8_t node_type; /* node node_type */ - uint8_t data_type; /* node data node_type */ - uint8_t idtype; /* id node information */ - - union { /* value node */ - char char_value; - short short_value; - int int_value; - long long_value; - void* ptr; - } value; - union - { - /* point to variable identifier or function identifier */ - struct finsh_var *var; - struct finsh_sysvar *sysvar; - struct finsh_syscall*syscall; - }id; - - /* sibling and child node */ - struct finsh_node *sibling, *child; -}; - -struct finsh_parser -{ - uint8_t* parser_string; - - struct finsh_token token; - struct finsh_node* root; -}; - -/** - * @ingroup finsh - * - * The basic data type in finsh shell - */ -enum finsh_type { - finsh_type_unknown = 0, /**< unknown data type */ - finsh_type_void, /**< void */ - finsh_type_voidp, /**< void pointer */ - finsh_type_char, /**< char */ - finsh_type_uchar, /**< unsigned char */ - finsh_type_charp, /**< char pointer */ - finsh_type_short, /**< short */ - finsh_type_ushort, /**< unsigned short */ - finsh_type_shortp, /**< short pointer */ - finsh_type_int, /**< int */ - finsh_type_uint, /**< unsigned int */ - finsh_type_intp, /**< int pointer */ - finsh_type_long, /**< long */ - finsh_type_ulong, /**< unsigned long */ - finsh_type_longp /**< long pointer */ -}; - -/* init finsh environment */ -int finsh_init(struct finsh_parser* parser); -/* flush finsh node, text segment */ -int finsh_flush(struct finsh_parser* parser); -/* reset all of finsh */ -int finsh_reset(struct finsh_parser* parser); #ifdef RT_USING_DEVICE -void finsh_set_device(const char* device_name); + void finsh_set_device(const char *device_name); #endif -/* run finsh parser to generate abstract synatx tree */ -void finsh_parser_run (struct finsh_parser* parser, const unsigned char* string); -/* run compiler to compile abstract syntax tree */ -int finsh_compiler_run(struct finsh_node* node); -/* run finsh virtual machine */ -void finsh_vm_run(void); - -/* get variable value */ -struct finsh_var* finsh_var_lookup(const char* name); -/* get bottom value of stack */ -long finsh_stack_bottom(void); - -/* get error number of finsh */ -uint8_t finsh_errno(void); -/* get error string */ -const char* finsh_error_string(uint8_t type); - -#ifdef RT_USING_HEAP -/** - * @ingroup finsh - * - * This function appends a system call to finsh runtime environment - * @param name the name of system call - * @param func the function pointer of system call - */ -void finsh_syscall_append(const char* name, syscall_func func); - -/** - * @ingroup finsh - * - * This function appends a system variable to finsh runtime environment - * @param name the name of system variable - * @param type the data type of system variable - * @param addr the address of system variable - */ -void finsh_sysvar_append(const char* name, uint8_t type, void* addr); -#endif #endif diff --git a/components/finsh/finsh_api.h b/components/finsh/finsh_api.h deleted file mode 100644 index fd9e6a773e..0000000000 --- a/components/finsh/finsh_api.h +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef FINSH_API_H__ -#define FINSH_API_H__ - -#if defined(_MSC_VER) -#pragma section("FSymTab$f",read) -#pragma section("VSymTab",read) -#endif - -typedef long (*syscall_func)(void); - -/* system call table */ -struct finsh_syscall -{ - const char* name; /* the name of system call */ -#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB) - const char* desc; /* description of system call */ -#endif - syscall_func func; /* the function address of system call */ -}; -extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end; - -/* find out system call, which should be implemented in user program */ -struct finsh_syscall* finsh_syscall_lookup(const char* name); - -#ifdef FINSH_USING_SYMTAB - -#ifdef __TI_COMPILER_VERSION__ -#define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab")) -#define __TI_FINSH_EXPORT_VAR(v) PRAGMA(DATA_SECTION(v,"VSymTab")) -#endif - - #ifdef FINSH_USING_DESCRIPTION - #ifdef _MSC_VER - #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - const char __fsym_##cmd##_name[] = #cmd; \ - const char __fsym_##cmd##_desc[] = #desc; \ - __declspec(allocate("FSymTab$f")) \ - const struct finsh_syscall __fsym_##cmd = \ - { \ - __fsym_##cmd##_name, \ - __fsym_##cmd##_desc, \ - (syscall_func)&name \ - }; - #pragma comment(linker, "/merge:FSymTab=mytext") - - #define FINSH_VAR_EXPORT(name, type, desc) \ - const char __vsym_##name##_name[] = #name; \ - const char __vsym_##name##_desc[] = #desc; \ - __declspec(allocate("VSymTab")) \ - const struct finsh_sysvar __vsym_##name = \ - { \ - __vsym_##name##_name, \ - __vsym_##name##_desc, \ - type, \ - (void*)&name \ - }; - - #elif defined(__TI_COMPILER_VERSION__) - #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \ - const char __fsym_##cmd##_name[] = #cmd; \ - const char __fsym_##cmd##_desc[] = #desc; \ - const struct finsh_syscall __fsym_##cmd = \ - { \ - __fsym_##cmd##_name, \ - __fsym_##cmd##_desc, \ - (syscall_func)&name \ - }; - - #define FINSH_VAR_EXPORT(name, type, desc) \ - __TI_FINSH_EXPORT_VAR(__vsym_##name); \ - const char __vsym_##name##_name[] = #name; \ - const char __vsym_##name##_desc[] = #desc; \ - const struct finsh_sysvar __vsym_##name = \ - { \ - __vsym_##name##_name, \ - __vsym_##name##_desc, \ - type, \ - (void*)&name \ - }; - - #else - #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - const char __fsym_##cmd##_name[] RT_SECTION(".rodata.name") = #cmd; \ - const char __fsym_##cmd##_desc[] RT_SECTION(".rodata.name") = #desc; \ - RT_USED const struct finsh_syscall __fsym_##cmd RT_SECTION("FSymTab")= \ - { \ - __fsym_##cmd##_name, \ - __fsym_##cmd##_desc, \ - (syscall_func)&name \ - }; - - #define FINSH_VAR_EXPORT(name, type, desc) \ - const char __vsym_##name##_name[] RT_SECTION(".rodata.name") = #name; \ - const char __vsym_##name##_desc[] RT_SECTION(".rodata.name") = #desc; \ - RT_USED const struct finsh_sysvar __vsym_##name RT_SECTION("VSymTab")= \ - { \ - __vsym_##name##_name, \ - __vsym_##name##_desc, \ - type, \ - (void*)&name \ - }; - - #endif - #else - #ifdef _MSC_VER - #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - const char __fsym_##cmd##_name[] = #cmd; \ - __declspec(allocate("FSymTab$f")) \ - const struct finsh_syscall __fsym_##cmd = \ - { \ - __fsym_##cmd##_name, \ - (syscall_func)&name \ - }; - #pragma comment(linker, "/merge:FSymTab=mytext") - - #define FINSH_VAR_EXPORT(name, type, desc) \ - const char __vsym_##name##_name[] = #name; \ - __declspec(allocate("VSymTab")) const struct finsh_sysvar __vsym_##name = \ - { \ - __vsym_##name##_name, \ - type, \ - (void*)&name \ - }; - - #elif defined(__TI_COMPILER_VERSION__) - #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \ - const char __fsym_##cmd##_name[] = #cmd; \ - const struct finsh_syscall __fsym_##cmd = \ - { \ - __fsym_##cmd##_name, \ - (syscall_func)&name \ - }; - - #define FINSH_VAR_EXPORT(name, type, desc) \ - __TI_FINSH_EXPORT_VAR(__vsym_##name); \ - const char __vsym_##name##_name[] = #name; \ - const struct finsh_sysvar __vsym_##name = \ - { \ - __vsym_##name##_name, \ - type, \ - (void*)&name \ - }; - - #else - #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - const char __fsym_##cmd##_name[] = #cmd; \ - RT_USED const struct finsh_syscall __fsym_##cmd RT_SECTION("FSymTab")= \ - { \ - __fsym_##cmd##_name, \ - (syscall_func)&name \ - }; - - #define FINSH_VAR_EXPORT(name, type, desc) \ - const char __vsym_##name##_name[] = #name; \ - RT_USED const struct finsh_sysvar __vsym_##name RT_SECTION("VSymTab")= \ - { \ - __vsym_##name##_name, \ - type, \ - (void*)&name \ - }; - - #endif - #endif /* end of FINSH_USING_DESCRIPTION */ -#endif /* end of FINSH_USING_SYMTAB */ - -/** - * @ingroup finsh - * - * This macro exports a system function to finsh shell. - * - * @param name the name of function. - * @param desc the description of function, which will show in help. - */ -#define FINSH_FUNCTION_EXPORT(name, desc) \ - FINSH_FUNCTION_EXPORT_CMD(name, name, desc) - -/** - * @ingroup finsh - * - * This macro exports a system function with an alias name to finsh shell. - * - * @param name the name of function. - * @param alias the alias name of function. - * @param desc the description of function, which will show in help. - */ -#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc) \ - FINSH_FUNCTION_EXPORT_CMD(name, alias, desc) - -/** - * @ingroup finsh - * - * This macro exports a command to module shell. - * - * @param command the name of command. - * @param desc the description of command, which will show in help. - */ -#ifdef FINSH_USING_MSH -#define MSH_CMD_EXPORT(command, desc) \ - FINSH_FUNCTION_EXPORT_CMD(command, __cmd_##command, desc) -#define MSH_CMD_EXPORT_ALIAS(command, alias, desc) \ - FINSH_FUNCTION_EXPORT_ALIAS(command, __cmd_##alias, desc) -#else -#define MSH_CMD_EXPORT(command, desc) -#define MSH_CMD_EXPORT_ALIAS(command, alias, desc) -#endif - -#endif diff --git a/components/finsh/finsh_compiler.c b/components/finsh/finsh_compiler.c deleted file mode 100644 index 1cb4ff00a5..0000000000 --- a/components/finsh/finsh_compiler.c +++ /dev/null @@ -1,918 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include - -#include "finsh_node.h" -#include "finsh_error.h" -#include "finsh_var.h" -#include "finsh_ops.h" - -union finsh_value* finsh_compile_sp; /* stack pointer */ -uint8_t* finsh_compile_pc; /* PC */ - -#define finsh_code_byte(x) do { *finsh_compile_pc = (x); finsh_compile_pc ++; } while(0) -#define finsh_code_word(x) do { FINSH_SET16(finsh_compile_pc, x); finsh_compile_pc +=2; } while(0) -#define finsh_code_dword(x) do { FINSH_SET32(finsh_compile_pc, x); finsh_compile_pc +=4; } while(0) - -static int finsh_compile(struct finsh_node* node) -{ - if (node != NULL) - { - /* compile child node */ - if (finsh_node_child(node) != NULL) - finsh_compile(finsh_node_child(node)); - - /* compile current node */ - switch (node->node_type) - { - case FINSH_NODE_ID: - { - /* identifier::syscall */ - if (node->idtype & FINSH_IDTYPE_SYSCALL) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)node->id.syscall->func); - } - /* identifier::sysvar */ - else if (node->idtype & FINSH_IDTYPE_SYSVAR) - { - struct finsh_sysvar* sysvar; - - sysvar = node->id.sysvar; - if (sysvar != NULL) - { - switch (sysvar->type) - { - case finsh_type_char: - case finsh_type_uchar: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - } - else - { - /* load value */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - } - - finsh_code_dword((long)(sysvar->var)); - break; - - case finsh_type_short: - case finsh_type_ushort: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - } - else - { - /* load value */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - } - - finsh_code_dword((long)(sysvar->var)); - break; - - case finsh_type_int: - case finsh_type_uint: - case finsh_type_long: - case finsh_type_ulong: - case finsh_type_charp: - case finsh_type_shortp: - case finsh_type_intp: - case finsh_type_longp: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - } - else - { - /* load value */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - } - - finsh_code_dword((long)(sysvar->var)); - break; - } - } - } - /* identifier::var */ - else - { - struct finsh_var* var; - - var = node->id.var; - if (var != NULL) - { - switch (var->type) - { - case finsh_type_char: - case finsh_type_uchar: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - } - else - { - /* load value */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - } - - finsh_code_dword((long)&(var->value.char_value)); - break; - - case finsh_type_short: - case finsh_type_ushort: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - } - else - { - /* load value */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - } - - finsh_code_dword((long)&(var->value.short_value)); - break; - - case finsh_type_int: - case finsh_type_uint: - case finsh_type_long: - case finsh_type_ulong: - case finsh_type_charp: - case finsh_type_shortp: - case finsh_type_intp: - case finsh_type_longp: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* load address */ - finsh_code_byte(FINSH_OP_LD_DWORD); - } - else - { - /* load value */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - } - - finsh_code_dword((long)&(var->value.long_value)); - break; - } - } - } - } - break; - - /* load const */ - case FINSH_NODE_VALUE_CHAR: - finsh_code_byte(FINSH_OP_LD_BYTE); - finsh_code_byte(node->value.char_value); - break; - - case FINSH_NODE_VALUE_INT: - case FINSH_NODE_VALUE_LONG: - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword(node->value.long_value); - break; - - case FINSH_NODE_VALUE_NULL: - case FINSH_NODE_VALUE_STRING: - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((rt_ubase_t)node->value.ptr); - break; - - /* arithmetic operation */ - case FINSH_NODE_SYS_ADD: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_ADD_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_ADD_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_ADD_DWORD); - break; - - case FINSH_NODE_SYS_SUB: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_SUB_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_SUB_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_SUB_DWORD); - break; - - case FINSH_NODE_SYS_MUL: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_MUL_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_MUL_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_MUL_DWORD); - break; - - case FINSH_NODE_SYS_DIV: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_DIV_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_DIV_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_DIV_DWORD); - break; - - case FINSH_NODE_SYS_MOD: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_MOD_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_MOD_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_MOD_DWORD); - break; - - /* bit operation */ - case FINSH_NODE_SYS_AND: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_AND_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_AND_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_AND_DWORD); - break; - - case FINSH_NODE_SYS_OR: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_OR_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_OR_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_OR_DWORD); - break; - - case FINSH_NODE_SYS_XOR: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_XOR_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_XOR_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_XOR_DWORD); - break; - - case FINSH_NODE_SYS_BITWISE: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_BITWISE_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_BITWISE_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_BITWISE_DWORD); - break; - - case FINSH_NODE_SYS_SHL: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_SHL_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_SHL_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_SHL_DWORD); - break; - - case FINSH_NODE_SYS_SHR: - if (node->data_type == FINSH_DATA_TYPE_BYTE) finsh_code_byte(FINSH_OP_SHR_BYTE); - else if (node->data_type == FINSH_DATA_TYPE_WORD) finsh_code_byte(FINSH_OP_SHR_WORD); - else if (node->data_type == FINSH_DATA_TYPE_DWORD) finsh_code_byte(FINSH_OP_SHR_DWORD); - break; - - /* syscall */ - case FINSH_NODE_SYS_FUNC: - { - int parameters; - struct finsh_node* sibling; - - parameters = 0; - if (finsh_node_child(node) != NULL) - { - sibling = finsh_node_sibling(finsh_node_child(node)); - while (sibling != NULL) - { - parameters ++; - sibling = finsh_node_sibling(sibling); - } - - /* load address of function */ - // finsh_code_dword((long)&(node->var->value.ptr)); - - /* syscall parameters */ - finsh_code_byte(FINSH_OP_SYSCALL); - finsh_code_byte(parameters); - } - } - break; - - /* assign expression */ - case FINSH_NODE_SYS_ASSIGN: - if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID) - { - switch (finsh_node_child(node)->data_type) - { - case FINSH_DATA_TYPE_BYTE: - finsh_code_byte(FINSH_OP_ST_BYTE); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE_STACK); - break; - - case FINSH_DATA_TYPE_WORD: - finsh_code_byte(FINSH_OP_ST_WORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD_STACK); - break; - - case FINSH_DATA_TYPE_DWORD: - finsh_code_byte(FINSH_OP_ST_DWORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - break; - - default: - finsh_error_set(FINSH_ERROR_UNKNOWN_TYPE); - } - } - else if (finsh_node_child(node)->node_type == FINSH_NODE_SYS_GETVALUE) - { - switch ((finsh_node_child(node)->data_type) & 0x0F) - { - case FINSH_DATA_TYPE_BYTE: - finsh_code_byte(FINSH_OP_ST_BYTE); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE_STACK); - break; - - case FINSH_DATA_TYPE_WORD: - finsh_code_byte(FINSH_OP_ST_WORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD_STACK); - break; - - case FINSH_DATA_TYPE_DWORD: - finsh_code_byte(FINSH_OP_ST_DWORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - break; - - default: - finsh_error_set(FINSH_ERROR_UNKNOWN_TYPE); - } - } - break; - - /* pre-increase */ - case FINSH_NODE_SYS_PREINC: - if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID) - { - struct finsh_var* var; - var = finsh_node_child(node)->id.var; - - /* ld_dword &id */ - // finsh_code_byte(FINSH_OP_LD_DWORD); - - switch (node->data_type) - { - case FINSH_DATA_TYPE_BYTE: - /* address */ - // finsh_code_dword((long)&(var->value.char_value)); - - /* ld_value_byte &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - finsh_code_dword((long)&(var->value.char_value)); - - /* ld_byte 1 */ - finsh_code_byte(FINSH_OP_LD_BYTE); - finsh_code_byte(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_ADD_BYTE); - /* st_byte */ - finsh_code_byte(FINSH_OP_ST_BYTE); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - - break; - - case FINSH_DATA_TYPE_WORD: - /* address */ - // finsh_code_dword((long)&(var->value.short_value)); - - /* ld_value_word &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - finsh_code_dword((long)&(var->value.short_value)); - - /* ld_word 1 */ - finsh_code_byte(FINSH_OP_LD_WORD); - finsh_code_word(1); - - /* add_word */ - finsh_code_byte(FINSH_OP_ADD_WORD); - /* st_word */ - finsh_code_byte(FINSH_OP_ST_WORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - - break; - - case FINSH_DATA_TYPE_DWORD: - /* address */ - // finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword 1 */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword(1); - - /* add_dword */ - finsh_code_byte(FINSH_OP_ADD_DWORD); - /* st_dword */ - finsh_code_byte(FINSH_OP_ST_DWORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - - break; - } - } - break; - - /* pre-decrease */ - case FINSH_NODE_SYS_PREDEC: - if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID) - { - struct finsh_var* var; - var = finsh_node_child(node)->id.var; - - /* ld_dword &id */ - // finsh_code_byte(FINSH_OP_LD_DWORD); - - switch (node->data_type) - { - case FINSH_DATA_TYPE_BYTE: - /* address */ - // finsh_code_dword((long)&(var->value.char_value)); - - /* ld_value_byte &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - finsh_code_dword((long)&(var->value.char_value)); - - /* ld_byte 1 */ - finsh_code_byte(FINSH_OP_LD_BYTE); - finsh_code_byte(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_SUB_BYTE); - /* st_byte */ - finsh_code_byte(FINSH_OP_ST_BYTE); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - - break; - - case FINSH_DATA_TYPE_WORD: - /* address */ - // finsh_code_dword((long)&(var->value.short_value)); - - /* ld_value_word &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - finsh_code_dword((long)&(var->value.short_value)); - - /* ld_word 1 */ - finsh_code_byte(FINSH_OP_LD_WORD); - finsh_code_word(1); - - /* add_word */ - finsh_code_byte(FINSH_OP_SUB_WORD); - /* st_word */ - finsh_code_byte(FINSH_OP_ST_WORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - - break; - - case FINSH_DATA_TYPE_DWORD: - /* address */ - // finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword 1 */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword(1); - - /* add_dword */ - finsh_code_byte(FINSH_OP_SUB_DWORD); - /* st_dword */ - finsh_code_byte(FINSH_OP_ST_DWORD); - - /* load value again */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - - break; - } - } - break; - - /* increase */ - case FINSH_NODE_SYS_INC: - if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID) - { - struct finsh_var* var; - var = finsh_node_child(node)->id.var; - - switch (node->data_type) - { - case FINSH_DATA_TYPE_BYTE: - /* ld_value_byte &id */ - // finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - // finsh_code_dword((long)&(var->value.char_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)&(var->value.char_value)); - - /* ld_value_byte &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - finsh_code_dword((long)&(var->value.char_value)); - - /* ld_byte 1 */ - finsh_code_byte(FINSH_OP_LD_BYTE); - finsh_code_byte(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_ADD_BYTE); - /* get byte */ - finsh_code_byte(FINSH_OP_ST_BYTE); - - /* pop */ - finsh_code_byte(FINSH_OP_POP); - break; - - case FINSH_DATA_TYPE_WORD: - /* ld_value_word &id */ - // finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - // finsh_code_dword((long)&(var->value.short_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)&(var->value.short_value)); - - /* ld_value_word &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - finsh_code_dword((long)&(var->value.short_value)); - - /* ld_word 1 */ - finsh_code_byte(FINSH_OP_LD_WORD); - finsh_code_word(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_ADD_WORD); - /* get byte */ - finsh_code_byte(FINSH_OP_ST_WORD); - - /* pop */ - finsh_code_byte(FINSH_OP_POP); - break; - - case FINSH_DATA_TYPE_DWORD: - /* ld_value_dword &id */ - // finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - // finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)&(var->value.long_value)); - - /* ld_value_dword &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword 1 */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_ADD_DWORD); - /* get byte */ - finsh_code_byte(FINSH_OP_ST_DWORD); - - /* pop */ - finsh_code_byte(FINSH_OP_POP); - break; - } - } - break; - - /* decrease */ - case FINSH_NODE_SYS_DEC: - if (finsh_node_child(node) && finsh_node_child(node)->node_type == FINSH_NODE_ID) - { - struct finsh_var* var; - var = finsh_node_child(node)->id.var; - - switch (node->data_type) - { - case FINSH_DATA_TYPE_BYTE: - /* ld_value_byte &id */ - // finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - // finsh_code_dword((long)&(var->value.char_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)&(var->value.char_value)); - - /* ld_value_byte &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE); - finsh_code_dword((long)&(var->value.char_value)); - - /* ld_byte 1 */ - finsh_code_byte(FINSH_OP_LD_BYTE); - finsh_code_byte(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_SUB_BYTE); - /* get byte */ - finsh_code_byte(FINSH_OP_ST_BYTE); - - /* pop */ - finsh_code_byte(FINSH_OP_POP); - break; - - case FINSH_DATA_TYPE_WORD: - /* ld_value_word &id */ - // finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - // finsh_code_dword((long)&(var->value.short_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)&(var->value.short_value)); - - /* ld_value_word &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_WORD); - finsh_code_dword((long)&(var->value.short_value)); - - /* ld_word 1 */ - finsh_code_byte(FINSH_OP_LD_WORD); - finsh_code_word(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_SUB_WORD); - /* get byte */ - finsh_code_byte(FINSH_OP_ST_WORD); - - /* pop */ - finsh_code_byte(FINSH_OP_POP); - break; - - case FINSH_DATA_TYPE_DWORD: - /* ld_value_dword &id */ - // finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - // finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword &id */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword((long)&(var->value.long_value)); - - /* ld_value_dword &id */ - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD); - finsh_code_dword((long)&(var->value.long_value)); - - /* ld_dword 1 */ - finsh_code_byte(FINSH_OP_LD_DWORD); - finsh_code_dword(1); - - /* add_byte */ - finsh_code_byte(FINSH_OP_SUB_DWORD); - /* get byte */ - finsh_code_byte(FINSH_OP_ST_DWORD); - - /* pop */ - finsh_code_byte(FINSH_OP_POP); - break; - } - } - break; - - case FINSH_NODE_SYS_NULL: - finsh_code_dword(0); - break; - - case FINSH_NODE_SYS_GETVALUE: - if (node->idtype & FINSH_IDTYPE_ADDRESS) - { - /* nothing will be generated */ - } - else - { - switch (node->data_type) - { - case FINSH_DATA_TYPE_BYTE: - finsh_code_byte(FINSH_OP_LD_VALUE_BYTE_STACK); - break; - case FINSH_DATA_TYPE_WORD: - finsh_code_byte(FINSH_OP_LD_VALUE_WORD_STACK); - break; - case FINSH_DATA_TYPE_DWORD: - finsh_code_byte(FINSH_OP_LD_VALUE_DWORD_STACK); - break; - default: - break; - } - } - break; - - case FINSH_NODE_SYS_GETADDR: - /* nothing will be generated */ - break; - - default: - finsh_error_set(FINSH_ERROR_UNKNOWN_NODE); - break; - } - - /* compile sibling node */ - if (finsh_node_sibling(node) != NULL) - finsh_compile(finsh_node_sibling(node)); - } - - return 0; -} - -static int finsh_type_check(struct finsh_node* node, uint8_t is_addr) -{ - if (node != NULL) - { - /* address & value */ - if (node->node_type == FINSH_NODE_SYS_ASSIGN || - node->node_type == FINSH_NODE_SYS_PREINC || - node->node_type == FINSH_NODE_SYS_PREDEC || - node->node_type == FINSH_NODE_SYS_GETADDR) - { - /* address */ - finsh_type_check(finsh_node_child(node), FINSH_IDTYPE_ADDRESS); - } - else if (node->node_type == FINSH_NODE_SYS_GETVALUE && is_addr) - { - /* change the attribute of getvalue in left expr */ - finsh_type_check(finsh_node_child(node), 0); - } - else - { - /* transfer 'av' to child node */ - finsh_type_check(finsh_node_child(node), is_addr); - } - - /* always does not load address in sibling */ - finsh_type_check(finsh_node_sibling(node), FINSH_NODE_VALUE); - - /** set attribute of current node */ - - /* make sure the current node is address or value */ - if (node->idtype != FINSH_IDTYPE_SYSCALL) node->idtype |= is_addr; - - if (finsh_node_child(node) != NULL) - { - node->data_type = finsh_node_child(node)->data_type; - return 0; - } - - if (node->node_type == FINSH_NODE_ID) - { - if (node->idtype & FINSH_IDTYPE_VAR) - { - struct finsh_var* var; - - var = node->id.var; - if (var != NULL) - { - switch (var->type) - { - case finsh_type_void: - node->data_type = FINSH_DATA_TYPE_VOID; - break; - - case finsh_type_char: - case finsh_type_uchar: - node->data_type = FINSH_DATA_TYPE_BYTE; - break; - - case finsh_type_short: - case finsh_type_ushort: - node->data_type = FINSH_DATA_TYPE_WORD; - break; - - case finsh_type_int: - case finsh_type_uint: - case finsh_type_long: - case finsh_type_ulong: - node->data_type = FINSH_DATA_TYPE_DWORD; - break; - - case finsh_type_charp: - case finsh_type_voidp: - case finsh_type_shortp: - case finsh_type_intp: - case finsh_type_longp: - node->data_type = FINSH_DATA_TYPE_DWORD; - break; - - default: - finsh_error_set(FINSH_ERROR_UNKNOWN_TYPE); - break; - } - } - } - else if (node->idtype & FINSH_IDTYPE_SYSVAR) - { - struct finsh_sysvar *sysvar; - - sysvar = node->id.sysvar; - if (sysvar != NULL) - { - switch (sysvar->type) - { - case finsh_type_void: - node->data_type = FINSH_DATA_TYPE_VOID; - break; - - case finsh_type_char: - case finsh_type_uchar: - node->data_type = FINSH_DATA_TYPE_BYTE; - break; - - case finsh_type_short: - case finsh_type_ushort: - node->data_type = FINSH_DATA_TYPE_WORD; - break; - - case finsh_type_int: - case finsh_type_uint: - case finsh_type_long: - case finsh_type_ulong: - node->data_type = FINSH_DATA_TYPE_DWORD; - break; - - case finsh_type_charp: - case finsh_type_voidp: - case finsh_type_shortp: - case finsh_type_intp: - case finsh_type_longp: - node->data_type = FINSH_DATA_TYPE_DWORD; - break; - - default: - finsh_error_set(FINSH_ERROR_UNKNOWN_TYPE); - break; - } - } - } - } - else if (node->node_type == FINSH_NODE_VALUE_CHAR) - { - node->data_type = FINSH_DATA_TYPE_BYTE; - } - else if (node->node_type == FINSH_NODE_VALUE_INT || - node->node_type == FINSH_NODE_VALUE_LONG || - node->node_type == FINSH_NODE_VALUE_STRING || - node->node_type == FINSH_NODE_VALUE_NULL) - { - node->data_type = FINSH_DATA_TYPE_DWORD; - } - } - return 0; -} - -int finsh_compiler_run(struct finsh_node* node) -{ - struct finsh_node* sibling; - - /* type check */ - finsh_type_check(node, FINSH_NODE_VALUE); - - /* clean text segment and vm stack */ - memset(&text_segment[0], 0, sizeof(text_segment)); - memset(&finsh_vm_stack[0], 0, sizeof(finsh_vm_stack)); - - /* reset compile stack pointer and pc */ - finsh_compile_sp = &finsh_vm_stack[0]; - finsh_compile_pc = &text_segment[0]; - - /* compile node */ - sibling = node; - while (sibling != NULL) - { - struct finsh_node* current_node; - current_node = sibling; - - /* get sibling node */ - sibling = current_node->sibling; - - /* clean sibling node */ - current_node->sibling = NULL; - finsh_compile(current_node); - - /* pop current value */ - if (sibling != NULL) finsh_code_byte(FINSH_OP_POP); - } - - return 0; -} diff --git a/components/finsh/finsh_error.c b/components/finsh/finsh_error.c deleted file mode 100644 index a5cf2eb514..0000000000 --- a/components/finsh/finsh_error.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include "finsh_error.h" - -uint8_t global_errno; - -static const char * finsh_error_string_table[] = -{ - "No error", - "Invalid token", - "Expect a type", - "Unknown type", - "Variable exist", - "Expect a operater", - "Memory full", - "Unknown operator", - "Unknown node", - "Expect a character", - "Unexpect end", - "Unknown token", - "Float not supported", - "Unknown symbol", - "Null node" -}; - -int finsh_error_init() -{ - global_errno = FINSH_ERROR_OK; - - return 0; -} - -int finsh_error_set(uint8_t type) -{ - global_errno = type; - - return 0; -} - -uint8_t finsh_errno() -{ - return global_errno; -} - -const char* finsh_error_string(uint8_t type) -{ - return finsh_error_string_table[type]; -} diff --git a/components/finsh/finsh_error.h b/components/finsh/finsh_error.h deleted file mode 100644 index 8dfafd013c..0000000000 --- a/components/finsh/finsh_error.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_ERROR_H__ -#define __FINSH_ERROR_H__ - -#include - -int finsh_error_init(void); - -/* get error number */ -uint8_t finsh_errno(void); - -int finsh_error_set(uint8_t type); -const char* finsh_error_string(uint8_t type); - -#endif diff --git a/components/finsh/finsh_heap.c b/components/finsh/finsh_heap.c deleted file mode 100644 index 9f64d108dd..0000000000 --- a/components/finsh/finsh_heap.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include - -#include "finsh_var.h" - -ALIGN(RT_ALIGN_SIZE) -uint8_t finsh_heap[FINSH_HEAP_MAX]; -struct finsh_block_header -{ - uint32_t length; - struct finsh_block_header* next; -}; -#define BLOCK_HEADER(x) (struct finsh_block_header*)(x) -#define finsh_block_get_header(data) (struct finsh_block_header*)((uint8_t*)data - sizeof(struct finsh_block_header)) -#define finsh_block_get_data(header) (uint8_t*)((struct finsh_block_header*)header + 1) -#define HEAP_ALIGN_SIZE(size) (((size) + HEAP_ALIGNMENT - 1) & ~(HEAP_ALIGNMENT-1)) - -static struct finsh_block_header* free_list; -static struct finsh_block_header* allocate_list; - -static void finsh_heap_gc(void); - -static void finsh_block_insert(struct finsh_block_header** list, struct finsh_block_header* header); -static void finsh_block_remove(struct finsh_block_header** list, struct finsh_block_header* header); -static void finsh_block_split(struct finsh_block_header* header, size_t size); -static void finsh_block_merge(struct finsh_block_header** list, struct finsh_block_header* header); - -int finsh_heap_init(void) -{ - /* clear heap to zero */ - memset(&finsh_heap[0], 0, sizeof(finsh_heap)); - - /* init free and alloc list */ - free_list = BLOCK_HEADER(&finsh_heap[0]); - free_list->length = FINSH_HEAP_MAX - sizeof(struct finsh_block_header); - free_list->next = NULL; - - allocate_list = NULL; - - return 0; -} - -/** - * allocate a block from heap - */ -void* finsh_heap_allocate(size_t size) -{ - struct finsh_block_header* header; - - size = HEAP_ALIGN_SIZE(size); - - /* find the first fit block */ - for (header = free_list; - ((header != NULL) && (header->length <= size + sizeof(struct finsh_block_header))); - header = header->next) ; - - if (header == NULL) - { - finsh_heap_gc(); - - /* find the first fit block */ - for (header = free_list; - ((header != NULL) && (header->length < size + sizeof(struct finsh_block_header))); - header = header->next) ; - - /* there is no memory */ - if (header == NULL) return NULL; - } - - /* split block */ - finsh_block_split(header, size); - - /* remove from free list */ - finsh_block_remove(&free_list, header); - header->next = NULL; - - /* insert to allocate list */ - finsh_block_insert(&allocate_list, header); - - memset(finsh_block_get_data(header), 0, size); - - return finsh_block_get_data(header); -} - -/** - * release the allocated block - */ -void finsh_heap_free(void*ptr) -{ - struct finsh_block_header* header; - - /* get block header */ - header = finsh_block_get_header(ptr); - - /* remove from allocate list */ - finsh_block_remove(&allocate_list, header); - - /* insert to free list */ - finsh_block_insert(&free_list, header); - finsh_block_merge(&free_list, header); -} - -/** - * garbage collector - */ -static void finsh_heap_gc(void) -{ - int i; - struct finsh_block_header *header, *temp; - - temp = NULL; - - /* find the first fit block */ - for (header = allocate_list; header != NULL; ) - { - for (i = 0; i < FINSH_VARIABLE_MAX; i ++) - { - if (global_variable[i].type != finsh_type_unknown) - { - if (global_variable[i].value.ptr == finsh_block_get_data(header)) - break; - } - } - - temp = header; - header = header->next; - - /* this block is an unused block, release it */ - if (i == FINSH_VARIABLE_MAX) - { - finsh_heap_free(finsh_block_get_data(temp)); - } - } -} - -/** - * insert a block to list - */ -void finsh_block_insert(struct finsh_block_header** list, struct finsh_block_header* header) -{ - struct finsh_block_header* node; - - if (*list == NULL) - { - *list = header; - return; - } - - /* find out insert point */ - node = *list; - - if (node > header) - { - /* insert node in the header of list */ - header->next = node; - *list = header; - - return; - } - else - { - for (node = *list; node; node = node->next) - { - if (node->next > header) break; - - if (node->next == NULL) break; - } - } - - /* insert node */ - if (node->next != NULL) header->next = node->next; - node->next = header; -} - -/** - * remove block from list - */ -void finsh_block_remove(struct finsh_block_header** list, struct finsh_block_header* header) -{ - struct finsh_block_header* node; - - node = *list; - if (node == header) - { - /* remove list header */ - *list = header->next; - header->next = NULL; - - return; - } - - for (node = *list; node != NULL; node = node->next) - { - if (node->next == header) - { - node->next = header->next; - break; - } - } -} - -/** - * split block - */ -void finsh_block_split(struct finsh_block_header* header, size_t size) -{ - struct finsh_block_header* next; - - /* - * split header into two node: - * header->next->... - */ - next = BLOCK_HEADER((uint8_t*)header + sizeof(struct finsh_block_header) + size); - next->length = header->length - sizeof(struct finsh_block_header) - size; - header->length = size; - next->next = header->next; - - header->next = next; -} - -void finsh_block_merge(struct finsh_block_header** list, struct finsh_block_header* header) -{ - struct finsh_block_header* prev_node; - struct finsh_block_header* next_node; - - next_node = header->next; - - if (*list == header) prev_node = NULL; - else - { - /* find out the previous header */ - for (prev_node = *list; prev_node; prev_node =prev_node->next) - { - if (prev_node->next == header) - break; - } - } - - /* try merge node */ - - /* merge to previous node */ - if (prev_node != NULL && - ((uint8_t*)prev_node + prev_node->length + sizeof(struct finsh_block_header) - == (uint8_t*)header)) - { - /* is it close to next node? */ - if ((next_node != NULL) && - ((uint8_t*)header + header->length + sizeof(struct finsh_block_header) - == (uint8_t*)next_node)) - { - /* merge three node */ - prev_node->length += header->length + next_node->length + - 2 * sizeof(struct finsh_block_header); - - prev_node->next = next_node->next; - } - else - { - prev_node->length += header->length + sizeof(struct finsh_block_header); - prev_node->next = header->next; - } - } - else /* merge to last node */ - if ( (next_node != NULL) && - ((uint8_t*)header + header->length + sizeof(struct finsh_block_header) - == (uint8_t*)next_node)) - { - header->length += next_node->length + sizeof(struct finsh_block_header); - header->next = next_node->next; - } -} diff --git a/components/finsh/finsh_heap.h b/components/finsh/finsh_heap.h deleted file mode 100644 index f320c2771a..0000000000 --- a/components/finsh/finsh_heap.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include - -#ifndef __FINSH_HEAP_H__ -#define __FINSH_HEAP_H__ - -int finsh_heap_init(void); -void* finsh_heap_allocate(size_t size); -void finsh_heap_free(void*ptr); - -#endif diff --git a/components/finsh/finsh_init.c b/components/finsh/finsh_init.c deleted file mode 100644 index 76302a0516..0000000000 --- a/components/finsh/finsh_init.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include - -#include "finsh_node.h" -#include "finsh_vm.h" -#include "finsh_parser.h" -#include "finsh_var.h" -#include "finsh_error.h" -#include "finsh_heap.h" - -int finsh_init(struct finsh_parser* parser) -{ - finsh_parser_init(parser); - - /* finsh init */ - finsh_node_init(); - finsh_var_init(); - finsh_error_init(); - finsh_heap_init(); - - return 0; -} - -long finsh_stack_bottom() -{ - return finsh_vm_stack[0].long_value; -} - -int finsh_flush(struct finsh_parser* parser) -{ - finsh_parser_init(parser); - - /* finsh init */ - finsh_node_init(); - finsh_error_init(); - - return 0; -} - -int finsh_reset(struct finsh_parser* parser) -{ - /* finsh init */ - finsh_node_init(); - finsh_var_init(); - finsh_error_init(); - finsh_heap_init(); - - return 0; -} diff --git a/components/finsh/finsh_node.c b/components/finsh/finsh_node.c deleted file mode 100644 index 82a4c03f1e..0000000000 --- a/components/finsh/finsh_node.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include - -#include "finsh_node.h" -#include "finsh_error.h" -#include "finsh_var.h" -#include "finsh_heap.h" - -struct finsh_node global_node_table[FINSH_NODE_MAX]; - -int finsh_node_init() -{ - memset(global_node_table, 0, sizeof(global_node_table)); - - return 0; -} - -struct finsh_node* finsh_node_allocate(uint8_t type) -{ - int i; - - /* find an empty entry */ - for (i = 0; i < FINSH_NODE_MAX; i ++) - { - if (global_node_table[i].node_type == FINSH_NODE_UNKNOWN) break; - } - - if (i == FINSH_NODE_MAX) return NULL; - - /* fill type field */ - global_node_table[i].node_type = type; - - /* return this allocated node */ - return &global_node_table[i]; -} - -struct finsh_node* finsh_node_new_id(char* id) -{ - struct finsh_node* node; - void* symbol; - unsigned char type; - - symbol = NULL; - type = 0; - node = NULL; - - /* lookup variable firstly */ - symbol = (void*)finsh_var_lookup(id); - if (symbol == NULL) - { - /* then lookup system variable */ - symbol = (void*)finsh_sysvar_lookup(id); - if (symbol == NULL) - { - /* then lookup system call */ - symbol = (void*)finsh_syscall_lookup(id); - if (symbol != NULL) type = FINSH_IDTYPE_SYSCALL; - } - else type = FINSH_IDTYPE_SYSVAR; - } - else type = FINSH_IDTYPE_VAR; - - if (symbol != NULL) - { - /* allocate a new node */ - node = finsh_node_allocate(FINSH_NODE_ID); - - /* allocate node error */ - if (node == NULL) - { - finsh_error_set(FINSH_ERROR_MEMORY_FULL); - return NULL; - } - - /* fill node value according type */ - switch (type) - { - case FINSH_IDTYPE_VAR: - node->id.var = (struct finsh_var*)symbol; - break; - - case FINSH_IDTYPE_SYSVAR: - node->id.sysvar = (struct finsh_sysvar*)symbol; - break; - - case FINSH_IDTYPE_SYSCALL: - node->id.syscall = (struct finsh_syscall*)symbol; - break; - } - /* fill identifier type */ - node->idtype = type; - } - else finsh_error_set(FINSH_ERROR_UNKNOWN_SYMBOL); - - return node; -} - -struct finsh_node* finsh_node_new_char(char c) -{ - struct finsh_node* node; - - node = finsh_node_allocate(FINSH_NODE_VALUE_CHAR); - if (node == NULL) - { - finsh_error_set(FINSH_ERROR_MEMORY_FULL); - return NULL; - } - - node->value.char_value = c; - return node; -} - -struct finsh_node* finsh_node_new_int(int i) -{ - struct finsh_node* node; - - node = finsh_node_allocate(FINSH_NODE_VALUE_INT); - if (node == NULL) - { - finsh_error_set(FINSH_ERROR_MEMORY_FULL); - return NULL; - } - - node->value.int_value = i; - return node; -} - -struct finsh_node* finsh_node_new_long(long l) -{ - struct finsh_node* node; - - node = finsh_node_allocate(FINSH_NODE_VALUE_LONG); - if (node == NULL) - { - finsh_error_set(FINSH_ERROR_MEMORY_FULL); - return NULL; - } - - node->value.long_value = l; - return node; -} - -struct finsh_node* finsh_node_new_string(char* s) -{ - struct finsh_node* node; - - node = finsh_node_allocate(FINSH_NODE_VALUE_STRING); - if (node == NULL) - { - finsh_error_set(FINSH_ERROR_MEMORY_FULL); - return NULL; - } - - /* make string */ - node->value.ptr = finsh_heap_allocate(strlen(s) + 1); - strncpy(node->value.ptr, s, strlen(s)); - ((uint8_t*)node->value.ptr)[strlen(s)] = '\0'; - - return node; -} - -struct finsh_node* finsh_node_new_ptr(void* ptr) -{ - struct finsh_node* node; - - node = finsh_node_allocate(FINSH_NODE_VALUE_NULL); - if (node == NULL) - { - finsh_error_set(FINSH_ERROR_MEMORY_FULL); - return NULL; - } - - node->value.ptr = ptr; - return node; -} diff --git a/components/finsh/finsh_node.h b/components/finsh/finsh_node.h deleted file mode 100644 index ff4333df13..0000000000 --- a/components/finsh/finsh_node.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_NODE_H__ -#define __FINSH_NODE_H__ - -#include - -#define FINSH_NODE_UNKNOWN 0 -#define FINSH_NODE_ID 1 - -#define FINSH_NODE_VALUE_CHAR 2 -#define FINSH_NODE_VALUE_INT 3 -#define FINSH_NODE_VALUE_LONG 4 -#define FINSH_NODE_VALUE_STRING 5 -#define FINSH_NODE_VALUE_NULL 6 - -#define FINSH_NODE_SYS_ADD 7 -#define FINSH_NODE_SYS_SUB 8 -#define FINSH_NODE_SYS_MUL 9 -#define FINSH_NODE_SYS_DIV 10 -#define FINSH_NODE_SYS_MOD 11 -#define FINSH_NODE_SYS_AND 12 -#define FINSH_NODE_SYS_OR 13 -#define FINSH_NODE_SYS_XOR 14 -#define FINSH_NODE_SYS_BITWISE 15 -#define FINSH_NODE_SYS_SHL 16 -#define FINSH_NODE_SYS_SHR 17 -#define FINSH_NODE_SYS_FUNC 18 -#define FINSH_NODE_SYS_ASSIGN 19 -#define FINSH_NODE_SYS_CAST 20 -#define FINSH_NODE_SYS_PREINC 21 -#define FINSH_NODE_SYS_PREDEC 22 -#define FINSH_NODE_SYS_INC 23 -#define FINSH_NODE_SYS_DEC 24 -#define FINSH_NODE_SYS_GETVALUE 25 -#define FINSH_NODE_SYS_GETADDR 26 -#define FINSH_NODE_SYS_NULL 27 - -#define FINSH_DATA_TYPE_VOID 0x00 -#define FINSH_DATA_TYPE_BYTE 0x01 -#define FINSH_DATA_TYPE_WORD 0x02 -#define FINSH_DATA_TYPE_DWORD 0x03 -#define FINSH_DATA_TYPE_PTR 0x10 - -#define FINSH_NODE_VALUE 0 -#define FINSH_NODE_ADDRESS 1 -#define FINSH_NODE_FUNCTION 2 - -int finsh_node_init(void); - -struct finsh_node* finsh_node_allocate(uint8_t type); -struct finsh_node* finsh_node_new_id(char* id); -struct finsh_node* finsh_node_new_char(char c); -struct finsh_node* finsh_node_new_int(int i); -struct finsh_node* finsh_node_new_long(long l); -struct finsh_node* finsh_node_new_string(char* s); -struct finsh_node* finsh_node_new_ptr(void* ptr); - -#define finsh_node_sibling(node) ((node)->sibling) -#define finsh_node_child(node) ((node)->child) - -#endif diff --git a/components/finsh/finsh_ops.c b/components/finsh/finsh_ops.c deleted file mode 100644 index ec8b8cb58a..0000000000 --- a/components/finsh/finsh_ops.c +++ /dev/null @@ -1,603 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include "finsh_ops.h" -#include "finsh_vm.h" - -#define OP_BIN_BYTE(x) do {\ - (finsh_sp - 2)->char_value = (finsh_sp - 2)->char_value x (finsh_sp - 1)->char_value; \ - finsh_sp--; \ - }while (0) - -#define OP_BIN_WORD(x) do {\ - (finsh_sp - 2)->short_value = (finsh_sp - 2)->short_value x (finsh_sp - 1)->short_value; \ - finsh_sp--; \ - }while (0) - -#define OP_BIN_DWORD(x) do {\ - (finsh_sp - 2)->long_value = (finsh_sp - 2)->long_value x (finsh_sp - 1)->long_value; \ - finsh_sp--; \ - }while (0) - -/* --- noop --- */ -void OP_no_op() -{ - /* none */ - return ; -} - -/* --- add --- */ -void OP_add_byte() -{ - OP_BIN_BYTE(+); - - return ; -} - -void OP_add_word() -{ - OP_BIN_WORD(+); - - return ; -} - -void OP_add_dword() -{ - OP_BIN_DWORD(+); - - return ; -} - -/* --- sub --- */ -void OP_sub_byte() -{ - OP_BIN_BYTE(-); - - return ; -} - -void OP_sub_word() -{ - OP_BIN_WORD(-); - - return ; -} - -void OP_sub_dword() -{ - OP_BIN_DWORD(-); - - return ; -} - -/* --- div --- */ -void OP_div_byte() -{ - OP_BIN_BYTE(/); - - return ; -} - -void OP_div_word() -{ - OP_BIN_WORD(/); - - return ; -} - -void OP_div_dword() -{ - OP_BIN_DWORD(/); - - return ; -} - -/* --- mod --- */ -void OP_mod_byte() -{ - OP_BIN_BYTE(%); - - return ; -} - -void OP_mod_word() -{ - OP_BIN_WORD(%); - - return ; -} - -void OP_mod_dword() -{ - OP_BIN_DWORD(%); - - return ; -} - -/* --- mul --- */ -void OP_mul_byte() -{ - OP_BIN_BYTE(*); - - return ; -} - -void OP_mul_word() -{ - OP_BIN_WORD(*); - - return ; -} - -void OP_mul_dword() -{ - OP_BIN_DWORD(*); - - return ; -} - -/* --- and --- */ -void OP_and_byte() -{ - OP_BIN_BYTE(&); - - return ; -} - -void OP_and_word() -{ - OP_BIN_WORD(&); - - return ; -} - -void OP_and_dword() -{ - OP_BIN_DWORD(&); - - return ; -} - -/* --- or --- */ -void OP_or_byte() -{ - OP_BIN_BYTE(|); - - return ; -} - -void OP_or_word() -{ - OP_BIN_WORD(|); - - return ; -} - -void OP_or_dword() -{ - OP_BIN_DWORD(|); - - return ; -} - -/* --- xor --- */ -void OP_xor_byte() -{ - OP_BIN_BYTE(^); - - return ; -} - -void OP_xor_word() -{ - OP_BIN_WORD(^); - - return ; -} - -void OP_xor_dword() -{ - OP_BIN_DWORD(^); - - return ; -} - -/* --- bw --- */ -void OP_bw_byte() -{ - (finsh_sp - 1)->char_value = ~ ((finsh_sp - 1)->char_value); - - return ; -} - -void OP_bw_word() -{ - (finsh_sp - 1)->short_value = ~ ((finsh_sp - 1)->short_value); - - return ; -} - -void OP_bw_dword() -{ - (finsh_sp - 1)->long_value = ~ ((finsh_sp - 1)->long_value); - - return ; -} - -/* --- shl --- */ -void OP_shl_byte() -{ - OP_BIN_BYTE(<<); - - return ; -} - -void OP_shl_word() -{ - OP_BIN_WORD(<<); - - return ; -} - -void OP_shl_dword() -{ - OP_BIN_DWORD(<<); - - return ; -} - -/* --- shr --- */ -void OP_shr_byte() -{ - OP_BIN_BYTE(>>); - - return ; -} - -void OP_shr_word() -{ - OP_BIN_WORD(>>); - - return ; -} - -void OP_shr_dword() -{ - OP_BIN_DWORD(>>); - - return ; -} - -/* --- ld --- */ -void OP_ld_byte() -{ - finsh_sp->char_value = *finsh_pc; - - finsh_sp++; - finsh_pc++; - - return ; -} - -void OP_ld_word() -{ - finsh_sp->short_value = FINSH_GET16(finsh_pc); - - finsh_sp ++; - finsh_pc += 2; - - return ; -} - -void OP_ld_dword() -{ - finsh_sp->long_value = FINSH_GET32(finsh_pc); - - finsh_sp ++; - finsh_pc += 4; - - return ; -} - -void OP_ld_value_byte() -{ - char* c; - - c = (char*) (FINSH_GET32(finsh_pc)); - - finsh_sp->char_value = *c; - - finsh_sp ++; - finsh_pc += 4; - - return; -} - -void OP_ld_value_byte_stack() -{ - char* c; - - c = (char *)(finsh_sp - 1)->long_value; - (finsh_sp - 1)->char_value = *c; - - return; -} - -void OP_ld_value_word() -{ - short* s; - - s = (short*) (FINSH_GET32(finsh_pc)); - - finsh_sp->short_value = *s; - - finsh_sp ++; - finsh_pc += 4; - - return; -} - -void OP_ld_value_word_stack() -{ - short* s; - - s = (short *)(finsh_sp - 1)->long_value; - (finsh_sp - 1)->short_value = *s; - - return; -} - -void OP_ld_value_dword() -{ - long* l; - - l = (long*) (FINSH_GET32(finsh_pc)); - - finsh_sp->long_value = *l; - - finsh_sp ++; - finsh_pc += 4; - - return; -} - -void OP_ld_value_dword_stack() -{ - long* l; - - l = (long *)(finsh_sp - 1)->long_value; - (finsh_sp - 1)->long_value = *l; - - return; -} - -/* --- st --- */ -/* - * 2006-4-16 bernard - * fixed the sp move bug - */ -void OP_st_byte() -{ - *(char*)((finsh_sp - 2)->long_value) = (finsh_sp - 1)->char_value; - finsh_sp --; - - return ; -} - -/* - * 2006-4-16 bernard - * fixed the sp move bug - */ -void OP_st_word() -{ - *(short*)((finsh_sp - 2)->long_value) = (finsh_sp - 1)->short_value; - finsh_sp --; - - return ; -} - -/* - * 2006-4-16 bernard - * fixed the sp move bug - */ -void OP_st_dword() -{ - *(long*)((finsh_sp - 2)->long_value) = (finsh_sp - 1)->long_value; - finsh_sp --; - - return ; -} - -/* --- pop --- */ -void OP_pop() -{ - finsh_sp --; - return ; -} - -/* --- call --- */ -void OP_call() -{ - /* the max number of arg*/ - unsigned long parameterv[16]; - unsigned int parameters, i; - - typedef unsigned long var_t; - typedef var_t (*op_func)(); - op_func f; - var_t r; - - parameters = *finsh_pc ++; - - i = 0; finsh_sp --; - while (i < parameters) - { - parameterv[parameters - 1 - i] = finsh_sp->long_value; - finsh_sp --; - i++; - } - - f = (op_func)(finsh_sp->long_value); - switch (parameters) - { - case 0: - r = f(0); - break; - - case 1: - r = f(parameterv[0]); - break; - - case 2: - r = f(parameterv[0], parameterv[1]); - break; - - case 3: - r = f(parameterv[0], parameterv[1], parameterv[2]); - break; - - case 4: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3]); - break; - - case 5: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4]); - break; - - case 6: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5]); - break; - - case 7: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6]); - break; - - case 8: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7]); - break; - - case 9: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8]); - break; - - case 10: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9]); - break; - - case 11: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9], parameterv[10]); - break; - - case 12: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9], parameterv[10], parameterv[11]); - break; - - case 13: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9], parameterv[10], parameterv[11], - parameterv[12]); - break; - - case 14: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9], parameterv[10], parameterv[11], - parameterv[12], parameterv[13]); - break; - - case 15: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9], parameterv[10], parameterv[11], - parameterv[12], parameterv[13], parameterv[14]); - break; - - case 16: - r = f(parameterv[0], parameterv[1], parameterv[2], parameterv[3], - parameterv[4], parameterv[5], parameterv[6], parameterv[7], - parameterv[8], parameterv[9], parameterv[10], parameterv[11], - parameterv[12], parameterv[13], parameterv[14], parameterv[15]); - break; - - default: - r = 0; - break; - } - - finsh_sp->long_value = r; - finsh_sp ++; - - return ; -} - -const op_func op_table[] = -{ - /* 00 */ OP_no_op, - /* 01 */ OP_add_byte, - /* 02 */ OP_add_word, - /* 03 */ OP_add_dword, - /* 04 */ OP_sub_byte, - /* 05 */ OP_sub_word, - /* 06 */ OP_sub_dword, - /* 07 */ OP_div_byte, - /* 08 */ OP_div_word, - /* 09 */ OP_div_dword, - /* 10 */ OP_mod_byte, - /* 11 */ OP_mod_word, - /* 12 */ OP_mod_dword, - /* 13 */ OP_mul_byte, - /* 14 */ OP_mul_word, - /* 15 */ OP_mul_dword, - /* 16 */ OP_and_byte, - /* 17 */ OP_and_word, - /* 18 */ OP_and_dword, - /* 19 */ OP_or_byte, - /* 20 */ OP_or_word, - /* 21 */ OP_or_dword, - /* 22 */ OP_xor_byte, - /* 23 */ OP_xor_word, - /* 24 */ OP_xor_dword, - /* 25 */ OP_bw_byte, - /* 26 */ OP_bw_word, - /* 27 */ OP_bw_dword, - /* 28 */ OP_shl_byte, - /* 29 */ OP_shl_word, - /* 30 */ OP_shl_dword, - /* 31 */ OP_shr_byte, - /* 32 */ OP_shr_word, - /* 33 */ OP_shr_dword, - /* 34 */ OP_ld_byte, - /* 35 */ OP_ld_word, - /* 36 */ OP_ld_dword, - /* 37 */ OP_ld_value_byte, - /* 38 */ OP_ld_value_word, - /* 39 */ OP_ld_value_dword, - /* 40 */ OP_st_byte, - /* 41 */ OP_st_word, - /* 42 */ OP_st_dword, - /* 43 */ OP_pop, - /* 44 */ OP_call, - /* 45 */ OP_ld_value_byte_stack, - /* 46 */ OP_ld_value_word_stack, - /* 47 */ OP_ld_value_dword_stack, - NULL -}; diff --git a/components/finsh/finsh_ops.h b/components/finsh/finsh_ops.h deleted file mode 100644 index 0cc945f078..0000000000 --- a/components/finsh/finsh_ops.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_OP_H__ -#define __FINSH_OP_H__ - -#include "finsh_vm.h" - -/* - * FinC VM specification - * Memory - * .VAR - * - * .STACK - * - * .HEAP - * - * .TEXT - * OP [op1] - */ - -#define FINSH_OP_NOOP 0x00 - -/* add @ r1 = r2 + r3 */ -#define FINSH_OP_ADD_BYTE 0x01 -#define FINSH_OP_ADD_WORD 0x02 -#define FINSH_OP_ADD_DWORD 0x03 - -/* sub @ r1 = r2 - r3 */ -#define FINSH_OP_SUB_BYTE 0x04 -#define FINSH_OP_SUB_WORD 0x05 -#define FINSH_OP_SUB_DWORD 0x06 - -/* div @ r1 = r2 / r3 */ -#define FINSH_OP_DIV_BYTE 0x07 -#define FINSH_OP_DIV_WORD 0x08 -#define FINSH_OP_DIV_DWORD 0x09 - -/* mod @ r1 = r2 % r3 */ -#define FINSH_OP_MOD_BYTE 0x0A -#define FINSH_OP_MOD_WORD 0x0B -#define FINSH_OP_MOD_DWORD 0x0C - -/* mul @ r1 = r2 * r3 */ -#define FINSH_OP_MUL_BYTE 0x0D -#define FINSH_OP_MUL_WORD 0x0E -#define FINSH_OP_MUL_DWORD 0x0F - -/* and @ r1 = r2 & r3 */ -#define FINSH_OP_AND_BYTE 0x10 -#define FINSH_OP_AND_WORD 0x11 -#define FINSH_OP_AND_DWORD 0x12 - -/* or @ r1 = r2 | r3 */ -#define FINSH_OP_OR_BYTE 0x13 -#define FINSH_OP_OR_WORD 0x14 -#define FINSH_OP_OR_DWORD 0x15 - -/* xor @ r1 = r2 ^ r3 */ -#define FINSH_OP_XOR_BYTE 0x16 -#define FINSH_OP_XOR_WORD 0x17 -#define FINSH_OP_XOR_DWORD 0x18 - -/* bw @ r1 = ~r2 */ -#define FINSH_OP_BITWISE_BYTE 0x19 -#define FINSH_OP_BITWISE_WORD 0x1A -#define FINSH_OP_BITWISE_DWORD 0x1B - -/* shl @ r1 = r2 << r3 */ -#define FINSH_OP_SHL_BYTE 0x1C -#define FINSH_OP_SHL_WORD 0x1D -#define FINSH_OP_SHL_DWORD 0x1E - -/* shr @ r1 = r2 >> r3 */ -#define FINSH_OP_SHR_BYTE 0x1F -#define FINSH_OP_SHR_WORD 0x20 -#define FINSH_OP_SHR_DWORD 0x21 - -/* ld @ r1 = [r2] */ -#define FINSH_OP_LD_BYTE 0x22 -#define FINSH_OP_LD_WORD 0x23 -#define FINSH_OP_LD_DWORD 0x24 - -#define FINSH_OP_LD_VALUE_BYTE 0x25 -#define FINSH_OP_LD_VALUE_WORD 0x26 -#define FINSH_OP_LD_VALUE_DWORD 0x27 - -/* st @ [r2] = r1 */ -#define FINSH_OP_ST_BYTE 0x28 -#define FINSH_OP_ST_WORD 0x29 -#define FINSH_OP_ST_DWORD 0x2A - -/* pop */ -#define FINSH_OP_POP 0x2B - -/* call r1 @ [r1](stack) */ -#define FINSH_OP_SYSCALL 0x2C - -/* load value from stack */ -#define FINSH_OP_LD_VALUE_BYTE_STACK 0x2D -#define FINSH_OP_LD_VALUE_WORD_STACK 0x2E -#define FINSH_OP_LD_VALUE_DWORD_STACK 0x2F - -/* halt */ -#define FINSH_OP_HALT 0xFF - -typedef void (*op_func)(); -extern const op_func op_table[]; - -#endif diff --git a/components/finsh/finsh_parser.c b/components/finsh/finsh_parser.c deleted file mode 100644 index 4b8b4af7e4..0000000000 --- a/components/finsh/finsh_parser.c +++ /dev/null @@ -1,986 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - * 2013-10-09 Bernard fix the command line too long issue. - */ -#include - -#include "finsh_token.h" -#include "finsh_node.h" -#include "finsh_error.h" -#include "finsh_parser.h" -#include "finsh_var.h" - -/* - * the structure of abstract syntax tree: - * root____________ - * | \ - * child__ sibling__ - * | \ | \ - * child sibling child sibling - * ... - */ -static enum finsh_type proc_type(struct finsh_parser* self); -static int proc_identifier(struct finsh_parser* self, char* id); -static struct finsh_node* proc_variable_decl(struct finsh_parser* self); -static struct finsh_node* proc_expr(struct finsh_parser* self); -static struct finsh_node* proc_assign_expr(struct finsh_parser* self); -static struct finsh_node* proc_inclusive_or_expr(struct finsh_parser* self); -static struct finsh_node* proc_exclusive_or_expr(struct finsh_parser* self); -static struct finsh_node* proc_and_expr(struct finsh_parser* self); -static struct finsh_node* proc_shift_expr(struct finsh_parser* self); -static struct finsh_node* proc_additive_expr(struct finsh_parser* self); -static struct finsh_node* proc_multiplicative_expr(struct finsh_parser* self); -static struct finsh_node* proc_cast_expr(struct finsh_parser* self); -static struct finsh_node* proc_unary_expr(struct finsh_parser* self); -static struct finsh_node* proc_postfix_expr(struct finsh_parser* self); -static struct finsh_node* proc_primary_expr(struct finsh_parser* self); -static struct finsh_node* proc_param_list(struct finsh_parser* self); -static struct finsh_node* proc_expr_statement(struct finsh_parser* self); -static struct finsh_node* make_sys_node(uint8_t type, struct finsh_node* node1, - struct finsh_node* node2); - -/* check token */ -#define check_token(token, lex, type) if ( (token) != (type) ) \ - { \ - finsh_error_set(FINSH_ERROR_INVALID_TOKEN); \ - finsh_token_replay(lex); \ - } - -/* is the token a data type? */ -#define is_base_type(token) ((token) == finsh_token_type_void \ - || (token) == finsh_token_type_char \ - || (token) == finsh_token_type_short \ - || (token) == finsh_token_type_int \ - || (token) == finsh_token_type_long) - -/* get the next token */ -#define next_token(token, lex) (token) = finsh_token_token(lex) - -/* match a specified token */ -#define match_token(token, lex, type) next_token(token, lex); \ - check_token(token, lex, type) - -/* -process for function and variable declaration. -decl_variable -> type declaration_list ';' -declarator_list -> declarator_list ',' declarator - | declarator -declarator -> identifier - | identifier ASSIGN expr_assign -*/ -static struct finsh_node* proc_variable_decl(struct finsh_parser* self) -{ - enum finsh_token_type token; - enum finsh_type type; - char id[FINSH_NAME_MAX + 1]; - - struct finsh_node *node; - struct finsh_node *end; - struct finsh_node *assign; - - node = NULL; - end = NULL; - - /* get type */ - type = proc_type(self); - - /*process id.*/ - if (proc_identifier(self, id) == 0) - { - /* if add variable failed */ - if (finsh_var_insert(id, type) < 0) - { - finsh_error_set(FINSH_ERROR_VARIABLE_EXIST); - } - } - - next_token(token, &(self->token)); - switch ( token ) - { - case finsh_token_type_comma:/*',', it's a variable_list declaration.*/ - if (proc_identifier(self, id) == 0) - { - /* if add variable failed */ - if (finsh_var_insert(id, type) < 0) - { - finsh_error_set(FINSH_ERROR_VARIABLE_EXIST); - } - } - - next_token(token, &(self->token)); - if ( token == finsh_token_type_assign ) - { - /* get the right side of assign expression */ - assign = proc_assign_expr(self); - - if (assign != NULL) - { - struct finsh_node* idnode; - - idnode = finsh_node_new_id(id); - end = make_sys_node(FINSH_NODE_SYS_ASSIGN, idnode, assign); - node = end; - - next_token(token, &(self->token)); - } - } - - while ( token == finsh_token_type_comma ) - { - if (proc_identifier(self, id) == 0) - { - /* if add variable failed */ - if (finsh_var_insert(id, type) < 0) - { - finsh_error_set(FINSH_ERROR_VARIABLE_EXIST); - } - } - - next_token(token, &(self->token)); - if ( token == finsh_token_type_assign ) - { - /* get the right side of assign expression */ - assign = proc_assign_expr(self); - - if (assign != NULL) - { - struct finsh_node* idnode; - - idnode = finsh_node_new_id(id); - - /* make assign expression node */ - if (node != NULL) - { - finsh_node_sibling(end) = make_sys_node(FINSH_NODE_SYS_ASSIGN, idnode, assign); - end = finsh_node_sibling(end); - } - else - { - end = make_sys_node(FINSH_NODE_SYS_ASSIGN, idnode, assign); - node = end; - } - - next_token(token, &(self->token)); - } - } - } - - check_token(token, &(self->token), finsh_token_type_semicolon); - return node; - - case finsh_token_type_assign:/*'=', it's a variable with assign declaration.*/ - { - struct finsh_node *idnode; - - assign = proc_assign_expr(self); - if (assign != NULL) - { - idnode = finsh_node_new_id(id); - - /* make assign expression node */ - end = make_sys_node(FINSH_NODE_SYS_ASSIGN, idnode, assign); - node = end; - - next_token(token, &(self->token)); - } - - while ( token == finsh_token_type_comma ) - { - if (proc_identifier(self, id) == 0) - { - /* if add variable failed */ - if (finsh_var_insert(id, type) < 0) - { - finsh_error_set(FINSH_ERROR_VARIABLE_EXIST); - } - } - - next_token(token, &(self->token)); - if (token == finsh_token_type_assign) - { - /* get the right side of assign expression */ - assign = proc_assign_expr(self); - - if (assign != NULL) - { - idnode = finsh_node_new_id(id); - - /* make assign expression node */ - if (node != NULL) - { - finsh_node_sibling(end) = make_sys_node(FINSH_NODE_SYS_ASSIGN, idnode, assign); - end = finsh_node_sibling(end); - } - else - { - end = make_sys_node(FINSH_NODE_SYS_ASSIGN, idnode, assign); - node = end; - } - - next_token(token, &(self->token)); - } - } - } - - check_token(token, &(self->token), finsh_token_type_semicolon); - return node; - } - - case finsh_token_type_semicolon:/*';', it's a variable declaration.*/ - return node; - - default: - finsh_error_set(FINSH_ERROR_EXPECT_TYPE); - - return NULL; - } -} - -/* -type -> type_prefix type_basic | type_basic -type_prefix -> UNSIGNED -type_basic -> VOID - | CHAR - | SHORT - | INT - | STRING -*/ -static enum finsh_type proc_type(struct finsh_parser* self) -{ - enum finsh_type type; - enum finsh_token_type token; - - /* set init type */ - type = finsh_type_unknown; - - next_token(token, &(self->token)); - if ( is_base_type(token) ) /* base_type */ - { - switch (token) - { - case finsh_token_type_void: - type = finsh_type_void; - break; - - case finsh_token_type_char: - type = finsh_type_char; - break; - - case finsh_token_type_short: - type = finsh_type_short; - break; - - case finsh_token_type_int: - type = finsh_type_int; - break; - - case finsh_token_type_long: - type = finsh_type_long; - break; - - default: - goto __return; - } - } - else if ( token == finsh_token_type_unsigned ) /* unsigned base_type */ - { - next_token(token, &(self->token)); - if ( is_base_type(token) ) - { - switch (token) - { - case finsh_token_type_char: - type = finsh_type_uchar; - break; - - case finsh_token_type_short: - type = finsh_type_ushort; - break; - - case finsh_token_type_int: - type = finsh_type_uint; - break; - - case finsh_token_type_long: - type = finsh_type_ulong; - break; - - default: - goto __return; - } - } - else - { - finsh_token_replay(&(self->token)); - finsh_error_set(FINSH_ERROR_EXPECT_TYPE); - } - } - else - { - goto __return; - } - - /* parse for pointer */ - next_token(token, &(self->token)); - if (token == finsh_token_type_mul) - { - switch (type) - { - case finsh_type_void: - type = finsh_type_voidp; - break; - - case finsh_type_char: - case finsh_type_uchar: - type = finsh_type_charp; - break; - - case finsh_type_short: - case finsh_type_ushort: - type = finsh_type_shortp; - break; - - case finsh_type_int: - case finsh_type_uint: - type = finsh_type_intp; - break; - - case finsh_type_long: - case finsh_type_ulong: - type = finsh_type_longp; - break; - - default: - type = finsh_type_voidp; - break; - } - } - else finsh_token_replay(&(self->token)); - - return type; - -__return: - finsh_token_replay(&(self->token)); - finsh_error_set(FINSH_ERROR_UNKNOWN_TYPE); - - return type; -} - -/* -identifier -> IDENTIFIER -*/ -static int proc_identifier(struct finsh_parser* self, char* id) -{ - enum finsh_token_type token; - - match_token(token, &(self->token), finsh_token_type_identifier); - - strncpy(id, (char*)self->token.string, FINSH_NAME_MAX); - - return 0; -} - -/* -statement_expr -> ';' - | expr ';' -*/ -static struct finsh_node* proc_expr_statement(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* expr; - - expr = NULL; - next_token(token, &(self->token)); - if ( token != finsh_token_type_semicolon ) - { - finsh_token_replay(&(self->token)); - expr = proc_expr(self); - - match_token(token, &(self->token), finsh_token_type_semicolon); - } - - return expr; -} - -/* -expr -> expr_assign -*/ -static struct finsh_node* proc_expr(struct finsh_parser* self) -{ - return proc_assign_expr(self); -} - -/* -expr_assign -> expr_inclusive_or - | expr_unary ASSIGN expr_assign -*/ -static struct finsh_node* proc_assign_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* or; - struct finsh_node* assign; - - or = proc_inclusive_or_expr(self); - - next_token(token, &(self->token)); - - if (token == finsh_token_type_assign) - { - assign = proc_assign_expr(self); - - return make_sys_node(FINSH_NODE_SYS_ASSIGN, or, assign); - } - else finsh_token_replay(&(self->token)); - - return or; -} - -/* -expr_inclusive_or -> expr_exclusive_or - | expr_inclusive_or '|' expr_exclusive_or -*/ -static struct finsh_node* proc_inclusive_or_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* xor; - struct finsh_node* xor_new; - - xor = proc_exclusive_or_expr(self); - - next_token(token, &(self->token)); - while ( token == finsh_token_type_or ) - { - xor_new = proc_exclusive_or_expr(self); - - if (xor_new == NULL) finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - else xor = make_sys_node(FINSH_NODE_SYS_OR, xor, xor_new); - - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return xor; -} - -/* -expr_exclusive_or -> expr_and - | expr_exclusive '^' expr_and -*/ -static struct finsh_node* proc_exclusive_or_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* and; - struct finsh_node* and_new; - - and = proc_and_expr(self); - next_token(token, &(self->token)); - while ( token == finsh_token_type_xor ) - { - and_new = proc_and_expr(self); - if (and_new == NULL) finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - else and = make_sys_node(FINSH_NODE_SYS_XOR, and, and_new); - - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return and; -} - -/* -expr_and -> expr_shift - | expr_and '&' expr_shift -*/ -static struct finsh_node* proc_and_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* shift; - struct finsh_node* shift_new; - - shift = proc_shift_expr(self); - - next_token(token, &(self->token)); - while ( token == finsh_token_type_and ) - { - shift_new = proc_shift_expr(self); - - if (shift_new == NULL) finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - else shift = make_sys_node(FINSH_NODE_SYS_AND, shift, shift_new); - - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return shift; -} - -/* -expr_shift -> expr_additive - | expr_shift '<<' expr_additive - | expr_shift '>>' expr_additive -*/ -static struct finsh_node* proc_shift_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* add; - struct finsh_node* add_new; - - add = proc_additive_expr(self); - - next_token(token, &(self->token)); - while ( token == finsh_token_type_shl || token == finsh_token_type_shr) - { - add_new = proc_additive_expr(self); - if (add_new == NULL) finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - else - { - switch (token) - { - case finsh_token_type_shl: - add = make_sys_node(FINSH_NODE_SYS_SHL, add, add_new); - break; - case finsh_token_type_shr: - add = make_sys_node(FINSH_NODE_SYS_SHR, add, add_new); - break; - default: - finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - break; - } - } - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return add; -} - -/* -expr_additive -> expr_multiplicative - | expr_additive SUB expr_multiplicative - | expr_additive ADD expr_multiplicative -*/ -static struct finsh_node* proc_additive_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* mul; - struct finsh_node* mul_new; - - mul = proc_multiplicative_expr(self); - - next_token(token, &(self->token)); - while ( token == finsh_token_type_sub || token == finsh_token_type_add ) - { - mul_new = proc_multiplicative_expr(self); - if (mul_new == NULL) finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - else - { - switch (token) - { - case finsh_token_type_sub: - mul = make_sys_node(FINSH_NODE_SYS_SUB, mul, mul_new); - break; - case finsh_token_type_add: - mul = make_sys_node(FINSH_NODE_SYS_ADD, mul, mul_new); - break; - default: - finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - break; - } - } - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return mul; -} - -/* -expr_multiplicative -> expr_cast - | expr_multiplicative '*' expr_cast - | expr_multiplicative '/' expr_cast - | expr_multiplicative '%' expr_cast -*/ -static struct finsh_node* proc_multiplicative_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* cast; - struct finsh_node* cast_new; - - cast = proc_cast_expr(self); - next_token(token, &(self->token)); - while (token == finsh_token_type_mul || - token == finsh_token_type_div || - token == finsh_token_type_mod ) - { - cast_new = proc_cast_expr(self); - if (cast_new == NULL) finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - else - { - switch (token) - { - case finsh_token_type_mul: - cast = make_sys_node(FINSH_NODE_SYS_MUL, cast, cast_new); - break; - - case finsh_token_type_div: - cast = make_sys_node(FINSH_NODE_SYS_DIV, cast, cast_new); - break; - - case finsh_token_type_mod: - cast = make_sys_node(FINSH_NODE_SYS_MOD, cast, cast_new); - break; - - default: - finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - break; - } - } - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return cast; -} - -/* -20060313, add recast parse -expr_cast -> expr_unary - | '(' type ')' expr_cast -*/ -static struct finsh_node* proc_cast_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - enum finsh_type type; - struct finsh_node* cast; - - next_token(token, &(self->token)); - if (token == finsh_token_type_left_paren) - { - type = proc_type(self); - match_token(token, &(self->token), finsh_token_type_right_paren); - - cast = proc_cast_expr(self); - if (cast != NULL) - { - cast->data_type = type; - return cast; - } - } - - finsh_token_replay(&(self->token)); - return proc_unary_expr(self); -} - -/* -20050921, add '*' and '&' -expr_unary -> expr_postfix - | ADD expr_cast - | INC expr_cast - | SUB expr_cast - | DEC expr_cast - | '~' expr_cast - | '*' expr_cast - | '&' expr_cast -*/ -static struct finsh_node* proc_unary_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node *cast; - - next_token(token, &(self->token)); - switch (token) - { - case finsh_token_type_add: /* + */ - cast = proc_cast_expr(self); - return cast; - - case finsh_token_type_inc: /* ++ */ - cast = proc_cast_expr(self); - return make_sys_node(FINSH_NODE_SYS_PREINC, cast, NULL); - - case finsh_token_type_sub: /* - */ - cast = proc_cast_expr(self); - return make_sys_node(FINSH_NODE_SYS_SUB, finsh_node_new_long(0), cast); - - case finsh_token_type_dec: /* -- */ - cast = proc_cast_expr(self); - return make_sys_node(FINSH_NODE_SYS_PREDEC, cast, NULL); - - case finsh_token_type_bitwise: /* ~ */ - cast = proc_cast_expr(self); - return make_sys_node(FINSH_NODE_SYS_BITWISE, cast, NULL); - - case finsh_token_type_mul: /* * */ - cast = proc_cast_expr(self); - return make_sys_node(FINSH_NODE_SYS_GETVALUE, cast, NULL); - - case finsh_token_type_and: /* & */ - cast = proc_cast_expr(self); - return make_sys_node(FINSH_NODE_SYS_GETADDR, cast, NULL); - - default: - finsh_token_replay(&(self->token)); - return proc_postfix_expr(self); - } -} - -/* -expr_postfix -> expr_primary - | expr_postfix INC - | expr_postfix DEC - | expr_postfix '(' param_list ')' -*/ -static struct finsh_node* proc_postfix_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* postfix; - - postfix = proc_primary_expr(self); - - next_token(token, &(self->token)); - while ( token == finsh_token_type_inc || - token == finsh_token_type_dec || - token == finsh_token_type_left_paren ) - { - switch (token) - { - case finsh_token_type_inc :/* '++' */ - postfix = make_sys_node(FINSH_NODE_SYS_INC, postfix, NULL); - break; - - case finsh_token_type_dec :/* '--' */ - postfix = make_sys_node(FINSH_NODE_SYS_DEC, postfix, NULL); - break; - - case finsh_token_type_left_paren :/* '(' */ - { - struct finsh_node* param_list; - - param_list = NULL; - next_token(token, &(self->token)); - if (token != finsh_token_type_right_paren) - { - finsh_token_replay(&(self->token)); - param_list = proc_param_list(self); - - match_token(token, &(self->token), finsh_token_type_right_paren); - } - - postfix = make_sys_node(FINSH_NODE_SYS_FUNC, postfix, param_list); - } - break; - - default: - break; - } - - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - return postfix; -} - -/* -expr_primary -> literal - | '(' expr ')' - | identifier -*/ -static struct finsh_node* proc_primary_expr(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node* expr; - - next_token(token, &(self->token)); - switch ( token ) - { - case finsh_token_type_identifier: - { - char id[FINSH_NAME_MAX + 1]; - - finsh_token_replay(&(self->token)); - proc_identifier(self, id); - return finsh_node_new_id(id); - } - - case finsh_token_type_left_paren: - expr = proc_expr(self); - match_token(token, &(self->token), finsh_token_type_right_paren); - return expr; - - case finsh_token_type_value_int: - return finsh_node_new_int(self->token.value.int_value); - - case finsh_token_type_value_long: - return finsh_node_new_long(self->token.value.long_value); - - case finsh_token_type_value_char: - return finsh_node_new_char(self->token.value.char_value); - - case finsh_token_type_value_string: - return finsh_node_new_string((char*)self->token.string); - - case finsh_token_type_value_null: - return finsh_node_new_ptr(NULL); - - default: - finsh_error_set(FINSH_ERROR_INVALID_TOKEN); - break; - } - - return NULL; -} - -/* -param_list -> empty - | expr_assign - | param_list ',' expr_assign -*/ -static struct finsh_node* proc_param_list(struct finsh_parser* self) -{ - enum finsh_token_type token; - struct finsh_node *node, *assign; - - assign = proc_assign_expr(self); - if (assign == NULL) return NULL; - node = assign; - - next_token(token, &(self->token)); - while (token == finsh_token_type_comma ) - { - finsh_node_sibling(assign) = proc_assign_expr(self); - - if (finsh_node_sibling(assign) != NULL) assign = finsh_node_sibling(assign); - else finsh_error_set(FINSH_ERROR_EXPECT_OPERATOR); - - next_token(token, &(self->token)); - } - - finsh_token_replay(&(self->token)); - - return node; -} - -/* -make a new node as following tree: -new_node -| -node1__ - \ - node2 -*/ -static struct finsh_node* make_sys_node(uint8_t type, struct finsh_node* node1, struct finsh_node* node2) -{ - struct finsh_node* node; - - node = finsh_node_allocate(type); - - if ((node1 != NULL) && (node != NULL)) - { - finsh_node_child(node) = node1; - finsh_node_sibling(node1) = node2; - } - else finsh_error_set(FINSH_ERROR_NULL_NODE); - - return node; -} - -/* -start -> statement_expr | decl_variable -*/ -void finsh_parser_run(struct finsh_parser* self, const uint8_t* string) -{ - enum finsh_token_type token; - struct finsh_node *node; - - node = NULL; - - /* init parser */ - self->parser_string = (uint8_t*)string; - - /* init token */ - finsh_token_init(&(self->token), self->parser_string); - - /* get next token */ - next_token(token, &(self->token)); - while (token != finsh_token_type_eof && token != finsh_token_type_bad) - { - switch (token) - { - case finsh_token_type_identifier: - /* process expr_statement */ - finsh_token_replay(&(self->token)); - - if (self->root != NULL) - { - finsh_node_sibling(node) = proc_expr_statement(self); - if (finsh_node_sibling(node) != NULL) - node = finsh_node_sibling(node); - } - else - { - node = proc_expr_statement(self); - self->root = node; - } - break; - - default: - if (is_base_type(token) || token == finsh_token_type_unsigned) - { - /* variable decl */ - finsh_token_replay(&(self->token)); - - if (self->root != NULL) - { - finsh_node_sibling(node) = proc_variable_decl(self); - if (finsh_node_sibling(node) != NULL) - node = finsh_node_sibling(node); - } - else - { - node = proc_variable_decl(self); - self->root = node; - } - } - else - { - /* process expr_statement */ - finsh_token_replay(&(self->token)); - - if (self->root != NULL) - { - finsh_node_sibling(node) = proc_expr_statement(self); - if (finsh_node_sibling(node) != NULL) - node = finsh_node_sibling(node); - else next_token(token, &(self->token)); - } - else - { - node = proc_expr_statement(self); - self->root = node; - } - } - - break; - } - - /* no root found, break out */ - if (self->root == NULL) break; - - /* get next token */ - next_token(token, &(self->token)); - } -} - -int finsh_parser_init(struct finsh_parser* self) -{ - memset(self, 0, sizeof(struct finsh_parser)); - - return 0; -} diff --git a/components/finsh/finsh_parser.h b/components/finsh/finsh_parser.h deleted file mode 100644 index 2d0148093a..0000000000 --- a/components/finsh/finsh_parser.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_PARSER_H__ -#define __FINSH_PARSER_H__ - -#include - -int finsh_parser_init(struct finsh_parser* self); -void finsh_parser_run(struct finsh_parser* self, const uint8_t* string); - -#endif diff --git a/components/finsh/finsh_token.c b/components/finsh/finsh_token.c deleted file mode 100644 index dfd613da5b..0000000000 --- a/components/finsh/finsh_token.c +++ /dev/null @@ -1,598 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - * 2013-04-03 Bernard strip more characters. - */ -#include -#include - -#include "finsh_token.h" -#include "finsh_error.h" - -#define is_alpha(ch) ((ch | 0x20) - 'a') < 26u -#define is_digit(ch) ((ch) >= '0' && (ch) <= '9') -#define is_xdigit(ch) (((ch) >= '0' && (ch) <= '9') || (((ch | 0x20) - 'a') < 6u)) -#define is_separator(ch) !(((ch) >= 'a' && (ch) <= 'z') \ - || ((ch) >= 'A' && (ch) <= 'Z') || ((ch) >= '0' && (ch) <= '9') || ((ch) == '_')) -#define is_eof(self) (self)->eof - -struct name_table -{ - char* name; - enum finsh_token_type type; -}; - -/* keyword */ -static const struct name_table finsh_name_table[] = -{ - {"void", finsh_token_type_void}, - {"char", finsh_token_type_char}, - {"short", finsh_token_type_short}, - {"int", finsh_token_type_int}, - {"long", finsh_token_type_long}, - {"unsigned", finsh_token_type_unsigned}, - - {"NULL", finsh_token_type_value_null}, - {"null", finsh_token_type_value_null} -}; - -static char token_next_char(struct finsh_token* self); -static void token_prev_char(struct finsh_token* self); -static long token_spec_number(char* string, int length, int b); -static void token_run(struct finsh_token* self); -static int token_match_name(struct finsh_token* self, const char* str); -static void token_proc_number(struct finsh_token* self); -static uint8_t* token_proc_string(struct finsh_token* self); -static void token_trim_space(struct finsh_token* self); -static char token_proc_char(struct finsh_token* self); -static int token_proc_escape(struct finsh_token* self); - -void finsh_token_init(struct finsh_token* self, uint8_t* line) -{ - memset(self, 0, sizeof(struct finsh_token)); - - self->line = line; -} - -enum finsh_token_type finsh_token_token(struct finsh_token* self) -{ - if ( self->replay ) self->replay = 0; - else token_run(self); - - return (enum finsh_token_type)self->current_token; -} - -void finsh_token_get_token(struct finsh_token* self, uint8_t* token) -{ - strncpy((char*)token, (char*)self->string, FINSH_NAME_MAX); -} - -int token_get_string(struct finsh_token* self, uint8_t* str) -{ - unsigned char *p=str; - char ch; - - ch = token_next_char(self); - if (is_eof(self)) return -1; - - str[0] = '\0'; - - if ( is_digit(ch) )/*the first character of identifier is not a digit.*/ - { - token_prev_char(self); - return -1; - } - - while (!is_separator(ch) && !is_eof(self)) - { - *p++ = ch; - - ch = token_next_char(self); - } - self->eof = 0; - - token_prev_char(self); - *p = '\0'; - - return 0; -} - -/* -get next character. -*/ -static char token_next_char(struct finsh_token* self) -{ - if (self->eof) return '\0'; - - if (self->position == (int)strlen((char*)self->line) || self->line[self->position] =='\n') - { - self->eof = 1; - self->position = 0; - return '\0'; - } - - return self->line[self->position++]; -} - -static void token_prev_char(struct finsh_token* self) -{ - if ( self->eof ) return; - - if ( self->position == 0 ) return; - else self->position--; -} - -static void token_run(struct finsh_token* self) -{ - char ch; - - token_trim_space(self); /* first trim space and tab. */ - token_get_string(self, &(self->string[0])); - - if ( is_eof(self) ) /*if it is eof, break;*/ - { - self->current_token = finsh_token_type_eof; - return ; - } - - if (self->string[0] != '\0') /*It is a key word or a identifier.*/ - { - if ( !token_match_name(self, (char*)self->string) ) - { - self->current_token = finsh_token_type_identifier; - } - } - else/*It is a operator character.*/ - { - ch = token_next_char(self); - - switch ( ch ) - { - case '(': - self->current_token = finsh_token_type_left_paren; - break; - - case ')': - self->current_token = finsh_token_type_right_paren; - break; - - case ',': - self->current_token = finsh_token_type_comma; - break; - - case ';': - self->current_token = finsh_token_type_semicolon; - break; - - case '&': - self->current_token = finsh_token_type_and; - break; - - case '*': - self->current_token = finsh_token_type_mul; - break; - - case '+': - ch = token_next_char(self); - - if ( ch == '+' ) - { - self->current_token = finsh_token_type_inc; - } - else - { - token_prev_char(self); - self->current_token = finsh_token_type_add; - } - break; - - case '-': - ch = token_next_char(self); - - if ( ch == '-' ) - { - self->current_token = finsh_token_type_dec; - } - else - { - token_prev_char(self); - self->current_token = finsh_token_type_sub; - } - break; - - case '/': - ch = token_next_char(self); - if (ch == '/') - { - /* line comments, set to end of file */ - self->current_token = finsh_token_type_eof; - } - else - { - token_prev_char(self); - self->current_token = finsh_token_type_div; - } - break; - - case '<': - ch = token_next_char(self); - - if ( ch == '<' ) - { - self->current_token = finsh_token_type_shl; - } - else - { - token_prev_char(self); - self->current_token = finsh_token_type_bad; - } - break; - - case '>': - ch = token_next_char(self); - - if ( ch == '>' ) - { - self->current_token = finsh_token_type_shr; - } - else - { - token_prev_char(self); - self->current_token = finsh_token_type_bad; - } - break; - - case '|': - self->current_token = finsh_token_type_or; - break; - - case '%': - self->current_token = finsh_token_type_mod; - break; - - case '~': - self->current_token = finsh_token_type_bitwise; - break; - - case '^': - self->current_token = finsh_token_type_xor; - break; - - case '=': - self->current_token = finsh_token_type_assign; - break; - - case '\'': - self->value.char_value = token_proc_char(self); - self->current_token = finsh_token_type_value_char; - break; - - case '"': - token_proc_string(self); - self->current_token = finsh_token_type_value_string; - break; - - default: - if ( is_digit(ch) ) - { - token_prev_char(self); - token_proc_number(self); - break; - } - - finsh_error_set(FINSH_ERROR_UNKNOWN_TOKEN); - self->current_token = finsh_token_type_bad; - - break; - } - } -} - -static int token_match_name(struct finsh_token* self, const char* str) -{ - int i; - - for (i = 0; i < sizeof(finsh_name_table)/sizeof(struct name_table); i++) - { - if ( strcmp(finsh_name_table[i].name, str)==0 ) - { - self->current_token = finsh_name_table[i].type; - return 1; - } - } - - return 0; -} - -static void token_trim_space(struct finsh_token* self) -{ - char ch; - while ( (ch = token_next_char(self)) ==' ' || - ch == '\t' || - ch == '\r'); - - token_prev_char(self); -} - -static char token_proc_char(struct finsh_token* self) -{ - char ch; - char buf[4], *p; - - p = buf; - ch = token_next_char(self); - - if ( ch == '\\' ) - { - ch = token_next_char(self); - switch ( ch ) - { - case 'n': ch = '\n'; break; - case 't': ch = '\t'; break; - case 'v': ch = '\v'; break; - case 'b': ch = '\b'; break; - case 'r': ch = '\r'; break; - case '\\': ch = '\\'; break; - case '\'': ch = '\''; break; - default : - while ( is_digit(ch) )/*for '\113' char*/ - { - ch = token_next_char(self); - *p++ = ch; - } - - token_prev_char(self); - *p = '\0'; - ch = atoi(p); - break; - } - } - - if ( token_next_char(self) != '\'' ) - { - token_prev_char(self); - finsh_error_set(FINSH_ERROR_EXPECT_CHAR); - return ch; - } - - return ch; -} - -static uint8_t* token_proc_string(struct finsh_token* self) -{ - uint8_t* p; - - for ( p = &self->string[0]; p - &(self->string[0]) < FINSH_STRING_MAX; ) - { - char ch = token_next_char(self); - - if ( is_eof(self) ) - { - finsh_error_set(FINSH_ERROR_UNEXPECT_END); - return NULL;; - } - if ( ch == '\\' ) - { - ch = token_proc_escape(self); - } - else if ( ch == '"' )/*end of string.*/ - { - *p = '\0'; - return self->string; - } - - *p++ = ch; - } - - return NULL; -} - -static int token_proc_escape(struct finsh_token* self) -{ - char ch; - int result=0; - - ch = token_next_char(self); - switch (ch) - { - case 'n': - result = '\n'; - break; - case 't': - result = '\t'; - break; - case 'v': - result = '\v'; - break; - case 'b': - result = '\b'; - break; - case 'r': - result = '\r'; - break; - case 'f': - result = '\f'; - break; - case 'a': - result = '\007'; - break; - case '"': - result = '"'; - break; - case 'x': - case 'X': - result = 0; - ch = token_next_char(self); - while (is_xdigit(ch)) - { - result = result * 16 + ((ch < 'A') ? (ch - '0') : (ch | 0x20) - 'a' + 10); - ch = token_next_char(self); - } - token_prev_char(self); - break; - default: - if ( (ch - '0') < 8u) - { - result = 0; - while ( (ch - '0') < 8u ) - { - result = result*8 + ch - '0'; - ch = token_next_char(self); - } - - token_prev_char(self); - } - break; - } - - return result; -} - -/* -(0|0x|0X|0b|0B)number+(l|L) -*/ -static void token_proc_number(struct finsh_token* self) -{ - char ch; - char *p, buf[128]; - long value; - - value = 0; - p = buf; - - ch = token_next_char(self); - if ( ch == '0' ) - { - int b; - ch = token_next_char(self); - if ( ch == 'x' || ch == 'X' )/*it's a hex number*/ - { - b = 16; - ch = token_next_char(self); - while ( is_digit(ch) || is_alpha(ch) ) - { - *p++ = ch; - ch = token_next_char(self); - } - - *p = '\0'; - } - else if ( ch == 'b' || ch == 'B' ) - { - b = 2; - ch = token_next_char(self); - while ( (ch=='0')||(ch=='1') ) - { - *p++ = ch; - ch = token_next_char(self); - } - - *p = '\0'; - } - else if ( '0' <= ch && ch <= '7' ) - { - b = 8; - while ( '0' <= ch && ch <= '7' ) - { - *p++ = ch; - ch = token_next_char(self); - } - - *p = '\0'; - } - else - { - token_prev_char(self); - - /* made as 0 value */ - self->value.int_value = 0; - self->current_token = finsh_token_type_value_int; - return; - } - - self->value.int_value = token_spec_number(buf, strlen(buf), b); - self->current_token = finsh_token_type_value_int; - } - else - { - while ( is_digit(ch) ) - { - value = value*10 + ( ch - '0' ); - ch = token_next_char(self); - } - - self->value.int_value = value; - self->current_token = finsh_token_type_value_int; - } - - switch ( ch ) - { - case 'l': - case 'L': - self->current_token = finsh_token_type_value_long; - break; - - default: - token_prev_char(self); - break; - } -} - -/*use 64 bit number*/ -#define BN_SIZE 2 - -static long token_spec_number(char* string, int length, int b) -{ - char* p; - int t; - int i, j, shift=1; - unsigned int bn[BN_SIZE], v; - long d; - - p = string; - i = 0; - - switch ( b ) - { - case 16: shift = 4; - break; - case 8: shift = 3; - break; - case 2: shift = 1; - break; - default: break; - } - - for ( j=0; j='a' && t <='f' ) - { - t = t - 'a' +10; - } - else if ( t >='A' && t <='F' ) - { - t = t - 'A' +10; - } - else t = t - '0'; - - for ( j=0; j> (32 - shift); - } - i++; - } - - d = (long)bn[0]; - - return d; -} diff --git a/components/finsh/finsh_token.h b/components/finsh/finsh_token.h deleted file mode 100644 index 9845357b8e..0000000000 --- a/components/finsh/finsh_token.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_TOKEN_H__ -#define __FINSH_TOKEN_H__ - -#include - -enum finsh_token_type -{ - finsh_token_type_left_paren = 1, /* ( */ - finsh_token_type_right_paren , /* ) */ - finsh_token_type_comma , /* , */ - finsh_token_type_semicolon , /* ; */ - finsh_token_type_mul , /* * */ - finsh_token_type_add , /* + */ - finsh_token_type_inc , /* ++ */ - finsh_token_type_sub , /* - */ - finsh_token_type_dec , /* -- */ - finsh_token_type_div , /* / */ - finsh_token_type_mod , /* % */ - finsh_token_type_assign , /* = */ - finsh_token_type_and, /* & */ - finsh_token_type_or, /* | */ - finsh_token_type_xor, /* ^ */ - finsh_token_type_bitwise, /* ~ */ - finsh_token_type_shl, /* << */ - finsh_token_type_shr, /* >> */ - finsh_token_type_comments, /* // */ - /*-- data type --*/ - finsh_token_type_void, /* void */ - finsh_token_type_char, /* char */ - finsh_token_type_short, /* short */ - finsh_token_type_int, /* int */ - finsh_token_type_long, /* long */ - finsh_token_type_unsigned, /* unsigned */ - /* data value type */ - finsh_token_type_value_char, /* v:char */ - finsh_token_type_value_int, /* v:int */ - finsh_token_type_value_long, /* v:long */ - finsh_token_type_value_string, /* v:string */ - finsh_token_type_value_null, /* NULL */ - /*-- others --*/ - finsh_token_type_identifier, /* ID */ - finsh_token_type_bad, /* bad token */ - finsh_token_type_eof -}; - -#define finsh_token_position(self) (self)->position -#define finsh_token_replay(self) (self)->replay = 1 - -void finsh_token_init(struct finsh_token* self, uint8_t* script); - -enum finsh_token_type finsh_token_token(struct finsh_token* self); -void finsh_token_get_token(struct finsh_token* self, uint8_t* token); - -#endif diff --git a/components/finsh/finsh_var.c b/components/finsh/finsh_var.c deleted file mode 100644 index 2e3df30c6d..0000000000 --- a/components/finsh/finsh_var.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - * 2012-04-27 Bernard fixed finsh_var_delete issue which - * is found by Grissiom. - */ -#include -#include "finsh_var.h" - -struct finsh_var global_variable[FINSH_VARIABLE_MAX]; -struct finsh_sysvar_item* global_sysvar_list; - -int finsh_var_init() -{ - memset(global_variable, 0, sizeof(global_variable)); - - return 0; -} - -int finsh_var_insert(const char* name, int type) -{ - int i, empty; - - empty = -1; - for (i = 0; i < FINSH_VARIABLE_MAX; i ++) - { - /* there is a same name variable exist. */ - if (strncmp(global_variable[i].name, name, FINSH_NAME_MAX) == 0) - return -1; - - if (global_variable[i].type == finsh_type_unknown && empty == -1) - { - empty = i; - } - } - - /* there is no empty entry */ - if (empty == -1) return -1; - - /* insert entry */ - strncpy(global_variable[empty].name, name, FINSH_NAME_MAX); - global_variable[empty].type = type; - - /* return the offset */ - return empty; -} - -int finsh_var_delete(const char* name) -{ - int i; - - for (i = 0; i < FINSH_VARIABLE_MAX; i ++) - { - if (strncmp(global_variable[i].name, name, FINSH_NAME_MAX) == 0) - break; - } - - /* can't find variable */ - if (i == FINSH_VARIABLE_MAX) return -1; - - memset(&global_variable[i], 0, sizeof(struct finsh_var)); - - return 0; -} - -struct finsh_var* finsh_var_lookup(const char* name) -{ - int i; - - for (i = 0; i < FINSH_VARIABLE_MAX; i ++) - { - if (strncmp(global_variable[i].name, name, FINSH_NAME_MAX) == 0) - break; - } - - /* can't find variable */ - if (i == FINSH_VARIABLE_MAX) return NULL; - - return &global_variable[i]; -} - -#ifdef RT_USING_HEAP -void finsh_sysvar_append(const char* name, uint8_t type, void* var_addr) -{ - /* create a sysvar */ - struct finsh_sysvar_item* item; - - item = (struct finsh_sysvar_item*) rt_malloc (sizeof(struct finsh_sysvar_item)); - if (item != NULL) - { - item->next = NULL; - item->sysvar.name = rt_strdup(name); - item->sysvar.type = type; - item->sysvar.var = var_addr; - - if (global_sysvar_list == NULL) - { - global_sysvar_list = item; - } - else - { - item->next = global_sysvar_list; - global_sysvar_list = item; - } - } -} -#endif - -struct finsh_sysvar* finsh_sysvar_lookup(const char* name) -{ - struct finsh_sysvar* index; - struct finsh_sysvar_item* item; - - for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) - { - if (strcmp(index->name, name) == 0) - return index; - } - - /* find in sysvar list */ - item = global_sysvar_list; - while (item != NULL) - { - if (strncmp(item->sysvar.name, name, strlen(name)) == 0) - { - return &(item->sysvar); - } - - /* move to next item */ - item = item->next; - } - - /* can't find variable */ - return NULL; -} diff --git a/components/finsh/finsh_var.h b/components/finsh/finsh_var.h deleted file mode 100644 index 796f979441..0000000000 --- a/components/finsh/finsh_var.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_VAR_H__ -#define __FINSH_VAR_H__ - -#include - -/* - * The variable in finsh is put in data segment as a global variable. - * The 'finsh_var' structure presents the structure of variable in data segment. - */ -struct finsh_var -{ - char name[FINSH_NAME_MAX + 1]; /* the name of variable */ - - uint8_t type; /* the type of variable */ - - /* variable value */ - union { - char char_value; - short short_value; - int int_value; - long long_value; - void* ptr; - }value; -}; -extern struct finsh_var global_variable[]; - -int finsh_var_init(void); -int finsh_var_insert(const char* name, int type); -int finsh_var_delete(const char* name); -struct finsh_var* finsh_var_lookup(const char* name); - -#endif diff --git a/components/finsh/finsh_vm.c b/components/finsh/finsh_vm.c deleted file mode 100644 index e56cedbdfb..0000000000 --- a/components/finsh/finsh_vm.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#include - -#include "finsh_vm.h" -#include "finsh_ops.h" -#include "finsh_var.h" - -/* stack */ -union finsh_value finsh_vm_stack[FINSH_STACK_MAX]; -/* text segment */ -uint8_t text_segment[FINSH_TEXT_MAX]; - -union finsh_value* finsh_sp; /* stack pointer */ -uint8_t* finsh_pc; /* PC */ - -/* syscall list, for dynamic system call register */ -struct finsh_syscall_item* global_syscall_list = NULL; - -// #define FINSH_VM_DISASSEMBLE -void finsh_vm_run() -{ - uint8_t op; - - /* if you want to disassemble the byte code, please define FINSH_VM_DISASSEMBLE */ -#ifdef FINSH_VM_DISASSEMBLE - void finsh_disassemble(); - finsh_disassemble(); -#endif - - /* set sp(stack pointer) to the beginning of stack */ - finsh_sp = &finsh_vm_stack[0]; - - /* set pc to the beginning of text segment */ - finsh_pc = &text_segment[0]; - - while ((finsh_pc - &text_segment[0] >= 0) && - (finsh_pc - &text_segment[0] < FINSH_TEXT_MAX)) - { - /* get op */ - op = *finsh_pc++; - - /* call op function */ - op_table[op](); - } -} - -#ifdef RT_USING_HEAP -void finsh_syscall_append(const char* name, syscall_func func) -{ - /* create the syscall */ - struct finsh_syscall_item* item; - - item = (struct finsh_syscall_item*)rt_malloc(sizeof(struct finsh_syscall_item)); - if (item != RT_NULL) - { - item->next = NULL; - item->syscall.name = rt_strdup(name); - item->syscall.func = func; - - if (global_syscall_list == NULL) - { - global_syscall_list = item; - } - else - { - item->next = global_syscall_list; - global_syscall_list = item; - } - } -} -#endif - -struct finsh_syscall* finsh_syscall_lookup(const char* name) -{ - struct finsh_syscall* index; - struct finsh_syscall_item* item; - - for (index = _syscall_table_begin; index < _syscall_table_end; FINSH_NEXT_SYSCALL(index)) - { - if (strcmp(index->name, name) == 0) - return index; - } - - /* find on syscall list */ - item = global_syscall_list; - while (item != NULL) - { - if (strncmp(item->syscall.name, name, strlen(name)) == 0) - { - return &(item->syscall); - } - - item = item->next; - } - - return NULL; -} - -#ifdef FINSH_VM_DISASSEMBLE -void finsh_disassemble() -{ - uint8_t *pc, op; - - pc = &text_segment[0]; - while (*pc != 0) - { - op = *pc; - switch (op) - { - case FINSH_OP_ADD_BYTE: - pc ++; - rt_kprintf("addb\n"); - break; - - case FINSH_OP_SUB_BYTE: - pc ++; - rt_kprintf("subb\n"); - break; - - case FINSH_OP_DIV_BYTE: - pc ++; - rt_kprintf("divb\n"); - break; - - case FINSH_OP_MOD_BYTE: - pc ++; - rt_kprintf("modb\n"); - break; - - case FINSH_OP_MUL_BYTE: - pc ++; - rt_kprintf("mulb\n"); - break; - - case FINSH_OP_AND_BYTE: - pc ++; - rt_kprintf("andb\n"); - break; - - case FINSH_OP_OR_BYTE: - pc ++; - rt_kprintf("orb\n"); - break; - - case FINSH_OP_XOR_BYTE: - pc ++; - rt_kprintf("xorb\n"); - break; - - case FINSH_OP_BITWISE_BYTE: - pc ++; - rt_kprintf("bwb\n"); - break; - - case FINSH_OP_SHL_BYTE: - pc ++; - rt_kprintf("shlb\n"); - break; - - case FINSH_OP_SHR_BYTE: - pc ++; - rt_kprintf("shrb\n"); - break; - - case FINSH_OP_LD_BYTE: - pc ++; - rt_kprintf("ldb %d\n", *pc++); - break; - - case FINSH_OP_LD_VALUE_BYTE: - pc ++; - rt_kprintf("ldb [0x%x]\n", FINSH_GET32(pc)); - pc += 4; - break; - - case FINSH_OP_ST_BYTE: - pc ++; - rt_kprintf("stb\n"); - break; - - case FINSH_OP_ADD_WORD: - pc ++; - rt_kprintf("addw\n"); - break; - - case FINSH_OP_SUB_WORD: - pc ++; - rt_kprintf("subw\n"); - break; - - case FINSH_OP_DIV_WORD: - pc ++; - rt_kprintf("divw\n"); - break; - - case FINSH_OP_MOD_WORD: - pc ++; - rt_kprintf("modw\n"); - break; - - case FINSH_OP_MUL_WORD: - pc ++; - rt_kprintf("mulw\n"); - break; - - case FINSH_OP_AND_WORD: - pc ++; - rt_kprintf("andw\n"); - break; - - case FINSH_OP_OR_WORD: - pc ++; - rt_kprintf("orw\n"); - break; - - case FINSH_OP_XOR_WORD: - pc ++; - rt_kprintf("xorw\n"); - break; - - case FINSH_OP_BITWISE_WORD: - pc ++; - rt_kprintf("bww\n"); - break; - - case FINSH_OP_SHL_WORD: - pc ++; - rt_kprintf("shlw\n"); - break; - - case FINSH_OP_SHR_WORD: - pc ++; - rt_kprintf("shrw\n"); - break; - - case FINSH_OP_LD_WORD: - pc ++; - rt_kprintf("ldw %d\n", FINSH_GET16(pc)); - pc += 2; - break; - - case FINSH_OP_LD_VALUE_WORD: - pc ++; - rt_kprintf("ldw [0x%x]\n", FINSH_GET32(pc)); - pc += 4; - break; - - case FINSH_OP_ST_WORD: - pc ++; - rt_kprintf("stw\n"); - break; - - case FINSH_OP_ADD_DWORD: - pc ++; - rt_kprintf("addd\n"); - break; - - case FINSH_OP_SUB_DWORD: - pc ++; - rt_kprintf("subd\n"); - break; - - case FINSH_OP_DIV_DWORD: - pc ++; - rt_kprintf("divd\n"); - break; - - case FINSH_OP_MOD_DWORD: - pc ++; - rt_kprintf("modd\n"); - break; - - case FINSH_OP_MUL_DWORD: - pc ++; - rt_kprintf("muld\n"); - break; - - case FINSH_OP_AND_DWORD: - pc ++; - rt_kprintf("andd\n"); - break; - - case FINSH_OP_OR_DWORD: - pc ++; - rt_kprintf("ord\n"); - break; - - case FINSH_OP_XOR_DWORD: - pc ++; - rt_kprintf("xord\n"); - break; - - case FINSH_OP_BITWISE_DWORD: - pc ++; - rt_kprintf("bwd\n"); - break; - - case FINSH_OP_SHL_DWORD: - pc ++; - rt_kprintf("shld\n"); - break; - - case FINSH_OP_SHR_DWORD: - pc ++; - rt_kprintf("shrd\n"); - break; - - case FINSH_OP_LD_DWORD: - pc ++; - rt_kprintf("ldd 0x%x\n", FINSH_GET32(pc)); - pc += 4; - break; - - case FINSH_OP_LD_VALUE_DWORD: - pc ++; - rt_kprintf("ldd [0x%x]\n", FINSH_GET32(pc)); - pc += 4; - break; - - case FINSH_OP_ST_DWORD: - pc ++; - rt_kprintf("std\n"); - break; - - case FINSH_OP_POP: - rt_kprintf("pop\n"); - pc ++; - break; - - case FINSH_OP_SYSCALL: - pc ++; - rt_kprintf("syscall %d\n", *pc++); - break; - - case FINSH_OP_LD_VALUE_BYTE_STACK: - pc ++; - rt_kprintf("ldb [sp]\n"); - break; - - case FINSH_OP_LD_VALUE_WORD_STACK: - pc ++; - rt_kprintf("ldw [sp]\n"); - break; - - case FINSH_OP_LD_VALUE_DWORD_STACK: - pc ++; - rt_kprintf("ldd [sp]\n"); - break; - - default: - return; - } - } -} -#endif diff --git a/components/finsh/finsh_vm.h b/components/finsh/finsh_vm.h deleted file mode 100644 index 15d5da1ef8..0000000000 --- a/components/finsh/finsh_vm.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ -#ifndef __FINSH_VM_H__ -#define __FINSH_VM_H__ - -#include - -#include "finsh_var.h" - -union finsh_value { - char char_value; - short short_value; - long long_value; - void* ptr; -}; - -extern union finsh_value* finsh_sp; /* stack pointer */ -extern uint8_t* finsh_pc; /* PC */ - -/* stack */ -extern union finsh_value finsh_vm_stack[FINSH_STACK_MAX]; -/* text segment */ -extern uint8_t text_segment[FINSH_TEXT_MAX]; - -void finsh_vm_run(void); -//void finsh_disassemble(void); - -#endif diff --git a/components/finsh/msh.c b/components/finsh/msh.c index ed12219c2e..648b4bbd69 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -10,61 +10,27 @@ * 2017-07-19 Aubr.Cool limit argc to RT_FINSH_ARG_MAX */ #include +#include -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH + +#ifndef FINSH_ARG_MAX + #define FINSH_ARG_MAX 8 +#endif #include "msh.h" -#include -#include +#include "shell.h" #ifdef RT_USING_DFS -#include + #include #endif #ifdef RT_USING_MODULE -#include -#endif - -#ifndef FINSH_ARG_MAX -#define FINSH_ARG_MAX 8 + #include #endif typedef int (*cmd_function_t)(int argc, char **argv); -#ifdef FINSH_USING_MSH -#ifdef FINSH_USING_MSH_ONLY -rt_bool_t msh_is_used(void) -{ - return RT_TRUE; -} -#else -#ifdef FINSH_USING_MSH_DEFAULT -static rt_bool_t __msh_state = RT_TRUE; -#else -static rt_bool_t __msh_state = RT_FALSE; -#endif -rt_bool_t msh_is_used(void) -{ - return __msh_state; -} - -static int msh_exit(int argc, char **argv) -{ - /* return to finsh shell mode */ - __msh_state = RT_FALSE; - return 0; -} -FINSH_FUNCTION_EXPORT_ALIAS(msh_exit, __cmd_exit, return to RT-Thread shell mode.); - -static int msh_enter(void) -{ - /* enter module shell mode */ - __msh_state = RT_TRUE; - return 0; -} -FINSH_FUNCTION_EXPORT_ALIAS(msh_enter, msh, use module shell); -#endif - int msh_help(int argc, char **argv) { rt_kprintf("RT-Thread shell commands:\n"); @@ -87,7 +53,7 @@ int msh_help(int argc, char **argv) return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(msh_help, __cmd_help, RT-Thread shell help.); +MSH_CMD_EXPORT_ALIAS(msh_help, help, RT - Thread shell help.); int cmd_ps(int argc, char **argv) { @@ -102,7 +68,7 @@ int cmd_ps(int argc, char **argv) list_thread(); return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_ps, __cmd_ps, List threads in the system.); +MSH_CMD_EXPORT_ALIAS(cmd_ps, ps, List threads in the system.); #ifdef RT_USING_HEAP int cmd_free(int argc, char **argv) @@ -117,7 +83,7 @@ int cmd_free(int argc, char **argv) #endif return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_free, __cmd_free, Show the memory usage in the system.); +MSH_CMD_EXPORT_ALIAS(cmd_free, free, Show the memory usage in the system.); #endif static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX]) @@ -128,7 +94,8 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX]) rt_size_t i; ptr = cmd; - position = 0; argc = 0; + position = 0; + argc = 0; while (position < length) { @@ -136,13 +103,14 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX]) while ((*ptr == ' ' || *ptr == '\t') && position < length) { *ptr = '\0'; - ptr ++; position ++; + ptr ++; + position ++; } - if(argc >= FINSH_ARG_MAX) + if (argc >= FINSH_ARG_MAX) { rt_kprintf("Too many args ! We only Use:\n"); - for(i = 0; i < argc; i++) + for (i = 0; i < argc; i++) { rt_kprintf("%s ", argv[i]); } @@ -155,8 +123,10 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX]) /* handle string */ if (*ptr == '"') { - ptr ++; position ++; - argv[argc] = ptr; argc ++; + ptr ++; + position ++; + argv[argc] = ptr; + argc ++; /* skip this string */ while (*ptr != '"' && position < length) @@ -165,15 +135,19 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX]) { if (*(ptr + 1) == '"') { - ptr ++; position ++; + ptr ++; + position ++; } } - ptr ++; position ++; + ptr ++; + position ++; } if (position >= length) break; /* skip '"' */ - *ptr = '\0'; ptr ++; position ++; + *ptr = '\0'; + ptr ++; + position ++; } else { @@ -181,7 +155,8 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX]) argc ++; while ((*ptr != ' ' && *ptr != '\t') && position < length) { - ptr ++; position ++; + ptr ++; + position ++; } if (position >= length) break; } @@ -340,7 +315,7 @@ static int _msh_exec_lwp(char *cmd, rt_size_t length) int fd = -1; char *pg_name; - extern int exec(char*, int, char**); + extern int exec(char *, int, char **); /* find the size of first command */ while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) @@ -642,6 +617,4 @@ void msh_auto_complete(char *prefix) return ; } -#endif - -#endif /* FINSH_USING_MSH */ +#endif /* RT_USING_FINSH */ diff --git a/components/finsh/msh.h b/components/finsh/msh.h index 17c7a39ef1..b9b037586e 100644 --- a/components/finsh/msh.h +++ b/components/finsh/msh.h @@ -13,7 +13,6 @@ #include -rt_bool_t msh_is_used(void); int msh_exec(char *cmd, rt_size_t length); void msh_auto_complete(char *prefix); diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c index 3f21cc6f34..8f067efd98 100644 --- a/components/finsh/msh_file.c +++ b/components/finsh/msh_file.c @@ -11,7 +11,7 @@ #include -#if defined(FINSH_USING_MSH) && defined(RT_USING_DFS) +#if defined(RT_USING_FINSH) && defined(RT_USING_DFS) #include #include "msh.h" @@ -144,7 +144,7 @@ int msh_exec_script(const char *cmd_line, int size) } #ifdef DFS_USING_WORKDIR -extern char working_directory[]; + extern char working_directory[]; #endif static int cmd_ls(int argc, char **argv) @@ -614,19 +614,19 @@ static int cmd_tail(int argc, char **argv) rt_uint32_t required_lines = 0; rt_uint32_t after_xxx_line = 0; - if(argc < 2) + if (argc < 2) { rt_kprintf("Usage: tail [-n numbers] \n"); return -1; } - else if(argc == 2) + else if (argc == 2) { required_lines = 10; /* default: 10 lines from tail */ file_name = argv[1]; } - else if(rt_strcmp(argv[1], "-n") == 0) + else if (rt_strcmp(argv[1], "-n") == 0) { - if(argv[2][0] != '+') + if (argv[2][0] != '+') { required_lines = atoi(argv[2]); } @@ -659,9 +659,9 @@ static int cmd_tail(int argc, char **argv) rt_kprintf("\nTotal Number of lines:%d\n", total_lines); - if(after_xxx_line != 0) + if (after_xxx_line != 0) { - if(total_lines > after_xxx_line) + if (total_lines > after_xxx_line) { required_lines = total_lines - after_xxx_line; } @@ -700,7 +700,7 @@ static int cmd_tail(int argc, char **argv) close(fd); return 0; } -MSH_CMD_EXPORT_ALIAS(cmd_tail, tail, print the last N-lines data of the given file); +MSH_CMD_EXPORT_ALIAS(cmd_tail, tail, print the last N - lines data of the given file); -#endif /* defined(FINSH_USING_MSH) && defined(RT_USING_DFS) */ +#endif /* defined(RT_USING_FINSH) && defined(RT_USING_DFS) */ diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 87dc6e0745..48651d2c4f 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -19,75 +19,62 @@ */ #include +#include +#include #ifdef RT_USING_FINSH -#include "finsh.h" #include "shell.h" - -#ifdef FINSH_USING_MSH #include "msh.h" -#endif -#ifdef _WIN32 -#include /* for putchar */ -#endif +#if defined(RT_USING_DFS) + #include +#endif /* RT_USING_DFS */ /* finsh thread */ #ifndef RT_USING_HEAP -static struct rt_thread finsh_thread; -ALIGN(RT_ALIGN_SIZE) -static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE]; -struct finsh_shell _shell; + static struct rt_thread finsh_thread; + ALIGN(RT_ALIGN_SIZE) + static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE]; + struct finsh_shell _shell; #endif /* finsh symtab */ #ifdef FINSH_USING_SYMTAB -struct finsh_syscall *_syscall_table_begin = NULL; -struct finsh_syscall *_syscall_table_end = NULL; -struct finsh_sysvar *_sysvar_table_begin = NULL; -struct finsh_sysvar *_sysvar_table_end = NULL; + struct finsh_syscall *_syscall_table_begin = NULL; + struct finsh_syscall *_syscall_table_end = NULL; #endif struct finsh_shell *shell; static char *finsh_prompt_custom = RT_NULL; #if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) -struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call) +struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call) { unsigned int *ptr; - ptr = (unsigned int*) (call + 1); - while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _syscall_table_end)) + ptr = (unsigned int *)(call + 1); + while ((*ptr == 0) && ((unsigned int *)ptr < (unsigned int *) _syscall_table_end)) ptr ++; - return (struct finsh_syscall*)ptr; + return (struct finsh_syscall *)ptr; } -struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call) -{ - unsigned int *ptr; - ptr = (unsigned int*) (call + 1); - while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _sysvar_table_end)) - ptr ++; - - return (struct finsh_sysvar*)ptr; -} #endif /* defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) */ #ifdef RT_USING_HEAP -int finsh_set_prompt(const char * prompt) +int finsh_set_prompt(const char *prompt) { - if(finsh_prompt_custom) + if (finsh_prompt_custom) { rt_free(finsh_prompt_custom); finsh_prompt_custom = RT_NULL; } /* strdup */ - if(prompt) + if (prompt) { - finsh_prompt_custom = (char *)rt_malloc(strlen(prompt)+1); - if(finsh_prompt_custom) + finsh_prompt_custom = (char *)rt_malloc(strlen(prompt) + 1); + if (finsh_prompt_custom) { strcpy(finsh_prompt_custom, prompt); } @@ -97,14 +84,10 @@ int finsh_set_prompt(const char * prompt) } #endif /* RT_USING_HEAP */ -#ifdef RT_USING_DFS -#include -#endif /* RT_USING_DFS */ +#define _MSH_PROMPT "msh " const char *finsh_get_prompt(void) { -#define _MSH_PROMPT "msh " -#define _PROMPT "finsh " static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0}; /* check prompt mode */ @@ -114,17 +97,12 @@ const char *finsh_get_prompt(void) return finsh_prompt; } - if(finsh_prompt_custom) + if (finsh_prompt_custom) { - strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt)-1); + strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1); return finsh_prompt; } - -#ifdef FINSH_USING_MSH - if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT); - else -#endif - strcpy(finsh_prompt, _PROMPT); + strcpy(finsh_prompt, _MSH_PROMPT); #if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR) /* get current working directory */ @@ -288,7 +266,8 @@ rt_uint32_t finsh_get_echo() * @return result, RT_EOK on OK, -RT_ERROR on the new password length is less than * FINSH_PASSWORD_MIN or greater than FINSH_PASSWORD_MAX */ -rt_err_t finsh_set_password(const char *password) { +rt_err_t finsh_set_password(const char *password) +{ rt_ubase_t level; rt_size_t pw_len = rt_strlen(password); @@ -372,71 +351,12 @@ static void finsh_wait_auth(void) static void shell_auto_complete(char *prefix) { - rt_kprintf("\n"); -#ifdef FINSH_USING_MSH - if (msh_is_used() == RT_TRUE) - { - msh_auto_complete(prefix); - } - else -#endif - { -#ifndef FINSH_USING_MSH_ONLY - extern void list_prefix(char * prefix); - list_prefix(prefix); -#endif - } + msh_auto_complete(prefix); rt_kprintf("%s%s", FINSH_PROMPT, prefix); } -#ifndef FINSH_USING_MSH_ONLY -void finsh_run_line(struct finsh_parser *parser, const char *line) -{ - const char *err_str; - - if(shell->echo_mode) - rt_kprintf("\n"); - finsh_parser_run(parser, (unsigned char *)line); - - /* compile node root */ - if (finsh_errno() == 0) - { - finsh_compiler_run(parser->root); - } - else - { - err_str = finsh_error_string(finsh_errno()); - rt_kprintf("%s\n", err_str); - } - - /* run virtual machine */ - if (finsh_errno() == 0) - { - char ch; - finsh_vm_run(); - - ch = (unsigned char)finsh_stack_bottom(); - if (ch > 0x20 && ch < 0x7e) - { - rt_kprintf("\t'%c', %d, 0x%08x\n", - (unsigned char)finsh_stack_bottom(), - (unsigned int)finsh_stack_bottom(), - (unsigned int)finsh_stack_bottom()); - } - else - { - rt_kprintf("\t%d, 0x%08x\n", - (unsigned int)finsh_stack_bottom(), - (unsigned int)finsh_stack_bottom()); - } - } - - finsh_flush(parser); -} -#endif - #ifdef FINSH_USING_HISTORY static rt_bool_t shell_handle_history(struct finsh_shell *shell) { @@ -508,10 +428,6 @@ void finsh_thread_entry(void *parameter) shell->echo_mode = 0; #endif -#ifndef FINSH_USING_MSH_ONLY - finsh_init(&shell->parser); -#endif - #if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE) /* set console device as shell device */ if (shell->device == RT_NULL) @@ -694,26 +610,9 @@ void finsh_thread_entry(void *parameter) #ifdef FINSH_USING_HISTORY shell_push_history(shell); #endif - -#ifdef FINSH_USING_MSH - if (msh_is_used() == RT_TRUE) - { - if (shell->echo_mode) - rt_kprintf("\n"); - msh_exec(shell->line, shell->line_position); - } - else -#endif - { -#ifndef FINSH_USING_MSH_ONLY - /* add ';' and run the command line */ - shell->line[shell->line_position] = ';'; - - if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line); - else - if (shell->echo_mode) rt_kprintf("\n"); -#endif - } + if (shell->echo_mode) + rt_kprintf("\n"); + msh_exec(shell->line, shell->line_position); rt_kprintf(FINSH_PROMPT); memset(shell->line, 0, sizeof(shell->line)); @@ -766,23 +665,14 @@ void finsh_system_function_init(const void *begin, const void *end) _syscall_table_end = (struct finsh_syscall *) end; } -void finsh_system_var_init(const void *begin, const void *end) -{ - _sysvar_table_begin = (struct finsh_sysvar *) begin; - _sysvar_table_end = (struct finsh_sysvar *) end; -} - #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ #ifdef FINSH_USING_SYMTAB -#pragma section="FSymTab" -#pragma section="VSymTab" + #pragma section="FSymTab" #endif #elif defined(__ADSPBLACKFIN__) /* for VisaulDSP++ Compiler*/ #ifdef FINSH_USING_SYMTAB -extern "asm" int __fsymtab_start; -extern "asm" int __fsymtab_end; -extern "asm" int __vsymtab_start; -extern "asm" int __vsymtab_end; + extern "asm" int __fsymtab_start; + extern "asm" int __fsymtab_end; #endif #elif defined(_MSC_VER) #pragma section("FSymTab$a", read) @@ -820,32 +710,21 @@ int finsh_system_init(void) #ifdef __ARMCC_VERSION /* ARM C Compiler */ extern const int FSymTab$$Base; extern const int FSymTab$$Limit; - extern const int VSymTab$$Base; - extern const int VSymTab$$Limit; finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit); -#ifndef FINSH_USING_MSH_ONLY - finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit); -#endif #elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */ finsh_system_function_init(__section_begin("FSymTab"), __section_end("FSymTab")); - finsh_system_var_init(__section_begin("VSymTab"), - __section_end("VSymTab")); #elif defined (__GNUC__) || defined(__TI_COMPILER_VERSION__) || defined(__TASKING__) /* GNU GCC Compiler and TI CCS */ extern const int __fsymtab_start; extern const int __fsymtab_end; - extern const int __vsymtab_start; - extern const int __vsymtab_end; finsh_system_function_init(&__fsymtab_start, &__fsymtab_end); - finsh_system_var_init(&__vsymtab_start, &__vsymtab_end); #elif defined(__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */ finsh_system_function_init(&__fsymtab_start, &__fsymtab_end); - finsh_system_var_init(&__vsymtab_start, &__vsymtab_end); #elif defined(_MSC_VER) unsigned int *ptr_begin, *ptr_end; - if(shell) + if (shell) { rt_kprintf("finsh shell already init.\n"); return RT_EOK; diff --git a/components/finsh/shell.h b/components/finsh/shell.h index 6a2737f422..b671db0849 100644 --- a/components/finsh/shell.h +++ b/components/finsh/shell.h @@ -15,20 +15,20 @@ #include "finsh.h" #ifndef FINSH_THREAD_PRIORITY -#define FINSH_THREAD_PRIORITY 20 + #define FINSH_THREAD_PRIORITY 20 #endif #ifndef FINSH_THREAD_STACK_SIZE -#define FINSH_THREAD_STACK_SIZE 2048 + #define FINSH_THREAD_STACK_SIZE 2048 #endif #ifndef FINSH_CMD_SIZE -#define FINSH_CMD_SIZE 80 + #define FINSH_CMD_SIZE 80 #endif #define FINSH_OPTION_ECHO 0x01 #define FINSH_PROMPT finsh_get_prompt() -const char* finsh_get_prompt(void); -int finsh_set_prompt(const char * prompt); +const char *finsh_get_prompt(void); +int finsh_set_prompt(const char *prompt); #ifdef FINSH_USING_HISTORY #ifndef FINSH_HISTORY_LINES @@ -49,7 +49,7 @@ int finsh_set_prompt(const char * prompt); #endif /* FINSH_USING_AUTH */ #ifndef FINSH_THREAD_NAME -#define FINSH_THREAD_NAME "tshell" + #define FINSH_THREAD_NAME "tshell" #endif enum input_stat @@ -64,7 +64,7 @@ struct finsh_shell enum input_stat stat; - rt_uint8_t echo_mode:1; + rt_uint8_t echo_mode: 1; rt_uint8_t prompt_mode: 1; #ifdef FINSH_USING_HISTORY @@ -74,10 +74,6 @@ struct finsh_shell char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE]; #endif -#ifndef FINSH_USING_MSH_ONLY - struct finsh_parser parser; -#endif - char line[FINSH_CMD_SIZE + 1]; rt_uint16_t line_position; rt_uint16_t line_curpos; @@ -95,16 +91,16 @@ void finsh_set_echo(rt_uint32_t echo); rt_uint32_t finsh_get_echo(void); int finsh_system_init(void); -void finsh_set_device(const char* device_name); -const char* finsh_get_device(void); +void finsh_set_device(const char *device_name); +const char *finsh_get_device(void); char finsh_getchar(void); rt_uint32_t finsh_get_prompt_mode(void); void finsh_set_prompt_mode(rt_uint32_t prompt_mode); #ifdef FINSH_USING_AUTH -rt_err_t finsh_set_password(const char *password); -const char *finsh_get_password(void); + rt_err_t finsh_set_password(const char *password); + const char *finsh_get_password(void); #endif #endif diff --git a/components/finsh/symbol.c b/components/finsh/symbol.c deleted file mode 100644 index c6623e2d82..0000000000 --- a/components/finsh/symbol.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2010-03-22 Bernard first version - */ - -#include - -#if defined(RT_USING_FINSH) && !defined(FINSH_USING_SYMTAB) - -#include "finsh.h" - -long hello(void); -long version(void); -long list(void); -long list_thread(void); -long list_sem(void); -long list_mutex(void); -long list_fevent(void); -long list_event(void); -long list_mailbox(void); -long list_msgqueue(void); -long list_mempool(void); -long list_timer(void); - -struct finsh_syscall _syscall_table[] = -{ - {"hello", hello}, - {"version", version}, - {"list", list}, - {"list_thread", list_thread}, -#ifdef RT_USING_SEMAPHORE - {"list_sem", list_sem}, -#endif -#ifdef RT_USING_MUTEX - {"list_mutex", list_mutex}, -#endif -#ifdef RT_USING_FEVENT - {"list_fevent", list_fevent}, -#endif -#ifdef RT_USING_EVENT - {"list_event", list_event}, -#endif -#ifdef RT_USING_MAILBOX - {"list_mb", list_mailbox}, -#endif -#ifdef RT_USING_MESSAGEQUEUE - {"list_mq", list_msgqueue}, -#endif -#ifdef RT_USING_MEMPOOL - {"list_memp", list_mempool}, -#endif - {"list_timer", list_timer}, -}; -struct finsh_syscall *_syscall_table_begin = &_syscall_table[0]; -struct finsh_syscall *_syscall_table_end = &_syscall_table[sizeof(_syscall_table) / sizeof(struct finsh_syscall)]; - -struct finsh_sysvar *_sysvar_table_begin = NULL; -struct finsh_sysvar *_sysvar_table_end = NULL; - -#endif /* RT_USING_FINSH && !FINSH_USING_SYMTAB */ - diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index ce4c358993..be6041a663 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -302,7 +302,7 @@ int remove(const char *filename) #endif } -#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS) +#if defined(RT_USING_FINSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS) /* use system(const char *string) implementation in the msh */ #else int system(const char *string) diff --git a/components/net/at/Kconfig b/components/net/at/Kconfig index 4aedbb888b..6cf7fdade6 100644 --- a/components/net/at/Kconfig +++ b/components/net/at/Kconfig @@ -68,7 +68,7 @@ if RT_USING_AT config AT_USING_CLI bool "Enable CLI(Command-Line Interface) for AT commands" default y - depends on FINSH_USING_MSH + depends on RT_USING_FINSH config AT_PRINT_RAW_CMD bool "Enable print RAW format AT command communication data" diff --git a/components/net/lwip-2.0.2/src/apps/tftp/tftp_port.c b/components/net/lwip-2.0.2/src/apps/tftp/tftp_port.c index e14e34cfec..59e64c7a3b 100644 --- a/components/net/lwip-2.0.2/src/apps/tftp/tftp_port.c +++ b/components/net/lwip-2.0.2/src/apps/tftp/tftp_port.c @@ -66,8 +66,6 @@ static void tftp_server(uint8_t argc, char **argv) } FINSH_FUNCTION_EXPORT(tftp_server, start tftp server.); -#if defined(FINSH_USING_MSH) MSH_CMD_EXPORT(tftp_server, start tftp server.); -#endif /* defined(FINSH_USING_MSH) */ #endif /* defined(RT_USING_FINSH) */ diff --git a/components/net/lwip-2.0.3/src/apps/tftp/tftp_port.c b/components/net/lwip-2.0.3/src/apps/tftp/tftp_port.c index e14e34cfec..59e64c7a3b 100644 --- a/components/net/lwip-2.0.3/src/apps/tftp/tftp_port.c +++ b/components/net/lwip-2.0.3/src/apps/tftp/tftp_port.c @@ -66,8 +66,6 @@ static void tftp_server(uint8_t argc, char **argv) } FINSH_FUNCTION_EXPORT(tftp_server, start tftp server.); -#if defined(FINSH_USING_MSH) MSH_CMD_EXPORT(tftp_server, start tftp server.); -#endif /* defined(FINSH_USING_MSH) */ #endif /* defined(RT_USING_FINSH) */ diff --git a/components/net/lwip-2.1.2/src/apps/tftp/tftp_port.c b/components/net/lwip-2.1.2/src/apps/tftp/tftp_port.c index e14e34cfec..59e64c7a3b 100644 --- a/components/net/lwip-2.1.2/src/apps/tftp/tftp_port.c +++ b/components/net/lwip-2.1.2/src/apps/tftp/tftp_port.c @@ -66,8 +66,6 @@ static void tftp_server(uint8_t argc, char **argv) } FINSH_FUNCTION_EXPORT(tftp_server, start tftp server.); -#if defined(FINSH_USING_MSH) MSH_CMD_EXPORT(tftp_server, start tftp server.); -#endif /* defined(FINSH_USING_MSH) */ #endif /* defined(RT_USING_FINSH) */ diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c index c36fc6ff26..89ba58cf48 100644 --- a/components/utilities/ulog/ulog.c +++ b/components/utilities/ulog/ulog.c @@ -1075,7 +1075,7 @@ const char *ulog_global_filter_kw_get(void) return ulog.filter.keyword; } -#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) +#ifdef(RT_USING_FINSH) #include static void _print_lvl_info(void) @@ -1250,7 +1250,7 @@ static void ulog_filter(uint8_t argc, char **argv) } } MSH_CMD_EXPORT(ulog_filter, Show ulog filter settings); -#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */ +#endif defined(RT_USING_FINSH) #endif /* ULOG_USING_FILTER */ rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool_t support_color) diff --git a/examples/file/listdir.c b/examples/file/listdir.c index 06c746a642..9649347734 100644 --- a/examples/file/listdir.c +++ b/examples/file/listdir.c @@ -67,7 +67,6 @@ void list_dir(const char* path) #include FINSH_FUNCTION_EXPORT(list_dir, list directory); -#ifdef FINSH_USING_MSH static void cmd_list_dir(int argc, char *argv[]) { char* filename; @@ -84,5 +83,4 @@ static void cmd_list_dir(int argc, char *argv[]) list_dir(filename); } MSH_CMD_EXPORT_ALIAS(cmd_list_dir, list_dir, list directory); -#endif /* FINSH_USING_MSH */ #endif /* RT_USING_FINSH */ diff --git a/examples/file/readspeed.c b/examples/file/readspeed.c index ffc19635cf..61b1a8a696 100644 --- a/examples/file/readspeed.c +++ b/examples/file/readspeed.c @@ -58,7 +58,6 @@ void readspeed(const char* filename, int block_size) #include FINSH_FUNCTION_EXPORT(readspeed, perform file read test); -#ifdef FINSH_USING_MSH static void cmd_readspeed(int argc, char *argv[]) { char* filename; @@ -83,5 +82,4 @@ static void cmd_readspeed(int argc, char *argv[]) readspeed(filename, block_size); } FINSH_FUNCTION_EXPORT_ALIAS(cmd_readspeed, __cmd_readspeed, test file system read speed); -#endif /* FINSH_USING_MSH */ #endif /* RT_USING_FINSH */ diff --git a/examples/file/readwrite.c b/examples/file/readwrite.c index 56f3b7e16c..9b27da1b01 100644 --- a/examples/file/readwrite.c +++ b/examples/file/readwrite.c @@ -147,7 +147,6 @@ __exit: /* export to finsh */ FINSH_FUNCTION_EXPORT(readwrite, perform file read and write test); -#ifdef FINSH_USING_MSH static void cmd_readwrite(int argc, char *argv[]) { char* filename; @@ -164,5 +163,4 @@ static void cmd_readwrite(int argc, char *argv[]) readwrite(filename); } FINSH_FUNCTION_EXPORT_ALIAS(cmd_readwrite, __cmd_readwrite, perform file read and write test); -#endif /* FINSH_USING_MSH */ #endif /* RT_USING_FINSH */ diff --git a/examples/file/writespeed.c b/examples/file/writespeed.c index 680761583c..8ae6f6e5a8 100644 --- a/examples/file/writespeed.c +++ b/examples/file/writespeed.c @@ -66,7 +66,6 @@ void writespeed(const char* filename, int total_length, int block_size) #include FINSH_FUNCTION_EXPORT(writespeed, perform file write test); -#ifdef FINSH_USING_MSH static void cmd_writespeed(int argc, char *argv[]) { char* filename; @@ -94,5 +93,4 @@ static void cmd_writespeed(int argc, char *argv[]) writespeed(filename, length, block_size); } FINSH_FUNCTION_EXPORT_ALIAS(cmd_writespeed, __cmd_writespeed, test file system write speed); -#endif /* FINSH_USING_MSH */ #endif /* RT_USING_FINSH */ diff --git a/examples/kernel/tc_comm.c b/examples/kernel/tc_comm.c index b98c97d9b3..0a43ca3855 100644 --- a/examples/kernel/tc_comm.c +++ b/examples/kernel/tc_comm.c @@ -25,7 +25,6 @@ static const char* _tc_current; static void (*_tc_cleanup)(void) = RT_NULL; static rt_uint32_t _tc_scale = 1; -FINSH_VAR_EXPORT(_tc_scale, finsh_type_int, the testcase timer timeout scale) static rt_uint32_t _tc_loop; diff --git a/examples/libc/termios_test.c b/examples/libc/termios_test.c index f65bff1a9f..f3a6ce3a1c 100644 --- a/examples/libc/termios_test.c +++ b/examples/libc/termios_test.c @@ -356,8 +356,8 @@ int termios_test(int argc, char **argv) #ifdef RT_USING_FINSH #include - #ifdef FINSH_USING_MSH + #ifdef RT_USING_FINSH MSH_CMD_EXPORT_ALIAS(termios_test, termtest, e.g: termtest /dev/uart4 115200); - #endif /* FINSH_USING_MSH */ + #endif /* RT_USING_FINSH */ #endif /* RT_USING_FINSH */ diff --git a/examples/test/hwtimer_test.c b/examples/test/hwtimer_test.c index 15d7aa830f..08b0c5acaf 100644 --- a/examples/test/hwtimer_test.c +++ b/examples/test/hwtimer_test.c @@ -105,7 +105,7 @@ EXIT: return err; } -#ifdef FINSH_USING_MSH +#ifdef RT_USING_FINSH MSH_CMD_EXPORT(hwtimer, "Test hardware timer"); #endif #endif /* RT_USING_HWTIMER */ diff --git a/include/rtdef.h b/include/rtdef.h index 278676bcef..c0fcb8fce1 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -277,7 +277,6 @@ typedef int (*init_fn_t)(void); /* define these to empty, even if not include finsh.h file */ #define FINSH_FUNCTION_EXPORT(name, desc) #define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc) -#define FINSH_VAR_EXPORT(name, type, desc) #define MSH_CMD_EXPORT(command, desc) #define MSH_CMD_EXPORT_ALIAS(command, alias, desc) diff --git a/include/rtthread.h b/include/rtthread.h index cf47a48efe..5e02af3f9e 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -585,7 +585,7 @@ void rt_assert_handler(const char *ex, const char *func, rt_size_t line); #endif /* RT_DEBUG */ #ifdef RT_USING_FINSH -#include +#include #endif /**@}*/ -- cgit v1.3.1 From aab382c32ed0fb795d12191c7a59265f574e8466 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 30 Aug 2021 22:27:09 -0400 Subject: [rtlibc] remove libc_dirent.h --- components/dfs/include/dfs.h | 19 ++++++------------- components/dfs/include/dfs_posix.h | 8 -------- components/libc/compilers/common/dirent.h | 27 ++++++++++++++++++--------- include/libc/libc_dirent.h | 17 ----------------- include/rtlibc.h | 1 - 5 files changed, 24 insertions(+), 48 deletions(-) delete mode 100644 include/libc/libc_dirent.h (limited to 'include') diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index 80dc433787..6af8bbd99f 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -16,10 +16,13 @@ #include #include -#include -#include +#include #include +#ifdef __cplusplus +extern "C" { +#endif + #ifndef DFS_FILESYSTEMS_MAX #define DFS_FILESYSTEMS_MAX 2 #endif @@ -63,9 +66,7 @@ #define DFS_F_EOF 0x04000000 #define DFS_F_ERR 0x08000000 -#ifdef __cplusplus -extern "C" { -#endif +#include struct statfs { @@ -74,14 +75,6 @@ struct statfs size_t f_bfree; /* free blocks in file system */ }; -struct dirent -{ - uint8_t d_type; /* The type of the file */ - uint8_t d_namlen; /* The length of the not including the terminating null file name */ - uint16_t d_reclen; /* length of this record */ - char d_name[DFS_PATH_MAX]; /* The null-terminated file name */ -}; - struct dfs_fdtable { uint32_t maxfd; diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 0475460d95..ec7cdc9de4 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -21,14 +21,6 @@ extern "C" { #endif -typedef struct -{ - int fd; /* directory file */ - char buf[512]; - int num; - int cur; -} DIR; - /* directory api*/ int mkdir(const char *path, mode_t mode); DIR *opendir(const char *name); diff --git a/components/libc/compilers/common/dirent.h b/components/libc/compilers/common/dirent.h index bfba586093..6727d96788 100644 --- a/components/libc/compilers/common/dirent.h +++ b/components/libc/compilers/common/dirent.h @@ -6,10 +6,14 @@ * Change Logs: * Date Author Notes */ -#ifndef __RTT_DIRENT_H__ -#define __RTT_DIRENT_H__ +#ifndef __DIRENT_H__ +#define __DIRENT_H__ -#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* * dirent.h - format of directory entries @@ -26,27 +30,32 @@ #define DT_REG 0x01 #define DT_DIR 0x02 -#ifdef __cplusplus -extern "C" { -#endif - #ifndef HAVE_DIR_STRUCTURE +#define HAVE_DIR_STRUCTURE typedef struct { int fd; /* directory file */ char buf[512]; int num; int cur; -} DIR; +}DIR; #endif #ifndef HAVE_DIRENT_STRUCTURE +#define HAVE_DIRENT_STRUCTURE + +#ifdef DFS_PATH_MAX +#define DIRENT_NAME_MAX DFS_PATH_MAX +#else +#define DIRENT_NAME_MAX 256 +#endif + struct dirent { rt_uint8_t d_type; /* The type of the file */ rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ rt_uint16_t d_reclen; /* length of this record */ - char d_name[256]; /* The null-terminated file name */ + char d_name[DIRENT_NAME_MAX]; /* The null-terminated file name */ }; #endif diff --git a/include/libc/libc_dirent.h b/include/libc/libc_dirent.h deleted file mode 100644 index a86332e633..0000000000 --- a/include/libc/libc_dirent.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 - */ - -#ifndef LIBC_DIRENT_H__ -#define LIBC_DIRENT_H__ - -#define DT_UNKNOWN 0x00 -#define DT_REG 0x01 -#define DT_DIR 0x02 - -#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 4b145b1b1b..b59a29dadb 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -14,7 +14,6 @@ /* definitions for libc if toolchain has no these definitions */ #include "libc/libc_stat.h" #include "libc/libc_fcntl.h" -#include "libc/libc_dirent.h" #ifndef RT_USING_LIBC #if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) -- cgit v1.3.1 From 8da9f78d7274f462852096ca2cae3d6e284fd51f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 11 Sep 2021 11:07:51 +0800 Subject: [libc] remove rtlibc --- bsp/qemu-riscv-virt64/driver/plic.c | 3 +- bsp/qemu-riscv-virt64/driver/sbi.c | 4 +- bsp/qemu-riscv-virt64/driver/sbi.h | 1 + components/dfs/include/dfs.h | 2 + components/dfs/include/dfs_posix.h | 16 +-- components/drivers/rtc/rtc.c | 7 +- components/libc/compilers/common/fcntl.h | 72 ++++++++++++++ components/libc/compilers/common/none-gcc/fcntl.h | 18 ---- .../libc/compilers/common/none-gcc/sys/stat.h | 76 +++++++++++++- components/libc/compilers/common/sys/ioctl.h | 2 + components/libc/compilers/dlib/libc.c | 2 +- components/libc/compilers/newlib/stdio.c | 2 +- components/libc/libdl/dlelf.h | 7 +- components/net/lwip-1.4.1/src/lwipopts.h | 1 + components/net/lwip-2.0.2/src/lwipopts.h | 1 + components/net/lwip-2.0.3/src/lwipopts.h | 1 + components/net/lwip-2.1.2/src/lwipopts.h | 1 + components/net/netdev/src/netdev_ipaddr.c | 2 +- components/net/sal_socket/socket/net_netdb.c | 1 + include/libc/libc_fcntl.h | 98 ------------------ include/libc/libc_stat.h | 110 --------------------- include/rtdef.h | 3 - include/rtlibc.h | 31 ------ libcpu/mips/common/ptrace.h | 2 +- libcpu/risc-v/virt64/cpuport.c | 2 +- 25 files changed, 171 insertions(+), 294 deletions(-) create mode 100644 components/libc/compilers/common/fcntl.h delete mode 100644 components/libc/compilers/common/none-gcc/fcntl.h delete mode 100644 include/libc/libc_fcntl.h delete mode 100644 include/libc/libc_stat.h delete mode 100644 include/rtlibc.h (limited to 'include') diff --git a/bsp/qemu-riscv-virt64/driver/plic.c b/bsp/qemu-riscv-virt64/driver/plic.c index f502bc9da0..6e2ec5e84e 100644 --- a/bsp/qemu-riscv-virt64/driver/plic.c +++ b/bsp/qemu-riscv-virt64/driver/plic.c @@ -7,7 +7,8 @@ * Date Author Notes * 2021-05-20 bigmagic first version */ -#include "rtthread.h" +#include +#include #include "plic.h" #include #include "encoding.h" diff --git a/bsp/qemu-riscv-virt64/driver/sbi.c b/bsp/qemu-riscv-virt64/driver/sbi.c index f848ec7810..129e8fcb0e 100644 --- a/bsp/qemu-riscv-virt64/driver/sbi.c +++ b/bsp/qemu-riscv-virt64/driver/sbi.c @@ -72,8 +72,8 @@ sbi_get_impl_version(void) void sbi_print_version(void) { - u_int major; - u_int minor; + int major; + int minor; /* For legacy SBI implementations. */ if (sbi_spec_version == 0) diff --git a/bsp/qemu-riscv-virt64/driver/sbi.h b/bsp/qemu-riscv-virt64/driver/sbi.h index b42d558f53..1e7ad6b4b8 100644 --- a/bsp/qemu-riscv-virt64/driver/sbi.h +++ b/bsp/qemu-riscv-virt64/driver/sbi.h @@ -48,6 +48,7 @@ #ifndef _MACHINE_SBI_H_ #define _MACHINE_SBI_H_ +#include #include /* SBI Specification Version */ diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index 0fd8c2dccc..9f112f9656 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index ec7cdc9de4..98da0f854f 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -16,22 +16,15 @@ #define __DFS_POSIX_H__ #include +#include #ifdef __cplusplus extern "C" { #endif -/* directory api*/ -int mkdir(const char *path, mode_t mode); -DIR *opendir(const char *name); -struct dirent *readdir(DIR *d); -long telldir(DIR *d); -void seekdir(DIR *d, off_t offset); -void rewinddir(DIR *d); -int closedir(DIR *d); /* file api*/ -int open(const char *file, int flags, ...); + int close(int d); #if defined(RT_USING_NEWLIB) && defined(_EXFUN) @@ -45,11 +38,7 @@ int write(int fd, const void *buf, size_t len); off_t lseek(int fd, off_t offset, int whence); int rename(const char *from, const char *to); int unlink(const char *pathname); -int stat(const char *file, struct stat *buf); -int fstat(int fildes, struct stat *buf); int fsync(int fildes); -int fcntl(int fildes, int cmd, ...); -int ioctl(int fildes, int cmd, ...); int ftruncate(int fd, off_t length); /* directory api*/ @@ -62,7 +51,6 @@ int statfs(const char *path, struct statfs *buf); int access(const char *path, int amode); int pipe(int fildes[2]); -int mkfifo(const char *path, mode_t mode); #ifdef __cplusplus } diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index 35e7ddc3c4..bc75c83e7d 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -223,7 +223,7 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) /** * get date and time or set (local timezone) [year month day hour min sec] */ -static void date(uint8_t argc, char **argv) +static void date(int argc, char **argv) { if (argc == 1) { @@ -235,8 +235,9 @@ static void date(uint8_t argc, char **argv) else if (argc >= 7) { /* set time and date */ - uint16_t year; - uint8_t month, day, hour, min, sec; + rt_uint16_t year; + rt_uint8_t month, day, hour, min, sec; + year = atoi(argv[1]); month = atoi(argv[2]); day = atoi(argv[3]); diff --git a/components/libc/compilers/common/fcntl.h b/components/libc/compilers/common/fcntl.h new file mode 100644 index 0000000000..b98f540627 --- /dev/null +++ b/components/libc/compilers/common/fcntl.h @@ -0,0 +1,72 @@ +/* + * 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 + +#if defined(_WIN32) +#define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR) +#endif + +#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/none-gcc/fcntl.h b/components/libc/compilers/common/none-gcc/fcntl.h deleted file mode 100644 index f247b926e9..0000000000 --- a/components/libc/compilers/common/none-gcc/fcntl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef FCNTL_H__ -#define FCNTL_H__ - -#include - -#ifdef RT_USING_DFS -#include -#endif - -#endif diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h index c8f65df435..107c15decf 100644 --- a/components/libc/compilers/common/none-gcc/sys/stat.h +++ b/components/libc/compilers/common/none-gcc/sys/stat.h @@ -5,9 +5,79 @@ * * Change Logs: * Date Author Notes + * 2021-09-02 Meco Man First version */ - #ifndef __SYS_STAT_H__ - #define __SYS_STAT_H__ +#ifndef __SYS_STAT_H__ +#define __SYS_STAT_H__ - #endif +#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/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index 51f51f2ea4..b926a71875 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -235,4 +235,6 @@ struct winsize { #define SIOCDEVPRIVATE 0x89F0 #define SIOCPROTOPRIVATE 0x89E0 +int ioctl(int fildes, int cmd, ...); + #endif diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c index d0dca7c5f6..097d736bfe 100644 --- a/components/libc/compilers/dlib/libc.c +++ b/components/libc/compilers/dlib/libc.c @@ -9,7 +9,7 @@ */ #include #include - +#include #include #include "libc.h" diff --git a/components/libc/compilers/newlib/stdio.c b/components/libc/compilers/newlib/stdio.c index ce5bdb75cb..baccafad87 100644 --- a/components/libc/compilers/newlib/stdio.c +++ b/components/libc/compilers/newlib/stdio.c @@ -9,7 +9,7 @@ */ #include #include - +#include #include #include "libc.h" diff --git a/components/libc/libdl/dlelf.h b/components/libc/libdl/dlelf.h index 540fe2c8aa..ab6cc5565d 100644 --- a/components/libc/libdl/dlelf.h +++ b/components/libc/libdl/dlelf.h @@ -28,12 +28,7 @@ typedef rt_int32_t Elf64_Sword; typedef rt_uint32_t Elf64_Word; typedef rt_uint64_t Elf64_Xword; typedef rt_int64_t Elf64_Sxword; -typedef uint16_t Elf64_Section; - - - - - +typedef rt_uint16_t Elf64_Section; /* e_ident[] magic number */ #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h index 9148066d50..a5e035b53a 100644 --- a/components/net/lwip-1.4.1/src/lwipopts.h +++ b/components/net/lwip-1.4.1/src/lwipopts.h @@ -533,6 +533,7 @@ #ifndef LWIP_SOCKET #define LWIP_SOCKET 1 #endif +#include /* * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h index fdfe1437b2..fe6e2fef6f 100644 --- a/components/net/lwip-2.0.2/src/lwipopts.h +++ b/components/net/lwip-2.0.2/src/lwipopts.h @@ -572,6 +572,7 @@ #ifndef LWIP_SOCKET #define LWIP_SOCKET 1 #endif +#include /* * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. diff --git a/components/net/lwip-2.0.3/src/lwipopts.h b/components/net/lwip-2.0.3/src/lwipopts.h index fdfe1437b2..fe6e2fef6f 100644 --- a/components/net/lwip-2.0.3/src/lwipopts.h +++ b/components/net/lwip-2.0.3/src/lwipopts.h @@ -572,6 +572,7 @@ #ifndef LWIP_SOCKET #define LWIP_SOCKET 1 #endif +#include /* * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h index a964ab13ac..81409a9d0a 100644 --- a/components/net/lwip-2.1.2/src/lwipopts.h +++ b/components/net/lwip-2.1.2/src/lwipopts.h @@ -579,6 +579,7 @@ #ifndef LWIP_SOCKET #define LWIP_SOCKET 1 #endif +#include /* * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. diff --git a/components/net/netdev/src/netdev_ipaddr.c b/components/net/netdev/src/netdev_ipaddr.c index 9abb41bd14..afb6d1d962 100644 --- a/components/net/netdev/src/netdev_ipaddr.c +++ b/components/net/netdev/src/netdev_ipaddr.c @@ -7,7 +7,7 @@ * Date Author Notes * 2018-05-18 ChenYong First version */ - +#include #include #include diff --git a/components/net/sal_socket/socket/net_netdb.c b/components/net/sal_socket/socket/net_netdb.c index 03b995c68d..1eb84e1c32 100644 --- a/components/net/sal_socket/socket/net_netdb.c +++ b/components/net/sal_socket/socket/net_netdb.c @@ -9,6 +9,7 @@ * 2108-05-24 ChenYong Add socket abstraction layer */ +#include #include #include diff --git a/include/libc/libc_fcntl.h b/include/libc/libc_fcntl.h deleted file mode 100644 index 945e674d35..0000000000 --- a/include/libc/libc_fcntl.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2018-02-07 Bernard Add O_DIRECTORY definition in NEWLIB mode. - * 2018-02-09 Bernard Add O_BINARY definition - */ - -#ifndef LIBC_FCNTL_H__ -#define LIBC_FCNTL_H__ - -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -#include - -#ifndef O_NONBLOCK -#define O_NONBLOCK 0x4000 -#endif - -#if defined(_WIN32) -#define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR) -#endif - -#ifndef F_GETFL -#define F_GETFL 3 -#endif -#ifndef F_SETFL -#define F_SETFL 4 -#endif - -#ifndef O_DIRECTORY -#define O_DIRECTORY 0x200000 -#endif - -#ifndef O_BINARY -#ifdef _O_BINARY -#define O_BINARY _O_BINARY -#else -#define O_BINARY 0 -#endif -#endif - -#else -#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 -#endif - -#endif diff --git a/include/libc/libc_stat.h b/include/libc/libc_stat.h deleted file mode 100644 index f680de4e06..0000000000 --- a/include/libc/libc_stat.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ - -#ifndef LIBC_STAT_H__ -#define LIBC_STAT_H__ - -#include - -#if defined(RT_USING_NEWLIB) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -/* use header file of newlib */ -#include - -#elif defined(_WIN32) -#include - -#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 - -#define S_IFSOCK 0140000 -#define S_IFLNK 0120000 -#define S_IFBLK 0060000 -#define S_IFIFO 0010000 -#define S_ISUID 0004000 -#define S_ISGID 0002000 -#define S_ISVTX 0001000 - -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) - -#else -#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 - -/* stat structure */ -#include -#include - -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]; -}; - -#endif - -#endif diff --git a/include/rtdef.h b/include/rtdef.h index c0fcb8fce1..3f5f4c5ef9 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -1146,9 +1146,6 @@ struct rt_device_graphic_ops /**@}*/ #endif -/* definitions for libc */ -#include "rtlibc.h" - #ifdef __cplusplus } #endif diff --git a/include/rtlibc.h b/include/rtlibc.h deleted file mode 100644 index b59a29dadb..0000000000 --- a/include/rtlibc.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-01-21 Bernard the first version - */ - -#ifndef RTLIBC_H__ -#define RTLIBC_H__ - -/* definitions for libc if toolchain has no these definitions */ -#include "libc/libc_stat.h" -#include "libc/libc_fcntl.h" - -#ifndef RT_USING_LIBC -#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) -typedef signed long off_t; -typedef int mode_t; -#endif -#endif - -#if defined(__MINGW32__) || defined(_WIN32) -typedef signed long off_t; -typedef int mode_t; -#endif - -#endif - diff --git a/libcpu/mips/common/ptrace.h b/libcpu/mips/common/ptrace.h index 8b82cca5d6..da800e05dc 100644 --- a/libcpu/mips/common/ptrace.h +++ b/libcpu/mips/common/ptrace.h @@ -63,7 +63,7 @@ struct pt_regs { * so it should be a part of pt_regs */ struct mips_fpu_struct fpu; #endif -} __aligned(8); +} __attribute__((aligned(8))); #endif /* Note: For call stack o32 ABI has 0x8 shadowsoace Here */ diff --git a/libcpu/risc-v/virt64/cpuport.c b/libcpu/risc-v/virt64/cpuport.c index 33cab19488..9b0c2cce6b 100644 --- a/libcpu/risc-v/virt64/cpuport.c +++ b/libcpu/risc-v/virt64/cpuport.c @@ -9,13 +9,13 @@ * 2021-02-11 lizhirui add gp support */ +#include #include #include #include "cpuport.h" #include "stack.h" - /** * @brief from thread used interrupt context switch * -- cgit v1.3.1