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.

279 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. stubs.c
  5. Abstract:
  6. This module implements memory check routine for the boot debugger.
  7. Author:
  8. David N. Cutler (davec) 3-Dec-96
  9. Environment:
  10. Kernel mode only.
  11. Revision History:
  12. --*/
  13. #include "bd.h"
  14. extern BOOLEAN PaeEnabled;
  15. BOOLEAN
  16. BdCheckPdeValid (
  17. IN PVOID Address
  18. )
  19. /*++
  20. Routine Description:
  21. This routine determines if the PDE for the specified address has the
  22. valid bit set.
  23. Agruments:
  24. Address - Supplies the virtual address to check.
  25. Return Value:
  26. A value of TRUE indicates that the PDE for the supplied virtual address
  27. does have the valid bit set, FALSE if it does not.
  28. --*/
  29. {
  30. PHARDWARE_PTE_X86PAE PdePae;
  31. PHARDWARE_PTE_X86 PdeX86;
  32. if (PaeEnabled) {
  33. //
  34. // Physical address extenions are enabled.
  35. //
  36. PdePae = (PHARDWARE_PTE_X86PAE)PDE_BASE_X86PAE;
  37. PdePae = &PdePae[ (ULONG)Address >> PDI_SHIFT_X86PAE ];
  38. if (PdePae->Valid == 0) {
  39. return FALSE;
  40. } else {
  41. return TRUE;
  42. }
  43. } else {
  44. //
  45. // Physical address extensions are not enabled.
  46. //
  47. PdeX86 = (PHARDWARE_PTE_X86)PDE_BASE;
  48. PdeX86 = &PdeX86[ (ULONG)Address >> PDI_SHIFT_X86 ];
  49. if (PdeX86->Valid == 0) {
  50. return FALSE;
  51. } else {
  52. return TRUE;
  53. }
  54. }
  55. }
  56. BOOLEAN
  57. BdCheckPteValid (
  58. IN PVOID Address
  59. )
  60. /*++
  61. Routine Description:
  62. This routine determines if the PTE for the specified address has the
  63. valid bit set.
  64. Agruments:
  65. Address - Supplies the virtual address to check.
  66. Return Value:
  67. A value of TRUE indicates that the PTE for the supplied virtual address
  68. does have the valid bit set, FALSE if it does not.
  69. --*/
  70. {
  71. PHARDWARE_PTE_X86PAE PtePae;
  72. PHARDWARE_PTE_X86 PteX86;
  73. if (PaeEnabled) {
  74. //
  75. // Physical address extenions are enabled.
  76. //
  77. PtePae = (PHARDWARE_PTE_X86PAE)PTE_BASE;
  78. PtePae = &PtePae[ (ULONG)Address >> PTI_SHIFT ];
  79. if (PtePae->Valid == 0) {
  80. return FALSE;
  81. } else {
  82. return TRUE;
  83. }
  84. } else {
  85. //
  86. // Physical address extensions are not enabled.
  87. //
  88. PteX86 = (PHARDWARE_PTE_X86)PTE_BASE;
  89. PteX86 = &PteX86[ (ULONG)Address >> PTI_SHIFT ];
  90. if (PteX86->Valid == 0) {
  91. return FALSE;
  92. } else {
  93. return TRUE;
  94. }
  95. }
  96. }
  97. PVOID
  98. BdReadCheck (
  99. IN PVOID Address
  100. )
  101. /*++
  102. Routine Description:
  103. This routine determines if the specified address can be read.
  104. Arguments:
  105. Address - Supplies the virtual address to check.
  106. Return Value:
  107. A value of NULL is returned if the address is not valid or readable.
  108. Otherwise, the physical address of the corresponding virtual address
  109. is returned.
  110. --*/
  111. {
  112. //
  113. // Check if the page containing the specified address is valid.
  114. //
  115. // N.B. If the address is valid, it is readable.
  116. //
  117. if (BdCheckPdeValid( Address ) == FALSE) {
  118. //
  119. // The PDE is not valid.
  120. //
  121. return NULL;
  122. }
  123. if (BdCheckPteValid( Address ) == FALSE) {
  124. //
  125. // The PDE was valid but the PTE is not.
  126. //
  127. return NULL;
  128. }
  129. return Address;
  130. }
  131. PVOID
  132. BdWriteCheck (
  133. IN PVOID Address
  134. )
  135. /*++
  136. Routine Description:
  137. This routine determines if the specified address can be written.
  138. Arguments:
  139. Address - Supplies the virtual address to check.
  140. Return Value:
  141. A value of NULL is returned if the address is not valid or writeable.
  142. Otherwise, the physical address of the corresponding virtual address
  143. is returned.
  144. --*/
  145. {
  146. //
  147. // Check if the page containing the specified address is valid.
  148. //
  149. // N.B. If the address is valid, it is writeable since the WP bit
  150. // is not set in cr0.
  151. //
  152. if (BdCheckPdeValid( Address ) == FALSE) {
  153. //
  154. // The PDE is not valid.
  155. //
  156. return NULL;
  157. }
  158. if (BdCheckPteValid( Address ) == FALSE) {
  159. //
  160. // The PDE was valid but the PTE is not.
  161. //
  162. return NULL;
  163. }
  164. return Address;
  165. }
  166. PVOID
  167. BdTranslatePhysicalAddress (
  168. IN PHYSICAL_ADDRESS Address
  169. )
  170. /*++
  171. Routine Description:
  172. This routine returns the phyiscal address for a physical address
  173. which is valid (mapped).
  174. Arguments:
  175. Address - Supplies the physical address to check.
  176. Return Value:
  177. Returns NULL if the address is not valid or readable. Otherwise,
  178. returns the physical address of the corresponding virtual address.
  179. --*/
  180. {
  181. return (PVOID)Address.LowPart;
  182. }