Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. wake.c
  5. Abstract:
  6. This module contains architecture dependent support for hibernation
  7. on IA-64.
  8. Author:
  9. Allen Kay (allen.m.kay@intel.com)
  10. Revision History:
  11. --*/
  12. #include <bldr.h>
  13. #if defined (HIBER_DEBUG)
  14. extern VOID HbPrint(PUCHAR);
  15. extern VOID HbPrintNum(ULONG n);
  16. extern VOID HbPrintHex(ULONG n);
  17. extern VOID HbPause(VOID);
  18. #define SHOWNUM(x) ((void) (HbPrint(#x " = "), HbPrintNum((ULONG) (x)), HbPrint("\r\n")))
  19. #define SHOWHEX(x) ((void) (HbPrint(#x " = "), HbPrintHex((ULONG) (x)), HbPrint("\r\n")))
  20. #endif
  21. //
  22. // When the hibernation image is read from disk each page must return to the
  23. // same page frame it came from. Some of those page frames are currently in
  24. // use by firmware or OS Loader, so the pages that belong there must be
  25. // loaded temporarily somewhere else and copied into place just before the
  26. // saved image is restarted.
  27. //
  28. // The hibernation file contains a list of pages that were not in use by
  29. // the saved image, and were allocated from memory marked as MemoryFree by
  30. // firmware. MapPage is initialized to point to this list; as pages are
  31. // needed for relocation, they are chosen from this list. RemapPage is
  32. // a corresponding array of where each relocated page actually belongs.
  33. //
  34. PPFN_NUMBER HiberMapPage;
  35. PPFN_NUMBER HiberRemapPage;
  36. ULONG HiberCurrentMapIndex;
  37. VOID
  38. HbInitRemap(
  39. PPFN_NUMBER FreeList
  40. )
  41. /*++
  42. Routine Description:
  43. Initialize memory allocation and remapping. Find a free page
  44. in the FreeList, copy the FreeList into it, and point HiberMapPage
  45. to it. Find another free page and and point HiberRemapPage to it.
  46. Initialize HiberLastRemap.
  47. Arguments:
  48. None.
  49. Return Value:
  50. None.
  51. --*/
  52. {
  53. HiberMapPage = HiberRemapPage = FreeList; // so HbNextSharedPage will work
  54. HiberMapPage = HbNextSharedPage(0, 0);
  55. RtlCopyMemory(HiberMapPage, FreeList, PAGE_SIZE);
  56. HiberRemapPage = HbNextSharedPage(0, 0);
  57. }
  58. PVOID
  59. HbMapPte (
  60. IN ULONG PteToMap,
  61. IN PFN_NUMBER Page
  62. )
  63. /*++
  64. Routine Description:
  65. Return a 32 superpage pointer to the specified physical page.
  66. (On x86, this function maps the page and returns a virtual address.)
  67. Arguments:
  68. PteToMap - unused, present only for x86 compatibility
  69. Page - the physical page (page frame number) to map,
  70. must be below 1 GB.
  71. Return Value:
  72. 32 bit superpage address of the page.
  73. --*/
  74. {
  75. ASSERT (Page < (1024L * 1024L * 1024L >> PAGE_SHIFT)) ;
  76. return (PVOID) ((Page << PAGE_SHIFT) + KSEG0_BASE) ;
  77. }
  78. PVOID
  79. HbNextSharedPage (
  80. IN ULONG PteToMap,
  81. IN PFN_NUMBER RealPage
  82. )
  83. /*++
  84. Routine Description:
  85. Allocates the next available page in the free list and
  86. maps the Hiber pte to the page. The allocated page
  87. is put onto the remap list.
  88. Arguments:
  89. PteToMap - unused, present only for x86 compatibility
  90. RealPage - The page to enter into the remap table for
  91. this allocation
  92. Return Value:
  93. Virtual address of the mapping
  94. --*/
  95. {
  96. PFN_NUMBER DestPage;
  97. ULONG i;
  98. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  99. HbPrint("HbNextSharedPage("); HbPrintHex(RealPage); HbPrint(")\r\n");
  100. SHOWNUM(HiberCurrentMapIndex);
  101. SHOWNUM(HiberNoMappings);
  102. #endif
  103. //
  104. // Loop until we find a free page which is not in
  105. // use by the loader image, then map it
  106. //
  107. while (HiberCurrentMapIndex < HiberNoMappings) {
  108. DestPage = HiberMapPage[HiberCurrentMapIndex];
  109. HiberCurrentMapIndex += 1;
  110. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  111. SHOWHEX(DestPage);
  112. #endif
  113. i = HbPageDisposition (DestPage);
  114. if (i == HbPageInvalid) {
  115. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  116. HbPrint("Invalid\n");
  117. HbPause();
  118. #endif
  119. HiberIoError = TRUE;
  120. return HiberBuffer;
  121. }
  122. if (i == HbPageNotInUse) {
  123. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  124. HbPrint("Not in use\r\n");
  125. HbPause();
  126. #endif
  127. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 4)
  128. HbPrint("\r\n"); HbPrintHex(RealPage); HbPrint(" at "); HbPrintHex(DestPage);
  129. #endif
  130. HiberMapPage[HiberLastRemap] = DestPage;
  131. HiberRemapPage[HiberLastRemap] = RealPage;
  132. HiberLastRemap += 1;
  133. return HbMapPte(PteToMap, DestPage);
  134. }
  135. #if defined (HIBER_DEBUG)
  136. SHOWNUM(i);
  137. #endif
  138. }
  139. #if defined (HIBER_DEBUG)
  140. HbPrint("Out of remap\r\n");
  141. HbPause();
  142. #endif
  143. HiberOutOfRemap = TRUE;
  144. return HiberBuffer;
  145. }
  146. VOID
  147. HiberSetupForWakeDispatch (
  148. VOID
  149. )
  150. {
  151. //
  152. // Make sure the I-cache is coherent with the wake dispatch code that was
  153. // copied to a free page.
  154. //
  155. }