X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/b0d623f7f2ae71ed96e60569f61f9a9a27016e80..db6096698656d32db7df630594bd9617ee54f828:/osfmk/i386/hibernate_restore.c diff --git a/osfmk/i386/hibernate_restore.c b/osfmk/i386/hibernate_restore.c index c1dfd4e16..f04a56c4a 100644 --- a/osfmk/i386/hibernate_restore.c +++ b/osfmk/i386/hibernate_restore.c @@ -29,19 +29,15 @@ #include #include -extern pd_entry_t BootstrapPTD[2048]; +#include -#define TWO_MEG_MASK 0xFFFFFFFFFFE00000ULL - -#define DST_INDEX 2047UL - -static char *dstPtr = (char *)(DST_INDEX << PDSHIFT); +extern pd_entry_t BootPTD[2048]; // src is virtually mapped, not page aligned, // dst is a physical 4k page aligned ptr, len is one 4K page // src & dst will not overlap -void +uintptr_t hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags) { (void)procFlags; @@ -50,25 +46,56 @@ hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t p uint32_t idx; if (src == 0) - return; - - if (dst < (uint64_t) (uintptr_t)dstPtr) - { - d = (uint64_t *) (uintptr_t)dst; - } - else - { - /* Outside 1-1 4G map so set up the mappings for the dest page using 2MB pages */ - BootstrapPTD[DST_INDEX] = (dst & TWO_MEG_MASK) | INTEL_PTE_PS | INTEL_PTE_VALID | INTEL_PTE_WRITE | INTEL_PTE_WRITE; - - /* Invalidate the page tables for this */ - invlpg((uintptr_t) dstPtr); + return (uintptr_t)dst; - /* Mask off the offset from the 2MB window */ - dst &= ~TWO_MEG_MASK; - d = (uint64_t *) (dstPtr + dst); - } + d = (uint64_t *)pal_hib_map(DEST_COPY_AREA, dst); s = (uint64_t *) (uintptr_t)src; + for (idx = 0; idx < (len / (uint32_t)sizeof(uint64_t)); idx++) d[idx] = s[idx]; + + return (uintptr_t)d; +} +#undef hibprintf + +void hibprintf(const char *fmt, ...); + +uintptr_t +pal_hib_map(uintptr_t virt, uint64_t phys) +{ + 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; + } + + 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); + BootPTD[index] = phys; + invlpg(virt); + BootPTD[index + 1] = (phys + I386_LPGBYTES); + invlpg(virt + I386_LPGBYTES); + + return (virt); +} + +void hibernateRestorePALState(uint32_t *arg) +{ + (void)arg; +} + +void +pal_hib_patchup(void) +{ }