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.

133 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. io.c
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "shelle.h"
  9. EFI_STATUS
  10. DumpMem (
  11. IN EFI_HANDLE ImageHandle,
  12. IN EFI_SYSTEM_TABLE *SystemTable
  13. );
  14. EFI_DRIVER_ENTRY_POINT(DumpMem)
  15. EFI_STATUS
  16. DumpMem (
  17. IN EFI_HANDLE ImageHandle,
  18. IN EFI_SYSTEM_TABLE *SystemTable
  19. )
  20. /*+++
  21. mem [Address] [Size] ;MMIO
  22. if no Address default address is EFI System Table
  23. if no size default size is 512;
  24. if ;MMIO then use memory mapped IO and not system memory
  25. --*/
  26. {
  27. EFI_STATUS Status;
  28. EFI_HANDLE Handle;
  29. EFI_DEVICE_PATH *DevicePath;
  30. EFI_DEVICE_IO_INTERFACE *IoDev;
  31. UINT64 Address;
  32. UINTN Size;
  33. UINT8 *Buffer;
  34. BOOLEAN MMIo;
  35. UINTN Index;
  36. CHAR16 *AddressStr, *SizeStr, *p;
  37. InstallInternalShellCommand (
  38. ImageHandle, SystemTable, DumpMem,
  39. L"mem", /* command */
  40. L"mem [Address] [size] [;MMIO]", /* command syntax */
  41. L"Dump Memory or Memory Mapped IO", /* 1 line descriptor */
  42. NULL /* command help page */
  43. );
  44. /*
  45. * The End Device Path represents the Root of the tree, thus get the global IoDev
  46. * for the system
  47. */
  48. InitializeShellApplication (ImageHandle, SystemTable);
  49. MMIo = FALSE;
  50. AddressStr = SizeStr = NULL;
  51. for (Index = 1; Index < SI->Argc; Index += 1) {
  52. p = SI->Argv[Index];
  53. if (*p == ';') {
  54. /* Shortcut! assume MMIo if ; exists */
  55. MMIo = TRUE;
  56. continue;
  57. } else if (*p == '-') {
  58. switch (p[1]) {
  59. case 'h':
  60. case 'H':
  61. case '?':
  62. default:
  63. Print (L"\n%Hmem%N [%HAddress%N] [%HSize%N] [%H;MMIO%N]\n");
  64. Print (L" if no %HAddress%N is specified the EFI System Table is used\n");
  65. Print (L" if no %HSize%N is specified 512 bytes is used\n");
  66. Print (L" if %H;MMIO%N is specified memory is referenced with the DeviceIo Protocol\n");
  67. return EFI_SUCCESS;
  68. };
  69. continue;
  70. }
  71. if (!AddressStr) {
  72. AddressStr = p;
  73. continue;
  74. }
  75. if (!SizeStr) {
  76. SizeStr = p;
  77. continue;
  78. }
  79. }
  80. Address = (AddressStr) ? xtoi(AddressStr) : (UINT64)SystemTable;
  81. Size = (SizeStr) ? xtoi(SizeStr) : 512;
  82. Print (L" Memory Address %016lx %0x Bytes\n", Address, Size);
  83. if (MMIo) {
  84. DevicePath = EndDevicePath;
  85. Status = BS->LocateDevicePath (&DeviceIoProtocol, &DevicePath, &Handle);
  86. if (!EFI_ERROR(Status)) {
  87. Status = BS->HandleProtocol (Handle, &DeviceIoProtocol, (VOID*)&IoDev);
  88. }
  89. if (EFI_ERROR(Status)) {
  90. Print (L"%E - handle protocol error %r%N", Status);
  91. return Status;
  92. }
  93. Buffer = AllocatePool (Size);
  94. if (Buffer == NULL) {
  95. return EFI_OUT_OF_RESOURCES;
  96. }
  97. IoDev->Mem.Read (IoDev, IO_UINT8, Address, Size, Buffer);
  98. } else {
  99. Buffer = (UINT8 *)Address;
  100. }
  101. DumpHex (2, (UINTN)Address, Size, Buffer);
  102. EFIStructsPrint (Buffer, Size, Address, NULL);
  103. if (MMIo) {
  104. FreePool (Buffer);
  105. }
  106. return EFI_SUCCESS;
  107. }