finsh_api.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * File : finsh_api.h
  3. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Change Logs:
  20. * Date Author Notes
  21. * 2010-03-22 Bernard first version
  22. */
  23. #ifndef FINSH_API_H__
  24. #define FINSH_API_H__
  25. #if defined(_MSC_VER)
  26. #pragma section("FSymTab$f",read)
  27. #pragma section("VSymTab",read)
  28. #endif
  29. typedef long (*syscall_func)(void);
  30. /* system call table */
  31. struct finsh_syscall
  32. {
  33. const char* name; /* the name of system call */
  34. #if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB)
  35. const char* desc; /* description of system call */
  36. #endif
  37. syscall_func func; /* the function address of system call */
  38. };
  39. extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end;
  40. /* find out system call, which should be implemented in user program */
  41. struct finsh_syscall* finsh_syscall_lookup(const char* name);
  42. #ifdef FINSH_USING_SYMTAB
  43. #ifdef __TI_COMPILER_VERSION__
  44. #define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab"))
  45. #define __TI_FINSH_EXPORT_VAR(v) PRAGMA(DATA_SECTION(v,"VSymTab"))
  46. #endif
  47. #ifdef FINSH_USING_DESCRIPTION
  48. #ifdef _MSC_VER
  49. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  50. const char __fsym_##cmd##_name[] = #cmd; \
  51. const char __fsym_##cmd##_desc[] = #desc; \
  52. __declspec(allocate("FSymTab$f")) \
  53. const struct finsh_syscall __fsym_##cmd = \
  54. { \
  55. __fsym_##cmd##_name, \
  56. __fsym_##cmd##_desc, \
  57. (syscall_func)&name \
  58. };
  59. #pragma comment(linker, "/merge:FSymTab=mytext")
  60. #define FINSH_VAR_EXPORT(name, type, desc) \
  61. const char __vsym_##name##_name[] = #name; \
  62. const char __vsym_##name##_desc[] = #desc; \
  63. __declspec(allocate("VSymTab")) \
  64. const struct finsh_sysvar __vsym_##name = \
  65. { \
  66. __vsym_##name##_name, \
  67. __vsym_##name##_desc, \
  68. type, \
  69. (void*)&name \
  70. };
  71. #elif defined(__TI_COMPILER_VERSION__)
  72. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  73. __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
  74. const char __fsym_##cmd##_name[] = #cmd; \
  75. const char __fsym_##cmd##_desc[] = #desc; \
  76. const struct finsh_syscall __fsym_##cmd = \
  77. { \
  78. __fsym_##cmd##_name, \
  79. __fsym_##cmd##_desc, \
  80. (syscall_func)&name \
  81. };
  82. #define FINSH_VAR_EXPORT(name, type, desc) \
  83. __TI_FINSH_EXPORT_VAR(__vsym_##name); \
  84. const char __vsym_##name##_name[] = #name; \
  85. const char __vsym_##name##_desc[] = #desc; \
  86. const struct finsh_sysvar __vsym_##name = \
  87. { \
  88. __vsym_##name##_name, \
  89. __vsym_##name##_desc, \
  90. type, \
  91. (void*)&name \
  92. };
  93. #else
  94. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  95. const char __fsym_##cmd##_name[] SECTION(".rodata.name") = #cmd; \
  96. const char __fsym_##cmd##_desc[] SECTION(".rodata.name") = #desc; \
  97. const struct finsh_syscall __fsym_##cmd SECTION("FSymTab")= \
  98. { \
  99. __fsym_##cmd##_name, \
  100. __fsym_##cmd##_desc, \
  101. (syscall_func)&name \
  102. };
  103. #define FINSH_VAR_EXPORT(name, type, desc) \
  104. const char __vsym_##name##_name[] SECTION(".rodata.name") = #name; \
  105. const char __vsym_##name##_desc[] SECTION(".rodata.name") = #desc; \
  106. const struct finsh_sysvar __vsym_##name SECTION("VSymTab")= \
  107. { \
  108. __vsym_##name##_name, \
  109. __vsym_##name##_desc, \
  110. type, \
  111. (void*)&name \
  112. };
  113. #endif
  114. #else
  115. #ifdef _MSC_VER
  116. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  117. const char __fsym_##cmd##_name[] = #cmd; \
  118. __declspec(allocate("FSymTab$f")) \
  119. const struct finsh_syscall __fsym_##cmd = \
  120. { \
  121. __fsym_##cmd##_name, \
  122. (syscall_func)&name \
  123. };
  124. #pragma comment(linker, "/merge:FSymTab=mytext")
  125. #define FINSH_VAR_EXPORT(name, type, desc) \
  126. const char __vsym_##name##_name[] = #name; \
  127. __declspec(allocate("VSymTab")) const struct finsh_sysvar __vsym_##name = \
  128. { \
  129. __vsym_##name##_name, \
  130. type, \
  131. (void*)&name \
  132. };
  133. #elif defined(__TI_COMPILER_VERSION__)
  134. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  135. __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
  136. const char __fsym_##cmd##_name[] = #cmd; \
  137. const struct finsh_syscall __fsym_##cmd = \
  138. { \
  139. __fsym_##cmd##_name, \
  140. (syscall_func)&name \
  141. };
  142. #define FINSH_VAR_EXPORT(name, type, desc) \
  143. __TI_FINSH_EXPORT_VAR(__vsym_##name); \
  144. const char __vsym_##name##_name[] = #name; \
  145. const struct finsh_sysvar __vsym_##name = \
  146. { \
  147. __vsym_##name##_name, \
  148. type, \
  149. (void*)&name \
  150. };
  151. #else
  152. #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
  153. const char __fsym_##cmd##_name[] = #cmd; \
  154. const struct finsh_syscall __fsym_##cmd SECTION("FSymTab")= \
  155. { \
  156. __fsym_##cmd##_name, \
  157. (syscall_func)&name \
  158. };
  159. #define FINSH_VAR_EXPORT(name, type, desc) \
  160. const char __vsym_##name##_name[] = #name; \
  161. const struct finsh_sysvar __vsym_##name SECTION("VSymTab")= \
  162. { \
  163. __vsym_##name##_name, \
  164. type, \
  165. (void*)&name \
  166. };
  167. #endif
  168. #endif /* end of FINSH_USING_DESCRIPTION */
  169. #endif /* end of FINSH_USING_SYMTAB */
  170. /**
  171. * @ingroup finsh
  172. *
  173. * This macro exports a system function to finsh shell.
  174. *
  175. * @param name the name of function.
  176. * @param desc the description of function, which will show in help.
  177. */
  178. #define FINSH_FUNCTION_EXPORT(name, desc) \
  179. FINSH_FUNCTION_EXPORT_CMD(name, name, desc)
  180. /**
  181. * @ingroup finsh
  182. *
  183. * This macro exports a system function with an alias name to finsh shell.
  184. *
  185. * @param name the name of function.
  186. * @param alias the alias name of function.
  187. * @param desc the description of function, which will show in help.
  188. */
  189. #define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc) \
  190. FINSH_FUNCTION_EXPORT_CMD(name, alias, desc)
  191. /**
  192. * @ingroup finsh
  193. *
  194. * This macro exports a command to module shell.
  195. *
  196. * @param command the name of command.
  197. * @param desc the description of command, which will show in help.
  198. */
  199. #ifdef FINSH_USING_MSH
  200. #define MSH_CMD_EXPORT(command, desc) \
  201. FINSH_FUNCTION_EXPORT_CMD(command, __cmd_##command, desc)
  202. #define MSH_CMD_EXPORT_ALIAS(command, alias, desc) \
  203. FINSH_FUNCTION_EXPORT_ALIAS(command, __cmd_##alias, desc)
  204. #else
  205. #define MSH_CMD_EXPORT(command, desc)
  206. #define MSH_CMD_EXPORT_ALIAS(command, alias, desc)
  207. #endif
  208. #endif