K. Lange 046ec9538f vmware: initialize vmware_mouse_byte or it resolves incorrectly by linker 7 months ago
..
README.md 8bf3e55f4e Add module README 2 years ago
ac97.c 53b3d3781d Fix up AC97 driver? 2 years ago
ata.c 96fe218d2f ata: apply same change for atapi 1 year ago
ataold.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
debug_sh.c 52d65d3099 debug_sh: fix bad format string in pci command 1 year ago
dospart.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
e1000.c 30b0b9477b e1000: add mobile chipset pci id 2 years ago
ext2.c 662ad3b407 kernel: remove calls to calloc (they confuse the tracker) 2 years ago
hda.c 1355502e6c Reorganize headers 2 years ago
iso9660.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
lfbvideo.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
net.c 131262bb1f kernel: change some log levels 2 years ago
packetfs.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
pcnet.c f10a54dd2b PIIX PIRQ handling? 2 years ago
pcspkr.c 931d3d3b13 pcspkr: accept -1 and 0 as special lengths 2 years ago
portio.c c75d31d7ca portio: /dev/port is a block device, not a character device (it support seek) 11 months ago
procfs.c ed6c60d51f procfs: fix BAR5 typo 1 year ago
ps2kbd.c 9bd27895bc ps2kbd: why are we giving current_process this 2 years ago
ps2mouse.c 095d087e1d IRQ stuff 2 years ago
random.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
rtl.c f10a54dd2b PIIX PIRQ handling? 2 years ago
serial.c 81ba10fe3f serial: new direct tty serial driver 2 years ago
snd.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago
tarfs.c 979f31bc46 tarfs: minor speedup, assuming well-ordered archives 1 year ago
tmpfs.c 5bf2cd5ea2 tmpfs: probably off-by-one, let's be safe 2 years ago
usbuhci.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
vbox.c aca47b862b toggle-relative-mouse: add query option 'get' 2 years ago
vgadbg.c 1355502e6c Reorganize headers 2 years ago
vgalog.c 4f0c5d8b49 vgalog: fix incomplete initializer 8 months ago
vidset.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
vmware.c 046ec9538f vmware: initialize vmware_mouse_byte or it resolves incorrectly by linker 7 months ago
xtest.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 2 years ago
zero.c de7463d141 kernel: 64-bit offsets for VFS 2 years ago

README.md

Kernel Modules

The Toaru kernel supports loadable modules which provide most of the device driver support.

A simple module requires a load and unload method, which are exposed along with a module name through the MODULE_DEF macro available from <kernel/module.h>.

#include <kernel/module.h>

static int load(void) {
	/* Run on module installation */
	return 0;
}

static int unload(void) {
	/* Clean up for removal */
	return 0;
}

MODULE_DEF(example_mod, load, unload);

Module Dependencies

If your module depends on another module being loaded, list each dependency using the MODULE_DEPENDS macro:

MODULE_DEF(extension_mod, load, unload);
MODULE_DEPENDS(example_mod);

Currently, dependencies are tested at load time, but the kernel will not load dependencies for you.

Dependency lists can be parsed by external tools to ensure modules are properly linked.

Kernel Functions

All non-static kernel functions are available for use in modules. For example, the logging functions may be used:

#include <kernel/logging.h>
#include <kernel/module.h>

static int load(void) {
	debug_print(WARNING, "Hello, world.");
	return 0;
}

static int unload(void) {
	return 0;
}

MODULE_DEF(printing_mod, load, unload);

Background Tasks

Device drivers, such as those for network devices, may want to create a background process to manage tasks. This can be done through the create_kernel_tasklet interface at device startup.

#include <kernel/process.h>
#include <kernel/module.h>

static void tasklet_run(void * data, char * name) {
	/* Perform tasklet activities */
	while (1) {
		do_thing();
	}
}

static int load(void) {
	create_kernel_tasklet(tasklet_run, "[demo-tasklet]", NULL);
	return 0;
}

static int unload(void) {
	/* Maybe clean up your tasklet here. */
	return 0;
}

MODULE_DEF(tasklet_mod, load, unload);

Caveats

  • Currently, unloading modules is not supported.
  • Modules which are expected to be loaded at runtime should be very careful of memory allocations they make, as they happen in a context which may not be shared with other processes. If you wish to make use of memory mappings, ensure that you are creating a new kernel tasklet to perform work. Attempting to access mapped memory from an interrupt handler or a device driver may not be possible if it was mapped at module installation.