X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fthreads%2Finit.c;h=ae864981341d110464c59985d3ccd94e8acf193a;hb=5fbedf1d20c2b2f2dbc8c7ebd64cc7b4812a44bf;hp=a3ab43d577c5d6a98bd629883c7f1e84c840034e;hpb=5e8c072fc51af0d3e6c3501c6f697b01c9c607b7;p=pintos-anon diff --git a/src/threads/init.c b/src/threads/init.c index a3ab43d..ae86498 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -38,30 +38,14 @@ static bool format_filesys; static char *initial_program; #endif +static thread_func main_thread; static void ram_init (void); static void argv_init (void); -static void -main_thread (void *aux UNUSED) -{ -#ifdef FILESYS - disk_init (); - filesys_init (format_filesys); - fsutil_run (); -#endif - -#ifdef USERPROG - if (initial_program != NULL) - thread_execute (initial_program); - else - PANIC ("no initial program specified"); -#endif -} - int main (void) { - /* Initialize prerequisites for calling printk(). */ + /* Needed by printk(), so initialize them very early. */ ram_init (); vga_init (); serial_init (); @@ -72,13 +56,14 @@ main (void) /* Parse command line. */ argv_init (); - /* Initialize memory system. */ + /* Initialize memory system, segments, paging. */ palloc_init (); paging_init (); tss_init (); gdt_init (); malloc_init (); + /* Set random seed if not already done. */ random_init (0); /* Initialize interrupt handlers. */ @@ -92,7 +77,25 @@ main (void) thread_start (); } +/* Initial thread. */ +static void +main_thread (void *aux UNUSED) +{ +#ifdef FILESYS + disk_init (); + filesys_init (format_filesys); + fsutil_run (); +#endif +#ifdef USERPROG + if (initial_program != NULL) + thread_execute (initial_program); + else + PANIC ("no initial program specified"); +#endif +} + +/* Clear BSS and obtain RAM size from loader. */ static void ram_init (void) { @@ -105,10 +108,11 @@ ram_init (void) extern char _start_bss, _end_bss; memset (&_start_bss, 0, &_end_bss - &_start_bss); - /* Get RAM size from loader. */ + /* Get RAM size from loader. See loader.S. */ ram_pages = *(uint32_t *) ptov (LOADER_RAM_PAGES); } - + +/* Parses the command line. */ static void argv_init (void) {