# Page table representation in the virtual address space of FreeBSD



## nav143 (Dec 5, 2011)

The following echoes the way page tables are represented in the virtual address for FreeBSD (amd64) 


```
// start by moving entries we care about to the bottom
  vpn_table_entry = vpn >> (9*level);

  // clear out any high order bits (sign extension)
  vpn_table_entry &= (1ul << ((4 - level) * 9)) - 1;

  // now, add in the right number of recursive PML4 entries
  for (i=4; i>=(4-level); i--) {
    vpn_table_entry |= (RECURSIVE << (9*i));
  }

  // shift up to account for size of PTE (64 bits).
  table_entry = (vpn_table_entry << 3);

  // add the sign extension back
  table_entry |= (unsigned long)-1 << 47;
```

Can someone help me with what does RECURSIVE mean and what values it generally takes? It would be very helpful if someone can explain with an example. I tried figuring it out but was not very clear. The kernel source is also not that clear. This is part of simulator that logs the virtual address of the faulting address in the event of a MMU cache miss.


----------



## SirDice (Dec 5, 2011)

nav143 said:
			
		

> Can someone help me with what does RECURSIVE mean and what values it generally takes?


I haven't looked at the code but it looks like a macro.

Also, you should be familiar with recursion


----------

