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.

228 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. libMemImage.c
  5. Abstract:
  6. Defines the routines for handling a memory buffer
  7. --*/
  8. #ifndef _LIB_MEM_IMAGE
  9. #define _LIB_MEM_IMAGE
  10. #include "libMisc.h"
  11. STATIC EFI_STATUS MemImageInit (VOID);
  12. STATIC EFI_STATUS MemImageOpen (VOID);
  13. STATIC EFI_STATUS MemImageClose (VOID);
  14. STATIC EFI_STATUS MemImageCleanup (VOID);
  15. STATIC EFI_STATUS MemImageRead (VOID);
  16. STATIC EFI_STATUS MemImageWrite (VOID);
  17. STATIC EFI_STATUS MemImageSetOffset (UINTN);
  18. STATIC EFI_STATUS MemImageSetSize (UINTN);
  19. extern EE_BUFFER_IMAGE BufferImage;
  20. EE_MEM_IMAGE MemImage = {
  21. NULL,
  22. 0,
  23. 0,
  24. MemImageInit,
  25. MemImageSetOffset,
  26. MemImageSetSize,
  27. };
  28. STATIC
  29. EFI_STATUS
  30. MemImageInit (
  31. VOID
  32. )
  33. {
  34. BufferImage.ImageCleanup();
  35. MemImage.IoFncs = AllocatePool(sizeof(EFI_DEVICE_IO_INTERFACE));
  36. BufferImage.ImageCleanup = MemImageCleanup;
  37. BufferImage.Open = MemImageOpen;
  38. BufferImage.Close = MemImageClose;
  39. BufferImage.Read = MemImageRead;
  40. BufferImage.Write = MemImageWrite;
  41. BufferImage.BufferType = MEM_BUFFER;
  42. return EFI_SUCCESS;
  43. }
  44. STATIC
  45. EFI_STATUS
  46. MemImageOpen (
  47. VOID
  48. )
  49. {
  50. EFI_STATUS Status;
  51. EFI_HANDLE Handle;
  52. EFI_DEVICE_PATH *DevicePath;
  53. EFI_DEV_PATH Node;
  54. ZeroMem(&Node,sizeof(Node));
  55. Node.DevPath.Type = HARDWARE_DEVICE_PATH;
  56. Node.DevPath.SubType = HW_MEMMAP_DP;
  57. SetDevicePathNodeLength(&Node.DevPath,sizeof(MEMMAP_DEVICE_PATH));
  58. Node.MemMap.StartingAddress = MemImage.Offset;
  59. Node.MemMap.EndingAddress = MemImage.Offset + MemImage.Size;
  60. DevicePath = AppendDevicePathNode (EndDevicePath, &Node.DevPath);
  61. Status = BS->LocateDevicePath(&DevicePathProtocol,
  62. &DevicePath,
  63. &Handle
  64. );
  65. if (EFI_ERROR(Status)) {
  66. EditorError(Status,L"MemImageOpen: Could not get DevicePath");
  67. return Status;
  68. }
  69. Status = BS->HandleProtocol (Handle,
  70. &DeviceIoProtocol,
  71. &MemImage.IoFncs
  72. );
  73. if (EFI_ERROR(Status)) {
  74. EditorError(Status,L"MemImageOpen: Could not get DeviceIo Protocol");
  75. return Status;
  76. }
  77. return EFI_SUCCESS;
  78. }
  79. STATIC
  80. EFI_STATUS
  81. MemImageClose (
  82. VOID
  83. )
  84. {
  85. LineDeleteAll(BufferImage.ListHead);
  86. BufferImage.NumBytes = 0;
  87. MainEditor.FileBuffer->Offset = 0x00;
  88. MainEditor.StatusBar->SetOffset(0x00);
  89. MainEditor.FileBuffer->LowVisibleOffset = 0x00;
  90. MainEditor.FileBuffer->SetPosition(DISP_START_ROW,HEX_POSITION);
  91. MainEditor.FileModified = FALSE;
  92. return EFI_SUCCESS;
  93. }
  94. STATIC
  95. EFI_STATUS
  96. MemImageCleanup (
  97. VOID
  98. )
  99. {
  100. if (MemImage.IoFncs != NULL) {
  101. FreePool(MemImage.IoFncs);
  102. }
  103. MemImage.Offset = 0;
  104. MemImage.Size = 0;
  105. BufferImage.ImageCleanup = Nothing;
  106. BufferImage.Open = Nothing;
  107. BufferImage.Close = Nothing;
  108. BufferImage.Read = Nothing;
  109. BufferImage.Write = Nothing;
  110. return EFI_SUCCESS;
  111. }
  112. STATIC
  113. EFI_STATUS
  114. MemImageRead (
  115. VOID
  116. )
  117. {
  118. EFI_STATUS Status;
  119. VOID *Buffer;
  120. Buffer = AllocatePool(MemImage.Size);
  121. Status = MemImage.IoFncs->Mem.Read (
  122. MemImage.IoFncs,
  123. IO_UINT8,
  124. MemImage.Offset,
  125. MemImage.Size,
  126. Buffer
  127. );
  128. if (EFI_ERROR(Status)) {
  129. EditorError(Status,L"MemImageRead: Trouble Reading Memory");
  130. return Status;
  131. }
  132. BufferToList(BufferImage.ListHead,MemImage.Size,Buffer);
  133. FreePool(Buffer);
  134. return EFI_SUCCESS;
  135. }
  136. STATIC
  137. EFI_STATUS
  138. MemImageWrite (
  139. VOID
  140. )
  141. {
  142. EFI_STATUS Status;
  143. VOID *Buffer;
  144. MemImage.Size = MainEditor.BufferImage->NumBytes;
  145. Buffer = AllocatePool(MemImage.Size);
  146. /*
  147. * Construct the buffer from the list of lines
  148. */
  149. Status = MemImage.IoFncs->Mem.Write (
  150. MemImage.IoFncs,
  151. IO_UINT8,
  152. MemImage.Offset,
  153. MemImage.Size,
  154. Buffer
  155. );
  156. if (EFI_ERROR(Status)) {
  157. EditorError(Status,L"Trouble Writing Memory");
  158. }
  159. FreePool(Buffer);
  160. return Status;
  161. }
  162. STATIC
  163. EFI_STATUS
  164. MemImageSetOffset (
  165. IN UINTN Offset
  166. )
  167. {
  168. MemImage.Offset = Offset;
  169. return EFI_SUCCESS;
  170. }
  171. STATIC
  172. EFI_STATUS
  173. MemImageSetSize (
  174. IN UINTN Size
  175. )
  176. {
  177. MemImage.Size = Size;
  178. return EFI_SUCCESS;
  179. }
  180. #endif _LIB_MEM_IMAGE