From: Ben Pfaff Date: Wed, 1 Sep 2004 22:36:36 +0000 (+0000) Subject: Misc cleanups in init, thread. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=commitdiff_plain;h=5fbedf1d20c2b2f2dbc8c7ebd64cc7b4812a44bf Misc cleanups in init, thread. --- diff --git a/src/lib/random.c b/src/lib/random.c index c9973d0..3fcf62d 100644 --- a/src/lib/random.c +++ b/src/lib/random.c @@ -1,6 +1,7 @@ #include "random.h" #include #include +#include "debug.h" /* RC4-based pseudo-random state. */ static uint8_t s[256]; 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) { diff --git a/src/threads/thread.c b/src/threads/thread.c index fed6b84..e31d838 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -24,11 +24,11 @@ static void idle (void *aux UNUSED); /* Thread function. */ struct kernel_thread_frame { void *eip; /* Return address. */ - void (*function) (void *); /* Function to call. */ + thread_func *function; /* Function to call. */ void *aux; /* Auxiliary data for function. */ }; -static void kernel_thread (void (*function) (void *aux), void *aux); +static void kernel_thread (thread_func *, void *aux); static struct thread *next_thread_to_run (void); static struct thread *new_thread (const char *name); @@ -76,7 +76,7 @@ thread_start (void) semaphore or some other form of synchronization if you need to ensure ordering. */ struct thread * -thread_create (const char *name, void (*function) (void *aux), void *aux) +thread_create (const char *name, thread_func *function, void *aux) { struct thread *t; struct kernel_thread_frame *kf; @@ -263,7 +263,7 @@ idle (void *aux UNUSED) /* Function used as the basis for a kernel thread. */ static void -kernel_thread (void (*function) (void *aux), void *aux) +kernel_thread (thread_func *function, void *aux) { ASSERT (function != NULL); diff --git a/src/threads/thread.h b/src/threads/thread.h index c452058..1dfde5a 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -37,7 +37,8 @@ struct thread void thread_init (void); void thread_start (void) NO_RETURN; -struct thread *thread_create (const char *name, void (*) (void *aux), void *); +typedef void thread_func (void *aux); +struct thread *thread_create (const char *name, thread_func *, void *); #ifdef USERPROG bool thread_execute (const char *filename); #endif