Does the xv6 kernel pagetable have the mapping of trapframe page by default?

63 Views Asked by At

I am learning the trap mechanism in xv6, getting confused when I enter the kernel and see some code like p->trapframe->epc = r_sepc().

I am wondering when do the kernel put this trapframe mapping into the kernel pagetable?

It seems counterintuitive if the kernel pagetable has this mapping by default, since each process's trapframe has the distinct physical adderss. So I think there must be some point that when the process traps into the kernel, kernel put its trapframe mapping into the kernel pagetable.

I am very appreciate if you can help me clarify the confusion!

When do the kernel put the process trapframe mapping into kernel pagetable.

1

There are 1 best solutions below

0
On

Yes.

xv6 takes the very simple direct map strategy as mentioned in chapter 3 - page tables. And p->trapframe is physical address of its trapframe page.

So when you access p->trapframe, it indeed operates with virtual address, but va equals pa in kernel page table, therefore, you don't have to worry about the access violation.