extern int UDI_LoadDriver(void *Base);
#endif
extern void StartupPrint(char *Str);
-extern tModule gKernelModules[];
+extern void gKernelModules;
extern void gKernelModulesEnd;
// === GLOBALS ===
tModule *gLoadedModules = NULL;
tModuleLoader *gModule_Loaders = NULL;
tModule *gLoadingModules = NULL;
+tModule **gapBuiltinModules = NULL;
char **gasBuiltinModuleArgs;
// === CODE ===
tModule *mod;
ENTER("pModule", Module);
+ LOG("Module->Magic = 0x%x", Module->Magic);
+ if(Module->Magic != MODULE_MAGIC) {
+ Log_Warning(
+ "Module",
+ "Module %p is no a valid Acess2 module (0x%08x != 0x%08x)",
+ Module, Module->Magic, MODULE_MAGIC
+ );
+ LEAVE('i', MODULE_ERR_BADMODULE);
+ return MODULE_ERR_BADMODULE;
+ }
+ LOG("Module->Name = %p \"%s\"", Module->Name, Module->Name);
+
+ if(Module->Arch != MODULE_ARCH_ID) {
+ Log_Warning(
+ "Module",
+ "Module %p (%s) is for another architecture (%i)",
+ Module, Module->Name, Module->Arch
+ );
+ }
deps = Module->Dependencies;
break;
}
if( mod ) {
- Log_Warning("Module", "Circular dependency detected");
+ Log_Warning("Module", "Circular dependency detected (%s and %s)",
+ mod->Name, Module->Name);
LEAVE_RET('i', -1);
}
// So, if it's not loaded, we better load it then
for( i = 0; i < giNumBuiltinModules; i ++ )
{
- if( strcmp(deps[j], gKernelModules[i].Name) == 0 )
+ if( strcmp(deps[j], gapBuiltinModules[i]->Name) == 0 )
break;
}
if( i == giNumBuiltinModules ) {
- Log_Warning("Module", "Dependency '%s' for module '%s' failed");
+ Log_Warning("Module", "Dependency '%s' for module '%s' failed",
+ deps[j], Module->Name);
return -1;
}
// Dependency is not loaded, so load it
ret = Module_int_Initialise(
- &gKernelModules[i],
+ gapBuiltinModules[i],
gasBuiltinModuleArgs ? gasBuiltinModuleArgs[i] : NULL
);
if( ret )
if(args) free(args);
+ // Remove from loading list
+ gLoadingModules = gLoadingModules->Next;
+
if( ret != MODULE_ERR_OK ) {
switch(ret)
{
}
LOG("ret = %i", ret);
- // Remove from loading list
- gLoadingModules = gLoadingModules->Next;
-
// Add to loaded list
LOCK( &glModuleSpinlock );
Module->Next = gLoadedModules;
LEAVE_RET('i', 0);
}
+/**
+ * \brief Scans the builtin modules and creates an array of them
+ */
+void Modules_int_GetBuiltinArray(void)
+{
+ int i;
+ tModule *module;
+
+ // Count
+ module = &gKernelModules;
+ i = 0;
+ while( (tVAddr)module < (tVAddr)&gKernelModulesEnd )
+ {
+ if(module->Magic == MODULE_MAGIC) {
+ i ++;
+ module ++;
+ }
+ else
+ module = (void*)( (tVAddr)module + 4 );
+ }
+
+ // Create
+ giNumBuiltinModules = i;
+ gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) );
+ gapBuiltinModules = malloc( giNumBuiltinModules * sizeof(tModule*) );
+
+
+ // Fill
+ module = &gKernelModules;
+ i = 0;
+ while( (tVAddr)module < (tVAddr)&gKernelModulesEnd )
+ {
+ if(module->Magic == MODULE_MAGIC) {
+ gapBuiltinModules[i] = module;
+ i ++;
+ module ++;
+ }
+ else
+ module = (void*)( (tVAddr)module + 4 );
+ }
+}
+
/**
* \brief Initialises builtin modules
*/
{
int i;
- // Count modules
- giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules;
- giNumBuiltinModules /= sizeof(tModule);
+ if( !gapBuiltinModules )
+ Modules_int_GetBuiltinArray();
for( i = 0; i < giNumBuiltinModules; i++ )
{
Module_int_Initialise(
- &gKernelModules[i],
+ gapBuiltinModules[i],
(gasBuiltinModuleArgs ? gasBuiltinModuleArgs[i] : NULL)
);
}
void Modules_SetBuiltinParams(char *Name, char *ArgString)
{
int i;
- if( gasBuiltinModuleArgs == NULL ) {
- giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules;
- giNumBuiltinModules /= sizeof(tModule);
- gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) );
+
+ if( gasBuiltinModuleArgs == NULL )
+ {
+ Modules_int_GetBuiltinArray();
}
- for( i = 0; i < giNumBuiltinModules; i ++ )
+ // I hate expensive scans
+ for( i = 0; i < giNumBuiltinModules; i++ )
{
- if(strcmp( gKernelModules[i].Name, Name ) == 0) {
+ if(strcmp( gapBuiltinModules[i]->Name, Name ) == 0) {
gasBuiltinModuleArgs[i] = ArgString;
return ;
}
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;
}