1 #include "threads/init.h"
10 #include "devices/kbd.h"
11 #include "devices/serial.h"
12 #include "devices/timer.h"
13 #include "devices/vga.h"
14 #include "threads/interrupt.h"
15 #include "threads/io.h"
16 #include "threads/loader.h"
17 #include "threads/malloc.h"
18 #include "threads/mmu.h"
19 #include "threads/paging.h"
20 #include "threads/palloc.h"
21 #include "threads/test.h"
22 #include "threads/thread.h"
24 #include "userprog/exception.h"
25 #include "userprog/gdt.h"
26 #include "userprog/syscall.h"
27 #include "userprog/tss.h"
30 #include "devices/disk.h"
31 #include "filesys/filesys.h"
32 #include "filesys/fsutil.h"
35 /* Amount of physical memory, in 4 kB pages. */
39 /* Format the filesystem? */
40 static bool format_filesys;
44 /* Initial program to run. */
45 static char *initial_program;
48 static void ram_init (void);
49 static void argv_init (void);
51 int main (void) NO_RETURN;
56 /* Needed by printf(), so initialize them very early. */
62 printf ("Pintos booting with %'d kB RAM...\n", ram_pages * 4);
64 /* Parse command line. */
67 /* Initialize memory system, segments, paging. */
77 /* Set random seed if not already done. */
80 /* Initialize interrupt handlers. */
89 /* Start thread scheduler and enable interrupts. */
94 /* Initialize filesystem. */
96 filesys_init (format_filesys);
100 printf ("Boot complete.\n");
103 /* Run a user program. */
104 if (initial_program != NULL)
106 printf ("\nExecuting '%s':\n", initial_program);
107 thread_execute (initial_program);
113 /* Terminate this thread. */
117 /* Clear BSS and obtain RAM size from loader. */
121 /* The "BSS" is a segment that should be initialized to zeros.
122 It isn't actually stored on disk or zeroed by the kernel
123 loader, so we have to zero it ourselves.
125 The start and end of the BSS segment is recorded by the
126 linker as _start_bss and _end_bss. See kernel.lds. */
127 extern char _start_bss, _end_bss;
128 memset (&_start_bss, 0, &_end_bss - &_start_bss);
130 /* Get RAM size from loader. See loader.S. */
131 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
134 /* Parses the command line. */
138 char *cmd_line, *pos;
139 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
143 /* The command line is made up of null terminated strings
144 followed by an empty string. Break it up into words. */
145 cmd_line = pos = ptov (LOADER_CMD_LINE);
146 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
148 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
152 pos = strchr (pos, '\0') + 1;
156 /* Parse the words. */
157 for (i = 0; i < argc; i++)
158 if (!strcmp (argv[i], "-rs"))
159 random_init (atoi (argv[++i]));
160 else if (!strcmp (argv[i], "-d"))
161 debug_enable (argv[++i]);
163 else if (!strcmp (argv[i], "-ex"))
164 initial_program = argv[++i];
167 else if (!strcmp (argv[i], "-f"))
168 format_filesys = true;
169 else if (!strcmp (argv[i], "-cp"))
170 fsutil_copy_arg = argv[++i];
171 else if (!strcmp (argv[i], "-p"))
172 fsutil_print_file = argv[++i];
173 else if (!strcmp (argv[i], "-r"))
174 fsutil_remove_file = argv[++i];
175 else if (!strcmp (argv[i], "-ls"))
176 fsutil_list_files = true;
177 else if (!strcmp (argv[i], "-D"))
178 fsutil_dump_filesys = true;
180 else if (!strcmp (argv[i], "-u"))
184 " -rs SEED Seed random seed to SEED.\n"
185 " -d CLASS[,...] Enable the given classes of debug messages.\n"
187 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
190 " -f Format the filesystem disk (hdb or hd0:1).\n"
191 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
192 " or hd1:0) into the filesystem as FILENAME\n"
193 " -p FILENAME Print the contents of FILENAME\n"
194 " -r FILENAME Delete FILENAME\n"
195 " -ls List the files in the filesystem\n"
196 " -D Dump complete filesystem contents\n"
201 PANIC ("unknown option `%s'", argv[i]);