aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2023-04-25 16:39:54 +0400
committerJoursoir <chat@joursoir.net>2023-04-25 16:39:54 +0400
commit21cbc15a690e7c82d778de3eff973084f4198b4e (patch)
tree4317d7ea1432e89a820e1218861e415e560ec907
downloadcpui-drv-21cbc15a690e7c82d778de3eff973084f4198b4e.tar.gz
cpui-drv-21cbc15a690e7c82d778de3eff973084f4198b4e.tar.bz2
cpui-drv-21cbc15a690e7c82d778de3eff973084f4198b4e.zip
initial commit
-rw-r--r--Makefile9
-rw-r--r--README.md3
-rw-r--r--cpui-drv.c36
3 files changed, 48 insertions, 0 deletions
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 <linux/module.h>
+
+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