proc.c
//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;
  ptable.pFreeList=0;
ptable.pReadyList[0]=0;
ptable.pReadyList[1]=0;
ptable.pReadyList[2]=0;
acquire(&ptable.lock);
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
{
    if(p->state == UNUSED)
      {
	AddFreeList(p); 
	}
}
  release(&ptable.lock);
  extern char _binary_initcode_start[], _binary_initcode_size[];
  p = allocproc();
  p->uid=0;
  p->gid=1;
  p->priority=1;
  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("/");
  p->state = RUNNABLE;
acquire(&ptable.lock);
AddReadyList(p);
release(&ptable.lock);
}
void userinit ( void ) { struct proc * p ; ptable . pFreeList = 0 ; ptable . pReadyList [ 0 ] = 0 ; ptable . pReadyList [ 1 ] = 0 ; ptable . pReadyList [ 2 ] = 0 ; acquire ( & ptable . lock ) ; for ( p = ptable . proc ; p < & ptable . proc [ NPROC ] ; p ++ ) { if ( p -> state == UNUSED ) { AddFreeList ( p ) ; } } release ( & ptable . lock ) ; extern char _binary_initcode_start [ ] , _binary_initcode_size [ ] ; p = allocproc ( ) ; p -> uid = 0 ; p -> gid = 1 ; p -> priority = 1 ; 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 ( " " ) ; p -> state = RUNNABLE ; acquire ( & ptable . lock ) ; AddReadyList ( p ) ; release ( & ptable . lock ) ; }
PAGEBREAK: 32
Set up first user process.
PAGEBREAK : 32 Set up first user process .
//send unused process to free table to be added //struct proc *p; // beginning of initcode.S