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.

370 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. dprot.c
  5. Abstract:
  6. Shell environment - dump protocol functions for the "dh" command
  7. Revision History
  8. --*/
  9. #include "shelle.h"
  10. STATIC CHAR16 *SEnvDP_IlleagalStr[] = {
  11. L"Illegal"
  12. };
  13. STATIC CHAR16 *SEnvDP_HardwareStr[] = {
  14. L"Illegal", L"PCI", L"PCCARD", L"MemMap", L"VENDOR"
  15. };
  16. STATIC CHAR16 *SEnvDP_PnP_Str[] = {
  17. L"Illegal", L"PnP"
  18. };
  19. STATIC CHAR16 *SEnvDP_MessageStr[] = {
  20. L"Illegal", L"ATAPI", L"SCSI", L"FIBRE Channel",
  21. L"1394", L"USB", L"I2O", L"TCP/IPv4", L"TCP/IPv6",
  22. L"NGIO", L"VENDOR"
  23. };
  24. STATIC CHAR16 *SEnvDP_MediaStr[] = {
  25. L"Illegal", L"Hard Drive", L"CD-ROM", L"VENDOR", L"File Path", L"Media Protocol"
  26. };
  27. STATIC CHAR16 *SEnvDP_BBS_Str[] = {
  28. L"Illegal", L"BBS"
  29. };
  30. struct DevicePathTypes {
  31. UINT8 Type;
  32. UINT8 MaxSubType;
  33. CHAR16 *TypeString;
  34. CHAR16 **SubTypeStr;
  35. VOID (*Function)(EFI_DEVICE_PATH *);
  36. };
  37. VOID
  38. SEnvHardwareDevicePathEntry (
  39. IN EFI_DEVICE_PATH *DevicePath
  40. )
  41. {
  42. VENDOR_DEVICE_PATH *VendorDevicePath;
  43. if (DevicePathType(DevicePath) != HW_PCI_DP) {
  44. return;
  45. }
  46. if (DevicePathSubType(DevicePath) == HW_VENDOR_DP) {
  47. VendorDevicePath = (VENDOR_DEVICE_PATH *)DevicePath;
  48. Print(L"\n%N Guid %g",
  49. &VendorDevicePath->Guid
  50. );
  51. }
  52. }
  53. VOID
  54. SEnvPnpDevicePathEntry (
  55. IN EFI_DEVICE_PATH *DevicePath
  56. )
  57. {
  58. ACPI_HID_DEVICE_PATH *AcpiDevicePath;
  59. if (DevicePathType(DevicePath) != ACPI_DEVICE_PATH) {
  60. return;
  61. }
  62. if (DevicePathSubType(DevicePath) == ACPI_DP) {
  63. AcpiDevicePath = (ACPI_HID_DEVICE_PATH *)DevicePath;
  64. Print(L"\n%N HID %x, UID %x",
  65. AcpiDevicePath->HID,
  66. AcpiDevicePath->UID
  67. );
  68. }
  69. }
  70. VOID
  71. SEnvMediaDevicePathEntry (
  72. IN EFI_DEVICE_PATH *DevicePath
  73. )
  74. {
  75. HARDDRIVE_DEVICE_PATH *HardDriveDevicePath;
  76. CDROM_DEVICE_PATH *CDDevicePath;
  77. VENDOR_DEVICE_PATH *VendorDevicePath;
  78. FILEPATH_DEVICE_PATH *FilePath;
  79. MEDIA_PROTOCOL_DEVICE_PATH *MediaProtocol;
  80. if (DevicePathType(DevicePath) != MEDIA_DEVICE_PATH) {
  81. return;
  82. }
  83. switch (DevicePathSubType(DevicePath)) {
  84. case MEDIA_HARDDRIVE_DP:
  85. HardDriveDevicePath = (HARDDRIVE_DEVICE_PATH *)DevicePath;
  86. Print(L"\n%N Partition (%d) Start (%lX) Size (%lX)",
  87. HardDriveDevicePath->PartitionNumber,
  88. HardDriveDevicePath->PartitionStart,
  89. HardDriveDevicePath->PartitionSize
  90. );
  91. break;
  92. case MEDIA_CDROM_DP:
  93. CDDevicePath = (CDROM_DEVICE_PATH *)DevicePath;
  94. Print(L"\n%N BootEntry (%x) Start (%lX) Size (%lX)",
  95. CDDevicePath->BootEntry,
  96. CDDevicePath->PartitionStart,
  97. CDDevicePath->PartitionSize
  98. );
  99. break;
  100. case MEDIA_VENDOR_DP:
  101. VendorDevicePath = (VENDOR_DEVICE_PATH *)DevicePath;
  102. Print(L"\n%N Guid %g",
  103. &VendorDevicePath->Guid
  104. );
  105. break;
  106. case MEDIA_FILEPATH_DP:
  107. FilePath = (FILEPATH_DEVICE_PATH *) DevicePath;
  108. Print(L"\n%N File '%hs'", FilePath->PathName);
  109. break;
  110. case MEDIA_PROTOCOL_DP:
  111. MediaProtocol = (MEDIA_PROTOCOL_DEVICE_PATH *) DevicePath;
  112. Print(L"\n%N Protocol '%hg'", &MediaProtocol->Protocol);
  113. break;
  114. };
  115. }
  116. struct DevicePathTypes SEnvDP_Strings[] = {
  117. 0x00, 0x01, L"Illegal", SEnvDP_IlleagalStr, NULL,
  118. 0x01, 0x03, L"Hardware", SEnvDP_HardwareStr, SEnvHardwareDevicePathEntry,
  119. 0x02, 0x01, L"PNP", SEnvDP_PnP_Str, SEnvPnpDevicePathEntry,
  120. 0x03, 0x0a, L"Messaging", SEnvDP_MessageStr, NULL,
  121. 0x04, 0x05, L"Media", SEnvDP_MediaStr, SEnvMediaDevicePathEntry,
  122. 0x05, 0x01, L"BBS", SEnvDP_BBS_Str, NULL,
  123. END_DEVICE_PATH_TYPE, 0x01, L"End", SEnvDP_IlleagalStr, NULL
  124. };
  125. VOID
  126. SEnvPrintDevicePathEntry (
  127. IN EFI_DEVICE_PATH *DevicePath,
  128. IN BOOLEAN Verbose
  129. )
  130. {
  131. UINT8 Type;
  132. UINT8 SubType;
  133. INTN i;
  134. Type = DevicePathType(DevicePath);
  135. SubType = DevicePathSubType(DevicePath);
  136. for (i=0; SEnvDP_Strings[i].Type != END_DEVICE_PATH_TYPE;i++) {
  137. if (Type == SEnvDP_Strings[i].Type) {
  138. if (SubType > SEnvDP_Strings[i].MaxSubType) {
  139. SubType = 0;
  140. }
  141. Print(L"\n%N %s Device Path for %s",
  142. SEnvDP_Strings[i].TypeString,
  143. SEnvDP_Strings[i].SubTypeStr[SubType]
  144. );
  145. if (Verbose) {
  146. if(SEnvDP_Strings[i].Function != NULL) {
  147. SEnvDP_Strings[i].Function(DevicePath);
  148. }
  149. }
  150. return;
  151. }
  152. }
  153. Print(L"\n%E Device Path Error%N - Unknown Device Type");
  154. DbgPrint (D_ERROR, "%EDevice Path Error%N - Unknown Device Type");
  155. }
  156. VOID
  157. SEnvDPath (
  158. IN EFI_HANDLE h,
  159. IN VOID *Interface
  160. )
  161. {
  162. EFI_DEVICE_PATH *DevicePath, *DevicePathNode;
  163. CHAR16 *Str;
  164. DevicePath = Interface;
  165. Str = DevicePathToStr (DevicePath);
  166. DevicePath = UnpackDevicePath (DevicePath);
  167. DevicePathNode = DevicePath;
  168. while (!IsDevicePathEnd(DevicePathNode)) {
  169. SEnvPrintDevicePathEntry(DevicePathNode, TRUE);
  170. DevicePathNode = NextDevicePathNode(DevicePathNode);
  171. }
  172. Print (L"\n AsStr:%N '%s'\n", Str);
  173. FreePool (Str);
  174. FreePool (DevicePath);
  175. }
  176. VOID
  177. SEnvDPathTok (
  178. IN EFI_HANDLE h,
  179. IN VOID *Interface
  180. )
  181. {
  182. EFI_DEVICE_PATH *DevicePath;
  183. CHAR16 *Str, *Disp;
  184. UINTN Len;
  185. DevicePath = Interface;
  186. Str = DevicePathToStr (DevicePath);
  187. Disp = L"";
  188. if (Str) {
  189. Len = StrLen(Str);
  190. Disp = Str;
  191. if (Len > 30) {
  192. Disp = Str + Len - 30;
  193. Disp[0] = '.';
  194. Disp[1] = '.';
  195. }
  196. }
  197. Print (L"DevPath(%s)", Disp);
  198. if (Str) {
  199. FreePool (Str);
  200. }
  201. }
  202. VOID
  203. SEnvTextOut (
  204. IN EFI_HANDLE h,
  205. IN VOID *Interface
  206. )
  207. {
  208. SIMPLE_TEXT_OUTPUT_INTERFACE *Dev;
  209. INTN i;
  210. UINTN Col, Row;
  211. EFI_STATUS Status;
  212. Dev = Interface;
  213. Print (L"Attrib %x",
  214. Dev->Mode->Attribute
  215. );
  216. for (i=0; i < Dev->Mode->MaxMode; i++) {
  217. Status = Dev->QueryMode (Dev, i, &Col, &Row);
  218. Print (L"\n%N %hc mode %d: ",
  219. i == Dev->Mode->Mode ? '*' : ' ',
  220. i
  221. );
  222. if (EFI_ERROR(Status)) {
  223. Print (L"%error %rx\n", Status);
  224. } else {
  225. Print (L"col %3d row %3d", Col, Row);
  226. }
  227. }
  228. }
  229. VOID
  230. SEnvBlkIo (
  231. IN EFI_HANDLE h,
  232. IN VOID *Interface
  233. )
  234. {
  235. EFI_BLOCK_IO *BlkIo;
  236. EFI_BLOCK_IO_MEDIA *BlkMedia;
  237. VOID *Buffer;
  238. BlkIo = Interface;
  239. BlkMedia = BlkIo->Media;
  240. /* issue a dumby read to the device to check for media change */
  241. Buffer = AllocatePool (BlkMedia->BlockSize);
  242. if (Buffer) {
  243. BlkIo->ReadBlocks(BlkIo, BlkMedia->MediaId, 0, BlkMedia->BlockSize, Buffer);
  244. FreePool (Buffer);
  245. }
  246. Print (L"%s%esMId:%x ",
  247. BlkMedia->RemovableMedia ? L"Removable " : L"Fixed ",
  248. BlkMedia->MediaPresent ? L"" : L"not-present ",
  249. BlkMedia->MediaId
  250. );
  251. Print (L"bsize %x, lblock %lx (%,ld), %s %s %s",
  252. BlkMedia->BlockSize,
  253. BlkMedia->LastBlock,
  254. MultU64x32 (BlkMedia->LastBlock + 1, BlkMedia->BlockSize),
  255. BlkMedia->LogicalPartition ? L"partition" : L"raw",
  256. BlkMedia->ReadOnly ? L"ro" : L"rw",
  257. BlkMedia->WriteCaching ? L"cached" : L"!cached"
  258. );
  259. }
  260. VOID
  261. SEnvImageTok (
  262. IN EFI_HANDLE h,
  263. IN VOID *Interface
  264. )
  265. {
  266. EFI_LOADED_IMAGE *Image;
  267. CHAR16 *Tok;
  268. Image = Interface;
  269. Tok = DevicePathToStr (Image->FilePath);
  270. Print (L"%HImage%N(%s) ", Tok);
  271. if (Tok) {
  272. FreePool (Tok);
  273. }
  274. }
  275. VOID
  276. SEnvImage (
  277. IN EFI_HANDLE h,
  278. IN VOID *Interface
  279. )
  280. {
  281. EFI_LOADED_IMAGE *Image;
  282. CHAR16 *FilePath;
  283. Image = Interface;
  284. FilePath = DevicePathToStr (Image->FilePath);
  285. Print (L" File:%hs\n", FilePath);
  286. if (!Image->ImageBase) {
  287. Print (L" %EInternal Image:%N %s\n", FilePath);
  288. Print (L" CodeType......: %s\n", MemoryTypeStr(Image->ImageCodeType));
  289. Print (L" DataType......: %s\n", MemoryTypeStr(Image->ImageDataType));
  290. } else {
  291. Print (L" ParentHandle..: %X\n", Image->ParentHandle);
  292. Print (L" SystemTable...: %X\n", Image->SystemTable);
  293. Print (L" DeviceHandle..: %X\n", Image->DeviceHandle);
  294. Print (L" FilePath......: %s\n", FilePath);
  295. Print (L" ImageBase.....: %X - %X\n",
  296. Image->ImageBase,
  297. (CHAR8 *) Image->ImageBase + Image->ImageSize
  298. );
  299. Print (L" ImageSize.....: %lx\n", Image->ImageSize);
  300. Print (L" CodeType......: %s\n", MemoryTypeStr(Image->ImageCodeType));
  301. Print (L" DataType......: %s\n", MemoryTypeStr(Image->ImageDataType));
  302. }
  303. if (FilePath) {
  304. FreePool (FilePath);
  305. }
  306. }