9 int Module_LoadMem(void *Buffer, Uint Length, char *ArgString);
10 int Module_LoadFile(char *Path, char *ArgString);
11 int Module_int_ResolveDeps(tModule *Info);
12 int Module_IsLoaded(char *Name);
15 extern tModule gKernelModules[];
16 extern void gKernelModulesEnd;
19 int giNumBuiltinModules = 0;
20 int giModuleSpinlock = 0;
21 tModule *gLoadedModules = NULL;
24 int Modules_LoadBuiltins()
27 giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules;
28 giNumBuiltinModules /= sizeof(tModule);
30 for( i = 0; i < giNumBuiltinModules; i++ )
32 Log("Initialising %p '%s' v%i.%i...",
34 gKernelModules[i].Name,
35 gKernelModules[i].Version>>8, gKernelModules[i].Version & 0xFF
37 gKernelModules[i].Init(NULL);
44 * \fn int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
45 * \brief Load a module from a memory location
47 int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
49 char path[VFS_MEMPATH_SIZE];
51 VFS_GetMemPath(Buffer, Length, path);
53 return Module_LoadFile( path, ArgString );
57 * \fn int Module_LoadFile(char *Path, char *ArgString)
58 * \brief Load a module from a file
60 int Module_LoadFile(char *Path, char *ArgString)
66 base = Binary_LoadKernel(Path);
69 if(base == NULL) return 0;
71 // Check for Acess Driver
72 if( Binary_FindSymbol(base, "DriverInfo", (Uint*)&info ) == 0 )
75 // Check for EDI Driver
76 if( Binary_FindSymbol(base, "driver_init", NULL ) == 0 )
78 Binary_Relocate(base); // Relocate
79 return Module_InitEDI( base ); // And intialise
83 // Unknown module type?, return error
86 Warning("Module_LoadMem: Module has neither a Module Info struct, nor an EDI entrypoint");
88 Warning("Module_LoadMem: Module does not have a Module Info struct");
94 if(info->Magic != MODULE_MAGIC)
96 Warning("Module_LoadMem: Module's magic value is invalid (0x%x != 0x%x)", info->Magic, MODULE_MAGIC);
100 // Check Architecture
101 if(info->Arch != MODULE_ARCH_ID)
103 Warning("Module_LoadMem: Module is for a different architecture");
107 // Resolve Dependencies
108 if( !Module_int_ResolveDeps(info) ) {
114 //if( info->Init( ArgString ) != 0 )
115 if( info->Init( NULL ) == 0 )
122 LOCK( &giModuleSpinlock );
123 info->Next = gLoadedModules;
124 gLoadedModules = info;
125 RELEASE( &giModuleSpinlock );
131 * \fn int Module_int_ResolveDeps(tModule *Info)
132 * \brief Resolves the dependencies
134 * \note Currently does not resolve the dependencies, just checks them
136 int Module_int_ResolveDeps(tModule *Info)
138 char **names = Info->Dependencies;
140 // Walk dependencies array
141 for( ; *names; names++ )
143 // Check if the module is loaded
144 if( !Module_IsLoaded(*names) ) {
145 Warning("Module `%s' requires `%s', which is not loaded\n", Info->Name, *names);
153 * \fn int Module_IsLoaded(char *Name)
154 * \brief Checks if a module is loaded
155 * \param Name Name of module to find
157 int Module_IsLoaded(char *Name)
159 tModule *mod = gLoadedModules;
162 for( ; mod; mod = mod->Next )
164 // If found, return true
165 if(strcmp(mod->Name, Name) == 0)
168 // not found - return false