-#ifdef USERPROG
-/* Starts a new thread running a user program loaded from
- FILENAME, and adds it to the ready queue. If thread_start()
- has been called, then new thread may be scheduled before
- thread_execute() returns.*/
-tid_t
-thread_execute (const char *filename)
-{
- struct thread *t;
- struct intr_frame *if_;
- struct switch_entry_frame *ef;
- struct switch_threads_frame *sf;
- void (*start) (void);
- tid_t tid;
-
- ASSERT (filename != NULL);
-
- t = new_thread (filename, PRI_DEFAULT);
- if (t == NULL)
- return TID_ERROR;
- tid = t->tid;
-
- if (!addrspace_load (t, filename, &start))
- PANIC ("%s: program load failed", filename);
-
- /* Interrupt frame. */
- if_ = alloc_frame (t, sizeof *if_);
- if_->es = SEL_UDSEG;
- if_->ds = SEL_UDSEG;
- if_->eip = start;
- if_->cs = SEL_UCSEG;
- if_->eflags = FLAG_IF | FLAG_MBS;
- if_->esp = PHYS_BASE;
- if_->ss = SEL_UDSEG;
-
- /* Stack frame for switch_entry(). */
- ef = alloc_frame (t, sizeof *ef);
- ef->eip = intr_exit;
-
- /* Stack frame for switch_threads(). */
- sf = alloc_frame (t, sizeof *sf);
- sf->eip = switch_entry;