3 * - By John Hodge (thePowersGang)
5 * - Architecture Independent System Init
11 extern void Arch_LoadBootModules(void);
12 extern int Modules_LoadBuiltins(void);
13 extern void Modules_SetBuiltinParams(char *Name, char *ArgString);
14 extern void Debug_SetKTerminal(const char *File);
17 void System_Init(char *Commandline);
18 void System_ParseCommandLine(char *ArgString);
19 void System_ExecuteCommandLine(void);
20 void System_ParseVFS(char *Arg);
21 void System_ParseModuleArgs(char *Arg);
22 void System_ParseSetting(char *Arg);
25 const char *gsInitBinary = "/Acess/SBin/init";
30 void System_Init(char *CommandLine)
32 // Parse Kernel's Command Line
33 System_ParseCommandLine(CommandLine);
36 Log_Log("Config", "Initialising builtin modules...");
37 Modules_LoadBuiltins();
38 Arch_LoadBootModules();
40 System_ExecuteCommandLine();
42 // - Execute the Config Script
43 Log_Log("Config", "Spawning init '%s'", gsInitBinary);
44 Proc_Spawn(gsInitBinary);
46 // Set the debug to be echoed to the terminal
47 Log_Log("Config", "Kernel now echoes to VT7 (Ctrl-Alt-F8)");
48 Debug_SetKTerminal("/Devices/VTerm/7");
52 * \fn void System_ParseCommandLine(char *ArgString)
53 * \brief Parses the kernel's command line and sets the environment
55 void System_ParseCommandLine(char *ArgString)
60 Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
62 // --- Get Arguments ---
64 for( argc = 0; argc < 32; argc++ )
67 while(*str == ' ') str++;
68 // Check for the end of the string
69 if(*str == '\0') { argc--; break;}
72 while(*str && !(*str == '"' && str[-1] != '\\'))
76 while(*str && *str != ' ')
79 if(*str == '\0') break; // Check for EOS
80 *str = '\0'; // Cap off argument string
81 str ++; // and increment the string pointer
84 argc ++; // Count last argument
86 // --- Parse Arguments (Pass 1) ---
87 for( i = 1; i < argc; i++ )
92 // Ignored on this pass
96 // --- Module Paramaters ---
97 // -VTerm:Width=640,Height=480,Scrollback=2
99 System_ParseModuleArgs( argv[i] );
101 // --- Config Options ---
102 // SCRIPT=/Acess/Conf/BootConf.cfg
104 System_ParseSetting( argv[i] );
110 void System_ExecuteCommandLine(void)
114 LOG("Invocation '%s'", argv[0]);
115 for( i = 1; i < argc; i++ )
117 LOG("argv[%i] = '%s'", i, argv[i]);
121 // Mount /System=ext2:/Devices/ATA/A1
122 // Symlink /Acess=/System/Acess2
124 System_ParseVFS( argv[i] );
131 * \fn void System_ParseVFS(char *Arg)
133 void System_ParseVFS(char *Arg)
139 // Search for the '=' token
140 while( *value && *value != '=' )
143 // Check if the equals was found
144 if( *value == '\0' ) {
145 Log_Warning("Config", "Expected '=' in the string '%s'", Arg);
150 *value = '\0'; value ++;
152 // Check assignment type
153 // - Symbolic Link <link>=<destination>
156 Log_Log("Config", "Symbolic link '%s' pointing to '%s'", Arg, value);
157 VFS_Symlink(Arg, value);
159 // - Mount <mountpoint>=<fs>:<device>
164 while(*dev && *dev != ':') dev++;
170 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
171 Log_Log("Config", "Creating directory '%s'", Arg, value);
177 Log_Log("Config", "Mounting '%s' to '%s' ('%s')", dev, Arg, value);
178 VFS_Mount(dev, Arg, value, "");
183 * \brief Parse a module argument string
184 * \param Arg Argument string
186 void System_ParseModuleArgs(char *Arg)
194 // Find the start of the args
195 i = strpos(name, ':');
197 Log_Warning("Config", "Module spec with no arguments");
210 Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
211 Modules_SetBuiltinParams(name, args);
215 * \fn void System_ParseSetting(char *Arg)
217 void System_ParseSetting(char *Arg)
222 // Search for the '=' token
223 while( *value && *value != '=' )
226 // Check for boolean/flag (no '=')
229 //if(strcmp(Arg, "") == 0) {
231 Log_Warning("Config", "Kernel flag '%s' is not recognised", Arg);
236 *value = '\0'; // Remove '='
237 value ++; // and eat it's position
239 if(strcmp(Arg, "INIT") == 0) {
240 Log_Log("Config", "Init binary: '%s'", value);
241 if(strlen(value) == 0)
244 gsInitBinary = value;
247 Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);