X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fmodules.c;h=e4f49b288e776b2b854bb771ad09ee3c5d92e213;hb=2639d91d3b55b1ac724ae84793f389b8ffce363c;hp=44c4cb518fb77cd44f43102f61484e9b08f8218f;hpb=1e7db40300bc594cf708bb6082a6e05a268da946;p=tpg%2Facess2.git diff --git a/Kernel/modules.c b/Kernel/modules.c index 44c4cb51..e4f49b28 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -2,9 +2,12 @@ * Acess2 * - Module Loader */ -#include +#include #include +#define USE_EDI 0 +#define USE_UDI 1 + // === PROTOTYPES === int Modules_LoadBuiltins(); int Module_LoadMem(void *Buffer, Uint Length, char *ArgString); @@ -13,6 +16,9 @@ int Module_IsLoaded(char *Name); // === IMPORTS === +#if USE_UDI +extern int UDI_LoadDriver(void *Base); +#endif extern void StartupPrint(char *Str); extern tModule gKernelModules[]; extern void gKernelModulesEnd; @@ -21,6 +27,7 @@ extern void gKernelModulesEnd; int giNumBuiltinModules = 0; int giModuleSpinlock = 0; tModule *gLoadedModules = NULL; +tModuleLoader *gModule_Loaders = NULL; // === CODE === int Modules_LoadBuiltins() @@ -112,6 +119,20 @@ int Modules_LoadBuiltins() return 0; } +/** + * \brief Registers a tModuleLoader with the kernel + * \param Loader Pointer to loader structure (must be persistent) + */ +int Module_RegisterLoader(tModuleLoader *Loader) +{ + if(!Loader) return 1; + + Loader->Next = gModule_Loaders; + gModule_Loaders = Loader; + + return 0; +} + /** * \fn int Module_LoadMem(void *Buffer, Uint Length, char *ArgString) * \brief Load a module from a memory location @@ -138,16 +159,26 @@ int Module_LoadFile(char *Path, char *ArgString) base = Binary_LoadKernel(Path); // Error check - if(base == NULL) return 0; + if(base == NULL) { + Warning("Module_LoadFile: Unable to load '%s'", Path); + return 0; + } // Check for Acess Driver if( Binary_FindSymbol(base, "DriverInfo", (Uint*)&info ) == 0 ) { + tModuleLoader *tmp; + for( tmp = gModule_Loaders; tmp; tmp = tmp->Next) + { + if( tmp->Detector(base) == 0 ) continue; + + return tmp->Loader(base); + } + #if USE_EDI // Check for EDI Driver - if( Binary_FindSymbol(base, "driver_init", NULL ) == 0 ) + if( Binary_FindSymbol(base, "driver_init", NULL ) != 0 ) { - Binary_Relocate(base); // Relocate return Module_InitEDI( base ); // And intialise } #endif @@ -155,9 +186,9 @@ int Module_LoadFile(char *Path, char *ArgString) // Unknown module type?, return error Binary_Unload(base); #if USE_EDI - Warning("Module_LoadMem: Module has neither a Module Info struct, nor an EDI entrypoint"); + Warning("Module_LoadFile: Module has neither a Module Info struct, nor an EDI entrypoint"); #else - Warning("Module_LoadMem: Module does not have a Module Info struct"); + Warning("Module_LoadFile: Module does not have a Module Info struct"); #endif return 0; } @@ -165,14 +196,14 @@ int Module_LoadFile(char *Path, char *ArgString) // Check magic number if(info->Magic != MODULE_MAGIC) { - Warning("Module_LoadMem: Module's magic value is invalid (0x%x != 0x%x)", info->Magic, MODULE_MAGIC); + Warning("Module_LoadFile: Module's magic value is invalid (0x%x != 0x%x)", info->Magic, MODULE_MAGIC); return 0; } // Check Architecture if(info->Arch != MODULE_ARCH_ID) { - Warning("Module_LoadMem: Module is for a different architecture"); + Warning("Module_LoadFile: Module is for a different architecture"); return 0; }