Changes to the module loader to handle specific errors from modules
[tpg/acess2.git] / Kernel / include / modules.h
1 /*
2  * AcessOS 2
3  * - Module Loader
4  */
5 #ifndef _MODULE_H
6 #define _MODULE_H
7
8 #define MODULE_MAGIC    ('A'|('M'<<8)|('D'<<16)|('\2'<<24))
9
10 // IA32 - Architecture 1
11 #if ARCHDIR == x86
12 # define MODULE_ARCH_ID 1
13 // IA64 - Architecture 2
14 #elif ARCHDIR == x64
15 # define MODULE_ARCH_ID 2
16 #else
17 # error "Unknown architecture when determining MODULE_ARCH_ID ('" #ARCHDIR "')"
18 #endif
19
20 #define MODULE_DEFINE(_flags,_ver,_ident,_entry,_deinit,_deps...) \
21         char *EXPAND_CONCAT(_DriverDeps_,_ident)[]={_deps};\
22         tModule __attribute__ ((section ("KMODULES"),unused))\
23         EXPAND_CONCAT(_DriverInfo_,_ident)=\
24         {MODULE_MAGIC,MODULE_ARCH_ID,_flags,_ver,NULL,EXPAND_STR(_ident),\
25         _entry,_deinit,EXPAND_CONCAT(_DriverDeps_,_ident)}
26
27 typedef struct sModule {
28         Uint32  Magic;
29         Uint8   Arch;
30         Uint8   Flags;
31         Uint16  Version;
32         struct sModule  *Next;
33         char    *Name;
34          int    (*Init)(char **Arguments);
35         void    (*Deinit)();
36         char    **Dependencies; // NULL Terminated List
37 } __attribute__((packed)) tModule;
38
39 enum eModuleErrors
40 {
41         MODULE_ERR_OK,  //!< No Error
42         MODULE_ERR_MISC,        //!< Misc Error
43         MODULE_ERR_NOTNEEDED,   //!< Module not needed
44         MODULE_ERR_MALLOC,      //!< Error with malloc/realloc/calloc
45         
46         MODULE_ERR_MAX
47 };
48
49 /**
50  * \brief Module Loader definition
51  * 
52  * Allows a module to extend the loader to recognise other module types
53  * E.g. EDI, UDI, Windows, Linux, ...
54  */
55 typedef struct sModuleLoader {
56         struct sModuleLoader    *Next;  //!< Kernel Only - Next loader in list
57         char    *Name;  //!< Friendly name for the loader
58          int    (*Detector)(void *Base);        //!< Simple detector function
59          int    (*Loader)(void *Base);  //!< Initialises the module
60          int    (*Unloader)(void *Base);        //!< Calls module's cleanup
61 } PACKED tModuleLoader;
62
63 /**
64  * \brief Registers a tModuleLoader with the kernel
65  * \param Loader        Pointer to loader structure (must be persistent)
66  */
67 extern int      Module_RegisterLoader(tModuleLoader *Loader);
68
69 #endif

UCC git Repository :: git.ucc.asn.au