I wan't to write a kernel module which uses quite a lot of inline assembly. Since I am used to Intel Syntax I would like to avoid AT&T Syntax completely. One way of doing this is shown in the following minimal example:
samplemodule.c
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
unsigned long foo(void) {
unsigned long ret = 0;
asm (
".intel_syntax noprefix\n"
"mov rbx, 1337\n"
"mov %0, rbx\n"
".att_syntax noprefix\n"
:"=r"(ret)
:
:"rbx"
);
return ret;
}
static int init_routine(void) {
printk(KERN_INFO "Sample Module init\n");
printk(KERN_INFO "Test: %lu\n", foo());
return 0;
}
static void exit_routine(void) {
printk(KERN_INFO "Sample Module exit\n");
}
module_init(init_routine);
module_exit(exit_routine);
Makefile
obj-m += samplemodule.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
So, whenever I want to inline assembly I have two write .intel_syntax noprefix\n...\n.att_syntax noprefix\n
. Are there other ways of accomplishing this? When compiling with gcc I used to simply pass the -masm=intel
argument to gcc which allowed me to freely use Intel Syntax. Is something similar possible in this case?