paging!
hey!
although i finally figured out how memory descriptors lists work in theory,
thanks to this article:
http://www.osronline.com/article.cfm?id=423
i dis assembled the MmBuildForNonPagedPool function anyways for the sake of
interest

, i found the
logic used to get the physical address a bit confusing and out of sync from
my knowledge of paging.
mov ecx,edx
shr ecx,12
and ecx,3FF8
mov edi,[ecx+C0600000]
nov ecx,[ecx+C0600004]
the above is an extract from the MmBuildForNonPagedPool function. the ecx
register initially stores Mdl.startVa
which is the starting virtual address of the buffer described by the
MDL(aligned to 4096 byte boundry or page frame size boundry).
in the second instruction the ecx register is shifted right 18 times, which
gives us the rightmost 14 bits of virtual address
i.e bits (31:18) the third instruction removes 3 leftmost bits. This implies
that the function multiplies rightmost 11 bits of the virutal address
with 8 (8 is the size of a page directory entry with PAE bit (5) of the CR4
register enabled) for example if we started with a
virtual address of say 81274567 then.. :
1000 0001 0010 0111 0100 0101 0110 0111 = 81274567 , starting virual address
0000 0000 0000 0000 0010 0000 0100 1001 = 00002049 , result after shifting
18 times
0000 0000 0000 0000 0010 0000 0100 1000 = 00002048 , after stripping the
last 3 bits which is the same as
1000 0001 001 (this first 11 bits of the VA) * 8 = 10 0000 0100 1000
this number (00002048 in our example) is used to index the page directory
(C0600000, page directory base virtual address when
PAE is set) notice that we fetch 8 bits from the page directory, 4 of them
are stored in edi and the other 4 are stored in ecx
Question1: which paging mechanism uses 11 bits to index a page directory ?
according to the intel manuals when PAE is on
2 bits are used to index the PDPT and 9 bits are used to index the page
directory.
here is the next set of asm instructions from the MmBuildForNonPagedPool
function :
mov [ebp-4],ecx ; store the higher 4 bytes of the PDE on the stack as ecx
is going to used in the following instructions
mov ecx,00000081; this clears all bits in ecx except bits 0 and 7
mov [ebp-8],edi ; store the lower 4 bytes of the PDE on the stack as edi is
going to used in the following instructions
and edi,ecx;
cmp edi,ecx; compare the bits 0 and bits 7 of the PDE
jnz 8050A00;
the jump is taken if bits 0 and 7 of the PDE are set, now it makes sense why
its checking for bit 0 as it indicates
wether the PDE is paged in or paged out, but the bit 7 according to the
intel manuals is set to 0 always then why bother
checking it? that is Question 2.
the MmBuildForNonPagedPool function is used when the physical pages
described by the virtual address buffer described by the MDL
is in non paged pool i.e the caller is sure that all the phyical pages
associated with the virutall address buffer are in nonpaged pool, so i am
guessing the jnz instruction is a check to insure that the PDE is paged in
(as page tables can be paged out) but i am not sure why its checking
for bit 7 :S
to confuse matters further :
once the jump is taken i.e the PDE is paged in :
SHR EDX,09 ; edx initially contains the mdl.startVa,
AND EDX,007FFFF8; the above 2 instructions multiply the rightmost 20 bits of
the Virtual address with 8
SUB EDX,40000000; is this compiler optimization? i dont understand how this
is better than, add EDX,C0000000??
anyways the purpose of this instruction is to index the Page table (sub
Question: according to the
intel manuals the page table base is obtained from the PDE? why is it
assumed that the Page table
base is always C0000000??)
mov ecx,[edx]; store the lower 4 bytes of the PTE in ecx
mov edi,[edx+04]; store the higher 4 bytes of the PTE in edi
SHRD ecx,edi,0C; shifts the 8 byte PTE 12 times to the right, its looking
for the page address base
AND ecx,03FFFFFF; its keeping 26 bits and stripping of the rest hmm
according to the manuals the page address base is only 24 bits
then why 26 bits? (this value is stored in the array below the MDL header so
i guess its the page address base) that is Question 4
thanks for your help