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");
64 * \fn void System_ParseCommandLine(char *ArgString)
65 * \brief Parses the kernel's command line and sets the environment
67 void System_ParseCommandLine(char *ArgString)
72 Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
74 // --- Get Arguments ---
76 for( argc = 0; argc < 32; argc++ )
79 while(*str == ' ') str++;
80 // Check for the end of the string
87 while(*str && !(*str == '"' && str[-1] != '\\'))
91 while(*str && *str != ' ')
94 if(*str == '\0') break; // Check for EOS
95 *str = '\0'; // Cap off argument string
96 str ++; // and increment the string pointer
99 argc ++; // Count last argument
101 // --- Parse Arguments (Pass 1) ---
102 for( i = 1; i < argc; i++ )
107 // Ignored on this pass
111 // --- Module Paramaters ---
112 // -VTerm:Width=640,Height=480,Scrollback=2
114 System_ParseModuleArgs( argv[i] );
116 // --- Config Options ---
117 // SCRIPT=/Acess/Conf/BootConf.cfg
119 System_ParseSetting( argv[i] );
125 void System_ExecuteCommandLine(void)
129 LOG("Invocation '%s'", argv[0]);
130 for( i = 1; i < argc; i++ )
132 LOG("argv[%i] = '%s'", i, argv[i]);
136 // Mount /System=ext2:/Devices/ATA/A1
137 // Symlink /Acess=/System/Acess2
139 System_ParseVFS( argv[i] );
146 * \fn void System_ParseVFS(char *Arg)
148 void System_ParseVFS(char *Arg)
154 // Search for the '=' token
155 while( *value && *value != '=' )
158 // Check if the equals was found
159 if( *value == '\0' ) {
160 Log_Warning("Config", "Expected '=' in the string '%s'", Arg);
165 *value = '\0'; value ++;
167 // Check assignment type
168 // - Symbolic Link <link>=<destination>
171 // Log_Log("Config", "Symbolic link '%s' pointing to '%s'", Arg, value);
172 VFS_Symlink(Arg, value);
174 // - Mount <mountpoint>=<fs>:<device>
179 while(*dev && *dev != ':') dev++;
185 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
186 // Log_Log("Config", "Creating directory '%s'", Arg, value);
192 // Log_Log("Config", "Mounting '%s' to '%s' ('%s')", dev, Arg, value);
193 VFS_Mount(dev, Arg, value, "");
198 * \brief Parse a module argument string
199 * \param Arg Argument string
201 void System_ParseModuleArgs(char *Arg)
209 // Find the start of the args
210 i = strpos(name, ':');
212 Log_Warning("Config", "Module spec with no arguments");
225 Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
226 Modules_SetBuiltinParams(name, args);
230 * \fn void System_ParseSetting(char *Arg)
232 void System_ParseSetting(char *Arg)
237 // Search for the '=' token
238 while( *value && *value != '=' )
241 // Check for boolean/flag (no '=')
244 //if(strcmp(Arg, "") == 0) {
246 Log_Warning("Config", "Kernel flag '%s' is not recognised", Arg);
251 *value = '\0'; // Remove '='
252 value ++; // and eat it's position
254 if(strcmp(Arg, "INIT") == 0) {
255 Log_Log("Config", "Init binary: '%s'", value);
256 if(strlen(value) == 0)
259 gsInitBinary = value;
262 Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);