pmtest8.asm notes

The function of pmtest8.asm, first execute the module at a certain linear address, then convert the address mapping relationship by changing cr3, and then execute the module at the same linear address. Since the address mapping has been changed, the results obtained twice should be different Output

LABEL_DESC_FLAT_C: Descriptor 0, 0fffffh, DA_CR | DA_32 | DA_LIMIT_4K; 0-4G
LABEL_DESC_FLAT_RW: Descriptor 0, 0fffffh, DA_DRW | DA_LIMIT_4K; 0-4G

Two descriptors to describe this segment, because we are not only to read and write this memory, but also executes the code, which may
attribute requirements descriptor is not the same, the segment base of these two segments are Is zero and the length is 4GB

SetupPaging:
According to the memory size to obtain the number of page tables for paging segment
start address SelectorFlatRW paging start address still starts from 0, but the page directory table, page table address becomes PageDirBase0 PageTblBase0

PagingDemo: The
main function is to copy the code piece displaying FOO characters to the specified location ProcFoo 0x00401000h
Copy the code piece displaying BAR characters to the specified location ProcBar 0x00501000h
Copy the ProcPagingDemo code to 0x00301000

The next four calls are the key points
1 call SetupPaging to start paging
2 call SelectorFlatC: ProcPagingDemo to start running the code at 301000
3 call PSwitch to switch the page directory to change the address mapping
4 call SelectorFlatC: ProcPagingDemo to run the code at 301000 again

In the second step, since there is no switching directory at this time, the running code is the code at 301000, here is the copied PagingDemoProc:
core code: mov eax, LinearAddrDemo
call eax
is calling LinearAddrDemo
but LinearAddrDemo equ 00401000h,
so jump directly to run 401000h Code, which shows FOO

PSwitch:

First paragraph paging address SelectorFlatRW memory size to get the number of page table is based on the same
page directory table is PageDirBase1 page table address is PageTblBase1
find the corresponding page table LinearAddrDemo after page, the address of the page table access page to replace the original access FOO internal address is the address of the page
now for there is a jump to the address of BAR
this completes the same address actually visited two codes

Guess you like

Origin blog.csdn.net/u012323667/article/details/79429573