- https://wiki.lazarus.freepascal.org/linux/kernel/module_development
- https://wiki.osdev.org/Pascal_Bare_Bones
Tested on Debian 12, kernel 6.1.0-28-amd64, FPC 3.3.1.
Make sure you have Free Pascal compiler, the kernel build tools, and kernel headers installed.
sudo apt install fpc build-essential linux-headers-$(uname -r)
$ cd src
$ make
...
make[1]: Leaving directory '/usr/src/linux-headers-6.1.0-28-amd64'
$ sudo insmod fpkmhello.ko
$ sudo dmesg
...
[10388.929879] KERNEL:INFO:Hello from Free Pascal!
$ lsmod | grep fpkmhello
fpkmhello 28672 0
$ sudo rmmod fpkmhello
$ sudo dmesg
...
[10388.929879] KERNEL:INFO:Hello from Free Pascal!
[10421.320454] KERNEL:INFO:Bye-bye!
Compiling system.pas
system.pas(12,10) Error: Duplicate identifier "Char"
You may get this error depending on which version FPC (e.g. 3.2.2) you're using. Try removing the line
Char = #0..#255;
from system.pas file.