RT-Thead SHELL 命令段定义实现方法

本文介绍了一种用于嵌入式系统的FinSH shell中系统调用表的实现方式。通过宏定义和特定的段属性,实现了系统调用名称、描述及函数地址的绑定,并通过初始化函数完成了系统调用表的构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;   
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值