I try write simple kernel module (v3.6) in nasm, but insmod say me:
$ sudo insmod ./hello.ko
insmod: ERROR: could not insert module ./hello.ko: Invalid module f
k you have to use gcc to compile it k and link it with the kernel directory...
change the Makefile to:
obj-m += memory_asm.o
memory_asm-objs := module.o main.o
$(KBUILD_EXTMOD)/main.o: $(src)/main.asm
nasm -f elf64 -o $@ $^ && echo "" > $(src)/.main.o.cmd
What I did was write a small C wrapper using the standard module macros and link it with the main module code that's written in asm. Use the normal kernel build system to build it.
module.c:
#include <linux/module.h>
MODULE_AUTHOR("A. U. Thor");
MODULE_DESCRIPTION("Description");
MODULE_LICENSE("GPL");
extern int asm_init(void);
int main_init(void)
{
return asm_init();
}
module_init(main_init);
main.asm:
[bits 64]
global asm_init
asm_init:
xor rax, rax
ret
Makefile:
obj-m += test.o
test-objs := module.o main.o
$(KBUILD_EXTMOD)/main.o: main.asm
nasm -f elf64 -o $@ $^
obj-m += memory_asm.o
memory_asm-objs := module.o main.o
$(KBUILD_EXTMOD)/main.o: $(src)/main.asm
nasm -f elf64 -o $@ $^ && echo "" > $(src)/.main.o.cmd
Build using command: make -C <path_to_kernel_src> M=$PWD