Modules Writing

From Go-OS
Jump to: navigation, search

Contents

Module files structure

A module should contain at least one source file (.c) and the informations file, called MODULE_INFO.

Special Files

MODULE_INFO

Format of this file is free for now. Please include details such as version, changelog, author, etc...

Module minimum

Sample :

http://5os.net/doxygen/world_8c.html

/**
 * \file world.c
 * \brief Sample module
 * \url http://5os.net/wiki/Modules_Writing
 */

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

#include <kernel/kprint.h>

/**
 * \return int Number of device(s) found
 * \brief Returns the count of hardware found dependent on this module
 */
int drv_dependent_hardware() {
 return 0; // we do not do hardware
}

/**
 * \return int MODULE_SUCCESS in case of success, or anything else if an error occured
 * \brief Load and init this module
 */
int drv_init() {
 kprintf(__FILE__ ":%d Hello world module is loaded!!\n", __LINE__);
 return MODULE_SUCCESS;
}

/**
 * \return int MODULE_SUCCESS if successfully unloaded. Return MODULE_GURU_LEFT if not implemented
 * \brief Uninit and unload this module
 */
int drv_uninit() {
 kprintf(__FILE__ ":%d Hello world module is UNloaded!!\n", __LINE__);
 return MODULE_SUCCESS;
}

/**
 * \brief Variable used to tell the kernel about this module, having the magic name "module_info"
 */
struct kernel_module_info module_info = {
 .api_version = MODULE_API_VERSION,
 .name = "helloworld",
 .userfriendly_name = "Sample hello-world module",
 .version = MODULE_VERSION(0, 0, 1),
 .drv_dependent_hardware = drv_dependent_hardware, // return count of dependent hardware detected
 .drv_init = drv_init, // init driver (returns a MODULE_* value)
 .drv_uninit = drv_uninit // uninit driver (unload, returns a MODULE_* value)
};
Personal tools