Page 1 of 1

INVLPG

Posted: Mon Dec 23, 2002 5:19 am
by DarylD
I have been furiously searching on google for the correct use of INVLPG, but its still not clear.

From the intel manual, its used as

invlpg mem

But is the memory address, an address of a page table or is it just a normal memory address??

I have found articles on when to use invlpg, but not actual real-life usage.

Re:INVLPG

Posted: Thu Dec 26, 2002 5:41 am
by Pype.Clicker
the "mem" argument you will put is a memory location which will be resolved (just as when you perform some "mov mem,eax" instruction) into an effective address and further into a virtual address using the selector in DS (except if you specify a segment override with i.e. invlpg [cs:some_label]).

Instead of issuing a 'read cycle" for this address, the CPU will remove any entry in its page cache related to virtual address AND 0xFFFFF000.
Note that there might be a separate page cache for data and instructions ... so i don't know if the CS: override is needed or not ... better check back intel 's doc to know.

Re:INVLPG

Posted: Sun Dec 29, 2002 6:04 am
by DarylD
I understand all that, but one thing the intel docs don't seem to make clear (well to me anyhow!) is whether this is indirect or not.

I.e. the following instruction:

INVLPG (100000)

Will this read in the address to use in the page invalidation from 100000 and then invalidate that or will it try to invalidate address ds:100000 itself?

Just so I am clear on this.

Thanks Pype,

Daryl.

Re:INVLPG

Posted: Mon Dec 30, 2002 5:32 am
by Pype.Clicker
invlpg [0x10000] will invalidate ds:0x10000
invlpg 0x10000 is invalid (this is a constant, not a memory location)
invlpg [eax+ecx*4] will invalidate ds:(result of effective address computation)

invlpg [es:0x0000] should be allowed as well.

Re:INVLPG

Posted: Mon Dec 30, 2002 6:53 am
by DarylD
Thanks Pype.

All is clear now, I just don't want to get weird paging errors later on because I am not doing things correct!

Daryl.

Re:INVLPG

Posted: Mon Dec 30, 2002 7:13 am
by Pype.Clicker

Code: Select all

#ifdef __PARANOIA__
#define invlpg(mem) asm("movl %%cr3,%%eax ; movl %%eax,%%cr3":::"memory")
#else
#define invlpg(mem) asm("invlpg %0"::"m"(mem):"memory")
#endif
and just #define __PARANOIA__ if you suspect something is going wr0ng :)