2010-03-22 07:49:57 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2010-03-22 07:49:57 +08:00
|
|
|
*
|
2018-10-14 19:28:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2010-03-22 07:49:57 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2010-03-22 Bernard first version
|
|
|
|
*/
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifndef __FINSH_H__
|
|
|
|
#define __FINSH_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma section("FSymTab$f",read)
|
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
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
|
2021-08-23 18:37:58 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
2021-08-23 17:30:05 +08:00
|
|
|
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__)
|
2021-08-23 18:37:58 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
2021-08-23 17:30:05 +08:00
|
|
|
__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 \
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#else
|
2021-08-23 18:37:58 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
2021-08-23 17:30:05 +08:00
|
|
|
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 \
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifdef _MSC_VER
|
2021-08-23 18:37:58 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
2021-08-23 17:30:05 +08:00
|
|
|
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__)
|
2021-08-23 18:37:58 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
2021-08-23 17:30:05 +08:00
|
|
|
__TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
|
|
|
|
const char __fsym_##cmd##_name[] = #cmd; \
|
|
|
|
const struct finsh_syscall __fsym_##cmd = \
|
|
|
|
{ \
|
|
|
|
__fsym_##cmd##_name, \
|
|
|
|
(syscall_func)&name \
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#else
|
2021-08-23 18:37:58 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
|
2021-08-23 17:30:05 +08:00
|
|
|
const char __fsym_##cmd##_name[] = #cmd; \
|
|
|
|
RT_USED const struct finsh_syscall __fsym_##cmd RT_SECTION("FSymTab")= \
|
|
|
|
{ \
|
|
|
|
__fsym_##cmd##_name, \
|
|
|
|
(syscall_func)&name \
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#endif
|
|
|
|
#endif /* end of FINSH_USING_DESCRIPTION */
|
|
|
|
#endif /* end of FINSH_USING_SYMTAB */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2021-08-23 18:37:58 +08:00
|
|
|
#define FINSH_FUNCTION_EXPORT(name, desc)
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2021-08-23 18:37:58 +08:00
|
|
|
#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/**
|
2021-08-23 17:30:05 +08:00
|
|
|
* @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.
|
2010-11-29 08:04:55 +08:00
|
|
|
*/
|
2021-08-23 17:30:05 +08:00
|
|
|
#define MSH_CMD_EXPORT(command, desc) \
|
2021-08-23 18:37:58 +08:00
|
|
|
MSH_FUNCTION_EXPORT_CMD(command, command, desc)
|
2021-08-23 17:30:05 +08:00
|
|
|
#define MSH_CMD_EXPORT_ALIAS(command, alias, desc) \
|
2021-08-23 18:37:58 +08:00
|
|
|
MSH_FUNCTION_EXPORT_CMD(command, alias, desc)
|
2021-08-23 17:30:05 +08:00
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* system call item */
|
|
|
|
struct finsh_syscall_item
|
|
|
|
{
|
2021-08-23 17:30:05 +08:00
|
|
|
struct finsh_syscall_item *next; /* next item */
|
2018-03-01 21:01:20 +08:00
|
|
|
struct finsh_syscall syscall; /* syscall */
|
2009-07-03 06:48:23 +08:00
|
|
|
};
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
extern struct finsh_syscall_item *global_syscall_list;
|
|
|
|
extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end;
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2013-01-22 12:44:47 +08:00
|
|
|
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
|
2021-08-23 17:30:05 +08:00
|
|
|
struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call);
|
|
|
|
#define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index)
|
2012-12-29 16:11:38 +08:00
|
|
|
#else
|
2021-08-23 17:30:05 +08:00
|
|
|
#define FINSH_NEXT_SYSCALL(index) index++
|
2012-12-29 16:11:38 +08:00
|
|
|
#endif
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
/* find out system call, which should be implemented in user program */
|
|
|
|
struct finsh_syscall *finsh_syscall_lookup(const char *name);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2009-09-28 07:58:05 +08:00
|
|
|
#ifdef RT_USING_DEVICE
|
2021-08-23 17:30:05 +08:00
|
|
|
void finsh_set_device(const char *device_name);
|
2009-09-28 07:58:05 +08:00
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#endif
|