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 void ram_init (void);
45 static void argv_init (void);
47 int main (void) NO_RETURN;
52 /* Needed by printk(), so initialize them very early. */
58 printk ("Booting cnachos86 with %'d kB RAM...\n", ram_pages * 4);
60 /* Parse command line. */
63 /* Initialize memory system, segments, paging. */
73 /* Set random seed if not already done. */
76 /* Initialize interrupt handlers. */
84 /* Start thread scheduler and enable interrupts. */
88 /* Initialize filesystem. */
90 filesys_init (format_filesys);
94 printk ("Boot complete.\n");
97 /* Run a user program. */
98 if (initial_program != NULL)
100 printk ("\nExecuting '%s':\n", initial_program);
101 thread_execute (initial_program);
105 /* Terminate this thread. */
109 /* Clear BSS and obtain RAM size from loader. */
113 /* The "BSS" is a segment that should be initialized to zeros.
114 It isn't actually stored on disk or zeroed by the kernel
115 loader, so we have to zero it ourselves.
117 The start and end of the BSS segment is recorded by the
118 linker as _start_bss and _end_bss. See kernel.lds. */
119 extern char _start_bss, _end_bss;
120 memset (&_start_bss, 0, &_end_bss - &_start_bss);
122 /* Get RAM size from loader. See loader.S. */
123 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
126 /* Parses the command line. */
130 char *cmd_line, *pos;
131 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
135 /* The command line is made up of null terminated strings
136 followed by an empty string. Break it up into words. */
137 cmd_line = pos = ptov (LOADER_CMD_LINE);
138 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
140 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
144 pos = strchr (pos, '\0') + 1;
148 /* Parse the words. */
149 for (i = 0; i < argc; i++)
150 if (!strcmp (argv[i], "-rs"))
151 random_init (atoi (argv[++i]));
152 else if (!strcmp (argv[i], "-d"))
153 debug_enable (argv[++i]);
155 else if (!strcmp (argv[i], "-ex"))
156 initial_program = argv[++i];
159 else if (!strcmp (argv[i], "-f"))
160 format_filesys = true;
161 else if (!strcmp (argv[i], "-cp"))
162 fsutil_copy_arg = argv[++i];
163 else if (!strcmp (argv[i], "-p"))
164 fsutil_print_file = argv[++i];
165 else if (!strcmp (argv[i], "-r"))
166 fsutil_remove_file = argv[++i];
167 else if (!strcmp (argv[i], "-ls"))
168 fsutil_list_files = true;
169 else if (!strcmp (argv[i], "-D"))
170 fsutil_dump_filesys = true;
172 else if (!strcmp (argv[i], "-u"))
176 " -rs SEED Seed random seed to SEED.\n"
177 " -d CLASS[,...] Enable the given classes of debug messages.\n"
179 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
182 " -f Format the filesystem disk (hdb or hd0:1).\n"
183 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
184 " or hd1:0) into the filesystem as FILENAME\n"
185 " -p FILENAME Print the contents of FILENAME\n"
186 " -r FILENAME Delete FILENAME\n"
187 " -ls List the files in the filesystem\n"
188 " -D Dump complete filesystem contents\n"
193 PANIC ("unknown option `%s'", argv[i]);