K. Lange 6c88956fa4 job control 3 years ago
..
README.md 8bf3e55f4e Add module README 4 years ago
ac97.c 53b3d3781d Fix up AC97 driver? 4 years ago
ata.c b9e0a85817 Don't show /dev/cdrom0 if it's empty (for now) 4 years ago
ataold.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
debug_sh.c b721c7483c debug_sh: use current process fd 0, 1 for shell, don't implement bad readline 3 years ago
dospart.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
e1000.c 30b0b9477b e1000: add mobile chipset pci id 4 years ago
ext2.c 35a2a4bc5c more filesystem permission things, add rm 4 years ago
hda.c 1355502e6c Reorganize headers 4 years ago
iso9660.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
lfbvideo.c 6898766fa0 lfbvideo: re-add old kludge vidmem locator as an option 4 years ago
net.c 36e9046ae8 Allow modules to install procfs entries 4 years ago
packetfs.c 35a2a4bc5c more filesystem permission things, add rm 4 years ago
pcnet.c f10a54dd2b PIIX PIRQ handling? 4 years ago
pcspkr.c eb1c435697 Remove unused debugshell dep for pcspkr 4 years ago
portio.c c1e42d2e07 add /dev/port 4 years ago
procfs.c 6c88956fa4 job control 3 years ago
ps2kbd.c 095d087e1d IRQ stuff 4 years ago
ps2mouse.c 095d087e1d IRQ stuff 4 years ago
random.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
rtl.c f10a54dd2b PIIX PIRQ handling? 4 years ago
serial.c 092ca7c196 tty: ascii DELETE for backspace; no serial conversion 3 years ago
snd.c 5dd763780a Unify list, tree, hashmap implementations with userspace/kernel 4 years ago
tmpfs.c c2b8449fd7 Reduce tmpfs debug message levels 4 years ago
usbuhci.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
vbox.c cdccc913ab Allow seamless and pointer integration to be turned off 4 years ago
vgadbg.c 1355502e6c Reorganize headers 4 years ago
vgalog.c 31214693dd Fixes to build kernel and modules with clang 4 years ago
vidset.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
vmware.c c4c8b42c53 vmware module description update 4 years ago
xtest.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 years ago
zero.c 557f578574 Don't use my given name in copyright headers; update everything to 2018 because why not 4 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.