Page address to physical address

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
FlashBurn

Page address to physical address

Post by FlashBurn »

I?ve written a function which should convert a page address into a physical address. But because of any reason, my function is incorrect!

Code: Select all

;----------------------------
;   Input:
;   EAX - address (paged)
;   ESI - address of PD
;   Output:
;   EAX - physical address
addr_page2phys:
   push eax
   push eax
   
   and eax,0ff300000h
   shr eax,22
   add esi,eax
   mov eax,[esi]
   and eax,0fffff000h
   mov esi,eax
   
   pop eax
   
   and eax,03ff000h
   shr eax,12
   add esi,eax
   mov eax,[esi]
   and eax,0fffff000h
   
   pop ebx
   
   and ebx,0fffh
   add eax,ebx
   
   ret
;----------------------------

User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Page address to physical address

Post by Pype.Clicker »

Code: Select all

and eax,0ff300000h
seems wrong.

0xff30 ==1111 1111 0011 0000

what you want is more likely to be 0xffc0 0000 ...
FlashBurn

Re:Page address to physical address

Post by FlashBurn »

Thanks, but this seems not to be the only problem, because it ?still doesn?t work :(
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Page address to physical address

Post by Pype.Clicker »

you seemed to forgot that page table entries are 4 bytes long ...

So, i wouldn't do

Code: Select all

 shr eax,22
   add esi,eax
   mov eax,[esi]
but rather

Code: Select all

  shr eax,
  mov eax,[eax*4+esi]
FlashBurn

Re:Page address to physical address

Post by FlashBurn »

Thanks, my function is working now ;D
Post Reply