The code is initializing the contents of the page directory. (See designated array initialization in C).
Consider this image of the contents of a page directory entry from OSDev Wiki:

Then consider this line of code:
[0] = (0) | PTE_P | PTE_W | PTE_PS
The code sets the value of the first page directory entry (index 0
) to 0 | PTE_P | PTE_W | PTE_PS
. This is a bitwise OR to set the various fields:
0
- clear all bits
PTE_P
- set the present bit
PTE_W
- set the read\write bit
PTE_PS
- set the 4MiB page size bit
The next line does a similar thing. Except it sets the contents of the 513th entry (index 512
(0x80000000 >> 22
)):
[KERNBASE >> PDXSHIFT] = (0) | PTE_P | PTE_W | PTE_PS
.
Aside:
The bit position of the flags of interest to xv6 is the same for page directory entries (PDE) and page table entries (PTE). Instead of creating separate constants for the PDE flags, the authors opted to share the constants... In my opinion, this shortcut makes the code slightly less clear in intent.
// Page table/directory entry flags.
#define PTE_P 0x001 // Present
#define PTE_W 0x002 // Writeable
#define PTE_U 0x004 // User
#define PTE_PS 0x080 // Page Size