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 ();
/* 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. */
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
+}
+\f
+/* Clear BSS and obtain RAM size from loader. */
static void
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);
}
-\f
+
+/* Parses the command line. */
static void
argv_init (void)
{
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);
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;
/* 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);
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