summaryrefslogtreecommitdiff
path: root/hello
diff options
context:
space:
mode:
Diffstat (limited to 'hello')
-rw-r--r--hello/Makefile12
-rw-r--r--hello/hello-1.c13
-rw-r--r--hello/hello-2.c21
-rw-r--r--hello/hello-3.c50
-rw-r--r--hello/hello-4.c28
-rw-r--r--hello/start.c15
-rw-r--r--hello/stop.c14
7 files changed, 153 insertions, 0 deletions
diff --git a/hello/Makefile b/hello/Makefile
new file mode 100644
index 0000000..d63aa3d
--- /dev/null
+++ b/hello/Makefile
@@ -0,0 +1,12 @@
+obj-m += hello-1.o
+obj-m += hello-2.o
+obj-m += hello-3.o
+obj-m += hello-4.o
+obj-m += startstop.o
+startstop-objs := start.o stop.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
diff --git a/hello/hello-1.c b/hello/hello-1.c
new file mode 100644
index 0000000..aa434a9
--- /dev/null
+++ b/hello/hello-1.c
@@ -0,0 +1,13 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+
+int init_module(void)
+{
+ printk(KERN_INFO "Hola, mundo! 1\n");
+ return 0;
+}
+
+void cleanup_module(void)
+{
+ printk(KERN_INFO "Adiós, mundo! 1\n");
+}
diff --git a/hello/hello-2.c b/hello/hello-2.c
new file mode 100644
index 0000000..5819e38
--- /dev/null
+++ b/hello/hello-2.c
@@ -0,0 +1,21 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+static int __init hello_2_init(void)
+{
+ printk(KERN_INFO "Hola, mundo! 2\n");
+ return 0;
+}
+
+static void __exit hello_2_exit(void)
+{
+ printk(KERN_INFO "Adiós, mundo! 2\n");
+}
+
+module_init(hello_2_init);
+module_exit(hello_2_exit);
+
+MODULE_AUTHOR("Guillermo Ramos");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Módulo tonto");
diff --git a/hello/hello-3.c b/hello/hello-3.c
new file mode 100644
index 0000000..a82e4a4
--- /dev/null
+++ b/hello/hello-3.c
@@ -0,0 +1,50 @@
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/stat.h>
+
+static short int myshort = 1;
+static int myint = 420;
+static long int mylong = 9999;
+static char* mystring = "blah";
+static int myintArray[2] = {-1, -1};
+static int arr_argc = 0;
+
+module_param(myshort, short, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+MODULE_PARM_DESC(myshort, "A short integer");
+module_param(myint, int, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
+MODULE_PARM_DESC(myint, "An integer");
+module_param(mylong, long, S_IRUSR);
+MODULE_PARM_DESC(mylong, "A long integer");
+module_param(mystring, charp, 0000);
+MODULE_PARM_DESC(mystring, "A character string");
+
+module_param_array(myintArray, int, &arr_argc, 0000);
+MODULE_PARM_DESC(myintArray, "An array of integers");
+
+static int __init hello_3_init(void)
+{
+ int i;
+ printk(KERN_INFO "Hola, mundo! 3\n============\n");
+ printk(KERN_INFO "myshort is a short integer: %hd\n", myshort);
+ printk(KERN_INFO "myint is an integer: %d\n", myint);
+ printk(KERN_INFO "mylong is a long integer: %ld\n", mylong);
+ printk(KERN_INFO "mystring is a string: %s\n", mystring);
+ for (i = 0; i < sizeof(myintArray)/sizeof(int); i++)
+ printk(KERN_INFO "myintArray[%d] = %d\n", i, myintArray[i]);
+ printk(KERN_INFO "got %d arguments for myintArray\n", arr_argc);
+ return 0;
+}
+
+static void __exit hello_3_exit(void)
+{
+ printk(KERN_INFO "Adiós, mundo! 3\n============\n");
+}
+
+module_init(hello_3_init);
+module_exit(hello_3_exit);
+
+MODULE_AUTHOR("Guillermo Ramos");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Módulo tonto");
diff --git a/hello/hello-4.c b/hello/hello-4.c
new file mode 100644
index 0000000..32e2cb6
--- /dev/null
+++ b/hello/hello-4.c
@@ -0,0 +1,28 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+static int __init hello_4_init(void)
+{
+ printk(KERN_DEBUG "DEBUG: Hola, mundo! 4\n");
+ printk(KERN_INFO "INFO: Hola, mundo! 4\n");
+ printk(KERN_NOTICE "NOTICE: Hola, mundo! 4\n");
+ printk(KERN_WARNING "WARNING: Hola, mundo! 4\n");
+ printk(KERN_CRIT "CRIT: Hola, mundo! 4\n");
+ printk(KERN_ALERT "ALERT: Hola, mundo! 4\n");
+ printk(KERN_EMERG "EMERG: Hola, mundo! 4\n");
+
+ return 0;
+}
+
+static void __exit hello_4_exit(void)
+{
+ printk(KERN_INFO "Adiós, mundo! 2\n");
+}
+
+module_init(hello_4_init);
+module_exit(hello_4_exit);
+
+MODULE_AUTHOR("Guillermo Ramos");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Módulo tonto");
diff --git a/hello/start.c b/hello/start.c
new file mode 100644
index 0000000..224aeed
--- /dev/null
+++ b/hello/start.c
@@ -0,0 +1,15 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+static int __init hello_2_init(void)
+{
+ printk(KERN_INFO "Hola, mundo! 2\n");
+ return 0;
+}
+
+module_init(hello_2_init);
+
+MODULE_AUTHOR("Guillermo Ramos");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Módulo tonto");
diff --git a/hello/stop.c b/hello/stop.c
new file mode 100644
index 0000000..46ba9a4
--- /dev/null
+++ b/hello/stop.c
@@ -0,0 +1,14 @@
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+static void __exit hello_2_exit(void)
+{
+ printk(KERN_INFO "Adiós, mundo! 2\n");
+}
+
+module_exit(hello_2_exit);
+
+MODULE_AUTHOR("Guillermo Ramos");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Módulo tonto");