summaryrefslogtreecommitdiffstats
path: root/documentation
diff options
context:
space:
mode:
authorRegina König2020-07-01 13:48:38 +0200
committerRegina König2020-07-01 13:48:38 +0200
commit35ca9df6f65a07b128e3cc15006c01aca2903e34 (patch)
tree9ae63df4f52d0569690330f6b073480d41d81b4c /documentation
parentadded GetMemoryMap.efi to efi shell (diff)
downloadmemtest86-35ca9df6f65a07b128e3cc15006c01aca2903e34.tar.gz
memtest86-35ca9df6f65a07b128e3cc15006c01aca2903e34.tar.xz
memtest86-35ca9df6f65a07b128e3cc15006c01aca2903e34.zip
some documentation about memory map
Diffstat (limited to 'documentation')
-rw-r--r--documentation/UEFI_from_spec/AllocatePool27
-rw-r--r--documentation/UEFI_from_spec/EFI_MEMORY_DESCRIPTOR60
-rw-r--r--documentation/UEFI_from_spec/GetMemoryMap29
-rw-r--r--documentation/UEFI_from_spec/mafiadoc.com_white-paper-a-tour-beyond-bios-memory-map-and-_59e074311723dd7ed9476f2c.pdfbin0 -> 1187378 bytes
-rw-r--r--documentation/code examples/boot_services.c55
5 files changed, 171 insertions, 0 deletions
diff --git a/documentation/UEFI_from_spec/AllocatePool b/documentation/UEFI_from_spec/AllocatePool
new file mode 100644
index 0000000..090a434
--- /dev/null
+++ b/documentation/UEFI_from_spec/AllocatePool
@@ -0,0 +1,27 @@
+Allocates pool memory
+
+typedef
+EFI_STATUS
+AllocatePool (
+ IN EFI_MEMORY_TYPE PoolType,
+ IN UINTN Size,
+ OUT VOID **Buffer
+ );
+
+
+PoolType Type of pool to allocate. PoolType values in range 0x80000000...0xFFFFFFFF reserved for use by
+ UEFI OS loaders that are provided by operating system vendors. Only illegal memory type values
+ are those in the range EfiMaxMemoryType..0x7FFFFFFFF
+Size Number of bytes to allocate from pool.
+Buffer Pointer to a pointer to the allocated buffer if the call succeeds. undefined otherwise.
+
+Description
+The AllocatePool() function allocates a memory region of Size bytes from memory of type
+PoolType and returns the address of the allocated memory in the location referenced by Buffer.
+This function allocates pages from EfiConventionalMemory as needed to grow the requested
+pool type. All allocations are eight-byte aligned.
+The allocated pool memory is returned to the available pool with the FreePool() function.
+Status Codes Returned
+EFI_SUCCESS The requested number of bytes was allocated.
+EFI_OUT_OF_RESOURCES The pool requested could not be allocated.
+EFI_INVALID_PARAMETER PoolType was invalid.
diff --git a/documentation/UEFI_from_spec/EFI_MEMORY_DESCRIPTOR b/documentation/UEFI_from_spec/EFI_MEMORY_DESCRIPTOR
new file mode 100644
index 0000000..72e8cc9
--- /dev/null
+++ b/documentation/UEFI_from_spec/EFI_MEMORY_DESCRIPTOR
@@ -0,0 +1,60 @@
+typedef struct {
+ UINT32 Type;
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
+ EFI_VIRTUAL_ADDRESS VirtualStart;
+ UINT64 NumberOfPages;
+ UINT64 Attribute;
+} EFI_MEMORY_DESCRIPTOR;
+
+
+Type Type of the memory region. Type EFI_MEMORY_TYPE is defined in the AllocatePages() function description.
+PhysicalStart Physical address of the first byte in the memory region. Physical start must be aligned on a 4 KB boundary.
+
+VirtualStart Virtual address of the first byte in the memory region. Virtual start must be aligned on a 4 KB boundary. NumberOfPages Number of 4 KB pages in the memory region.
+Attribute Attributes of the memory region that describe the bit mask of capabilities for that memory region, and not
+ necessarily the current settings for that memory region.
+
+
+
+//*******************************************************
+// Memory Attribute Definitions
+//*******************************************************
+// These types can be “ORed” together as needed.
+#define EFI_MEMORY_UC 0x0000000000000001
+#define EFI_MEMORY_WC 0x0000000000000002
+#define EFI_MEMORY_WT 0x0000000000000004
+#define EFI_MEMORY_WB 0x0000000000000008
+#define EFI_MEMORY_UCE 0x0000000000000010
+#define EFI_MEMORY_WP 0x0000000000001000
+#define EFI_MEMORY_RP 0x0000000000002000
+#define EFI_MEMORY_XP 0x0000000000004000
+#define EFI_MEMORY_RUNTIME 0x8000000000000000
+
+EFI_MEMORY_UC Memory cacheability attribute: The memory region supports being configured as not cacheable.
+EFI_MEMORY_WC Memory cacheability attribute: The memory region supports being configured as write combining.
+EFI_MEMORY_WT Memory cacheability attribute: The memory region supports being configured as cacheable with
+ a “write through” policy. Writes that hit in the cache will also be written to main memory.
+EFI_MEMORY_WB Memory cacheability attribute: The memory region supports being configured as cacheable with
+ a “write back” policy. Reads and writes that hit in the cache do not propagate to main memory.
+ Dirty data is written back to main memory when a new cache line is allocated.
+EFI_MEMORY_UCE Memory cacheability attribute: The memory region supports being configured as not cacheable,
+ exported, and supports the “fetch and add” semaphore mechanism.
+EFI_MEMORY_WP Physical memory protection attribute: The memory region supports being configured as
+ write-protected by system hardware.
+EFI_MEMORY_RP Physical memory protection attribute: The memory region supports being configured as
+ read-protected by system hardware.
+EFI_MEMORY_XP Physical memory protection attribute: The memory region supports being configured so it is
+ protected by system hardware from executing code.
+EFI_MEMORY_RUNTIME Runtime memory attribute: The memory region needs to be given a virtual mapping by the
+ operating system when SetVirtualAddressMap() is called (described in Chapter 7.3.)
+
+
+//*******************************************************
+//EFI_VIRTUAL_ADDRESS
+//*******************************************************
+typedef UINT64
+EFI_VIRTUAL_ADDRESS;
+//*******************************************************
+// Memory Descriptor Version Number
+//*******************************************************
+#define EFI_MEMORY_DESCRIPTOR_VERSION 1
diff --git a/documentation/UEFI_from_spec/GetMemoryMap b/documentation/UEFI_from_spec/GetMemoryMap
new file mode 100644
index 0000000..362228c
--- /dev/null
+++ b/documentation/UEFI_from_spec/GetMemoryMap
@@ -0,0 +1,29 @@
+Returns current memory map
+
+typedef
+EFI_STATUS
+GetMemoryMap (
+ IN OUT UINTN *MemoryMapSize,
+ IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
+ OUT UINTN *MapKey,
+ OUT UINTN *DescriptorSize,
+ OUT UINT32 *DescriptorVersion
+ );
+
+
+MemoryMapSize Pointer to the size in bytes of MemoryMap buffer. On input, it's the site of the buffer allocated by the caller.
+ On output, size of the buffer returned by the firmware if the buffer was large enough, or the size of the
+ buffer needed to contain the map if the buffer was too small.
+
+MemoryMap A pointer to the buffer in which firmware places the current memory map. Map is array of EFI_MEMORY_DESCRIPTORs.
+
+MapKey Pointer to the location in which firmware returns the key for the current memory map.
+
+DescriptorSize Pointer to location in which firmware returns the size in bytes of an individual EFI_MEMORY_DESCRIPTOR
+
+DescriptorVersion Pointer to location in which firmware returns version number associated with EFI_MEMORY_DESCRIPTOR.
+
+
+
+The memory map is only used to describe memory that is present in the system. Memory descriptors are never used to describe holes in the system memory map. Until ExitBootServices(), the memory map is owned by the firmware. The firmware's MapKey is changed every time something in the memory map changes. In order to successfully invoke ExitBootServices() the caller must provide the current memory map key.
+
diff --git a/documentation/UEFI_from_spec/mafiadoc.com_white-paper-a-tour-beyond-bios-memory-map-and-_59e074311723dd7ed9476f2c.pdf b/documentation/UEFI_from_spec/mafiadoc.com_white-paper-a-tour-beyond-bios-memory-map-and-_59e074311723dd7ed9476f2c.pdf
new file mode 100644
index 0000000..78741fe
--- /dev/null
+++ b/documentation/UEFI_from_spec/mafiadoc.com_white-paper-a-tour-beyond-bios-memory-map-and-_59e074311723dd7ed9476f2c.pdf
Binary files differ
diff --git a/documentation/code examples/boot_services.c b/documentation/code examples/boot_services.c
new file mode 100644
index 0000000..1cb57d7
--- /dev/null
+++ b/documentation/code examples/boot_services.c
@@ -0,0 +1,55 @@
+ /*
+extern EFI_BOOT_SERVICES *gBS;
+EFI_EXIT_BOOT_SERVICES gOrigExitBootServices;
+
+
+
+EFI_STATUS
+EFIAPI
+ExitBootServicesHook(IN EFI_HANDLE ImageHandle, IN UINTN MapKey){
+
+ // <hook related fun>
+ // Do fun hook-related stuff here
+ // </hook-related fun>
+
+ // Fix the pointer in the boot services table
+ // If you don't do this, sometimes your hook method will be called repeatedly, which you don't want
+ gBS->ExitBootServices = gOrigExitBootServices;
+
+ // Get the memory map
+ UINTN MemoryMapSize;
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ UINTN LocalMapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+ MemoryMap = NULL;
+ MemoryMapSize = 0;
+
+
+ do {
+ Status = gBS->GetMemoryMap(&MemoryMapSize, MemoryMap, &LocalMapKey, &DescriptorSize,&DescriptorVersion);
+ if (Status == EFI_BUFFER_TOO_SMALL){
+ MemoryMap = AllocatePool(MemoryMapSize + 1);
+ Status = gBS->GetMemoryMap(&MemoryMapSize, MemoryMap, &LocalMapKey, &DescriptorSize,&DescriptorVersion);
+ } else {
+ // Status is likely success - let the while() statement check success
+ }
+ DbgPrint(L"This time through the memory map loop, status = %r\n",Status);
+
+ } while (Status != EFI_SUCCESS);
+
+ return gOrigExitBootServices(ImageHandle,LocalMapKey);
+
+}
+EFI_STATUS
+EFIAPI
+HookDriverMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable){
+
+ // Store off the original pointer and replace it with your own
+ gOrigExitBootServices = gBS->ExitBootServices;
+ gBS->ExitBootServices = ExitBootServicesHook;
+
+ // It's hooked! Return EFI_SUCCESS so your driver stays in memory
+ return EFI_SUCCESS;
+}
+ */