龙芯内核添加系统调用介绍

添加主要有两个模块  1:交叉工具链的修改  2:内核代码的修改


 1:交叉工具链的修改

添加交叉工具链 新系统调用的 定义; 龙芯官网下载交叉工具链。 不妨按照以下思路来实现 添加过程,


在交叉工具链代码中全局查找 __NR_open , 以此为模版,在系统调用表的最后面添加上自己的定义。


交叉工具链:gcc-4.4-gnu


实现如下;  

1:在目录 sysroot/usr/include/asm/unistd.h   最后面添加自己的定义 :     #define __NR_wuheshi    (__NR_Linux + 360)      //需要跟在内核中定义一样、

2:在 目录  sysroot/usr/include/bit/syscall.h  最后添加定义                           #define   SYS_wuheshi     __NR_wuheshi

3: 在目录   sysroot/usr/include/asm-generic/unistd.h 最后添加

#define  __NR_wuheshi 285

      SYSCALL(__NR_wuheshi , sys_wuheshi)

4: 在sysroot/usr/include/bits/sched.h  这个路径可选则,只要能找到即可 添加: extern void sys_wuheshi(void);

以上定义必须和内核中的定义。


内核4.4.2

1:在内核系统调用表 syscall table中添加自己的 定义 

在arch/mips/kernel/scall64-o32.S 最后添加   PTR sys_wuheshi

2:添加函数声明

在include/linux/syscalls.h  添加 asmlinkage void sys_wuheshi(void);

3:添加函数实现

这个位置根据自己的功能选择, 我添加的是在 arch/mips/kernel/syscall.c  中添加

asmlinkage viod sys_wuheshi(void)

{

    printk("sys wuheshi here\n");

}

4: 添加系统调用 定义

在目录 arch/mips/include/uapi/asm/unistd.h  中添加    #define __NR_wuheshi    (__NR_Linux + 360)   

在 include/uapi/asm-generic/unistd.h 添加

#define __NR_wuheshi 285

__SYSCALL(__NR_wuheshi, sys_wuheshi)    


到此为止 添加工作结束,后面为测试阶段。

重新编译内核,最好用修改后的 交叉工具链。


写个test函数如下

       #define _GNU_SOURCE
       #include <unistd.h>
       #include <sys/syscall.h>
       #include <sys/types.h>


       int
       main(int argc, char *argv[])
       {
           tid = syscall(SYS_wuheshi);
       }


交叉编译一下 测试函数,在编译后的内核环境下执行, ok。

syscall 介绍

       int syscall(int number, ...);

DESCRIPTION
       syscall()  performs  the  system  call  whose  assembly  language  interface  has  the  specified  number  with  the specified arguments.  Symbolic constants for system calls can be found in the header file
       <sys/syscall.h>.



asmlinkage是个宏,使用它是为了保持传递参数在stack中。因为从汇编语言到C语言代码参数的传递是通过stack的,它也可能从stack中得到一些不需要的参数。Asmlinkage将要解析那些参数。


















  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值