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 void ram_init (void);
42 static void argv_init (void);
45 main_thread (void *aux UNUSED)
49 filesys_init (format_filesys);
54 if (initial_program != NULL)
55 thread_execute (initial_program);
57 PANIC ("no initial program specified");
64 /* Initialize prerequisites for calling printk(). */
70 printk ("Booting cnachos86 with %'d kB RAM...\n", ram_pages * 4);
72 /* Parse command line. */
75 /* Initialize memory system. */
84 /* Initialize interrupt handlers. */
89 /* Do everything else in a system thread. */
91 thread_create ("main", main_thread, NULL);
99 /* The "BSS" is a segment that should be initialized to zeros.
100 It isn't actually stored on disk or zeroed by the kernel
101 loader, so we have to zero it ourselves.
103 The start and end of the BSS segment is recorded by the
104 linker as _start_bss and _end_bss. See kernel.lds. */
105 extern char _start_bss, _end_bss;
106 memset (&_start_bss, 0, &_end_bss - &_start_bss);
108 /* Get RAM size from loader. */
109 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
115 char *cmd_line, *pos;
116 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
120 /* The command line is made up of null terminated strings
121 followed by an empty string. Break it up into words. */
122 cmd_line = pos = ptov (LOADER_CMD_LINE);
123 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
125 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
129 pos = strchr (pos, '\0') + 1;
133 /* Parse the words. */
134 for (i = 0; i < argc; i++)
135 if (!strcmp (argv[i], "-rs"))
136 random_init (atoi (argv[++i]));
137 else if (!strcmp (argv[i], "-d"))
138 debug_enable (argv[++i]);
140 else if (!strcmp (argv[i], "-ex"))
141 initial_program = argv[++i];
144 else if (!strcmp (argv[i], "-f"))
145 format_filesys = true;
146 else if (!strcmp (argv[i], "-cp"))
147 fsutil_copy_arg = argv[++i];
148 else if (!strcmp (argv[i], "-p"))
149 fsutil_print_file = argv[++i];
150 else if (!strcmp (argv[i], "-r"))
151 fsutil_remove_file = argv[++i];
152 else if (!strcmp (argv[i], "-ls"))
153 fsutil_list_files = true;
154 else if (!strcmp (argv[i], "-D"))
155 fsutil_dump_filesys = true;
157 else if (!strcmp (argv[i], "-u"))
161 " -rs SEED Seed random seed to SEED.\n"
162 " -d CLASS[,...] Enable the given classes of debug messages.\n"
164 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
167 " -f Format the filesystem disk (hdb or hd0:1).\n"
168 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
169 " or hd1:0) into the filesystem as FILENAME\n"
170 " -p FILENAME Print the contents of FILENAME\n"
171 " -r FILENAME Delete FILENAME\n"
172 " -ls List the files in the filesystem\n"
173 " -D Dump complete filesystem contents\n");
177 PANIC ("unknown option `%s'", argv[i]);