X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Finit.c;h=9ab04476741e4f4580afc15ed454e71e34a237e6;hb=b6b1e6db07a20a0b3025c2ae62a58e80c1af841b;hp=ae864981341d110464c59985d3ccd94e8acf193a;hpb=5fbedf1d20c2b2f2dbc8c7ebd64cc7b4812a44bf;p=pintos-anon diff --git a/src/threads/init.c b/src/threads/init.c index ae86498..9ab0447 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -1,28 +1,36 @@ -#include "init.h" -#include -#include +#include "threads/init.h" +#include +#include #include -#include "debug.h" -#include "gdt.h" -#include "interrupt.h" -#include "io.h" -#include "kbd.h" -#include "lib.h" -#include "loader.h" -#include "malloc.h" -#include "mmu.h" -#include "paging.h" -#include "palloc.h" -#include "random.h" -#include "serial.h" -#include "thread.h" -#include "timer.h" -#include "tss.h" -#include "vga.h" +#include +#include +#include +#include +#include +#include +#include "devices/kbd.h" +#include "devices/serial.h" +#include "devices/timer.h" +#include "devices/vga.h" +#include "threads/interrupt.h" +#include "threads/io.h" +#include "threads/loader.h" +#include "threads/malloc.h" +#include "threads/mmu.h" +#include "threads/paging.h" +#include "threads/palloc.h" +#include "threads/test.h" +#include "threads/thread.h" +#ifdef USERPROG +#include "userprog/exception.h" +#include "userprog/gdt.h" +#include "userprog/syscall.h" +#include "userprog/tss.h" +#endif #ifdef FILESYS -#include "filesys.h" -#include "disk.h" -#include "fsutil.h" +#include "devices/disk.h" +#include "filesys/filesys.h" +#include "filesys/fsutil.h" #endif /* Amount of physical memory, in 4 kB pages. */ @@ -38,20 +46,23 @@ static bool format_filesys; static char *initial_program; #endif -static thread_func main_thread; static void ram_init (void); static void argv_init (void); +int main (void) NO_RETURN; + int main (void) { - /* Needed by printk(), so initialize them very early. */ + /* Initialize everything needed for printf() first. */ ram_init (); + thread_init (); vga_init (); - serial_init (); + serial_init_poll (); + console_init (); /* Greet user. */ - printk ("Booting cnachos86 with %'d kB RAM...\n", ram_pages * 4); + printf ("Pintos booting with %'d kB RAM...\n", ram_pages * (PGSIZE / 1024)); /* Parse command line. */ argv_init (); @@ -59,40 +70,50 @@ main (void) /* Initialize memory system, segments, paging. */ palloc_init (); paging_init (); +#ifdef USERPROG tss_init (); gdt_init (); +#endif malloc_init (); - /* Set random seed if not already done. */ + /* Set random seed if argv_init() didn't. */ random_init (0); /* Initialize interrupt handlers. */ intr_init (); timer_init (); kbd_init (); +#ifdef USERPROG + exception_init (); + syscall_init (); +#endif - /* Do everything else in a system thread. */ - thread_init (); - thread_create ("main", main_thread, NULL); + /* Start thread scheduler and enable interrupts. */ thread_start (); -} + serial_init_queue (); -/* Initial thread. */ -static void -main_thread (void *aux UNUSED) -{ #ifdef FILESYS + /* Initialize filesystem. */ disk_init (); filesys_init (format_filesys); fsutil_run (); #endif + printf ("Boot complete.\n"); + #ifdef USERPROG + /* Run a user program. */ if (initial_program != NULL) - thread_execute (initial_program); - else - PANIC ("no initial program specified"); + { + printf ("\nExecuting '%s':\n", initial_program); + thread_execute (initial_program); + } +#else + test (); #endif + + /* Terminate this thread. */ + thread_exit (); } /* Clear BSS and obtain RAM size from loader. */ @@ -160,7 +181,7 @@ argv_init (void) #endif else if (!strcmp (argv[i], "-u")) { - printk ( + printf ( "Kernel options:\n" " -rs SEED Seed random seed to SEED.\n" " -d CLASS[,...] Enable the given classes of debug messages.\n" @@ -174,8 +195,9 @@ argv_init (void) " -p FILENAME Print the contents of FILENAME\n" " -r FILENAME Delete FILENAME\n" " -ls List the files in the filesystem\n" - " -D Dump complete filesystem contents\n"); + " -D Dump complete filesystem contents\n" #endif + ); } else PANIC ("unknown option `%s'", argv[i]);