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.

314 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. blprint.c
  5. Abstract:
  6. This module implements the OS loader debug logging routines.
  7. Author:
  8. Chuck Lenzmeier (chuckl) 2-Nov-1995
  9. Revision History:
  10. --*/
  11. #include "bldr.h"
  12. #include <stdio.h>
  13. #if DBG || BLLOGENABLED
  14. ULONG BlLogFileId = (ULONG)-1;
  15. ULONG BlLogActiveTargets = 0;
  16. VOID
  17. BlLogInitialize (
  18. ULONG LogfileDeviceId
  19. )
  20. {
  21. ARC_STATUS Status;
  22. BlLogActiveTargets = 0;
  23. if (BlLoaderBlock->LoadOptions != NULL) {
  24. if (strstr(BlLoaderBlock->LoadOptions,"DBGDISPLAY") != NULL) {
  25. BlLogActiveTargets |= LOG_DISPLAY;
  26. }
  27. if (strstr(BlLoaderBlock->LoadOptions,"DBGDEBUGGER") != NULL) {
  28. BlLogActiveTargets |= LOG_DEBUGGER;
  29. }
  30. if (strstr(BlLoaderBlock->LoadOptions,"DBGLOG") != NULL) {
  31. Status = BlOpen(LogfileDeviceId, "\\LDRDBG.LOG", ArcSupersedeReadWrite, &BlLogFileId);
  32. if (Status == 0) {
  33. BlLogActiveTargets |= LOG_LOGFILE;
  34. }
  35. }
  36. }
  37. #if 0
  38. BlLogArcDescriptors(LOG_ALL);
  39. BlLogMemoryDescriptors(LOG_ALL_W);
  40. #endif
  41. return;
  42. }
  43. VOID
  44. BlLogTerminate (
  45. VOID
  46. )
  47. {
  48. #if 0
  49. BlLogMemoryDescriptors(LOG_ALL);
  50. #endif
  51. BlLog((
  52. 0 ? BlLogActiveTargets | LOG_WAIT : BlLogActiveTargets,
  53. "BlLog terminating"
  54. ));
  55. if ((BlLogActiveTargets & LOG_LOGFILE) != 0) {
  56. BlClose(BlLogFileId);
  57. }
  58. BlLogActiveTargets = 0;
  59. return;
  60. }
  61. VOID
  62. BlLogWait (
  63. IN ULONG Targets
  64. )
  65. {
  66. if ((Targets & BlLogActiveTargets & LOG_DEBUGGER) != 0) {
  67. DbgBreakPoint( );
  68. } else if ((Targets & BlLogActiveTargets & LOG_DISPLAY) != 0) {
  69. BlLogWaitForKeystroke();
  70. }
  71. return;
  72. }
  73. VOID
  74. BlLogPrint (
  75. ULONG Targets,
  76. PCHAR Format,
  77. ...
  78. )
  79. {
  80. va_list arglist;
  81. int count;
  82. UCHAR buffer[79];
  83. ULONG activeTargets;
  84. activeTargets = Targets & BlLogActiveTargets;
  85. if (activeTargets != 0) {
  86. va_start(arglist, Format);
  87. count = _vsnprintf(buffer, sizeof(buffer), Format, arglist);
  88. if (count != -1) {
  89. RtlFillMemory(&buffer[count], sizeof(buffer)-count-2, ' ');
  90. }
  91. count = sizeof(buffer);
  92. buffer[count-2] = '\r';
  93. buffer[count-1] = '\n';
  94. if ((activeTargets & LOG_LOGFILE) != 0) {
  95. BlWrite(BlLogFileId, buffer, count, &count);
  96. }
  97. if ((activeTargets & LOG_DISPLAY) != 0) {
  98. ArcWrite(ARC_CONSOLE_OUTPUT, buffer, count, &count);
  99. }
  100. if ((activeTargets & LOG_DEBUGGER) != 0) {
  101. DbgPrint( buffer );
  102. }
  103. if ((Targets & LOG_WAIT) != 0) {
  104. BlLogWait( Targets );
  105. }
  106. }
  107. return;
  108. }
  109. VOID
  110. BlLogArcDescriptors (
  111. ULONG Targets
  112. )
  113. {
  114. PMEMORY_DESCRIPTOR CurrentDescriptor;
  115. ULONG activeTargets;
  116. activeTargets = Targets & BlLogActiveTargets;
  117. if (activeTargets != 0) {
  118. BlLog((activeTargets,"***** ARC Memory List *****"));
  119. CurrentDescriptor = NULL;
  120. while ((CurrentDescriptor = ArcGetMemoryDescriptor(CurrentDescriptor)) != NULL) {
  121. BlLog((activeTargets,
  122. "Descriptor %8x: Type %8x Base %8x Pages %8x",
  123. CurrentDescriptor,
  124. (USHORT)(CurrentDescriptor->MemoryType),
  125. CurrentDescriptor->BasePage,
  126. CurrentDescriptor->PageCount));
  127. }
  128. //BlLog((activeTargets,"***************************"));
  129. if ((Targets & LOG_WAIT) != 0) {
  130. BlLogWait( Targets );
  131. }
  132. }
  133. return;
  134. }
  135. VOID
  136. BlLogMemoryDescriptors (
  137. ULONG Targets
  138. )
  139. {
  140. PLIST_ENTRY CurrentLink;
  141. PMEMORY_ALLOCATION_DESCRIPTOR CurrentDescriptor;
  142. ULONG Index;
  143. ULONG ExpectedIndex;
  144. ULONG ExpectedBase;
  145. ULONG FoundIndex;
  146. PMEMORY_ALLOCATION_DESCRIPTOR FoundDescriptor;
  147. TYPE_OF_MEMORY LastType;
  148. ULONG FreeBlocks = 0;
  149. ULONG FreePages = 0;
  150. ULONG LargestFree = 0;
  151. ULONG activeTargets;
  152. activeTargets = Targets & BlLogActiveTargets;
  153. if (activeTargets != 0) {
  154. BlLog((activeTargets,"***** System Memory List *****"));
  155. ExpectedIndex = 0;
  156. ExpectedBase = 0;
  157. LastType = (ULONG)-1;
  158. do {
  159. Index = 0;
  160. FoundDescriptor = NULL;
  161. CurrentLink = BlLoaderBlock->MemoryDescriptorListHead.Flink;
  162. while (CurrentLink != &BlLoaderBlock->MemoryDescriptorListHead) {
  163. CurrentDescriptor = (PMEMORY_ALLOCATION_DESCRIPTOR)CurrentLink;
  164. if (CurrentDescriptor->BasePage == ExpectedBase) {
  165. if ((FoundDescriptor != NULL) && (FoundDescriptor->BasePage == ExpectedBase)) {
  166. BlLog((activeTargets,
  167. "ACK! Found multiple descriptors with base %x: %x and %x",
  168. ExpectedBase,
  169. FoundDescriptor,
  170. CurrentDescriptor));
  171. } else {
  172. FoundDescriptor = CurrentDescriptor;
  173. FoundIndex = Index;
  174. }
  175. } else if (CurrentDescriptor->BasePage > ExpectedBase) {
  176. if ((FoundDescriptor == NULL) ||
  177. (CurrentDescriptor->BasePage < FoundDescriptor->BasePage)) {
  178. FoundDescriptor = CurrentDescriptor;
  179. FoundIndex = Index;
  180. }
  181. }
  182. CurrentLink = CurrentLink->Flink;
  183. Index++;
  184. }
  185. if (FoundDescriptor != NULL) {
  186. if (FoundDescriptor->BasePage != ExpectedBase) {
  187. BlLog((activeTargets,
  188. " ACK! MISSING MEMORY! ACK! Base %8x Pages %8x",
  189. ExpectedBase,
  190. FoundDescriptor->BasePage - ExpectedBase));
  191. }
  192. BlLog((activeTargets,
  193. "%c%c%2d Descriptor %8x: Type %8x Base %8x Pages %8x",
  194. FoundDescriptor->MemoryType == LastType ? '^' : ' ',
  195. FoundIndex == ExpectedIndex ? ' ' : '*',
  196. FoundIndex,
  197. FoundDescriptor,
  198. (USHORT)(FoundDescriptor->MemoryType),
  199. FoundDescriptor->BasePage,
  200. FoundDescriptor->PageCount));
  201. if (FoundIndex == ExpectedIndex) {
  202. ExpectedIndex++;
  203. }
  204. ExpectedBase = FoundDescriptor->BasePage + FoundDescriptor->PageCount;
  205. LastType = FoundDescriptor->MemoryType;
  206. if (LastType != MemoryFree) {
  207. LastType = (ULONG)-1;
  208. } else {
  209. FreeBlocks++;
  210. FreePages += FoundDescriptor->PageCount;
  211. if (FoundDescriptor->PageCount > LargestFree) {
  212. LargestFree = FoundDescriptor->PageCount;
  213. }
  214. }
  215. }
  216. } while ( FoundDescriptor != NULL );
  217. BlLog((activeTargets,
  218. "Total free blocks %2d, free pages %4x, largest free %4x",
  219. FreeBlocks,
  220. FreePages,
  221. LargestFree));
  222. //BlLog((activeTargets,"******************************"));
  223. if ((Targets & LOG_WAIT) != 0) {
  224. BlLogWait( Targets );
  225. }
  226. }
  227. return;
  228. }
  229. VOID
  230. BlLogWaitForKeystroke (
  231. VOID
  232. )
  233. {
  234. UCHAR Key=0;
  235. ULONG Count;
  236. if ((BlLogActiveTargets & LOG_DISPLAY) != 0) {
  237. do {
  238. if (ArcGetReadStatus(ARC_CONSOLE_INPUT) == ESUCCESS) {
  239. ArcRead(ARC_CONSOLE_INPUT,
  240. &Key,
  241. sizeof(Key),
  242. &Count);
  243. break;
  244. }
  245. } while ( TRUE );
  246. }
  247. return;
  248. }
  249. #endif // DBG