finsh.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-03-22 Bernard first version
  9. */
  10. #ifndef __FINSH_H__
  11. #define __FINSH_H__
  12. #include <rtdef.h>
  13. #ifdef _MSC_VER
  14. #pragma section("FSymTab$f",read)
  15. #endif /* _MSC_VER */
  16. typedef long (*syscall_func)(void);
  17. #ifdef FINSH_USING_SYMTAB
  18. #ifdef __TI_COMPILER_VERSION__
  19. #define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab"))
  20. #endif /* __TI_COMPILER_VERSION__ */
  21. #ifdef FINSH_USING_DESCRIPTION
  22. #ifdef _MSC_VER
  23. #define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  24. const char __fsym_##cmd##_name[] = #cmd; \
  25. const char __fsym_##cmd##_desc[] = #desc; \
  26. __declspec(allocate("FSymTab$f")) \
  27. const struct finsh_syscall __fsym_##cmd = \
  28. { \
  29. __fsym_##cmd##_name, \
  30. __fsym_##cmd##_desc, \
  31. (syscall_func)&name \
  32. };
  33. #pragma comment(linker, "/merge:FSymTab=mytext")
  34. #elif defined(__TI_COMPILER_VERSION__)
  35. #ifdef __TMS320C28XX__
  36. #define RT_NOBLOCKED __attribute__((noblocked))
  37. #else
  38. #define RT_NOBLOCKED
  39. #endif
  40. #define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  41. __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
  42. const char __fsym_##cmd##_name[] = #cmd; \
  43. const char __fsym_##cmd##_desc[] = #desc; \
  44. rt_used RT_NOBLOCKED const struct finsh_syscall __fsym_##cmd = \
  45. { \
  46. __fsym_##cmd##_name, \
  47. __fsym_##cmd##_desc, \
  48. (syscall_func)&name \
  49. };
  50. #else
  51. #define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  52. const char __fsym_##cmd##_name[] rt_section(".rodata.name") = #cmd; \
  53. const char __fsym_##cmd##_desc[] rt_section(".rodata.name") = #desc; \
  54. rt_used const struct finsh_syscall __fsym_##cmd rt_section("FSymTab")= \
  55. { \
  56. __fsym_##cmd##_name, \
  57. __fsym_##cmd##_desc, \
  58. (syscall_func)&name \
  59. };
  60. #endif
  61. #else
  62. #ifdef _MSC_VER
  63. #define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  64. const char __fsym_##cmd##_name[] = #cmd; \
  65. __declspec(allocate("FSymTab$f")) \
  66. const struct finsh_syscall __fsym_##cmd = \
  67. { \
  68. __fsym_##cmd##_name, \
  69. (syscall_func)&name \
  70. };
  71. #pragma comment(linker, "/merge:FSymTab=mytext")
  72. #elif defined(__TI_COMPILER_VERSION__)
  73. #define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  74. __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
  75. const char __fsym_##cmd##_name[] = #cmd; \
  76. const struct finsh_syscall __fsym_##cmd = \
  77. { \
  78. __fsym_##cmd##_name, \
  79. (syscall_func)&name \
  80. };
  81. #else
  82. #define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  83. const char __fsym_##cmd##_name[] = #cmd; \
  84. rt_used const struct finsh_syscall __fsym_##cmd rt_section("FSymTab")= \
  85. { \
  86. __fsym_##cmd##_name, \
  87. (syscall_func)&name \
  88. };
  89. #endif
  90. #endif /* end of FINSH_USING_DESCRIPTION */
  91. #endif /* end of FINSH_USING_SYMTAB */
  92. /**
  93. * @ingroup finsh
  94. *
  95. * This macro exports a system function to finsh shell.
  96. *
  97. * @param name the name of function.
  98. * @param desc the description of function, which will show in help.
  99. */
  100. #define FINSH_FUNCTION_EXPORT(name, desc)
  101. /**
  102. * @ingroup finsh
  103. *
  104. * This macro exports a system function with an alias name to finsh shell.
  105. *
  106. * @param name the name of function.
  107. * @param alias the alias name of function.
  108. * @param desc the description of function, which will show in help.
  109. */
  110. #define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
  111. /**
  112. * @ingroup msh
  113. *
  114. * This macro exports a command to module shell.
  115. *
  116. * @param command is the name of the command.
  117. * @param desc is the description of the command, which will show in help list.
  118. */
  119. #define MSH_CMD_EXPORT(command, desc) \
  120. MSH_FUNCTION_EXPORT_CMD(command, command, desc)
  121. /**
  122. * @ingroup msh
  123. *
  124. * This macro exports a command with alias to module shell.
  125. *
  126. * @param command is the name of the command.
  127. * @param alias is the alias of the command.
  128. * @param desc is the description of the command, which will show in help list.
  129. */
  130. #define MSH_CMD_EXPORT_ALIAS(command, alias, desc) \
  131. MSH_FUNCTION_EXPORT_CMD(command, alias, desc)
  132. /* system call table */
  133. struct finsh_syscall
  134. {
  135. const char *name; /* the name of system call */
  136. #if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB)
  137. const char *desc; /* description of system call */
  138. #endif
  139. syscall_func func; /* the function address of system call */
  140. };
  141. /* system call item */
  142. struct finsh_syscall_item
  143. {
  144. struct finsh_syscall_item *next; /* next item */
  145. struct finsh_syscall syscall; /* syscall */
  146. };
  147. extern struct finsh_syscall_item *global_syscall_list;
  148. extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end;
  149. #if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
  150. struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call);
  151. #define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index)
  152. #else
  153. #define FINSH_NEXT_SYSCALL(index) index++
  154. #endif
  155. /* find out system call, which should be implemented in user program */
  156. struct finsh_syscall *finsh_syscall_lookup(const char *name);
  157. #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
  158. void finsh_set_device(const char *device_name);
  159. #endif
  160. #endif