1 #include "threads/init.h"
11 #include "devices/kbd.h"
12 #include "devices/serial.h"
13 #include "devices/timer.h"
14 #include "devices/vga.h"
15 #include "threads/interrupt.h"
16 #include "threads/io.h"
17 #include "threads/loader.h"
18 #include "threads/malloc.h"
19 #include "threads/mmu.h"
20 #include "threads/paging.h"
21 #include "threads/palloc.h"
22 #include "threads/test.h"
23 #include "threads/thread.h"
25 #include "userprog/exception.h"
26 #include "userprog/gdt.h"
27 #include "userprog/syscall.h"
28 #include "userprog/tss.h"
31 #include "devices/disk.h"
32 #include "filesys/filesys.h"
33 #include "filesys/fsutil.h"
36 /* Amount of physical memory, in 4 kB pages. */
40 /* Format the filesystem? */
41 static bool format_filesys;
45 /* Initial program to run. */
46 static char *initial_program;
49 static void ram_init (void);
50 static void argv_init (void);
52 int main (void) NO_RETURN;
57 /* Initialize everything needed for printf() first. */
65 printf ("Pintos booting with %'d kB RAM...\n", ram_pages * 4);
67 /* Parse command line. */
70 /* Initialize memory system, segments, paging. */
79 /* Set random seed if argv_init() didn't. */
82 /* Initialize interrupt handlers. */
91 /* Start thread scheduler and enable interrupts. */
96 /* Initialize filesystem. */
98 filesys_init (format_filesys);
102 printf ("Boot complete.\n");
105 /* Run a user program. */
106 if (initial_program != NULL)
108 printf ("\nExecuting '%s':\n", initial_program);
109 thread_execute (initial_program);
115 /* Terminate this thread. */
119 /* Clear BSS and obtain RAM size from loader. */
123 /* The "BSS" is a segment that should be initialized to zeros.
124 It isn't actually stored on disk or zeroed by the kernel
125 loader, so we have to zero it ourselves.
127 The start and end of the BSS segment is recorded by the
128 linker as _start_bss and _end_bss. See kernel.lds. */
129 extern char _start_bss, _end_bss;
130 memset (&_start_bss, 0, &_end_bss - &_start_bss);
132 /* Get RAM size from loader. See loader.S. */
133 ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES);
136 /* Parses the command line. */
140 char *cmd_line, *pos;
141 char *argv[LOADER_CMD_LINE_LEN / 2 + 1];
145 /* The command line is made up of null terminated strings
146 followed by an empty string. Break it up into words. */
147 cmd_line = pos = ptov (LOADER_CMD_LINE);
148 while (pos < cmd_line + LOADER_CMD_LINE_LEN)
150 ASSERT (argc < LOADER_CMD_LINE_LEN / 2);
154 pos = strchr (pos, '\0') + 1;
158 /* Parse the words. */
159 for (i = 0; i < argc; i++)
160 if (!strcmp (argv[i], "-rs"))
161 random_init (atoi (argv[++i]));
162 else if (!strcmp (argv[i], "-d"))
163 debug_enable (argv[++i]);
165 else if (!strcmp (argv[i], "-ex"))
166 initial_program = argv[++i];
169 else if (!strcmp (argv[i], "-f"))
170 format_filesys = true;
171 else if (!strcmp (argv[i], "-cp"))
172 fsutil_copy_arg = argv[++i];
173 else if (!strcmp (argv[i], "-p"))
174 fsutil_print_file = argv[++i];
175 else if (!strcmp (argv[i], "-r"))
176 fsutil_remove_file = argv[++i];
177 else if (!strcmp (argv[i], "-ls"))
178 fsutil_list_files = true;
179 else if (!strcmp (argv[i], "-D"))
180 fsutil_dump_filesys = true;
182 else if (!strcmp (argv[i], "-u"))
186 " -rs SEED Seed random seed to SEED.\n"
187 " -d CLASS[,...] Enable the given classes of debug messages.\n"
189 " -ex 'PROG [ARG...]' Run PROG, passing the optional arguments.\n"
192 " -f Format the filesystem disk (hdb or hd0:1).\n"
193 " -cp FILENAME:SIZE Copy SIZE bytes from the scratch disk (hdc\n"
194 " or hd1:0) into the filesystem as FILENAME\n"
195 " -p FILENAME Print the contents of FILENAME\n"
196 " -r FILENAME Delete FILENAME\n"
197 " -ls List the files in the filesystem\n"
198 " -D Dump complete filesystem contents\n"
203 PANIC ("unknown option `%s'", argv[i]);