I have read chapter 4 (Paging) of Intel's manual and successfully created a function returning a PTE value by given address. Here it is:
Code: Select all
__asm__ __volatile__ ( "movl %%cr3, %%eax\n\t"
"andl $0xfffff000, %%eax\n\t"
"addl $0xc0000000, %%eax\n\t"
"movl %1, %%ebx\n\t"
"shrl $22, %%ebx\n\t"
"sall $2, %%ebx\n\t"
"addl %%ebx, %%eax\n\t"
"movl (%%eax), %%eax\n\t"
"andl $0xfffff000, %%eax\n\t"
"addl $0xc0000000, %%eax\n\t"
"movl %1, %%ebx\n\t"
"andl $0x003ff000, %%ebx\n\t"
"shrl $12, %%ebx\n\t"
"sall $2, %%ebx\n\t"
"addl %%ebx, %%eax\n\t"
"movl (%%eax), %%eax\n\t"
"movl %%eax, %0\n\t"
:"=r"(pte)
:"r" (addr)
:"%eax", "%edx"
);
......
movl %1, %%ebx
shrl $30, %%ebx
movl (%%eax,%%ebx,0x8),%eax
:"=r"(pdpte_first32)
:"r" (addr)
:"%eax", "%ebx"
I need bits 51:12 from PDPTEi because they refer to the page directory. I can store these bits in two registers (32 in one and the remaining 8 in another) but I don't know how to use them to access the page directory. With 32 bit addresses I put the address in some register and use "(register)" to access the address but now I have 40 bits.
It will be great if you can provide some examples.