Page 1 of 1

Page address to physical address

Posted: Fri Mar 28, 2003 7:49 am
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
;----------------------------


Re:Page address to physical address

Posted: Fri Mar 28, 2003 7:58 am
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 ...

Re:Page address to physical address

Posted: Fri Mar 28, 2003 12:11 pm
by FlashBurn
Thanks, but this seems not to be the only problem, because it ?still doesn?t work :(

Re:Page address to physical address

Posted: Sat Mar 29, 2003 4:07 pm
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]

Re:Page address to physical address

Posted: Sun Mar 30, 2003 4:18 am
by FlashBurn
Thanks, my function is working now ;D