mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.6k stars 2.38k forks source link

Why `kvminithart()` has to be called after `procinit()` #134

Open imabackstabber opened 1 year ago

imabackstabber commented 1 year ago

I notice that in procinit(),there is code like:


// initialize the proc table at boot time.
void
procinit(void)
{
  struct proc *p;

  initlock(&pid_lock, "nextpid");
  for(p = proc; p < &proc[NPROC]; p++) {
      initlock(&p->lock, "proc");

      // Allocate a page for the process's kernel stack.
      // Map it high in memory, followed by an invalid
      // guard page.
      char *pa = kalloc();
      if(pa == 0)
        panic("kalloc");
      uint64 va = KSTACK((int) (p - proc));
      kvmmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
      p->kstack = va;
  }
  kvminithart();
}

It will call kvminithart(), which will call w_satp() and flush TLB. I'm wondering why kvminithart() is needed.It seems that procinit() just add PTEs to kernel pagetable but didn't change the physical address of it.So why call kvminithart() again here?