title: What's the mechanism behind P2V, V2P macro in Xv6
body: <p>I know there is a mapping mechanism in how a virtual address turns out into a physical.</p>
  
  <p>Just like the following, a linear address contains three parts</p>
  
  <ol>
  <li>Page Directory index</li>
  <li>Page Table index</li>
  <li>Offset</li>
  </ol>
  
  <p>Here is the illustration:</p>
  
  <p><a href="https://i.stack.imgur.com/StAUY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/StAUY.png" alt="Page Translation Picture"></a></p>
  
  <p>Now, when I take a look at the source code of Xv6 in memorylayout.h</p>
  
  <pre><code>#define V2P(a) (((uint) (a)) - KERNBASE)
  #define P2V(a) (((void *) (a)) + KERNBASE)
  
  #define V2P_WO(x) ((x) - KERNBASE)    // same as V2P, but without casts
  #define P2V_WO(x) ((x) + KERNBASE)    // same as P2V, but without casts
  </code></pre>
  
  <p>How can the V2P or P2V work correctly without doing the process of the address translation?</p>