-long
-hibernate_kernel_entrypoint(uint32_t p1,
- uint32_t p2, uint32_t p3, uint32_t p4)
-{
- uint64_t headerPhys;
- uint64_t mapPhys;
- uint64_t srcPhys;
- uint64_t imageReadPhys;
- uint64_t pageIndexPhys;
- uint32_t idx;
- uint32_t * pageIndexSource;
- hibernate_page_list_t * map;
- uint32_t stage;
- uint32_t count;
- uint32_t ppnum;
- uint32_t page;
- uint32_t conflictCount;
- uint32_t compressedSize;
- uint32_t uncompressedPages;
- uint32_t copyPageListHeadPage;
- uint32_t pageListPage;
- uint32_t * copyPageList;
- uint32_t * src;
- uint32_t copyPageIndex;
- uint32_t sum;
- uint32_t pageSum;
- uint32_t nextFree;
- uint32_t lastImagePage;
- uint32_t lastMapPage;
- uint32_t lastPageIndexPage;
- uint32_t handoffPages;
- uint32_t handoffPageCount;
-
- C_ASSERT(sizeof(IOHibernateImageHeader) == 512);
-
- headerPhys = ptoa_64(p1);
-
- if ((kIOHibernateDebugRestoreLogs & gIOHibernateDebugFlags) && !debug_probe())
- gIOHibernateDebugFlags &= ~kIOHibernateDebugRestoreLogs;
-
- debug_code(kIOHibernateRestoreCodeImageStart, headerPhys);
-
- bcopy_internal((void *) pal_hib_map(IMAGE_AREA, headerPhys),
- gIOHibernateCurrentHeader,
- sizeof(IOHibernateImageHeader));
-
- debug_code(kIOHibernateRestoreCodeSignature, gIOHibernateCurrentHeader->signature);
-
- mapPhys = headerPhys
- + (offsetof(IOHibernateImageHeader, fileExtentMap)
- + gIOHibernateCurrentHeader->fileExtentMapSize
- + ptoa_32(gIOHibernateCurrentHeader->restore1PageCount)
- + gIOHibernateCurrentHeader->previewSize);
-
- map = (hibernate_page_list_t *) pal_hib_map(BITMAP_AREA, mapPhys);
-
- lastImagePage = atop_64(headerPhys + gIOHibernateCurrentHeader->image1Size);
- lastMapPage = atop_64(mapPhys + gIOHibernateCurrentHeader->bitmapSize);
-
- handoffPages = gIOHibernateCurrentHeader->handoffPages;
- handoffPageCount = gIOHibernateCurrentHeader->handoffPageCount;
-
- debug_code(kIOHibernateRestoreCodeImageEnd, ptoa_64(lastImagePage));
- debug_code(kIOHibernateRestoreCodeMapStart, mapPhys);
- debug_code(kIOHibernateRestoreCodeMapEnd, ptoa_64(lastMapPage));
-
- debug_code(kIOHibernateRestoreCodeMapVirt, (uintptr_t) map);
- debug_code(kIOHibernateRestoreCodeHandoffPages, ptoa_64(handoffPages));
- debug_code(kIOHibernateRestoreCodeHandoffCount, handoffPageCount);
-
- // knock all the image pages to be used out of free map
- for (ppnum = atop_64(headerPhys); ppnum <= lastImagePage; ppnum++)
- {
- hibernate_page_bitset(map, FALSE, ppnum);
- }
- // knock all the handoff pages to be used out of free map
- for (ppnum = handoffPages; ppnum < (handoffPages + handoffPageCount); ppnum++)
- {
- hibernate_page_bitset(map, FALSE, ppnum);
- }
-
- nextFree = 0;
- hibernate_page_list_grab(map, &nextFree);
-
- sum = gIOHibernateCurrentHeader->actualRestore1Sum;
- gIOHibernateCurrentHeader->diag[0] = atop_64(headerPhys);
- gIOHibernateCurrentHeader->diag[1] = sum;
-
- uncompressedPages = 0;
- conflictCount = 0;
- copyPageListHeadPage = 0;
- copyPageList = 0;
- copyPageIndex = PAGE_SIZE >> 2;
-
- compressedSize = PAGE_SIZE;
- stage = 2;
- count = 0;
- srcPhys = 0;
-
- if (gIOHibernateCurrentHeader->previewSize)
- {
- pageIndexPhys = headerPhys
- + (offsetof(IOHibernateImageHeader, fileExtentMap)
- + gIOHibernateCurrentHeader->fileExtentMapSize
- + ptoa_32(gIOHibernateCurrentHeader->restore1PageCount));
- imageReadPhys = (pageIndexPhys + gIOHibernateCurrentHeader->previewPageListSize);
- lastPageIndexPage = atop_64(imageReadPhys);
- pageIndexSource = (uint32_t *) pal_hib_map(IMAGE2_AREA, pageIndexPhys);
- }
- else
- {
- pageIndexPhys = 0;
- lastPageIndexPage = 0;
- imageReadPhys = (mapPhys + gIOHibernateCurrentHeader->bitmapSize);
- }
-
- debug_code(kIOHibernateRestoreCodePageIndexStart, pageIndexPhys);
- debug_code(kIOHibernateRestoreCodePageIndexEnd, ptoa_64(lastPageIndexPage));
-
- while (1)
- {
- switch (stage)
- {
- case 2:
- // copy handoff data
- count = srcPhys ? 0 : handoffPageCount;
- if (!count)
- break;
- if (count > gIOHibernateHandoffPageCount) count = gIOHibernateHandoffPageCount;
- srcPhys = ptoa_64(handoffPages);
- break;
-
- case 1:
- // copy pageIndexSource pages == preview image data
- if (!srcPhys)
- {
- if (!pageIndexPhys) break;
- srcPhys = imageReadPhys;
- }
- ppnum = pageIndexSource[0];
- count = pageIndexSource[1];
- pageIndexSource += 2;
- pageIndexPhys += 2 * sizeof(pageIndexSource[0]);
- imageReadPhys = srcPhys;
- break;
-
- case 0:
- // copy pages
- if (!srcPhys) srcPhys = (mapPhys + gIOHibernateCurrentHeader->bitmapSize);
- src = (uint32_t *) pal_hib_map(IMAGE_AREA, srcPhys);
- ppnum = src[0];
- count = src[1];
- srcPhys += 2 * sizeof(*src);
- imageReadPhys = srcPhys;
- break;
- }