Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "types.h"
- #include "PMM.h"
- HIVSTATUS PmmVaToPhysicalAddress
- (u32 pdeBase,
- u32 virtualAdd,
- u32 *physicalAdd) {
- u32 pdeEntry, pteEntry, pageEntry;
- pdeEntry = __CR3_READ(pdeBase) + __VA_PDE_OFF(virtualAdd);
- pteEntry = __SET_PDE(pdeEntry) + __VA_PTE_OFF(virtualAdd);
- //pageEntry = __SET_PTE(pteEntry) + __VA_PAGE_OFF(virtualAdd);
- *physicalAdd = __SET_PTE(pteEntry) + __VA_PAGE_OFF(virtualAdd);
- return STATUS_SUCCESS;
- }
- HIVSTATUS PmmMapPhysicalPages
- (u32 physicalAdd,
- u32 size,
- u32 *virtualAdd,
- u32 pdeBase) {
- PPTE pte;
- u32 nPages, oldPteBase, oldPdeB;
- u32 *pteBase, *pdeB;
- u32 v_table, v_offset, v_dir;
- u32 index = 1;
- //See how many pages I've to locate
- nPages = size/4096;
- if (nPages % 4096 != 0) nPages++;
- //Find va of a random PTE, because the stored datas
- //are reloaded and saved for each restore.
- //Then I just assign standard pte flag values;
- //Check if bde base has PS flag to 0 (pte base)
- //FIXME: I need a pte for each page!
- *pdeB = __CR3_READ(pdeBase);
- oldPdeB = *pdeB;
- for (*pdeB; *pdeB < MAX_PTE_SIZE; *pdeB++) {
- if (pdeB[7] == 0) break;
- else continue;
- }
- *pteBase = __SET_PDE(*pdeB);
- oldPteBase = *pteBase;
- for (*pteBase; *pteBase < MAX_PTE_SIZE; *pteBase++) {
- if (pteBase[0] == 1) break;
- else continue;
- }
- v_table = *pteBase - oldPteBase;
- v_offset = physicalAdd - __PHY_PAGE_BASE(physicalAdd);
- v_dir = *pdeB - oldPdeB;
- *virtualAdd = V_ALIGN(v_dir, v_table, v_offset);
- pte = (PPTE)pteBase;
- pte->Physical = (u32)__PHY_PAGE_BASE(physicalAdd);
- pte->Present = 1;
- pte->ReadWrite = 1;
- pte->Accessed = 0;
- pte->UserSup = 0;
- pte->WriteTh = 0;
- pte->CacheDi = 0;
- pte->Dirty = 0;
- pte->PAT = 0;
- pte->Reserved = 0;
- pte->Global = 0;
- //HOWTO: return logical address
- return STATUS_SUCCESS;
- }
Add Comment
Please, Sign In to add comment