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");
93 LOG("info = %p\n", info);
94 Debug_HexDump("info", info, 6*4);
97 if(info->Magic != MODULE_MAGIC)
99 Warning("Module_LoadMem: Module's magic value is invalid (0x%x != 0x%x)", info->Magic, MODULE_MAGIC);
103 // Check Architecture
104 if(info->Arch != MODULE_ARCH_ID)
106 Warning("Module_LoadMem: Module is for a different architecture");
110 // Resolve Dependencies
111 if( !Module_int_ResolveDeps(info) ) {
117 //if( info->Init( ArgString ) != 0 )
118 if( info->Init( NULL ) == 0 )
125 LOCK( &giModuleSpinlock );
126 info->Next = gLoadedModules;
127 gLoadedModules = info;
128 RELEASE( &giModuleSpinlock );
134 * \fn int Module_int_ResolveDeps(tModule *Info)
135 * \brief Resolves the dependencies
137 * \note Currently does not resolve the dependencies, just checks them
139 int Module_int_ResolveDeps(tModule *Info)
141 char **names = Info->Dependencies;
143 // Walk dependencies array
144 for( ; *names; names++ )
146 // Check if the module is loaded
147 if( !Module_IsLoaded(*names) ) {
148 Warning("Module `%s' requires `%s', which is not loaded\n", Info->Name, *names);
156 * \fn int Module_IsLoaded(char *Name)
157 * \brief Checks if a module is loaded
158 * \param Name Name of module to find
160 int Module_IsLoaded(char *Name)
162 tModule *mod = gLoadedModules;
165 for( ; mod; mod = mod->Next )
167 // If found, return true
168 if(strcmp(mod->Name, Name) == 0)
171 // not found - return false