proc.c
void
userinit(void)
{
  struct proc *p;
  extern char _binary_initcode_start[], _binary_initcode_size[];

  p = allocproc();

  initproc = p;
  if((p->pgdir = setupkvm()) == 0)
    panic("userinit: out of memory?");
  inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
  p->sz = PGSIZE;
  memset(p->tf, 0, sizeof(*p->tf));
  p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
  p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
  p->tf->es = p->tf->ds;
  p->tf->ss = p->tf->ds;
  p->tf->eflags = FL_IF;
  p->tf->esp = PGSIZE;
  p->tf->eip = 0;  // beginning of initcode.S

  safestrcpy(p->name, "initcode", sizeof(p->name));
  p->cwd = namei("/");

  // this assignment to p->state lets other cores
  // run this process. the acquire forces the above
  // writes to be visible, and the lock is also needed
  // because the assignment might not be atomic.
  acquire(&ptable.lock);
  p->state = RUNNABLE;
  if(strategy == 1 || (strategy == 3 && grtexists() == 0 && frrexists() == 1)){
    insert(queue_frr, p, &queuedata_frr);
  }



  release(&ptable.lock);
}
//PAGEBREAK: 32
// Set up first user process.
32
Set up first user process.
32 Set up first user process .
void
userinit(void)
{
  struct proc *p;
  extern char _binary_initcode_start[], _binary_initcode_size[];
  p = allocproc();
  initproc = p;
  if((p->pgdir = setupkvm()) == 0)
    panic("userinit: out of memory?");
  inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
  p->sz = PGSIZE;
  memset(p->tf, 0, sizeof(*p->tf));
  p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
  p->tf->ds = (SEG_UDATA << 3) | DPL_USER;
  p->tf->es = p->tf->ds;
  p->tf->ss = p->tf->ds;
  p->tf->eflags = FL_IF;
  p->tf->esp = PGSIZE;
  p->tf->eip = 0;  
  safestrcpy(p->name, "initcode", sizeof(p->name));
  p->cwd = namei("/");
  acquire(&ptable.lock);
  p->state = RUNNABLE;
  if(strategy == 1 || (strategy == 3 && grtexists() == 0 && frrexists() == 1)){
    insert(queue_frr, p, &queuedata_frr);
  }
  release(&ptable.lock);
}
void userinit ( void ) { struct proc * p ; extern char _binary_initcode_start [ ] , _binary_initcode_size [ ] ; p = allocproc ( ) ; initproc = p ; if ( ( p -> pgdir = setupkvm ( ) ) == 0 ) panic ( " " ) ; inituvm ( p -> pgdir , _binary_initcode_start , ( int ) _binary_initcode_size ) ; p -> sz = PGSIZE ; memset ( p -> tf , 0 , sizeof ( * p -> tf ) ) ; p -> tf -> cs = ( SEG_UCODE << 3 ) | DPL_USER ; p -> tf -> ds = ( SEG_UDATA << 3 ) | DPL_USER ; p -> tf -> es = p -> tf -> ds ; p -> tf -> ss = p -> tf -> ds ; p -> tf -> eflags = FL_IF ; p -> tf -> esp = PGSIZE ; p -> tf -> eip = 0 ; safestrcpy ( p -> name , " " , sizeof ( p -> name ) ) ; p -> cwd = namei ( " " ) ; acquire ( & ptable . lock ) ; p -> state = RUNNABLE ; if ( strategy == 1 || ( strategy == 3 && grtexists ( ) == 0 && frrexists ( ) == 1 ) ) { insert ( queue_frr , p , & queuedata_frr ) ; } release ( & ptable . lock ) ; }
PAGEBREAK: 32
Set up first user process.
PAGEBREAK : 32 Set up first user process .
// beginning of initcode.S // this assignment to p->state lets other cores // run this process. the acquire forces the above // writes to be visible, and the lock is also needed // because the assignment might not be atomic.