typedef long (*syscall_func)();
#include <stdarg.h>
//段定义
#define SECTION(x) __attribute__((section(x)))
/* system call table */
struct finsh_syscall
{
const char* name; /* the name of system call */
const char* desc; /* description of system call */
syscall_func func; /* the function address of system call */
};
#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \
const char __fsym_##cmd##_name[] SECTION(".rodata.name") = #cmd; \
const char __fsym_##cmd##_desc[] SECTION(".rodata.name") = #desc; \
const struct finsh_syscall __fsym_##cmd SECTION("FSymTab")= \
{ \
__fsym_##cmd##_name, \
__fsym_##cmd##_desc, \
(syscall_func)&name \
};
#define FINSH_FUNCTION_EXPORT(name, desc) \
FINSH_FUNCTION_EXPORT_CMD(name, name, desc)
static void enc28j60(void)
{
}
FINSH_FUNCTION_EXPORT(enc28j60, dump enc28j60 registers);
extern const int FSymTab$$Base;
extern const int FSymTab$$Limit;
struct finsh_syscall *_syscall_table_begin = NULL;
struct finsh_syscall *_syscall_table_end = NULL;
void finsh_system_function_init(const void *begin, const void *end)
{
_syscall_table_begin = (struct finsh_syscall *) begin;
_syscall_table_end = (struct finsh_syscall *) end;
__fsym_enc28j60.func();
}
const struct finsh_syscall *P;
int finsh_system_init(void)
{
finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
P = &__fsym_enc28j60;
}
RT-Thead SHELL 命令段定义实现方法
最新推荐文章于 2025-04-09 11:35:00 发布
本文介绍了一种用于嵌入式系统的FinSH shell中系统调用表的实现方式。通过宏定义和特定的段属性,实现了系统调用名称、描述及函数地址的绑定,并通过初始化函数完成了系统调用表的构建。
5055

被折叠的 条评论
为什么被折叠?



