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.

232 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. misc.c
  5. Abstract:
  6. This module implements machine dependent miscellaneous kernel functions.
  7. Author:
  8. David N. Cutler (davec) - 6-Dec-2000
  9. Environment:
  10. Kernel mode only.
  11. --*/
  12. #include "ki.h"
  13. VOID
  14. KeRestoreProcessorSpecificFeatures(
  15. VOID
  16. )
  17. /*++
  18. Routine Description:
  19. Restore processor specific features. This routine is called
  20. when processors have been restored to a powered on state to
  21. restore those things which are not part of the processor's
  22. "normal" context which may have been lost. For example, this
  23. routine is called when a system is resumed from hibernate or
  24. suspend.
  25. Arguments:
  26. None.
  27. Return Value:
  28. None.
  29. --*/
  30. {
  31. //
  32. // All Amd64 processors should support PAT.
  33. //
  34. ASSERT (KeFeatureBits & KF_PAT);
  35. //
  36. // Restore MSR_PAT of current processor.
  37. //
  38. KiSetPageAttributesTable();
  39. return;
  40. }
  41. VOID
  42. KeSaveStateForHibernate (
  43. IN PKPROCESSOR_STATE ProcessorState
  44. )
  45. /*++
  46. Routine Description:
  47. Saves all processor-specific state that must be preserved
  48. across an S4 state (hibernation).
  49. Arguments:
  50. ProcessorState - Supplies the KPROCESSOR_STATE where the current CPU's
  51. state is to be saved.
  52. Return Value:
  53. None.
  54. --*/
  55. {
  56. RtlCaptureContext(&ProcessorState->ContextFrame);
  57. ProcessorState->SpecialRegisters.MsrGsBase = ReadMSR(MSR_GS_BASE);
  58. ProcessorState->SpecialRegisters.MsrGsSwap = ReadMSR(MSR_GS_SWAP);
  59. ProcessorState->SpecialRegisters.MsrStar = ReadMSR(MSR_STAR);
  60. ProcessorState->SpecialRegisters.MsrLStar = ReadMSR(MSR_LSTAR);
  61. ProcessorState->SpecialRegisters.MsrCStar = ReadMSR(MSR_CSTAR);
  62. ProcessorState->SpecialRegisters.MsrSyscallMask = ReadMSR(MSR_SYSCALL_MASK);
  63. ProcessorState->ContextFrame.Rip = (ULONG_PTR)_ReturnAddress();
  64. ProcessorState->ContextFrame.Rsp = (ULONG_PTR)&ProcessorState;
  65. KiSaveProcessorControlState(ProcessorState);
  66. }
  67. #if DBG
  68. VOID
  69. KiCheckForDpcTimeout (
  70. IN PKPRCB Prcb
  71. )
  72. /*++
  73. Routine Description:
  74. This function increments the time spent in the current DPC routine and
  75. checks if the result exceeds the system DPC time out limit. If the result
  76. exceeds the system DPC time out limit, then a warning message is printed
  77. and a break point is executed if the kernel debugger is active.
  78. Arguments:
  79. Prcb - Supplies the address of the current PRCB.
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. //
  85. // Increment the time spent in the current DPC routine and check if the
  86. // system DPC time out limit has been exceeded.
  87. //
  88. if ((Prcb->DebugDpcTime += 1) >= KiDPCTimeout) {
  89. //
  90. // The system DPC time out limit has been exceeded.
  91. //
  92. DbgPrint("*** DPC routine execution time exceeds 1 sec --"
  93. " This is not a break in KeUpdateSystemTime\n");
  94. if (KdDebuggerEnabled != 0) {
  95. DbgBreakPoint();
  96. }
  97. Prcb->DebugDpcTime = 0;
  98. }
  99. }
  100. #endif
  101. VOID
  102. KiInstantiateInlineFunctions (
  103. VOID
  104. )
  105. /*++
  106. Routine Description:
  107. This function exists solely to instantiate functions that are:
  108. - Exported from the kernel
  109. - Inlined within the kernel
  110. - For whatever reason are not instantiated elsewhere in the kernel
  111. Note: This funcion is never actually executed
  112. Arguments:
  113. None
  114. Return Value:
  115. None
  116. --*/
  117. {
  118. KeRaiseIrqlToDpcLevel();
  119. }
  120. VOID
  121. KiProcessNMI (
  122. IN PKTRAP_FRAME TrapFrame,
  123. IN PKEXCEPTION_FRAME ExceptionFrame
  124. )
  125. /*++
  126. Routine Description:
  127. This function processes a nonmaskable interrupt (NMI).
  128. N.B. This function is called from the NMI trap routine with interrupts
  129. disabled.
  130. Arguments:
  131. TrapFrame - Supplies a pointer to a trap frame.
  132. ExceptionFrame - Supplies a pointer to an exception frame.
  133. Return Value:
  134. None.
  135. --*/
  136. {
  137. //
  138. // Process NMI callback functions.
  139. //
  140. // If no callback function handles the NMI, then let the HAL handle it.
  141. //
  142. if (KiHandleNmi() == FALSE) {
  143. KiAcquireSpinLockCheckForFreeze(&KiNMILock, TrapFrame, ExceptionFrame);
  144. HalHandleNMI(NULL);
  145. KeReleaseSpinLockFromDpcLevel(&KiNMILock);
  146. }
  147. return;
  148. }