3 * - By John Hodge (thePowersGang)
5 * - Architecture Independent System Init
12 extern void Arch_LoadBootModules(void);
13 extern int Modules_LoadBuiltins(void);
14 extern void Modules_SetBuiltinParams(char *Name, char *ArgString);
15 extern void Debug_SetKTerminal(const char *File);
16 extern void Timer_CallbackThread(void *);
19 void System_Init(char *Commandline);
20 void System_ParseCommandLine(char *ArgString);
21 void System_ExecuteCommandLine(void);
22 void System_ParseVFS(char *Arg);
23 void System_ParseModuleArgs(char *Arg);
24 void System_ParseSetting(char *Arg);
27 const char *gsInitBinary = "/Acess/SBin/init";
32 void System_Init(char *CommandLine)
34 Proc_SpawnWorker(Timer_CallbackThread, NULL);
36 // Parse Kernel's Command Line
37 System_ParseCommandLine(CommandLine);
40 Log_Log("Config", "Initialising builtin modules...");
41 Modules_LoadBuiltins();
42 Arch_LoadBootModules();
44 System_ExecuteCommandLine();
46 // - Execute the Config Script
47 Log_Log("Config", "Spawning init '%s'", gsInitBinary);
48 if(Proc_Clone(CLONE_VM|CLONE_NOUSER) == 0)
50 const char *args[] = {gsInitBinary, 0};
51 Proc_Execve(gsInitBinary, args, &args[1], 0);
52 Log_KernelPanic("System", "Unable to spawn init '%s'", gsInitBinary);
55 // Set the debug to be echoed to the terminal
56 Log_Log("Config", "Kernel now echoes to VT7 (Ctrl-Alt-F8)");
57 Debug_SetKTerminal("/Devices/VTerm/7");
61 * \fn void System_ParseCommandLine(char *ArgString)
62 * \brief Parses the kernel's command line and sets the environment
64 void System_ParseCommandLine(char *ArgString)
69 Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
71 // --- Get Arguments ---
73 for( argc = 0; argc < 32; argc++ )
76 while(*str == ' ') str++;
77 // Check for the end of the string
78 if(*str == '\0') { argc--; break;}
81 while(*str && !(*str == '"' && str[-1] != '\\'))
85 while(*str && *str != ' ')
88 if(*str == '\0') break; // Check for EOS
89 *str = '\0'; // Cap off argument string
90 str ++; // and increment the string pointer
93 argc ++; // Count last argument
95 // --- Parse Arguments (Pass 1) ---
96 for( i = 1; i < argc; i++ )
101 // Ignored on this pass
105 // --- Module Paramaters ---
106 // -VTerm:Width=640,Height=480,Scrollback=2
108 System_ParseModuleArgs( argv[i] );
110 // --- Config Options ---
111 // SCRIPT=/Acess/Conf/BootConf.cfg
113 System_ParseSetting( argv[i] );
119 void System_ExecuteCommandLine(void)
123 LOG("Invocation '%s'", argv[0]);
124 for( i = 1; i < argc; i++ )
126 LOG("argv[%i] = '%s'", i, argv[i]);
130 // Mount /System=ext2:/Devices/ATA/A1
131 // Symlink /Acess=/System/Acess2
133 System_ParseVFS( argv[i] );
140 * \fn void System_ParseVFS(char *Arg)
142 void System_ParseVFS(char *Arg)
148 // Search for the '=' token
149 while( *value && *value != '=' )
152 // Check if the equals was found
153 if( *value == '\0' ) {
154 Log_Warning("Config", "Expected '=' in the string '%s'", Arg);
159 *value = '\0'; value ++;
161 // Check assignment type
162 // - Symbolic Link <link>=<destination>
165 Log_Log("Config", "Symbolic link '%s' pointing to '%s'", Arg, value);
166 VFS_Symlink(Arg, value);
168 // - Mount <mountpoint>=<fs>:<device>
173 while(*dev && *dev != ':') dev++;
179 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
180 Log_Log("Config", "Creating directory '%s'", Arg, value);
186 Log_Log("Config", "Mounting '%s' to '%s' ('%s')", dev, Arg, value);
187 VFS_Mount(dev, Arg, value, "");
192 * \brief Parse a module argument string
193 * \param Arg Argument string
195 void System_ParseModuleArgs(char *Arg)
203 // Find the start of the args
204 i = strpos(name, ':');
206 Log_Warning("Config", "Module spec with no arguments");
219 Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
220 Modules_SetBuiltinParams(name, args);
224 * \fn void System_ParseSetting(char *Arg)
226 void System_ParseSetting(char *Arg)
231 // Search for the '=' token
232 while( *value && *value != '=' )
235 // Check for boolean/flag (no '=')
238 //if(strcmp(Arg, "") == 0) {
240 Log_Warning("Config", "Kernel flag '%s' is not recognised", Arg);
245 *value = '\0'; // Remove '='
246 value ++; // and eat it's position
248 if(strcmp(Arg, "INIT") == 0) {
249 Log_Log("Config", "Init binary: '%s'", value);
250 if(strlen(value) == 0)
253 gsInitBinary = value;
256 Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);