- int index;
-
- switch(v) {
- case DEST_COPY_AREA:
- index = 1;
- break;
- case SRC_COPY_AREA:
- index = 2;
- break;
- case COPY_PAGE_AREA:
- index = 3;
- break;
- default:
- index = -1;
- asm("cli;hlt;");
- }
-
- uint64_t *ptes = (uint64_t *)HIB_PTES;
-
- /* Outside 1-1 4G map so set up the mappings for the dest page using 2MB pages */
- ptes[index] = (p & FOUR_K_MASK) | INTEL_PTE_VALID | INTEL_PTE_WRITE;
-
- /* Invalidate the page tables for this */
- invlpg((uintptr_t)v);
-
- return v;
+ uintptr_t index;
+
+ switch (virt)
+ {
+ case DEST_COPY_AREA:
+ case SRC_COPY_AREA:
+ case COPY_PAGE_AREA:
+ case BITMAP_AREA:
+ case IMAGE_AREA:
+ case IMAGE2_AREA:
+ break;
+
+ default:
+ asm("cli;hlt;");
+ break;
+ }
+ if (phys < IMAGE2_AREA)
+ {
+ // first 4Gb is all mapped,
+ // and do not expect source areas to cross 4Gb
+ return (phys);
+ }
+ index = (virt >> I386_LPGSHIFT);
+ virt += (uintptr_t)(phys & I386_LPGMASK);
+ phys = ((phys & ~((uint64_t)I386_LPGMASK)) | INTEL_PTE_PS | INTEL_PTE_VALID | INTEL_PTE_WRITE);
+ if (phys == BootPTD[index]) return (virt);
+ BootPTD[index] = phys;
+ invlpg(virt);
+ BootPTD[index + 1] = (phys + I386_LPGBYTES);
+ invlpg(virt + I386_LPGBYTES);
+
+ return (virt);