When we try to read/write some data to/from a specific address we must know where the first page directory is stored and the address we want translate.
As for the first page directory (as far as I know linux uses 4-level paging, so the first one should be
PGD), and for Intel -
CR3 register will contain the address of PGD, but where the virtual address is stored? How will MMU understand that it should translate exactly this or that address?
UPD: I think I should clarify my question and provide a few details how I see that:
As I understood, when some virtual address's gonna be translated we have next steps:
- Check the TLB.
- If TLB hits then we have physical address (PA)
- If it does not, we have to process translation fault
- During translation fault we have to walk through software page tables to find the PA.
- Here have to switch to kernel mode. (Btw, I know that usually kernel page tables and user page tables are the same, the difference is only in privileges, so is there a way that we won't switch to kernel mode?)
- Then we're gonna set CR3 register to PGD address (or another top level page directory)
- Now that's our work to walk through this table or not? If software should do it on its own then we know that VA (Virtual Address) within some var and can look for PA in page tables??? Or this work on MMU (or like smth that) and it will go through these tables and as for CR3 will know where the PGD, but how it can understand what address this is translating? Is it in some register or already loaded somewhere in memory?
Thank you for your time!