mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Added chapter 2 source file for hello_world kernel module
This commit is contained in:
parent
66c0446388
commit
ba961a1fee
2 changed files with 54 additions and 0 deletions
6
src/chapters/2/hello_world/Makefile
Normal file
6
src/chapters/2/hello_world/Makefile
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Makefile for hello_world kernel module
|
||||
|
||||
KMOD= hello_world
|
||||
SRCS= hello_world.c
|
||||
|
||||
.include <bsd.kmod.mk>
|
||||
48
src/chapters/2/hello_world/hello_world.c
Normal file
48
src/chapters/2/hello_world/hello_world.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* hello_world.c - Simple FreeBSD kernel module
|
||||
* Prints messages when loaded and unloaded
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
/*
|
||||
* Load handler - called when the module is loaded
|
||||
*/
|
||||
static int
|
||||
hello_world_load(module_t mod, int cmd, void *arg)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (cmd) {
|
||||
case MOD_LOAD:
|
||||
printf("Hello World! Kernel module loaded.\n");
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
printf("Goodbye World! Kernel module unloaded.\n");
|
||||
break;
|
||||
default:
|
||||
error = EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Module declaration
|
||||
*/
|
||||
static moduledata_t hello_world_mod = {
|
||||
"hello_world", /* module name */
|
||||
hello_world_load, /* event handler */
|
||||
NULL /* extra data */
|
||||
};
|
||||
|
||||
/*
|
||||
* Register the module with the kernel
|
||||
* DECLARE_MODULE(name, data, sub-system, order)
|
||||
*/
|
||||
DECLARE_MODULE(hello_world, hello_world_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
||||
MODULE_VERSION(hello_world, 1);
|
||||
Loading…
Reference in a new issue