mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
kernel modules: hack up quick floating point example
This commit is contained in:
@@ -13,6 +13,11 @@ ccflags-y := \
|
||||
-Wno-declaration-after-statement \
|
||||
$(CCFLAGS)
|
||||
|
||||
ifeq ($(ARCH),x86)
|
||||
# https://github.com/cirosantilli/linux-kernel-module-cheat#floating-point-in-kernel-modules
|
||||
CFLAGS_REMOVE_float.o += -mno-sse -mno-sse2
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
|
||||
all:
|
||||
|
||||
31
kernel_modules/float.c
Normal file
31
kernel_modules/float.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#floating-point-in-kernel-modules */
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <asm/fpu/api.h> /* kernel_fpu_begin, kernel_fpu_end */
|
||||
|
||||
/* float params are not supported, so we just go with int. */
|
||||
static int myfloat = 1;
|
||||
static int enable_fpu = 1;
|
||||
module_param(myfloat, int, S_IRUSR | S_IWUSR);
|
||||
module_param(enable_fpu, int, S_IRUSR | S_IWUSR);
|
||||
|
||||
static int myinit(void)
|
||||
{
|
||||
if (enable_fpu) {
|
||||
kernel_fpu_begin();
|
||||
}
|
||||
if ((float)myfloat + 1.5f == 2.5f) {
|
||||
pr_info("magic value\n");
|
||||
}
|
||||
if (enable_fpu) {
|
||||
kernel_fpu_end();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void myexit(void) {}
|
||||
|
||||
module_init(myinit)
|
||||
module_exit(myexit)
|
||||
MODULE_LICENSE("GPL");
|
||||
Reference in New Issue
Block a user