Skip to content

Instantly share code, notes, and snippets.

@frednora
Created September 22, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frednora/061d1f27efddb8d1e307a4de3990af75 to your computer and use it in GitHub Desktop.
Save frednora/061d1f27efddb8d1e307a4de3990af75 to your computer and use it in GitHub Desktop.
virt-to-phys
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