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.

207 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. memmap.c
  5. Abstract:
  6. Shell app "memmap"
  7. Revision History
  8. --*/
  9. #include "shell.h"
  10. /*
  11. *
  12. */
  13. EFI_STATUS
  14. InitializeMemmap (
  15. IN EFI_HANDLE ImageHandle,
  16. IN EFI_SYSTEM_TABLE *SystemTable
  17. );
  18. BOOLEAN
  19. IsRealMemory (
  20. IN EFI_MEMORY_TYPE Type
  21. );
  22. /*
  23. *
  24. */
  25. EFI_DRIVER_ENTRY_POINT(InitializeMemmap)
  26. EFI_STATUS
  27. InitializeMemmap (
  28. IN EFI_HANDLE ImageHandle,
  29. IN EFI_SYSTEM_TABLE *SystemTable
  30. )
  31. {
  32. CHAR16 *p;
  33. UINTN Index;
  34. BOOLEAN PageBreaks;
  35. UINTN TempColumn;
  36. UINTN ScreenCount;
  37. UINTN ScreenSize;
  38. CHAR16 ReturnStr[1];
  39. EFI_MEMORY_DESCRIPTOR *Desc, *MemMap;
  40. UINTN DescriptorSize;
  41. UINT32 DescriptorVersion;
  42. UINTN NoDesc, MapKey;
  43. UINT64 Bytes;
  44. UINT64 NoPages[EfiMaxMemoryType];
  45. UINT64 TotalMemory;
  46. /*
  47. * Check to see if the app is to install as a "internal command"
  48. * to the shell
  49. */
  50. InstallInternalShellCommand (
  51. ImageHandle, SystemTable, InitializeMemmap,
  52. L"memmap", /* command */
  53. L"memmap [-b]", /* command syntax */
  54. L"Dumps memory map", /* 1 line descriptor */
  55. NULL /* command help page */
  56. );
  57. /*
  58. * We are no being installed as an internal command driver, initialize
  59. * as an nshell app and run
  60. */
  61. InitializeShellApplication (ImageHandle, SystemTable);
  62. PageBreaks = FALSE;
  63. for (Index = 1; Index < SI->Argc; Index += 1) {
  64. p = SI->Argv[Index];
  65. if (*p == '-') {
  66. switch (p[1]) {
  67. case 'b' :
  68. case 'B' :
  69. PageBreaks = TRUE;
  70. ST->ConOut->QueryMode (ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize);
  71. ScreenCount = 0;
  72. break;
  73. default:
  74. Print (L"%EDH: Unkown flag %s\n", p);
  75. return EFI_INVALID_PARAMETER;
  76. }
  77. }
  78. }
  79. /*
  80. *
  81. */
  82. MemMap = LibMemoryMap (&NoDesc, &MapKey, &DescriptorSize, &DescriptorVersion);
  83. if (!MemMap) {
  84. Print (L"Memory map was not returned\n");
  85. }
  86. ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);
  87. for (Index=0; Index < EfiMaxMemoryType; Index += 1) {
  88. NoPages[Index] = 0;
  89. }
  90. Desc = MemMap;
  91. Print(L"\n%HType Start End # Pages Attributes%N\n");
  92. for (Index=0; Index < NoDesc; Index += 1) {
  93. Bytes = LShiftU64(Desc->NumberOfPages, 12);
  94. p = MemoryTypeStr(Desc->Type);
  95. Print(L"%s %lX-%lX %lX %lX\n", p, Desc->PhysicalStart, Desc->PhysicalStart + Bytes - 1, Desc->NumberOfPages, Desc->Attribute);
  96. if (PageBreaks) {
  97. ScreenCount++;
  98. if (ScreenCount > ScreenSize - 4) {
  99. ScreenCount = 0;
  100. Print (L"\nPress Return to contiue :");
  101. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  102. Print (L"\n\n");
  103. }
  104. }
  105. NoPages[Desc->Type] += Desc->NumberOfPages;
  106. Desc = NextMemoryDescriptor(Desc, DescriptorSize);
  107. }
  108. Print(L"\n");
  109. if (PageBreaks) {
  110. ScreenCount++;
  111. if (ScreenCount > ScreenSize - 4) {
  112. ScreenCount = 0;
  113. Print (L"\nPress Return to contiue :");
  114. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  115. Print (L"\n\n");
  116. }
  117. }
  118. for (Index=0, TotalMemory = 0; Index < EfiMaxMemoryType; Index += 1) {
  119. if (NoPages[Index]) {
  120. Print(L" %s: %,7ld Pages (%,ld)\n",
  121. MemoryTypeStr((EFI_MEMORY_TYPE)Index),
  122. NoPages[Index],
  123. LShiftU64(NoPages[Index], 12)
  124. );
  125. if (PageBreaks) {
  126. ScreenCount++;
  127. if (ScreenCount > ScreenSize - 4) {
  128. ScreenCount = 0;
  129. Print (L"\nPress Return to contiue :");
  130. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  131. Print (L"\n\n");
  132. }
  133. }
  134. if (IsRealMemory((EFI_MEMORY_TYPE)(Index))) {
  135. TotalMemory += NoPages[Index];
  136. }
  137. }
  138. }
  139. Print(L"Total Memory: %,ld MB (%,ld) Bytes\n",
  140. RShiftU64(TotalMemory, 8),
  141. LShiftU64(TotalMemory, 12)
  142. );
  143. FreePool(MemMap);
  144. return EFI_SUCCESS;
  145. }
  146. BOOLEAN
  147. IsRealMemory (
  148. IN EFI_MEMORY_TYPE Type
  149. )
  150. {
  151. switch (Type) {
  152. case EfiLoaderCode:
  153. case EfiLoaderData:
  154. case EfiBootServicesCode:
  155. case EfiBootServicesData:
  156. case EfiRuntimeServicesCode:
  157. case EfiRuntimeServicesData:
  158. case EfiConventionalMemory:
  159. case EfiACPIReclaimMemory:
  160. case EfiACPIMemoryNVS:
  161. case EfiPalCode:
  162. /*
  163. * BugBug can EfiPalCode point to ROM?
  164. */
  165. return TRUE;
  166. break;
  167. default:
  168. return FALSE;
  169. break;
  170. }
  171. }