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 VFS_Open("/Devices/pts/vt0", VFS_OPENFLAG_READ|VFS_OPENFLAG_USER); // 0: stdin
52 VFS_Open("/Devices/pts/vt0", VFS_OPENFLAG_WRITE|VFS_OPENFLAG_USER); // 1: stdout
53 VFS_DuplicateFD(1, 2); // 2: stderr
54 Proc_Execve(gsInitBinary, args, &args[1], 0);
55 Log_KernelPanic("System", "Unable to spawn init '%s'", gsInitBinary);
58 // Set the debug to be echoed to the terminal
59 Log_Log("Config", "Kernel now echoes to VT7 (Ctrl-Alt-F8)");
60 Debug_SetKTerminal("/Devices/pts/vt7");
62 // Run a thread to reap unowned threads
66 // TODO: Inform init when a thread dies
67 int tid = Threads_WaitTID(-1, &status);
68 Log_Debug("Thread0", "Thread %i exited with status %i", tid, status);
73 * \fn void System_ParseCommandLine(char *ArgString)
74 * \brief Parses the kernel's command line and sets the environment
76 void System_ParseCommandLine(char *ArgString)
81 Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
83 // --- Get Arguments ---
85 for( argc = 0; argc < 32; argc++ )
88 while(*str == ' ') str++;
89 // Check for the end of the string
96 while(*str && !(*str == '"' && str[-1] != '\\'))
100 while(*str && *str != ' ')
103 if(*str == '\0') break; // Check for EOS
104 *str = '\0'; // Cap off argument string
105 str ++; // and increment the string pointer
108 argc ++; // Count last argument
110 // --- Parse Arguments (Pass 1) ---
111 for( i = 1; i < argc; i++ )
116 // Ignored on this pass
120 // --- Module Paramaters ---
121 // -VTerm:Width=640,Height=480,Scrollback=2
123 System_ParseModuleArgs( argv[i] );
125 // --- Config Options ---
126 // SCRIPT=/Acess/Conf/BootConf.cfg
128 System_ParseSetting( argv[i] );
134 void System_ExecuteCommandLine(void)
138 LOG("Invocation '%s'", argv[0]);
139 for( i = 1; i < argc; i++ )
141 LOG("argv[%i] = '%s'", i, argv[i]);
145 // Mount /System=ext2:/Devices/ATA/A1
146 // Symlink /Acess=/System/Acess2
148 System_ParseVFS( argv[i] );
155 * \fn void System_ParseVFS(char *Arg)
157 void System_ParseVFS(char *Arg)
163 // Search for the '=' token
164 while( *value && *value != '=' )
167 // Check if the equals was found
168 if( *value == '\0' ) {
169 Log_Warning("Config", "Expected '=' in the string '%s'", Arg);
174 *value = '\0'; value ++;
176 // Check assignment type
177 // - Symbolic Link <link>=<destination>
180 // Log_Log("Config", "Symbolic link '%s' pointing to '%s'", Arg, value);
181 VFS_Symlink(Arg, value);
183 // - Mount <mountpoint>=<fs>:<device>
188 while(*dev && *dev != ':') dev++;
194 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
195 // Log_Log("Config", "Creating directory '%s'", Arg, value);
201 // Log_Log("Config", "Mounting '%s' to '%s' ('%s')", dev, Arg, value);
202 VFS_Mount(dev, Arg, value, "");
207 * \brief Parse a module argument string
208 * \param Arg Argument string
210 void System_ParseModuleArgs(char *Arg)
218 // Find the start of the args
219 i = strpos(name, ':');
221 Log_Warning("Config", "Module spec with no arguments");
234 Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
235 Modules_SetBuiltinParams(name, args);
239 * \fn void System_ParseSetting(char *Arg)
241 void System_ParseSetting(char *Arg)
246 // Search for the '=' token
247 while( *value && *value != '=' )
250 // Check for boolean/flag (no '=')
253 //if(strcmp(Arg, "") == 0) {
255 Log_Warning("Config", "Kernel flag '%s' is not recognised", Arg);
260 *value = '\0'; // Remove '='
261 value ++; // and eat it's position
263 if(strcmp(Arg, "INIT") == 0) {
264 Log_Log("Config", "Init binary: '%s'", value);
265 if(strlen(value) == 0)
268 gsInitBinary = value;
271 Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);