The code of the module:
Code:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int disableCache_init(void)
{
        printk(KERN_ALERT "Disabling L1 and L2 caches.\n");
        __asm__(".intel_syntax noprefix\n\t"
                "mov    eax,cr0\n\t"
                "or     eax,(1 << 30)\n\t"
                "mov    cr0,eax\n\t"
                "wbinvd\n\t"
                ".att_syntax noprefix\n\t"
        : : : "eax" );
        return 0;
}
static void disableCache_exit(void)
{
        printk(KERN_ALERT "Enabling L1 and L2 caches.\n");
        __asm__(".intel_syntax noprefix\n\t"
                "mov    eax,cr0\n\t"
                "and     eax,~(1 << 30)\n\t"
                "mov    cr0,eax\n\t"
                "wbinvd\n\t"
                ".att_syntax noprefix\n\t"
        : : : "eax" );
}
module_init(disableCache_init);
module_exit(disableCache_exit);
And the Makefile:
Code:
EXTRA_CFLAGS = -m32
obj-m += disableCache.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
insmod command:
Code:
sudo insmod ./disableCache.ko


如果是64位系统,则make file中 -m32 改为-m64同时code 中所有的eax改为rax.

Logo

更多推荐