From 21cbc15a690e7c82d778de3eff973084f4198b4e Mon Sep 17 00:00:00 2001 From: Joursoir Date: Tue, 25 Apr 2023 16:39:54 +0400 Subject: initial commit --- Makefile | 9 +++++++++ README.md | 3 +++ cpui-drv.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 cpui-drv.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..006a8f4 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +BASE_NAME = cpui-drv +PATH_TO_KERNEL_SRC := /lib/modules/$(shell uname -r)/build +obj-m += $(BASE_NAME).o + +all: + $(MAKE) -C $(PATH_TO_KERNEL_SRC) M=$(PWD) modules + +clean: + $(MAKE) -C $(PATH_TO_KERNEL_SRC) M=$(PWD) clean diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f1088e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# CPU Internals Driver (cpui-drv) + +A driver that allows users to interact with various internal components of the CPU. Implemented and tested with Linux kernel v6.2 diff --git a/cpui-drv.c b/cpui-drv.c new file mode 100644 index 0000000..bcb6dba --- /dev/null +++ b/cpui-drv.c @@ -0,0 +1,36 @@ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include + +static int __init cpui_init(void) +{ + char id_str[13]; + uint32_t eax = 0, ebx, ecx, edx; + + if (!have_cpuid_p()) { + pr_err("CPUID instruction is NOT supported. Aborting.\n"); + return 1; + } + + cpuid(0, &eax, &ebx, &ecx, &edx); + pr_info("CPUID instruction is supported.\n"); + pr_info("Maximum Input Value for Basic CPUID Information = %d\n", eax); + memcpy(&(id_str[0]), &ebx, 4); + memcpy(&(id_str[4]), &edx, 4); + memcpy(&(id_str[8]), &ecx, 4); + id_str[12] = '\0'; + pr_info("Identity string = %s\n", id_str); + return 0; +} + +static void __exit cpui_exit(void) +{ + pr_info("Exit complete\n"); +} + +module_init(cpui_init); +module_exit(cpui_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Joursoir"); +MODULE_DESCRIPTION("A driver that allows users to interact with various internal components of the CPU"); \ No newline at end of file -- cgit v1.2.3-18-g5258