如何与文件.s GAS Assembly一起编译内核模块

时间:2019-08-06 12:41:52

标签: c makefile kernel-module gas

我想将文件.s GAS Assembly与我的内核模块(LKM)一起编译。我的内核Linux版本是5.1.20-200.fc29.x86_64。这是我的汇编文件asm.s:

 .globl  maxofthree

        .text
maxofthree:
        mov     %rdi, %rax              # result (rax) initially holds x
        cmp     %rsi, %rax              # is x less than y?
        cmovl   %rsi, %rax              # if so, set result to y
        cmp     %rdx, %rax              # is max(x,y) less than z?
        cmovl   %rdx, %rax              # if so, set result to z
        ret                             # the max will be in eax


And this is my driver.c:

#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/module.h>

int64_t maxofthree(int64_t, int64_t, int64_t);


static int __init hello_world_init(void)
{
    printk(KERN_INFO "Welcome \n");
        printk(KERN_INFO "This is the Simple Module\n");
        printk(KERN_INFO "Kernel Module Inserted Successfully...\n");
        printk("%lld\n", maxofthree(10, 20,30));
    return 0;
}

void __exit hello_world_exit(void)
{
    printk(KERN_INFO "Kernel Module Removed Successfully...\n");

}

module_init(hello_world_init);
module_exit(hello_world_exit);

EXPORT_SYMBOL_GPL(maxofthree);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Max");
MODULE_DESCRIPTION("Simple driver");
MODULE_VERSION("2:1.0");

在我写的Makefile中:

obj-m += driver.o
driver-objs += fileasm.o

KDIR = /lib/modules/$(shell uname -r)/build

all:
        make -C $(KDIR)  M=$(shell pwd) modules
clean:
        make -C $(KDIR)  M=$(shell pwd) clean

当我尝试编译时,出现以下警告消息:

WARNING: modpost: missing MODULE_LICENSE()

然后如果我尝试执行insmod driver.ko,则会收到:

module verification failed: signature and/or required key missing - tainting kernel

我该怎么办?

0 个答案:

没有答案