21 #include "exception.h"
31 /* Amount of physical memory, in 4 kB pages. */
35 /* Format the filesystem? */
36 static bool format_filesys;
40 /* Initial program to run. */
41 static char *initial_program;
44 static thread_func main_thread;
45 static void ram_init (void);
46 static void argv_init (void);
51 /* Needed by printk(), so initialize them very early. */
57 printk ("Booting cnachos86 with %'d kB RAM...\n", ram_pages * 4);
59 /* Parse command line. */
62 /* Initialize memory system, segments, paging. */
71 /* Set random seed if not already done. */
74 /* Initialize interrupt handlers. */
82 /* Do everything else in a system thread. */
84 thread_create ("main", main_thread, NULL);
90 main_thread (void *aux UNUSED)
94 filesys_init (format_filesys);
99 if (initial_program != NULL)
100 thread_execute (initial_program);
102 PANIC ("no initial program specified");
104 PANIC ("boot successful");
108 /* Clear BSS and obtain RAM size from loader. */
112 /* The "BSS" is a segment that should be initialized to zeros.
113 It isn't actually stored on disk or zeroed by the kernel
114 loader, so we have to zero it ourselves.
116 The start and end of the BSS segment is recorded by the
117 linker as _start_bss and _end_bss. See kernel.lds. */
118 extern char _start_bss, _end_bss;
119 memset (&_start_bss, 0, &_end_bss - &_start_bss);
121 /* Get RAM size from loader. See loader.S. */
122 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
125 /* Parses the command line. */
129 char *cmd_line, *pos;
130 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
134 /* The command line is made up of null terminated strings
135 followed by an empty string. Break it up into words. */
136 cmd_line = pos = ptov (LOADER_CMD_LINE);
137 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
139 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
143 pos = strchr (pos, '\0') + 1;
147 /* Parse the words. */
148 for (i = 0; i < argc; i++)
149 if (!strcmp (argv[i], "-rs"))
150 random_init (atoi (argv[++i]));
151 else if (!strcmp (argv[i], "-d"))
152 debug_enable (argv[++i]);
154 else if (!strcmp (argv[i], "-ex"))
155 initial_program = argv[++i];
158 else if (!strcmp (argv[i], "-f"))
159 format_filesys = true;
160 else if (!strcmp (argv[i], "-cp"))
161 fsutil_copy_arg = argv[++i];
162 else if (!strcmp (argv[i], "-p"))
163 fsutil_print_file = argv[++i];
164 else if (!strcmp (argv[i], "-r"))
165 fsutil_remove_file = argv[++i];
166 else if (!strcmp (argv[i], "-ls"))
167 fsutil_list_files = true;
168 else if (!strcmp (argv[i], "-D"))
169 fsutil_dump_filesys = true;
171 else if (!strcmp (argv[i], "-u"))
175 " -rs SEED Seed random seed to SEED.\n"
176 " -d CLASS[,...] Enable the given classes of debug messages.\n"
178 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
181 " -f Format the filesystem disk (hdb or hd0:1).\n"
182 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
183 " or hd1:0) into the filesystem as FILENAME\n"
184 " -p FILENAME Print the contents of FILENAME\n"
185 " -r FILENAME Delete FILENAME\n"
186 " -ls List the files in the filesystem\n"
187 " -D Dump complete filesystem contents\n"
192 PANIC ("unknown option `%s'", argv[i]);