static void ram_init (void);
static void gdt_init (void);
static void argv_init (void);
-void power_off (void);
static void
main_thread (void *aux UNUSED)
kbd_init ();
/* Do everything else in a system thread. */
- thread_init ();
- thread_start (thread_create ("main", main_thread, NULL));
+ thread_init ("main", main_thread, NULL);
}
static uint64_t
0x67, SYS_SYSTEM, TYPE_TSS_32_A, 0, GRAN_BYTE);
}
-uint64_t gdt[SEL_CNT];
+static uint64_t gdt[SEL_CNT];
struct tss *tss;
}
argv[argc] = NULL;
}
-\f
-void
-power_off (void)
-{
- const char s[] = "Shutdown";
- const char *p;
-
- printk ("Powering off...\n");
- for (p = s; *p != '\0'; p++)
- outb (0x8900, *p);
- for (;;);
-}
}
void
-thread_init (void)
+thread_init (const char *name, void (*function) (void *aux), void *aux)
{
+ struct thread *initial_thread;
+
+ ASSERT (intr_get_level () == IF_OFF);
+
list_init (&run_queue);
idle_thread = thread_create ("idle", idle, NULL);
+
+ initial_thread = thread_create (name, function, aux);
+ list_remove (&initial_thread->rq_elem);
+ initial_thread->status = THREAD_RUNNING;
+ switch_threads (NULL, initial_thread);
+
+ NOT_REACHED ();
}
-struct thread_root_frame
+struct kernel_thread_frame
{
void *eip; /* Return address. */
void (*function) (void *); /* Function to call. */
};
static void
-thread_root (void (*function) (void *aux), void *aux)
+kernel_thread (void (*function) (void *aux), void *aux)
{
ASSERT (function != NULL);
thread_create (const char *name, void (*function) (void *aux), void *aux)
{
struct thread *t;
- struct thread_root_frame *rf;
+ struct kernel_thread_frame *kf;
struct switch_entry_frame *ef;
struct switch_threads_frame *sf;
t = new_thread (name);
- /* Stack frame for thread_root(). */
- rf = alloc_frame (t, sizeof *rf);
- rf->eip = NULL;
- rf->function = function;
- rf->aux = aux;
+ /* Stack frame for kernel_thread(). */
+ kf = alloc_frame (t, sizeof *kf);
+ kf->eip = NULL;
+ kf->function = function;
+ kf->aux = aux;
/* Stack frame for switch_entry(). */
ef = alloc_frame (t, sizeof *ef);
- ef->eip = (void (*) (void)) thread_root;
+ ef->eip = (void (*) (void)) kernel_thread;
/* Stack frame for thread_switch(). */
sf = alloc_frame (t, sizeof *sf);
void
schedule_tail (struct thread *prev)
{
-#ifdef USERPROG
- struct thread *cur = thread_current ();
-#endif
-
ASSERT (intr_get_level () == IF_OFF);
#ifdef USERPROG
- addrspace_activate (&cur->addrspace);
+ addrspace_activate (&thread_current ()->addrspace);
#endif
if (prev != NULL && prev->status == THREAD_DYING)
intr_set_level (old_level);
}
-void
-thread_start (struct thread *t)
-{
- ASSERT (intr_get_level () == IF_OFF);
-
- if (t->status == THREAD_READY)
- list_remove (&t->rq_elem);
- t->status = THREAD_RUNNING;
- switch_threads (NULL, t);
- NOT_REACHED ();
-}
-
void
thread_exit (void)
{
thread_current ()->status = THREAD_BLOCKED;
thread_schedule ();
}
-
-static void
-tfunc (void *aux UNUSED)
-{
- for (;;)
- {
- size_t count, i;
- if (random_ulong () % 5 == 0)
- {
- printk ("%s exiting\n", thread_current ()->name);
- break;
- }
- count = random_ulong () % 25 * 10000;
- printk ("%s waiting %zu: ", thread_current ()->name, count);
- for (i = 0; i < count; i++);
- printk ("%s\n", thread_current ()->name);
- }
-}
-
-void
-thread_self_test (void)
-{
- struct thread *t;
- int i;
-
- for (i = 0; i < 4; i++)
- {
- char name[2];
- name[0] = 'a' + i;
- name[1] = 0;
- t = thread_create (name, tfunc, NULL);
- }
- thread_start (t);
-}
#endif
};
-void thread_init (void);
-
-struct thread *thread_create (const char *name,
- void (*function) (void *aux), void *aux);
+void thread_init (const char *name, void (*) (void *aux), void *) NO_RETURN;
+struct thread *thread_create (const char *name, void (*) (void *aux), void *);
void thread_destroy (struct thread *);
struct thread *thread_current (void);
bool thread_execute (const char *filename);
#endif
-void thread_start (struct thread *) NO_RETURN;
void thread_ready (struct thread *);
void thread_exit (void) NO_RETURN;
void thread_yield (void);
void thread_sleep (void);
-void thread_self_test (void);
-
#endif /* thread.h */