Confirmative question about 4-level and 5-level paging
Posted: Thu Aug 26, 2021 7:31 pm
Just reading through chapter 4 of the Intel SDMs, vol. 3A, so I can better understand paging (I find it a bit confusing myself, or at least how the structures work), and just want to confirm the layout of the paging structures and what CR3 points to.
This is my understanding of paging in long mode when CR4.LA57 is set and clear:
This is my understanding of paging in long mode when CR4.LA57 is set and clear:
- If CR4.LA57 is set, then:
- CR3 contains the physical address of a PML5 table in bits 51:12, with bits 11:0 representing flags/control bits.
- The PML5 table contains 512 PML5 entries, each of which points to a PML4 table (not a PML4 entry). Each PML5 entry contains the physical address of that entry in bits 51:12 (which are taken from CR3) and 11:3 (which are bits 56:48 of the physical linear address), with bits 2:0 clear.
- Each PML4 table referenced by each PML5 entry in the PML5 table contains 512 PML4 entries. Each PML4 entry contains the physical address of the PDPT it points to in bits 51:12 (taken from the PML5E) and bits 11:3 (physical linear address bits 47:39) and bits 2:0 clear.
- Each PML4 entry points to a PDPT. Every PDPT contains 512 PDTs. Each PDT points to a page table with the physical address of that PT in bits 51:12 (taken from the PML4E) and bits 11:3 (which are bits 38:30 of the physical linear address of the PT).
- Each PT contains 512 PTEs. Each PTE contains the physical address of a page in bits 51:12 (from the PDE) and bits 11:3 (which are bits 20:12 of the physical linear address).
- Finally, each page is mapped by using bits 51:12 (from the PTE) and setting bits 11:0 to bits 11:0 of the page.
- For 4-level paging, the process is identical but excludes the PML5 table.
- Create a PML5 or PML4 table and add one PML5 or PML4 entry to it, which points to my PDPT.
- Create a PDPT and add as many PDTs as I need to it, pointing to page tables.
- Create page tables at the specified addresses and write addresses for pages that I want to map into them, clearing the present bit.