diff --git a/20210430/Makefile b/20210430/Makefile new file mode 120000 index 0000000000000000000000000000000000000000..134aa0a7e9fd70818ec2dbee3f7201a161389434 --- /dev/null +++ b/20210430/Makefile @@ -0,0 +1 @@ +Makefile-modules-2 \ No newline at end of file diff --git a/20210430/Makefile-1 b/20210430/Makefile-1 new file mode 100644 index 0000000000000000000000000000000000000000..6176ca2ae44724e1c600350f8a9f3cb97baa74aa --- /dev/null +++ b/20210430/Makefile-1 @@ -0,0 +1,2 @@ +hello-3: hello-3.c + gcc -Wall -O hello-3.c -o hello-3 diff --git a/20210430/Makefile-2 b/20210430/Makefile-2 new file mode 100644 index 0000000000000000000000000000000000000000..4d111b46792c7bdf29ea38bfc9e31ebb38e6484a --- /dev/null +++ b/20210430/Makefile-2 @@ -0,0 +1,5 @@ +TARGET = hello-3 +CFLAGS = -Wall -O + +$(TARGET): hello-3.c + gcc $(CFLAGS) hello-3.c -o hello-3 diff --git a/20210430/Makefile-3 b/20210430/Makefile-3 new file mode 100644 index 0000000000000000000000000000000000000000..4c57b77d9975700f8790e9b677300a02b389e2c3 --- /dev/null +++ b/20210430/Makefile-3 @@ -0,0 +1,5 @@ +TARGET = hello-3 +CFLAGS = -Wall -O + +$(TARGET): $(TARGET).c + gcc $(CFLAGS) $< -o $(TARGET) diff --git a/20210430/Makefile-modules-1 b/20210430/Makefile-modules-1 new file mode 100644 index 0000000000000000000000000000000000000000..9c79a1d26b3f4b8e6490addcc38333ee13ecef48 --- /dev/null +++ b/20210430/Makefile-modules-1 @@ -0,0 +1,10 @@ +obj-m += hellomod-1.o + +# obj-m += hellomod-2.o +# obj-m += chardev-1.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/20210430/Makefile-modules-2 b/20210430/Makefile-modules-2 new file mode 100644 index 0000000000000000000000000000000000000000..8c9b708954395ea97aa4b355d93269b083ddfeb8 --- /dev/null +++ b/20210430/Makefile-modules-2 @@ -0,0 +1,9 @@ +obj-m = hellomod-1.o +obj-m += hellomod-2.o +obj-m += chardev-1.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/20210430/chardev-1.c b/20210430/chardev-1.c new file mode 100644 index 0000000000000000000000000000000000000000..17a6651a33313322de202fbcb6bbf82333c0b766 --- /dev/null +++ b/20210430/chardev-1.c @@ -0,0 +1,166 @@ +/* + * chardev.c: Creates a read-only char device that says how many times + * you've read from the dev file + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/fs.h> +#include <asm/uaccess.h> /* for put_user */ + +/* + * Prototypes - this would normally go in a .h file + */ +int init_module(void); +void cleanup_module(void); +static int device_open(struct inode *, struct file *); +static int device_release(struct inode *, struct file *); +static ssize_t device_read(struct file *, char *, size_t, loff_t *); +static ssize_t device_write(struct file *, const char *, size_t, loff_t *); + +#define SUCCESS 0 +#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */ +#define BUF_LEN 80 /* Max length of the message from the device */ + +/* + * Global variables are declared as static, so are global within the file. + */ + +static int Major; /* Major number assigned to our device driver */ +static int Device_Open = 0; /* Is device open? + * Used to prevent multiple access to device */ +static char msg[BUF_LEN]; /* The msg the device will give when asked */ +static char *msg_Ptr; + +static struct file_operations fops = { + .read = device_read, + .write = device_write, + .open = device_open, + .release = device_release +}; + +/* + * This function is called when the module is loaded + */ +int init_module(void) +{ + Major = register_chrdev(0, DEVICE_NAME, &fops); + + if (Major < 0) { + printk(KERN_ALERT "Registering char device failed with %d\n", Major); + return Major; + } + + printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major); + printk(KERN_INFO "the driver, create a dev file with\n"); + printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major); + printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n"); + printk(KERN_INFO "the device file.\n"); + printk(KERN_INFO "Remove the device file and module when done.\n"); + + return SUCCESS; +} + +/* + * This function is called when the module is unloaded + */ +void cleanup_module(void) +{ + /* + * Unregister the device + */ + unregister_chrdev(Major, DEVICE_NAME); +} + +/* + * Methods + */ + +/* + * Called when a process tries to open the device file, like + * "cat /dev/mycharfile" + */ +static int device_open(struct inode *inode, struct file *file) +{ + static int counter = 0; + + if (Device_Open) + return -EBUSY; + + Device_Open++; + sprintf(msg, "I already told you %d times Hello world!\n", counter++); + msg_Ptr = msg; + try_module_get(THIS_MODULE); + + return SUCCESS; +} + +/* + * Called when a process closes the device file. + */ +static int device_release(struct inode *inode, struct file *file) +{ + Device_Open--; /* We're now ready for our next caller */ + + /* + * Decrement the usage count, or else once you opened the file, you'll + * never get get rid of the module. + */ + module_put(THIS_MODULE); + + return 0; +} + +/* + * Called when a process, which already opened the dev file, attempts to + * read from it. + */ +static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */ + char *buffer, /* buffer to fill with data */ + size_t length, /* length of the buffer */ + loff_t * offset) +{ + /* + * Number of bytes actually written to the buffer + */ + int bytes_read = 0; + + /* + * If we're at the end of the message, + * return 0 signifying end of file + */ + if (*msg_Ptr == 0) + return 0; + + /* + * Actually put the data into the buffer + */ + while (length && *msg_Ptr) { + + /* + * The buffer is in the user data segment, not the kernel + * segment so "*" assignment won't work. We have to use + * put_user which copies data from the kernel data segment to + * the user data segment. + */ + put_user(*(msg_Ptr++), buffer++); + + length--; + bytes_read++; + } + + /* + * Most read functions return the number of bytes put into the buffer + */ + return bytes_read; +} + +/* + * Called when a process writes to dev file: echo "hi" > /dev/hello + */ +static ssize_t +device_write(struct file *filp, const char *buff, size_t len, loff_t * off) +{ + printk(KERN_ALERT "Sorry, this operation isn't supported.\n"); + return -EINVAL; +} diff --git a/20210430/chardev-2.c b/20210430/chardev-2.c new file mode 100644 index 0000000000000000000000000000000000000000..54b8e3f30a580c7896ea18a0e4358059a6c03a48 --- /dev/null +++ b/20210430/chardev-2.c @@ -0,0 +1,183 @@ +/* + * chardev.c: Creates a read-only char device that says how many times + * you've read from the dev file + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <asm/uaccess.h> /* for put_user */ + +/* + * Prototypes - this would normally go in a .h file + */ +int init_module(void); +void cleanup_module(void); +static int device_open(struct inode *, struct file *); +static int device_release(struct inode *, struct file *); +static ssize_t device_read(struct file *, char *, size_t, loff_t *); +static ssize_t device_write(struct file *, const char *, size_t, loff_t *); + +struct class *dev_Class; +struct device *chr_dev; + +#define SUCCESS 0 +#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */ +#define BUF_LEN 80 /* Max length of the message from the device */ + +/* + * Global variables are declared as static, so are global within the file. + */ + +static int Major; /* Major number assigned to our device driver */ +static int Device_Open = 0; /* Is device open? + * Used to prevent multiple access to device */ +static char msg[BUF_LEN]; /* The msg the device will give when asked */ +static char *msg_Ptr; + +static struct file_operations fops = { + .read = device_read, + .write = device_write, + .open = device_open, + .release = device_release +}; + +/* + * This function is called when the module is loaded + */ +int init_module(void) +{ + Major = register_chrdev(0, DEVICE_NAME, &fops); + + if (Major < 0) { + printk(KERN_ALERT "Registering char device failed with %d\n", Major); + return Major; + } + + // Create module class + printk(KERN_INFO "Creating device class LCD...\n"); + dev_Class = class_create(THIS_MODULE,DEVICE_NAME); + if( dev_Class == NULL) + { + printk( KERN_ALERT "Error! Class couldn't be created!\n" ); + return 1 ; + } + printk( KERN_INFO "Class created!\n" ); + // Create device in /dev/... + printk(KERN_INFO "Creating device\n"); + chr_dev = device_create(dev_Class, NULL, MKDEV(Major,0), NULL, DEVICE_NAME); + + printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major); + printk(KERN_INFO "the driver, create a dev file with\n"); + printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major); + printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n"); + printk(KERN_INFO "the device file.\n"); + printk(KERN_INFO "Remove the device file and module when done.\n"); + + return SUCCESS; +} + +/* + * This function is called when the module is unloaded + */ +void cleanup_module(void) +{ + /* + * Unregister the device + */ + unregister_chrdev(Major, DEVICE_NAME); +} + +/* + * Methods + */ + +/* + * Called when a process tries to open the device file, like + * "cat /dev/mycharfile" + */ +static int device_open(struct inode *inode, struct file *file) +{ + static int counter = 0; + + if (Device_Open) + return -EBUSY; + + Device_Open++; + sprintf(msg, "I already told you %d times Hello world!\n", counter++); + msg_Ptr = msg; + try_module_get(THIS_MODULE); + + return SUCCESS; +} + +/* + * Called when a process closes the device file. + */ +static int device_release(struct inode *inode, struct file *file) +{ + Device_Open--; /* We're now ready for our next caller */ + + /* + * Decrement the usage count, or else once you opened the file, you'll + * never get get rid of the module. + */ + module_put(THIS_MODULE); + + return 0; +} + +/* + * Called when a process, which already opened the dev file, attempts to + * read from it. + */ +static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */ + char *buffer, /* buffer to fill with data */ + size_t length, /* length of the buffer */ + loff_t * offset) +{ + /* + * Number of bytes actually written to the buffer + */ + int bytes_read = 0; + + /* + * If we're at the end of the message, + * return 0 signifying end of file + */ + if (*msg_Ptr == 0) + return 0; + + /* + * Actually put the data into the buffer + */ + while (length && *msg_Ptr) { + + /* + * The buffer is in the user data segment, not the kernel + * segment so "*" assignment won't work. We have to use + * put_user which copies data from the kernel data segment to + * the user data segment. + */ + put_user(*(msg_Ptr++), buffer++); + + length--; + bytes_read++; + } + + /* + * Most read functions return the number of bytes put into the buffer + */ + return bytes_read; +} + +/* + * Called when a process writes to dev file: echo "hi" > /dev/hello + */ +static ssize_t +device_write(struct file *filp, const char *buff, size_t len, loff_t * off) +{ + printk(KERN_ALERT "Sorry, this operation isn't supported.\n"); + return -EINVAL; +} diff --git a/20210430/chardev-3.c b/20210430/chardev-3.c new file mode 100644 index 0000000000000000000000000000000000000000..516a074f806e3f600009b39ca912bf5ab69e3989 --- /dev/null +++ b/20210430/chardev-3.c @@ -0,0 +1,198 @@ +/* + * chardev.c: Creates a read-only char device that says how many times + * you've read from the dev file + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <asm/uaccess.h> /* for put_user */ + +MODULE_LICENSE("GPL"); + +/* + * Prototypes - this would normally go in a .h file + */ +int init_module(void); +void cleanup_module(void); +static int device_open(struct inode *, struct file *); +static int device_release(struct inode *, struct file *); +static ssize_t device_read(struct file *, char *, size_t, loff_t *); +static ssize_t device_write(struct file *, const char *, size_t, loff_t *); + +struct class *dev_Class; +struct device *chr_dev; + +#define SUCCESS 0 +#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */ +#define BUF_LEN 80 /* Max length of the message from the device */ + +/* + * Global variables are declared as static, so are global within the file. + */ + +static int Major; /* Major number assigned to our device driver */ +static int Device_Open = 0; /* Is device open? + * Used to prevent multiple access to device */ +static char msg[BUF_LEN]; /* The msg the device will give when asked */ +static char *msg_Ptr; + +static struct file_operations fops = { + .read = device_read, + .write = device_write, + .open = device_open, + .release = device_release +}; + +/* + * This function is called when the module is loaded + */ +int init_module(void) +{ + Major = register_chrdev(0, DEVICE_NAME, &fops); + + if (Major < 0) { + printk(KERN_ALERT "Registering char device failed with %d\n", Major); + return Major; + } + + // Create module class + printk (KERN_INFO "Creating device class \"chardev\" ...\n"); + dev_Class = class_create (THIS_MODULE,DEVICE_NAME); + if( dev_Class == NULL) + { + printk (KERN_ALERT "Error! Class couldn't be created!\n"); + return 1; + } + printk (KERN_INFO "Class created!\n"); + // Create device in /dev/... + printk (KERN_INFO "Creating device\n"); + chr_dev = device_create (dev_Class, NULL, MKDEV (Major,0), NULL, DEVICE_NAME); + if (chr_dev == NULL) + { + printk( KERN_ALERT "Error! Device couldn't be created!\n" ); + return 1 ; + } + + return SUCCESS; +} + +/* + * This function is called when the module is unloaded + */ +void cleanup_module(void) +{ + printk(KERN_INFO "module chardev-4 cleanup\n"); + //Unregister the device + if (chr_dev) + { + printk(KERN_INFO "Unregister device ...\n"); + device_unregister(chr_dev); + printk(KERN_INFO "OK\n"); + } + + if (dev_Class) + { + printk(KERN_INFO "Unregister class ...\n"); + class_unregister(dev_Class); + printk(KERN_INFO "OK\n"); + } + + printk(KERN_INFO "Unregister Chardev ...\n"); + unregister_chrdev(Major, DEVICE_NAME); + printk(KERN_INFO "Device %s unregistered!\n", DEVICE_NAME); +} + +/* + * Methods + */ + +/* + * Called when a process tries to open the device file, like + * "cat /dev/mycharfile" + */ +static int device_open(struct inode *inode, struct file *file) +{ + static int counter = 0; + + if (Device_Open) + return -EBUSY; + + Device_Open++; + sprintf(msg, "I already told you %d times Hello world!\n", counter++); + msg_Ptr = msg; + try_module_get(THIS_MODULE); + + return SUCCESS; +} + +/* + * Called when a process closes the device file. + */ +static int device_release(struct inode *inode, struct file *file) +{ + Device_Open--; /* We're now ready for our next caller */ + + /* + * Decrement the usage count, or else once you opened the file, you'll + * never get get rid of the module. + */ + module_put(THIS_MODULE); + + return 0; +} + +/* + * Called when a process, which already opened the dev file, attempts to + * read from it. + */ +static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */ + char *buffer, /* buffer to fill with data */ + size_t length, /* length of the buffer */ + loff_t * offset) +{ + /* + * Number of bytes actually written to the buffer + */ + int bytes_read = 0; + + /* + * If we're at the end of the message, + * return 0 signifying end of file + */ + if (*msg_Ptr == 0) + return 0; + + /* + * Actually put the data into the buffer + */ + while (length && *msg_Ptr) { + + /* + * The buffer is in the user data segment, not the kernel + * segment so "*" assignment won't work. We have to use + * put_user which copies data from the kernel data segment to + * the user data segment. + */ + put_user(*(msg_Ptr++), buffer++); + + length--; + bytes_read++; + } + + /* + * Most read functions return the number of bytes put into the buffer + */ + return bytes_read; +} + +/* + * Called when a process writes to dev file: echo "hi" > /dev/hello + */ +static ssize_t +device_write(struct file *filp, const char *buff, size_t len, loff_t * off) +{ + printk(KERN_ALERT "Sorry, this operation isn't supported.\n"); + return -EINVAL; +} diff --git a/20210430/freedos.hd b/20210430/freedos.hd new file mode 100644 index 0000000000000000000000000000000000000000..bf24ea7697c79c81cbb1ff01ddb015a63faff730 Binary files /dev/null and b/20210430/freedos.hd differ diff --git a/20210430/hello-1.c b/20210430/hello-1.c new file mode 100644 index 0000000000000000000000000000000000000000..95edc4536cc17900a3dbb69c4ca9e3c66ec8da93 --- /dev/null +++ b/20210430/hello-1.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main (void) +{ + printf ("[H"); + printf ("[JH[0m"); + printf ("[Ke[0m"); + printf ("[Ll[0m"); + printf ("[Il[0m"); + printf ("[Ho[0m"); + return 0; +} diff --git a/20210430/hello-2.c b/20210430/hello-2.c new file mode 100644 index 0000000000000000000000000000000000000000..420d2eb570e62d4e7dbe2f7aaf351d5d55a9ff7a --- /dev/null +++ b/20210430/hello-2.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + printf ("\x1b[H\x1b[J"); + printf ("\x1b[00m\x1b[01;35m"); + printf ("Hello, world!\n"); + return 0; +} diff --git a/20210430/hello-3.c b/20210430/hello-3.c new file mode 100644 index 0000000000000000000000000000000000000000..b19d80e9bd0bd7c5ed8f54b20c6a50d9166f03ac --- /dev/null +++ b/20210430/hello-3.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("Hello, world!\n"); + return 0; +} diff --git a/20210430/hellomod-1.c b/20210430/hellomod-1.c new file mode 100644 index 0000000000000000000000000000000000000000..a9fef793369a4e24da98b91e1bb7c651190ceea2 --- /dev/null +++ b/20210430/hellomod-1.c @@ -0,0 +1,20 @@ +/* + * hello-1.c - The simplest kernel module. + */ +#include <linux/module.h> /* Needed by all modules */ +#include <linux/kernel.h> /* Needed for KERN_INFO */ + +int init_module(void) +{ + printk(KERN_INFO "Hello world 1.\n"); + + /* + * A non 0 return means init_module failed; module can't be loaded. + */ + return 0; +} + +void cleanup_module(void) +{ + printk(KERN_INFO "Goodbye world 1.\n"); +} diff --git a/20210430/hellomod-2.c b/20210430/hellomod-2.c new file mode 100644 index 0000000000000000000000000000000000000000..a2bb30b1329f9a2997a2d6164631618635f41f4c --- /dev/null +++ b/20210430/hellomod-2.c @@ -0,0 +1,22 @@ +/* + * hello-2.c - The simplest kernel module. + */ +#include <linux/module.h> /* Needed by all modules */ +#include <linux/kernel.h> /* Needed for KERN_INFO */ + +MODULE_LICENSE("GPL"); + +int init_module(void) +{ + printk(KERN_INFO "Hello world 2.\n"); + + /* + * A non 0 return means init_module failed; module can't be loaded. + */ + return 0; +} + +void cleanup_module(void) +{ + printk(KERN_INFO "Goodbye world 2.\n"); +} diff --git a/20210430/make-1.txt b/20210430/make-1.txt new file mode 100644 index 0000000000000000000000000000000000000000..56706abfce4ed9ae3aa8afaabd620525e2fb9f20 --- /dev/null +++ b/20210430/make-1.txt @@ -0,0 +1,40 @@ +cassini/home/peter/bo/2021ss/bs/20210430> cat Makefile +hello-3: hello-3.c + gcc -Wall -O hello-3.c -o hello-3 +cassini/home/peter/bo/2021ss/bs/20210430> cat hello-3.c +#include <stdio.h> + +int main (void) +{ + printf ("Hello, world!\n"); + return 0; +} +cassini/home/peter/bo/2021ss/bs/20210430> make +gcc -Wall -O hello-3.c -o hello-3 +cassini/home/peter/bo/2021ss/bs/20210430> ./hello-3 +Hello, world! +cassini/home/peter/bo/2021ss/bs/20210430> make +make: „hello-3“ ist bereits aktuell. +cassini/home/peter/bo/2021ss/bs/20210430> touch hello-3.c +cassini/home/peter/bo/2021ss/bs/20210430> ls -lrt +insgesamt 1120 +-rw-r--r-- 1 peter peter 1048576 Okt 22 2013 freedos.hd +-rw-r--r-- 1 peter peter 4069 Apr 4 2014 chardev-1.c +-rw-r--r-- 1 peter peter 390 Apr 4 2014 hellomod-1.c +-rw-r--r-- 1 peter peter 4659 Mai 5 2017 chardev-2.c +-rw-r--r-- 1 peter peter 414 Apr 26 2019 hellomod-2.c +-rw-r--r-- 1 peter peter 4997 Apr 26 2019 chardev-3.c +-rw-r--r-- 1 peter peter 230 Apr 30 12:06 SCRATCH +-rw-r--r-- 1 peter peter 210 Apr 30 12:25 nix-hello.c +-rw-r--r-- 1 peter peter 185 Apr 30 12:33 hello-1.c +-rw-r--r-- 1 peter peter 143 Apr 30 12:36 hello-2.c +-rwxr-xr-x 1 peter peter 16608 Apr 30 12:40 a.out +-rw-r--r-- 1 peter peter 208 Apr 30 12:52 Makefile-1 +-rw-r--r-- 1 peter peter 54 Apr 30 12:55 Makefile +-rwxr-xr-x 1 peter peter 16608 Apr 30 12:55 hello-3 +-rw-r--r-- 1 peter peter 82 Apr 30 12:56 hello-3.c +cassini/home/peter/bo/2021ss/bs/20210430> make +gcc -Wall -O hello-3.c -o hello-3 +cassini/home/peter/bo/2021ss/bs/20210430> ./hello-3 +Hello, world! +cassini/home/peter/bo/2021ss/bs/20210430> diff --git a/20210430/make-2.txt b/20210430/make-2.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f913d150da63f15b364b73e49a36d870c0690ad --- /dev/null +++ b/20210430/make-2.txt @@ -0,0 +1,11 @@ +TARGET = hello-3 +CFLAGS = -Wall -O + +$(TARGET): hello-3.c + gcc $(CFLAGS) hello-3.c -o hello-3 +cassini/home/peter/bo/2021ss/bs/20210430> make +make: „hello-3“ ist bereits aktuell. +cassini/home/peter/bo/2021ss/bs/20210430> touch hello-3.c +cassini/home/peter/bo/2021ss/bs/20210430> make +gcc -Wall -O hello-3.c -o hello-3 +cassini/home/peter/bo/2021ss/bs/20210430> diff --git a/20210430/make-3.txt b/20210430/make-3.txt new file mode 100644 index 0000000000000000000000000000000000000000..739e3e02731ba7f5e910aadda75962f3a802a030 --- /dev/null +++ b/20210430/make-3.txt @@ -0,0 +1,9 @@ +TARGET = hello-3 +CFLAGS = -Wall -O + +$(TARGET): $(TARGET).c + gcc $(CFLAGS) $< -o $(TARGET) +cassini/home/peter/bo/2021ss/bs/20210430> touch hello-3.c +cassini/home/peter/bo/2021ss/bs/20210430> make +gcc -Wall -O hello-3.c -o hello-3 +cassini/home/peter/bo/2021ss/bs/20210430> diff --git a/20210430/make-4.txt b/20210430/make-4.txt new file mode 100644 index 0000000000000000000000000000000000000000..3a4f21f40dc59736a8f9091996439a55635e6622 --- /dev/null +++ b/20210430/make-4.txt @@ -0,0 +1,26 @@ +cassini/home/peter/bo/2020ws/hp/20201217> cat philosophy.c +#include <stdio.h> +#include "answer.h" + +int main (void) +{ + printf ("The answer is %d.\n", answer ()); + return 0; +} +cassini/home/peter/bo/2020ws/hp/20201217> cat answer.h +extern int answer (void); +cassini/home/peter/bo/2020ws/hp/20201217> gcc -Wall -O philosophy.c -o philosophy +/usr/bin/ld: /tmp/ccPlT8mv.o: in function `main': +philosophy.c:(.text+0x5): undefined reference to `answer' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2020ws/hp/20201217> cat answer.c +#include "answer.h" + +int answer (void) +{ + return 23; +} +cassini/home/peter/bo/2020ws/hp/20201217> gcc -Wall -O philosophy.c answer.c -o philosophy +cassini/home/peter/bo/2020ws/hp/20201217> ./philosophy +The answer is 23. +cassini/home/peter/bo/2020ws/hp/20201217> diff --git a/20210430/make-5.txt b/20210430/make-5.txt new file mode 100644 index 0000000000000000000000000000000000000000..2bcefad9bdd3d855d3bfda6b91ab5b9b5f5c5d94 --- /dev/null +++ b/20210430/make-5.txt @@ -0,0 +1,14 @@ +cassini/home/peter/bo/2020ws/hp/20201217> gcc -Wall -O philosophy.c -c +cassini/home/peter/bo/2020ws/hp/20201217> ls -l philosophy* +-rwxr-xr-x 1 peter peter 16680 Apr 30 14:18 philosophy +-rw-r--r-- 1 peter peter 117 Jan 4 14:29 philosophy.c +-rw-r--r-- 1 peter peter 1632 Apr 30 14:19 philosophy.o +cassini/home/peter/bo/2020ws/hp/20201217> gcc -Wall -O answer.c -c +cassini/home/peter/bo/2020ws/hp/20201217> ls -l answer.* +-rw-r--r-- 1 peter peter 56 Jan 4 14:29 answer.c +-rw-r--r-- 1 peter peter 26 Jan 4 14:29 answer.h +-rw-r--r-- 1 peter peter 1208 Apr 30 14:20 answer.o +cassini/home/peter/bo/2020ws/hp/20201217> gcc philosophy.o answer.o -o philosophy +cassini/home/peter/bo/2020ws/hp/20201217> ./philosophy +The answer is 23. +cassini/home/peter/bo/2020ws/hp/20201217> diff --git a/20210430/modules-1.txt b/20210430/modules-1.txt new file mode 100644 index 0000000000000000000000000000000000000000..073503859f3c6cf906cfa5d6f33125032b996a08 --- /dev/null +++ b/20210430/modules-1.txt @@ -0,0 +1,40 @@ +cassini/home/peter/bo/2021ss/bs/20210430> cat hellomod-1.c +/* + * hello-1.c - The simplest kernel module. + */ +#include <linux/module.h> /* Needed by all modules */ +#include <linux/kernel.h> /* Needed for KERN_INFO */ + +int init_module(void) +{ + printk(KERN_INFO "Hello world 1.\n"); + + /* + * A non 0 return means init_module failed; module can't be loaded. + */ + return 0; +} + +void cleanup_module(void) +{ + printk(KERN_INFO "Goodbye world 1.\n"); +} +cassini/home/peter/bo/2021ss/bs/20210430> cat Makefile +obj-m = hellomod-1.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 +cassini/home/peter/bo/2021ss/bs/20210430> ls -lrt hellomod-1.* +-rw-r--r-- 1 peter peter 390 Apr 4 2014 hellomod-1.c +-rw-r--r-- 1 peter peter 132152 Apr 30 14:37 hellomod-1.o +-rw-r--r-- 1 peter peter 790 Apr 30 14:37 hellomod-1.mod.c +-rw-r--r-- 1 peter peter 139912 Apr 30 14:37 hellomod-1.mod.o +-rw-r--r-- 1 peter peter 270648 Apr 30 14:37 hellomod-1.ko +cassini/home/peter/bo/2021ss/bs/20210430> insmod hellomod-1.ko +bash: insmod: Kommando nicht gefunden. +cassini/home/peter/bo/2021ss/bs/20210430> sudo insmod hellomod-1.ko +[sudo] Passwort für peter: +cassini/home/peter/bo/2021ss/bs/20210430> diff --git a/20210430/modules-2.txt b/20210430/modules-2.txt new file mode 100644 index 0000000000000000000000000000000000000000..84e1d27e124fbbdb089681a36a200e96578c5f2a --- /dev/null +++ b/20210430/modules-2.txt @@ -0,0 +1,11 @@ +cassini/home/peter/bo/2021ss/bs/20210430> lsmod | head +Module Size Used by +hellomod_1 16384 0 +v4l2loopback 45056 0 +v4l2_common 16384 1 v4l2loopback +snd_seq_dummy 16384 0 +snd_hrtimer 16384 0 +snd_seq_midi 16384 0 +snd_seq_midi_event 16384 1 snd_seq_midi +snd_seq 81920 3 snd_seq_midi,snd_seq_midi_event,snd_seq_dummy +nfnetlink_queue 24576 0 diff --git a/20210430/modules-3.txt b/20210430/modules-3.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca94c8700124215570564875338badbd15e23d21 --- /dev/null +++ b/20210430/modules-3.txt @@ -0,0 +1,14 @@ +cassini/home/peter/bo/2021ss/bs/20210430> lsmod | head +Module Size Used by +hellomod_1 16384 0 +v4l2loopback 45056 0 +v4l2_common 16384 1 v4l2loopback +snd_seq_dummy 16384 0 +snd_hrtimer 16384 0 +snd_seq_midi 16384 0 +snd_seq_midi_event 16384 1 snd_seq_midi +snd_seq 81920 3 snd_seq_midi,snd_seq_midi_event,snd_seq_dummy +nfnetlink_queue 24576 0 +cassini/home/peter/bo/2021ss/bs/20210430> sudo rmmod hellomod_1 +cassini/home/peter/bo/2021ss/bs/20210430> lsmod | grep hello +cassini/home/peter/bo/2021ss/bs/20210430> diff --git a/20210430/modules-4.txt b/20210430/modules-4.txt new file mode 100644 index 0000000000000000000000000000000000000000..a9ff3a18c3e1ec936730f656d5bce2e0cb91454c --- /dev/null +++ b/20210430/modules-4.txt @@ -0,0 +1,53 @@ +cassini/root# tail -f /var/log/kern.log +Apr 30 13:16:56 cassini kernel: [1241542.399747] sd 6:0:0:0: [sdb] Mode Sense: 47 00 10 08 +Apr 30 13:16:56 cassini kernel: [1241542.400038] sd 6:0:0:0: [sdb] No Caching mode page found +Apr 30 13:16:56 cassini kernel: [1241542.400073] sd 6:0:0:0: [sdb] Assuming drive cache: write through +Apr 30 13:16:56 cassini kernel: [1241542.459524] sdb: sdb1 +Apr 30 13:16:56 cassini kernel: [1241542.460550] sd 6:0:0:0: [sdb] Attached SCSI disk +Apr 30 13:17:43 cassini kernel: [1241588.936525] EXT4-fs (dm-3): mounted filesystem with ordered data mode. Opts: (null) +Apr 30 14:43:13 cassini kernel: [1246719.130516] hellomod_1: module license 'unspecified' taints kernel. +Apr 30 14:43:13 cassini kernel: [1246719.130518] Disabling lock debugging due to kernel taint +Apr 30 14:43:13 cassini kernel: [1246719.132467] Hello world 1. +Apr 30 14:44:40 cassini kernel: [1246806.404588] Goodbye world 1. +obj-m = hellomod-1.o +obj-m += hellomod-2.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 +cassini/home/peter/bo/2021ss/bs/20210430> make +make -C /lib/modules/4.19.0-12-amd64/build M=/home/peter/bo/2021ss/bs/20210430 modules +make[1]: Verzeichnis „/usr/src/linux-headers-4.19.0-12-amd64“ wird betreten + CC [M] /home/peter/bo/2021ss/bs/20210430/hellomod-2.o + Building modules, stage 2. + MODPOST 2 modules +WARNING: modpost: missing MODULE_LICENSE() in /home/peter/bo/2021ss/bs/20210430/hellomod-1.o +see include/linux/module.h for more information + CC /home/peter/bo/2021ss/bs/20210430/hellomod-2.mod.o + LD [M] /home/peter/bo/2021ss/bs/20210430/hellomod-2.ko +make[1]: Verzeichnis „/usr/src/linux-headers-4.19.0-12-amd64“ wird verlassen +cassini/home/peter/bo/2021ss/bs/20210430> ls -l hellomod-2.* +-rw-r--r-- 1 peter peter 414 Apr 26 2019 hellomod-2.c +-rw-r--r-- 1 peter peter 277800 Apr 30 14:50 hellomod-2.ko +-rw-r--r-- 1 peter peter 790 Apr 30 14:50 hellomod-2.mod.c +-rw-r--r-- 1 peter peter 139912 Apr 30 14:50 hellomod-2.mod.o +-rw-r--r-- 1 peter peter 139416 Apr 30 14:50 hellomod-2.o +cassini/home/peter/bo/2021ss/bs/20210430> sudo insmod hellomod-2.ko +cassini/home/peter/bo/2021ss/bs/20210430> sudo rmmod hellomod-2.ko +cassini/home/peter/bo/2021ss/bs/20210430> + +cassini/root# tail -f /var/log/kern.log +Apr 30 13:16:56 cassini kernel: [1241542.399747] sd 6:0:0:0: [sdb] Mode Sense: 47 00 10 08 +Apr 30 13:16:56 cassini kernel: [1241542.400038] sd 6:0:0:0: [sdb] No Caching mode page found +Apr 30 13:16:56 cassini kernel: [1241542.400073] sd 6:0:0:0: [sdb] Assuming drive cache: write through +Apr 30 13:16:56 cassini kernel: [1241542.459524] sdb: sdb1 +Apr 30 13:16:56 cassini kernel: [1241542.460550] sd 6:0:0:0: [sdb] Attached SCSI disk +Apr 30 13:17:43 cassini kernel: [1241588.936525] EXT4-fs (dm-3): mounted filesystem with ordered data mode. Opts: (null) +Apr 30 14:43:13 cassini kernel: [1246719.130516] hellomod_1: module license 'unspecified' taints kernel. +Apr 30 14:43:13 cassini kernel: [1246719.130518] Disabling lock debugging due to kernel taint +Apr 30 14:43:13 cassini kernel: [1246719.132467] Hello world 1. +Apr 30 14:44:40 cassini kernel: [1246806.404588] Goodbye world 1. +Apr 30 14:51:18 cassini kernel: [1247204.245245] Hello world 2. +Apr 30 14:51:51 cassini kernel: [1247237.822197] Goodbye world 2. diff --git a/20210430/nix-hello.c b/20210430/nix-hello.c new file mode 100644 index 0000000000000000000000000000000000000000..cc2018703757a875b70c2aa3fd1a104d7e870301 --- /dev/null +++ b/20210430/nix-hello.c @@ -0,0 +1,15 @@ +int main (void) +{ + char *p = (char *) 0xb8000000; + *p++ = 'H'; + *p++ = 0x04; + *p++ = 'e'; + *p++ = 0x02; + *p++ = 'l'; + *p++ = 0x01; + *p++ = 'l'; + *p++ = 0x06; + *p++ = 'o'; + *p++ = 0x03; + return 0; +}