Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- system.pas
- (* Free Pascal Demo Kernel Module
- * System Unit Code
- * Based on work by Mazen Neifer, originally posted on
- * http://wiki.freepascal.org/linux/kernel/module_development
- * Stripped down to bare minimum needed for usable Hello World!
- * Some definitions also rearranged.
- * (c) Lukasz Sokol, 2011 License : GPL
- *)
- unit system;
- {$TYPEINFO OFF}
- interface
- {Paѕcal common type aliases}
- type
- {Basic embedded types}
- u8 = Byte;
- u16 = Word;
- u32 = LongWord;
- u64 = QWord;
- s8 = ShortInt;
- s16 = SmallInt;
- s32 = LongInt;
- s64 = Int64;
- {Integer types}
- DWord = LongWord;
- Cardinal = LongWord;
- Integer = SmallInt;
- UInt64 = QWord;
- {$ifdef CPU64}
- SizeInt = Int64;
- SizeUInt = QWord;
- PtrInt = Int64;
- PtrUInt = QWord;
- ValSInt = int64;
- ValUInt = qword;
- {$endif CPU64}
- {$ifdef CPU32}
- SizeInt = Longint;
- SizeUInt = DWord;
- PtrInt = Longint;
- PtrUInt = DWord;
- ValSInt = Longint;
- ValUInt = Cardinal;
- {$endif CPU32}
- {Zero - terminated strings }
- PChar = ^Char;
- PPChar = ^PChar;
- {Pointers}
- PSmallInt = ^Smallint;
- PShortInt = ^Shortint;
- PInteger = ^Integer;
- PByte = ^Byte;
- PWord = ^word;
- PDWord = ^DWord;
- PLongWord = ^LongWord;
- PLongint = ^Longint;
- PCardinal = ^Cardinal;
- PQWord = ^QWord;
- PInt64 = ^Int64;
- PPtrInt = ^PtrInt;
- PPtrUInt = ^PtrUInt;
- PSizeInt = ^SizeInt;
- PPointer = ^Pointer;
- PPPointer = ^PPointer;
- PBoolean = ^Boolean;
- PWordBool = ^WordBool;
- PLongBool = ^LongBool;
- {Other types}
- HRESULT = type Longint;
- TDateTime = type Double;
- TError = type Longint;
- const
- EPERM = 1;{Operation not permitted}
- ENOENT = 2;{No such file or directory}
- ESRCH = 3;{No such process}
- EINTR = 4;{Interrupted system call}
- EIO = 5;{I/O error}
- ENXIO = 6;{No such device or address}
- E2BIG = 7;{Argument list too long}
- ENOEXEC = 8;{Exec format error}
- EBADF = 9;{Bad file number}
- ECHILD = 10;{No child processes}
- EAGAIN = 11;{Try again}
- ENOMEM = 12;{Out of memory}
- EACCES = 13;{Permission denied}
- EFAULT = 14;{Bad address}
- ENOTBLK = 15;{Block device required}
- EBUSY = 16;{Device or resource busy}
- EEXIST = 17;{File exists}
- EXDEV = 18;{Cross-device link}
- ENODEV = 19;{No such device}
- ENOTDIR = 20;{Not a directory}
- EISDIR = 21;{Is a directory}
- EINVAL = 22;{Invalid argument}
- ENFILE = 23;{File table overflow}
- EMFILE = 24;{Too many open files}
- ENOTTY = 25;{Not a typewriter}
- ETXTBSY = 26;{Text file busy}
- EFBIG = 27;{File too large}
- ENOSPC = 28;{No space left on device}
- ESPIPE = 29;{Illegal seek}
- EROFS = 30;{Read-only file system}
- EMLINK = 31;{Too many links}
- EPIPE = 32;{Broken pipe}
- EDOM = 33;{Math argument out of domain of func}
- ERANGE = 34;{Math result not representable}
- type
- {Kernel types}
- mode_t = Word;
- nlink_t = DWord;
- uid_t = Word;
- gid_t = Word;
- off_t = LongInt;
- loff_t = Int64;
- Ploff_t = ^loff_t;
- size_t = DWord;
- ssize_t = LongInt;
- implementation
- end.
- ---
- --- kernel_module.pas
- (* Free Pascal Demo Kernel Module
- * Pascal Module Code
- * Based on work by Mazen Neifer, originally posted on
- * http://wiki.freepascal.org/linux/kernel/module_development
- * Stripped down to bare minimum needed for usable Hello World!
- * Some definitions also rearranged.
- * (c) Lukasz Sokol, 2011 License : GPL
- *)
- unit kernel_module;
- {$TYPEINFO OFF}
- interface
- procedure printk(fmt:PChar); cdecl;
- implementation
- const
- KERN_INFO='KERNEL:INFO:';
- KERN_ALERT='KERNEL:ALERT:';
- {$LINK kernel_module_info}
- procedure printk(fmt:PChar); cdecl; external;
- {This function is called when the module is loaded}
- function init_module: Integer; cdecl; export;
- begin
- printk(KERN_INFO + 'Hello World!'+#10+#0);
- init_module := 0;
- end;
- {This function is called when the module is unloaded}
- procedure cleanup_module; cdecl; export;
- begin
- printk(KERN_INFO + 'Bye-bye!'+#10+#0);
- end;
- end.
- ---
- --- kernel_module_info.c
- /* Free Pascal Demo Kernel Module
- * c code that is linked into Pascal after compile - needed for symbols
- * Based on work by Mazen Neifer, originally posted on
- * http://wiki.freepascal.org/linux/kernel/module_development
- * Stripped down to bare minimum needed for usable Hello World!
- * Some definitions also rearranged.
- * (c) Lukasz Sokol, 2011 License : GPL
- */
- #include <linux/module.h>
- MODULE_DESCRIPTION("Test Module written using FPC");
- MODULE_AUTHOR("Lukasz Sokol (fork)");
- MODULE_LICENSE("GPL");
- ---
- --- Makefile
- # Free Pascal Demo Kernel Module
- # * the Makefile
- # * Based on work by Mazen Neifer, originally posted on
- # * http://wiki.freepascal.org/linux/kernel/module_development
- # * Stripped down to bare minimum needed for usable Hello World!
- # * Some definitions also rearranged.
- # * (c) Lukasz Sokol, 2011 License : GPL
- # *)
- obj-m := kernel_pmodule.o
- kernel_pmodule-objs := kernel_module_info.o kernel_module.o system.o
- KDIR := /lib/modules/$(shell uname -r)/build
- PWD := $(shell pwd)
- default:kernel_module.o
- $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
- kernel_module.o: system.pas kernel_module.pas
- fpc kernel_module
- clean:
- ${RM} *.ko *.mod.c *.o *.ppu Module.symvers .*.ko.cmd .*.o.cmd
- ${RM} -r .tmp_versions
- ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement