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);
15 extern void Timer_CallbackThread(void *);
18 void System_Init(char *Commandline);
19 void System_ParseCommandLine(char *ArgString);
20 void System_ExecuteCommandLine(void);
21 void System_ParseVFS(char *Arg);
22 void System_ParseModuleArgs(char *Arg);
23 void System_ParseSetting(char *Arg);
26 const char *gsInitBinary = "/Acess/SBin/init";
31 void System_Init(char *CommandLine)
33 Proc_SpawnWorker(Timer_CallbackThread, NULL);
35 // Parse Kernel's Command Line
36 System_ParseCommandLine(CommandLine);
39 Log_Log("Config", "Initialising builtin modules...");
40 Modules_LoadBuiltins();
41 Arch_LoadBootModules();
43 System_ExecuteCommandLine();
45 // - Execute the Config Script
46 Log_Log("Config", "Spawning init '%s'", gsInitBinary);
47 Proc_Spawn(gsInitBinary);
49 // Set the debug to be echoed to the terminal
50 Log_Log("Config", "Kernel now echoes to VT7 (Ctrl-Alt-F8)");
51 Debug_SetKTerminal("/Devices/VTerm/7");
55 * \fn void System_ParseCommandLine(char *ArgString)
56 * \brief Parses the kernel's command line and sets the environment
58 void System_ParseCommandLine(char *ArgString)
63 Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
65 // --- Get Arguments ---
67 for( argc = 0; argc < 32; argc++ )
70 while(*str == ' ') str++;
71 // Check for the end of the string
72 if(*str == '\0') { argc--; break;}
75 while(*str && !(*str == '"' && str[-1] != '\\'))
79 while(*str && *str != ' ')
82 if(*str == '\0') break; // Check for EOS
83 *str = '\0'; // Cap off argument string
84 str ++; // and increment the string pointer
87 argc ++; // Count last argument
89 // --- Parse Arguments (Pass 1) ---
90 for( i = 1; i < argc; i++ )
95 // Ignored on this pass
99 // --- Module Paramaters ---
100 // -VTerm:Width=640,Height=480,Scrollback=2
102 System_ParseModuleArgs( argv[i] );
104 // --- Config Options ---
105 // SCRIPT=/Acess/Conf/BootConf.cfg
107 System_ParseSetting( argv[i] );
113 void System_ExecuteCommandLine(void)
117 LOG("Invocation '%s'", argv[0]);
118 for( i = 1; i < argc; i++ )
120 LOG("argv[%i] = '%s'", i, argv[i]);
124 // Mount /System=ext2:/Devices/ATA/A1
125 // Symlink /Acess=/System/Acess2
127 System_ParseVFS( argv[i] );
134 * \fn void System_ParseVFS(char *Arg)
136 void System_ParseVFS(char *Arg)
142 // Search for the '=' token
143 while( *value && *value != '=' )
146 // Check if the equals was found
147 if( *value == '\0' ) {
148 Log_Warning("Config", "Expected '=' in the string '%s'", Arg);
153 *value = '\0'; value ++;
155 // Check assignment type
156 // - Symbolic Link <link>=<destination>
159 Log_Log("Config", "Symbolic link '%s' pointing to '%s'", Arg, value);
160 VFS_Symlink(Arg, value);
162 // - Mount <mountpoint>=<fs>:<device>
167 while(*dev && *dev != ':') dev++;
173 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
174 Log_Log("Config", "Creating directory '%s'", Arg, value);
180 Log_Log("Config", "Mounting '%s' to '%s' ('%s')", dev, Arg, value);
181 VFS_Mount(dev, Arg, value, "");
186 * \brief Parse a module argument string
187 * \param Arg Argument string
189 void System_ParseModuleArgs(char *Arg)
197 // Find the start of the args
198 i = strpos(name, ':');
200 Log_Warning("Config", "Module spec with no arguments");
213 Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
214 Modules_SetBuiltinParams(name, args);
218 * \fn void System_ParseSetting(char *Arg)
220 void System_ParseSetting(char *Arg)
225 // Search for the '=' token
226 while( *value && *value != '=' )
229 // Check for boolean/flag (no '=')
232 //if(strcmp(Arg, "") == 0) {
234 Log_Warning("Config", "Kernel flag '%s' is not recognised", Arg);
239 *value = '\0'; // Remove '='
240 value ++; // and eat it's position
242 if(strcmp(Arg, "INIT") == 0) {
243 Log_Log("Config", "Init binary: '%s'", value);
244 if(strlen(value) == 0)
247 gsInitBinary = value;
250 Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);