X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fmodules.c;h=1dc114994016dfbc63b5097cd45318a28e851291;hb=3764c294f21229bdf700f436fa4884f5e76e0d3a;hp=689487395cc95c7956095514eee0e43a25ad636d;hpb=e939fc0ced4d445c24696636fe660dddbe035b1c;p=tpg%2Facess2.git diff --git a/Kernel/modules.c b/Kernel/modules.c index 68948739..1dc11499 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -2,7 +2,7 @@ * Acess2 * - Module Loader */ -#define DEBUG 1 +#define DEBUG 0 #include #include @@ -10,14 +10,15 @@ #define USE_UDI 0 // === PROTOTYPES === - int Module_int_Initialise(tModule *Module, char *ArgString); + int Module_int_Initialise(tModule *Module, const char *ArgString); +void Modules_int_GetBuiltinArray(void); void Modules_LoadBuiltins(void); void Modules_SetBuiltinParams(char *Name, char *ArgString); - int Module_RegisterLoader(tModuleLoader *Loader); - int Module_LoadMem(void *Buffer, Uint Length, char *ArgString); - int Module_LoadFile(char *Path, char *ArgString); +// int Module_RegisterLoader(tModuleLoader *Loader); +// int Module_LoadMem(void *Buffer, Uint Length, char *ArgString); +// int Module_LoadFile(char *Path, char *ArgString); int Module_int_ResolveDeps(tModule *Info); - int Module_IsLoaded(char *Name); + int Module_IsLoaded(const char *Name); // === EXPORTS === EXPORT(Module_RegisterLoader); @@ -26,13 +27,13 @@ EXPORT(Module_RegisterLoader); #if USE_UDI extern int UDI_LoadDriver(void *Base); #endif -extern void StartupPrint(char *Str); -extern void gKernelModules; -extern void gKernelModulesEnd; +extern void StartupPrint(const char *Str); +extern tModule gKernelModules; +extern tModule gKernelModulesEnd; // === GLOBALS === int giNumBuiltinModules = 0; -tSpinlock glModuleSpinlock; +tShortSpinlock glModuleSpinlock; tModule *gLoadedModules = NULL; tModuleLoader *gModule_Loaders = NULL; tModule *gLoadingModules = NULL; @@ -43,17 +44,18 @@ char **gasBuiltinModuleArgs; /** * \brief Initialises a module * \param Module Pointer to the module header + * \param ArgString Comma separated list of module arguments * \return Zero on success, eModuleErrors or -1 on error * \retval -1 Returned if a dependency fails, or a circular dependency * exists. * \retval 0 Returned on success * \retval >0 Error code form the module's initialisation function */ -int Module_int_Initialise(tModule *Module, char *ArgString) +int Module_int_Initialise(tModule *Module, const char *ArgString) { int i, j; int ret; - char **deps; + const char **deps; char **args; tModule *mod; @@ -179,10 +181,10 @@ int Module_int_Initialise(tModule *Module, char *ArgString) LOG("ret = %i", ret); // Add to loaded list - LOCK( &glModuleSpinlock ); + SHORTLOCK( &glModuleSpinlock ); Module->Next = gLoadedModules; gLoadedModules = Module; - RELEASE( &glModuleSpinlock ); + SHORTREL( &glModuleSpinlock ); LEAVE_RET('i', 0); } @@ -251,6 +253,33 @@ void Modules_LoadBuiltins() free(gasBuiltinModuleArgs); } +/** + * \brief Initialise a builtin module given it's name + * + * E.g. Used by VTerm to load an alternate video driver at runtime + */ +int Modules_InitialiseBuiltin(const char *Name) +{ + int i; + + // Check if it's loaded + if( Module_IsLoaded(Name) ) + return 0; + + if( !gapBuiltinModules ) + Modules_int_GetBuiltinArray(); + + for( i = 0; i < giNumBuiltinModules; i++ ) + { + if( strcmp(gapBuiltinModules[i]->Name, Name) == 0 ) { + return Module_int_Initialise(gapBuiltinModules[i], + (gasBuiltinModuleArgs ? gasBuiltinModuleArgs[i] : NULL) + ); + } + } + return -1; +} + /** * \brief Sets the parameters for a builtin module */ @@ -293,7 +322,7 @@ int Module_RegisterLoader(tModuleLoader *Loader) * \fn int Module_LoadMem(void *Buffer, Uint Length, char *ArgString) * \brief Load a module from a memory location */ -int Module_LoadMem(void *Buffer, Uint Length, char *ArgString) +int Module_LoadMem(void *Buffer, Uint Length, const char *ArgString) { char path[VFS_MEMPATH_SIZE]; @@ -303,10 +332,10 @@ int Module_LoadMem(void *Buffer, Uint Length, char *ArgString) } /** - * \fn int Module_LoadFile(char *Path, char *ArgString) + * \fn int Module_LoadFile(const char *Path, const char *ArgString) * \brief Load a module from a file */ -int Module_LoadFile(char *Path, char *ArgString) +int Module_LoadFile(const char *Path, const char *ArgString) { void *base; tModule *info; @@ -349,53 +378,12 @@ int Module_LoadFile(char *Path, char *ArgString) return 0; } - // Check magic number - if(info->Magic != MODULE_MAGIC) - { - Log_Warning("Module", "Module's magic value is invalid (0x%x != 0x%x)", info->Magic, MODULE_MAGIC); - return 0; - } - - // Check Architecture - if(info->Arch != MODULE_ARCH_ID) - { - Log_Warning("Module", "Module is for a different architecture"); - return 0; - } - - #if 1 + // Initialise (and register) if( Module_int_Initialise( info, ArgString ) ) { Binary_Unload(base); return 0; } - #else - // Resolve Dependencies - if( !Module_int_ResolveDeps(info) ) { - Binary_Unload(base); - return 0; - } - - Log_Log("Module", "Initialising %p '%s' v%i.%i...", - info, - info->Name, - info->Version>>8, info->Version & 0xFF - ); - - // Call Initialiser - //if( info->Init( ArgString ) != 0 ) - if( info->Init( NULL ) == 0 ) - { - Binary_Unload(base); - return 0; - } - - // Add to list - LOCK( &glModuleSpinlock ); - info->Next = gLoadedModules; - gLoadedModules = info; - RELEASE( &glModuleSpinlock ); - #endif return 1; } @@ -408,7 +396,7 @@ int Module_LoadFile(char *Path, char *ArgString) */ int Module_int_ResolveDeps(tModule *Info) { - char **names = Info->Dependencies; + const char **names = Info->Dependencies; // Walk dependencies array for( ; *names; names++ ) @@ -423,11 +411,11 @@ int Module_int_ResolveDeps(tModule *Info) } /** - * \fn int Module_IsLoaded(char *Name) + * \fn int Module_IsLoaded(const char *Name) * \brief Checks if a module is loaded * \param Name Name of module to find */ -int Module_IsLoaded(char *Name) +int Module_IsLoaded(const char *Name) { tModule *mod = gLoadedModules;