Lab Exercise 1, Section 2: The Kernel Module Compilation

Procedure

Kernel Module "Hello World"

Other than the fact that they run in kernel mode, kernel modules are similar in most ways to other C programs. The only notable exceptions are that they don't have access to the standard C library (which is itself a user-mode program) and they don't have a main() function. Kernel modules consist of code that responds to events in the kernel, so when loaded, they only register themselves to handle some event and exit. The function that registers the module is init_module(), and its corresponding cleanup function (called when the module is unloaded) is cleanup_module(). These are the only two functions necessary for a fully functional kernel module.

Kernel modules are relocatable object files, and so end in a .o extension. There are two ways you can make hello.o: You can compile it on the skiff board with its native compiler, or you can cross-compile it on a linux machine.

Fortunately, the two methods are nearly identical, differing only in the compiler used. The Makefile determines which platform you're compiling on and compensates accordingly. Skeleton code for this project is located in /net/hl1/j/src/modules [http], and it should compile both on the skiffs and on the cluster linux machines.

  1. Get the source, and add printk() messages to the entry and exit functions so you can see them working.

  2. Compile the hello.o module with make.

  3. On the skiff board, insert and remove the module with insmod hello.o and rmmod hello to verify that it's working.
This is how we'll compile and test much of the code written during the semester.