28 /* Amount of physical memory, in 4 kB pages. */
32 /* Format the filesystem? */
33 static bool format_filesys;
37 /* Initial program to run. */
38 static char *initial_program;
41 static thread_func main_thread;
42 static void ram_init (void);
43 static void argv_init (void);
48 /* Needed by printk(), so initialize them very early. */
54 printk ("Booting cnachos86 with %'d kB RAM...\n", ram_pages * 4);
56 /* Parse command line. */
59 /* Initialize memory system, segments, paging. */
66 /* Set random seed if not already done. */
69 /* Initialize interrupt handlers. */
74 /* Do everything else in a system thread. */
76 thread_create ("main", main_thread, NULL);
82 main_thread (void *aux UNUSED)
86 filesys_init (format_filesys);
91 if (initial_program != NULL)
92 thread_execute (initial_program);
94 PANIC ("no initial program specified");
98 /* Clear BSS and obtain RAM size from loader. */
102 /* The "BSS" is a segment that should be initialized to zeros.
103 It isn't actually stored on disk or zeroed by the kernel
104 loader, so we have to zero it ourselves.
106 The start and end of the BSS segment is recorded by the
107 linker as _start_bss and _end_bss. See kernel.lds. */
108 extern char _start_bss, _end_bss;
109 memset (&_start_bss, 0, &_end_bss - &_start_bss);
111 /* Get RAM size from loader. See loader.S. */
112 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
115 /* Parses the command line. */
119 char *cmd_line, *pos;
120 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
124 /* The command line is made up of null terminated strings
125 followed by an empty string. Break it up into words. */
126 cmd_line = pos = ptov (LOADER_CMD_LINE);
127 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
129 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
133 pos = strchr (pos, '\0') + 1;
137 /* Parse the words. */
138 for (i = 0; i < argc; i++)
139 if (!strcmp (argv[i], "-rs"))
140 random_init (atoi (argv[++i]));
141 else if (!strcmp (argv[i], "-d"))
142 debug_enable (argv[++i]);
144 else if (!strcmp (argv[i], "-ex"))
145 initial_program = argv[++i];
148 else if (!strcmp (argv[i], "-f"))
149 format_filesys = true;
150 else if (!strcmp (argv[i], "-cp"))
151 fsutil_copy_arg = argv[++i];
152 else if (!strcmp (argv[i], "-p"))
153 fsutil_print_file = argv[++i];
154 else if (!strcmp (argv[i], "-r"))
155 fsutil_remove_file = argv[++i];
156 else if (!strcmp (argv[i], "-ls"))
157 fsutil_list_files = true;
158 else if (!strcmp (argv[i], "-D"))
159 fsutil_dump_filesys = true;
161 else if (!strcmp (argv[i], "-u"))
165 " -rs SEED Seed random seed to SEED.\n"
166 " -d CLASS[,...] Enable the given classes of debug messages.\n"
168 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
171 " -f Format the filesystem disk (hdb or hd0:1).\n"
172 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
173 " or hd1:0) into the filesystem as FILENAME\n"
174 " -p FILENAME Print the contents of FILENAME\n"
175 " -r FILENAME Delete FILENAME\n"
176 " -ls List the files in the filesystem\n"
177 " -D Dump complete filesystem contents\n");
181 PANIC ("unknown option `%s'", argv[i]);