[国嵌攻略][109][Linux系统调用]

系统调用

函数实现体在内核空间,提供给应用程序来使用,就是一个系统调用。

 

工作流程

1.通过软中断(swi)从用户空间切换到内核空间。entry-common.S中的ENTRY(vector_swi)是用来处理软中断的。系统调用通常从r7寄存器中取出系统调用编号。

2.通过系统调用编号从系统调用表中找出调用的系统调用函数。也是是calls.S文件中找出系统调用编号对应的函数。

 

实现系统调用

1.打开.../kernel/printk.c,添加系统调用函数

void sys_iprint(){

    printk(“This is a new system call!\n”);

}

2.打开.../arch/arm/kernel/calls.S,添加系统调用入口

CALL(sys_iprint)

3.打开.../arch/arm/include/asm/unistd.h,条件系统调用编号

#define __NR_iprint   (__NR_SYSCALL_BASE+365)

 

4.重新编译内核

make clean

make uImage ARCH=arm CROSS_COMPILE=arm-liunx-

 

5.编写应用程序

//系统调用接口
void ipirnt(){
    __asm__(
        "ldr r7, =365\n"
        "swi\n"
        :
        :
        :"memory"
    );
}

int main(int argc, char **argv){
    ipirnt();
    
    return 0;
}

 

6.编译应用程序

arc-linux-gcc –static syscall.c –o syscall

posted @ 2016-03-06 15:04  盛夏夜  阅读(279)  评论(0编辑  收藏  举报