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/VTerm/0", VFS_OPENFLAG_READ|VFS_OPENFLAG_USER); // 0: stdin
52 VFS_Open("/Devices/VTerm/0", VFS_OPENFLAG_WRITE|VFS_OPENFLAG_USER); // 1: stdout
53 Proc_Execve(gsInitBinary, args, &args[1], 0);
54 Log_KernelPanic("System", "Unable to spawn init '%s'", gsInitBinary);
57 // Set the debug to be echoed to the terminal
58 Log_Log("Config", "Kernel now echoes to VT7 (Ctrl-Alt-F8)");
59 Debug_SetKTerminal("/Devices/VTerm/7");
63 * \fn void System_ParseCommandLine(char *ArgString)
64 * \brief Parses the kernel's command line and sets the environment
66 void System_ParseCommandLine(char *ArgString)
71 Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
73 // --- Get Arguments ---
75 for( argc = 0; argc < 32; argc++ )
78 while(*str == ' ') str++;
79 // Check for the end of the string
80 if(*str == '\0') { argc--; break;}
83 while(*str && !(*str == '"' && str[-1] != '\\'))
87 while(*str && *str != ' ')
90 if(*str == '\0') break; // Check for EOS
91 *str = '\0'; // Cap off argument string
92 str ++; // and increment the string pointer
95 argc ++; // Count last argument
97 // --- Parse Arguments (Pass 1) ---
98 for( i = 1; i < argc; i++ )
103 // Ignored on this pass
107 // --- Module Paramaters ---
108 // -VTerm:Width=640,Height=480,Scrollback=2
110 System_ParseModuleArgs( argv[i] );
112 // --- Config Options ---
113 // SCRIPT=/Acess/Conf/BootConf.cfg
115 System_ParseSetting( argv[i] );
121 void System_ExecuteCommandLine(void)
125 LOG("Invocation '%s'", argv[0]);
126 for( i = 1; i < argc; i++ )
128 LOG("argv[%i] = '%s'", i, argv[i]);
132 // Mount /System=ext2:/Devices/ATA/A1
133 // Symlink /Acess=/System/Acess2
135 System_ParseVFS( argv[i] );
142 * \fn void System_ParseVFS(char *Arg)
144 void System_ParseVFS(char *Arg)
150 // Search for the '=' token
151 while( *value && *value != '=' )
154 // Check if the equals was found
155 if( *value == '\0' ) {
156 Log_Warning("Config", "Expected '=' in the string '%s'", Arg);
161 *value = '\0'; value ++;
163 // Check assignment type
164 // - Symbolic Link <link>=<destination>
167 // Log_Log("Config", "Symbolic link '%s' pointing to '%s'", Arg, value);
168 VFS_Symlink(Arg, value);
170 // - Mount <mountpoint>=<fs>:<device>
175 while(*dev && *dev != ':') dev++;
181 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
182 // Log_Log("Config", "Creating directory '%s'", Arg, value);
188 // Log_Log("Config", "Mounting '%s' to '%s' ('%s')", dev, Arg, value);
189 VFS_Mount(dev, Arg, value, "");
194 * \brief Parse a module argument string
195 * \param Arg Argument string
197 void System_ParseModuleArgs(char *Arg)
205 // Find the start of the args
206 i = strpos(name, ':');
208 Log_Warning("Config", "Module spec with no arguments");
221 Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
222 Modules_SetBuiltinParams(name, args);
226 * \fn void System_ParseSetting(char *Arg)
228 void System_ParseSetting(char *Arg)
233 // Search for the '=' token
234 while( *value && *value != '=' )
237 // Check for boolean/flag (no '=')
240 //if(strcmp(Arg, "") == 0) {
242 Log_Warning("Config", "Kernel flag '%s' is not recognised", Arg);
247 *value = '\0'; // Remove '='
248 value ++; // and eat it's position
250 if(strcmp(Arg, "INIT") == 0) {
251 Log_Log("Config", "Init binary: '%s'", value);
252 if(strlen(value) == 0)
255 gsInitBinary = value;
258 Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);