Octacone wrote:
Ohhhh I get this. Thank you guys for helping. Now that I know how to access a specific virtual address, how do I map it? How to make 20 bit address equal a 32 bit one?
If you mean the 20 bits in the page table entry, they are simply same 32 bits of the 4 KB-aligned physical address, and thus the lowest 12 bits are zero, and thus only the high 20 bits are used. Since the lowest 12 bits are unused, the x86 processor uses them for the page flags. In fact, the reason the pages must be page-aligned is because only 20 bits are used.
For example, to map the physical memory at 0x1000, with read/write permissions, the page table entry for this page will contain 0x00001003. Notice how the lowest 12 bits are used for flags, while the unused bits are zero, and the actual page address is 20 bits in length. Bit 0 (value 1) here is the page present flag, while bit 1 (value 2) is the page writable flag.
To sum up and answer your question: to convert a 32-bit address to a 20-bit one you don't do anything, the 32-bit address just has to be 4 KB-aligned (i.e. bits 0 to 11 must be zero.) To convert a 20-bit address to a 32-bit one (i.e. getting the physical address from a page) you simply logical AND the value with 0xFFFFF000, which will clear everything except the 4 KB-aligned address; voila, you have the full 32-bit page-aligned address.