27 /* Amount of physical memory, in 4 kB pages. */
31 /* Format the filesystem? */
32 static bool format_filesys;
36 /* Initial program to run. */
37 static char *initial_program;
40 static void ram_init (void);
41 static void argv_init (void);
44 main_thread (void *aux UNUSED)
48 filesys_init (format_filesys);
53 if (initial_program != NULL)
54 thread_execute (initial_program);
56 PANIC ("no initial program specified");
63 /* Initialize prerequisites for calling printk(). */
69 printk ("Booting cnachos86 with %'d kB RAM...\n", ram_pages * 4);
71 /* Parse command line. */
74 /* Initialize memory system. */
82 /* Initialize interrupt handlers. */
87 /* Do everything else in a system thread. */
89 thread_create ("main", main_thread, NULL);
97 /* The "BSS" is a segment that should be initialized to zeros.
98 It isn't actually stored on disk or zeroed by the kernel
99 loader, so we have to zero it ourselves.
101 The start and end of the BSS segment is recorded by the
102 linker as _start_bss and _end_bss. See kernel.lds. */
103 extern char _start_bss, _end_bss;
104 memset (&_start_bss, 0, &_end_bss - &_start_bss);
106 /* Get RAM size from loader. */
107 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
113 char *cmd_line, *pos;
114 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
118 /* The command line is made up of null terminated strings
119 followed by an empty string. Break it up into words. */
120 cmd_line = pos = ptov (LOADER_CMD_LINE);
121 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
123 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
127 pos = strchr (pos, '\0') + 1;
131 /* Parse the words. */
132 for (i = 0; i < argc; i++)
133 if (!strcmp (argv[i], "-rs"))
134 random_init (atoi (argv[++i]));
135 else if (!strcmp (argv[i], "-d"))
136 debug_enable (argv[++i]);
138 else if (!strcmp (argv[i], "-ex"))
139 initial_program = argv[++i];
142 else if (!strcmp (argv[i], "-f"))
143 format_filesys = true;
144 else if (!strcmp (argv[i], "-cp"))
145 fsutil_copy_arg = argv[++i];
146 else if (!strcmp (argv[i], "-p"))
147 fsutil_print_file = argv[++i];
148 else if (!strcmp (argv[i], "-r"))
149 fsutil_remove_file = argv[++i];
150 else if (!strcmp (argv[i], "-ls"))
151 fsutil_list_files = true;
152 else if (!strcmp (argv[i], "-D"))
153 fsutil_dump_filesys = true;
155 else if (!strcmp (argv[i], "-u"))
159 " -rs SEED Seed random seed to SEED.\n"
160 " -d CLASS[,...] Enable the given classes of debug messages.\n"
162 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
165 " -f Format the filesystem disk (hdb or hd0:1).\n"
166 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
167 " or hd1:0) into the filesystem as FILENAME\n"
168 " -p FILENAME Print the contents of FILENAME\n"
169 " -r FILENAME Delete FILENAME\n"
170 " -ls List the files in the filesystem\n"
171 " -D Dump complete filesystem contents\n");
175 PANIC ("unknown option `%s'", argv[i]);