Created
September 22, 2018 20:28
-
-
Save frednora/061d1f27efddb8d1e307a4de3990af75 to your computer and use it in GitHub Desktop.
virt-to-phys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long | |
virtual_to_physical( unsigned long virtual_address, | |
unsigned long dir_address ) | |
{ | |
unsigned long address; | |
unsigned long *dir = (unsigned long *) dir_address; | |
unsigned long tmp; | |
int d = (int) virtual_address >> 22 & 0x3FF; | |
int t = (int) virtual_address >> 12 & 0x3FF; | |
int o = (int) (virtual_address & 0xFFF); | |
//temos o endereço da pt junto com as flags. | |
tmp = (unsigned long) dir[d]; | |
unsigned long *pt = (unsigned long *) (tmp & 0xFFFFF000); | |
//encontramos o endereço base do page frame. | |
tmp = (unsigned long) pt[t]; | |
address = (tmp & 0xFFFFF000); | |
return (unsigned long) (address + o); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment