Leaked source code of windows server 2003
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.

213 lines
4.9 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. UNREFERENCED_PARAMETER( PteToMap );
  76. ASSERT (Page < (1024L * 1024L * 1024L >> PAGE_SHIFT)) ;
  77. return (PVOID) ((Page << PAGE_SHIFT) + KSEG0_BASE) ;
  78. }
  79. PVOID
  80. HbNextSharedPage (
  81. IN ULONG PteToMap,
  82. IN PFN_NUMBER RealPage
  83. )
  84. /*++
  85. Routine Description:
  86. Allocates the next available page in the free list and
  87. maps the Hiber pte to the page. The allocated page
  88. is put onto the remap list.
  89. Arguments:
  90. PteToMap - unused, present only for x86 compatibility
  91. RealPage - The page to enter into the remap table for
  92. this allocation
  93. Return Value:
  94. Virtual address of the mapping
  95. --*/
  96. {
  97. PFN_NUMBER DestPage;
  98. ULONG i;
  99. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  100. HbPrint("HbNextSharedPage("); HbPrintHex(RealPage); HbPrint(")\r\n");
  101. SHOWNUM(HiberCurrentMapIndex);
  102. SHOWNUM(HiberNoMappings);
  103. #endif
  104. //
  105. // Loop until we find a free page which is not in
  106. // use by the loader image, then map it
  107. //
  108. while (HiberCurrentMapIndex < HiberNoMappings) {
  109. DestPage = HiberMapPage[HiberCurrentMapIndex];
  110. HiberCurrentMapIndex += 1;
  111. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  112. SHOWHEX(DestPage);
  113. #endif
  114. i = HbPageDisposition (DestPage);
  115. if (i == HbPageInvalid) {
  116. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  117. HbPrint("Invalid\n");
  118. HbPause();
  119. #endif
  120. HiberIoError = TRUE;
  121. return HiberBuffer;
  122. }
  123. if (i == HbPageNotInUse) {
  124. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 2)
  125. HbPrint("Not in use\r\n");
  126. HbPause();
  127. #endif
  128. #if defined (HIBER_DEBUG) && (HIBER_DEBUG & 4)
  129. HbPrint("\r\n"); HbPrintHex(RealPage); HbPrint(" at "); HbPrintHex(DestPage);
  130. #endif
  131. HiberMapPage[HiberLastRemap] = DestPage;
  132. HiberRemapPage[HiberLastRemap] = RealPage;
  133. HiberLastRemap += 1;
  134. return HbMapPte(PteToMap, DestPage);
  135. }
  136. #if defined (HIBER_DEBUG)
  137. SHOWNUM(i);
  138. #endif
  139. }
  140. #if defined (HIBER_DEBUG)
  141. HbPrint("Out of remap\r\n");
  142. HbPause();
  143. #endif
  144. HiberOutOfRemap = TRUE;
  145. return HiberBuffer;
  146. }
  147. VOID
  148. HiberSetupForWakeDispatch (
  149. VOID
  150. )
  151. {
  152. //
  153. // Make sure the I-cache is coherent with the wake dispatch code that was
  154. // copied to a free page.
  155. //
  156. }