2024.04.14
实验环境:

UEFI Shell命令行执行dmem命令的输出:

EFFD0018到底指向什么?

演示如何在NDB中观察鲜活的gST,这个极为重要的全局变量:

x Shell!gST
00000000`e9d68cc0  Shell!gST 
dq 0`e9d68cc0 l1
00000000`e9d68cc0  00000000`effd0018
dt -r EFI_SYSTEM_TABLE 0`effd0018
   +0x000 Hdr              : 
      +0x000 Signature        : 0x54535953`20494249
      +0x008 Revision         : 0x20046
      +0x00c HeaderSize       : 0x78
      +0x010 CRC32            : 0x98d251b8
      +0x014 Reserved         : 0
   +0x018 FirmwareVendor   : (null) 
   +0x020 FirmwareRevision : 0x10000
   +0x028 ConsoleInHandle  : 0x00000000`ef22a918 
   +0x030 ConIn            : (null) 
   +0x038 ConsoleOutHandle : 0x00000000`eeb75d18 
   +0x040 ConOut           : (null) 
   +0x048 StandardErrorHandle : 0x00000000`ef228e98 
   +0x050 StdErr           : (null) 
   +0x058 RuntimeServices  : (null) 
   +0x060 BootServices     : (null) 
   +0x068 NumberOfTableEntries : 0xd
   +0x070 ConfigurationTable : (null) 
?? sizeof(EFI_SYSTEM_TABLE)
unsigned int64 0x78
dqs 0`effd0018 l78/8
00000000`effd0018  54535953`20494249
00000000`effd0020  00000078`00020046
00000000`effd0028  00000000`98d251b8
00000000`effd0030  00000000`effde318
00000000`effd0038  00000000`00010000
00000000`effd0040  00000000`ef22a918
00000000`effd0048  00000000`eaa0e400 ConSplitterDxe!mConIn+0x10
00000000`effd0050  00000000`eeb75d18
00000000`effd0058  00000000`eeb3b020
00000000`effd0060  00000000`ef228e98
00000000`effd0068  00000000`eaa0e190 ConSplitterDxe!mStdErr+0x10
00000000`effd0070  00000000`effdff18
00000000`effd0078  00000000`3ec531d8 DxeCore!mBootServices
00000000`effd0080  00000000`0000000d
00000000`effd0088  00000000`effdfb18
dt EFI_CONFIGURATION_TABLE
   +0x000 VendorGuid       : 
   +0x010 VendorTable      : Ptr64 Void
dt EFI_CONFIGURATION_TABLE 0`effdfb18
   +0x000 VendorGuid       : 
   +0x010 VendorTable      : 0x00000000`3ec546f8 
db 0`3ec546f8
00000000`3ec546f8  01 00 00 00 00 00 00 00-00 36 6e 01 00 00 00 00  .........6n.....
00000000`3ec54708  00 00 00 00 00 00 00 00-ff ff ff ff ff ff ff ff  ................
00000000`3ec54718  d8 31 c5 3e 00 00 00 00-10 00 00 00 00 00 00 00  .1.>............
00000000`3ec54728  18 f7 df ef 00 00 00 00-18 f6 df ef 00 00 00 00  ................
00000000`3ec54738  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
00000000`3ec54748  00 00 00 00 00 00 00 00-50 47 c5 3e 00 00 00 00  ........PG.>....
00000000`3ec54758  50 47 c5 3e 00 00 00 00-60 47 c5 3e 00 00 00 00  PG.>....`G.>....
00000000`3ec54768  60 47 c5 3e 00 00 00 00-70 47 c5 3e 00 00 00 00  `G.>....pG.>....
dq 0`3ec546f8
00000000`3ec546f8  00000000`00000001 00000000`016e3600
00000000`3ec54708  00000000`00000000 ffffffff`ffffffff
00000000`3ec54718  00000000`3ec531d8 00000000`00000010
00000000`3ec54728  00000000`efdff718 00000000`efdff618
00000000`3ec54738  00000000`00000000 00000000`00000000
00000000`3ec54748  00000000`00000000 00000000`3ec54750
00000000`3ec54758  00000000`3ec54750 00000000`3ec54760
00000000`3ec54768  00000000`3ec54760 00000000`3ec54770
dt -r EFI_RUNTIME_SERVICES 0`effdff18
   +0x000 Hdr              : 
      +0x000 Signature        : 0x56524553`544e5552
      +0x008 Revision         : 0x20046
      +0x00c HeaderSize       : 0x88
      +0x010 CRC32            : 0x1925f001
      +0x014 Reserved         : 0
   +0x018 GetTime          : (null) 
   +0x020 SetTime          : (null) 
   +0x028 GetWakeupTime    : (null) 
   +0x030 SetWakeupTime    : (null) 
   +0x038 SetVirtualAddressMap : (null) 
   +0x040 ConvertPointer   : (null) 
   +0x048 GetVariable      : (null) 
   +0x050 GetNextVariableName : (null) 
   +0x058 SetVariable      : (null) 
   +0x060 GetNextHighMonotonicCount : (null) 
   +0x068 ResetSystem      : (null) 
   +0x070 UpdateCapsule    : (null) 
   +0x078 QueryCapsuleCapabilities : (null) 
   +0x080 QueryVariableInfo : (null) 
dqs 0`effdff18 l88/8
00000000`effdff18  56524553`544e5552
00000000`effdff20  00000088`00020046
00000000`effdff28  00000000`1925f001
00000000`effdff30  00000000`eaa21740 RealTimeClock!gST+0xffffffff`ffff1678
00000000`effdff38  00000000`eaa21514 RealTimeClock!gST+0xffffffff`ffff144c
00000000`effdff40  00000000`eaa20024 RealTimeClock!gST+0xffffffff`fffeff5c
00000000`effdff48  00000000`eaa20060 RealTimeClock!gST+0xffffffff`fffeff98
00000000`effdff50  00000000`eaf818d4 RuntimeDxe!gST+0xffffffff`ffff17a4
00000000`effdff58  00000000`eaf80008 RuntimeDxe!gST+0xffffffff`fffefed8
00000000`effdff60  00000000`eacc509c VariableRuntimeDxe!gST+0xffffffff`ffff4be4
00000000`effdff68  00000000`eacc1894 VariableRuntimeDxe!gST+0xffffffff`ffff13dc
00000000`effdff70  00000000`eacc723c VariableRuntimeDxe!gST+0xffffffff`ffff6d84
00000000`effdff78  00000000`eaef01d0 EmbeddedMonotonicCounter!gST+0xffffffff`ffff0188
00000000`effdff80  00000000`eac01700 Reset!gST+0xffffffff`ffff1698
00000000`effdff88  00000000`eaac1434 CapsuleRuntimeDxe!gST+0xffffffff`ffff13bc
00000000`effdff90  00000000`eaac1334 CapsuleRuntimeDxe!gST+0xffffffff`ffff12bc
00000000`effdff98  00000000`eacc11c4 VariableRuntimeDxe!gST+0xffffffff`ffff0d0c

结合源代码:

重要数据结构(所在位置):

///
/// EFI Runtime Services Table.
///
typedef struct {
  ///
  /// The table header for the EFI Runtime Services Table.
  ///
  EFI_TABLE_HEADER                  Hdr;

  //
  // Time Services
  //
  EFI_GET_TIME                      GetTime;
  EFI_SET_TIME                      SetTime;
  EFI_GET_WAKEUP_TIME               GetWakeupTime;
  EFI_SET_WAKEUP_TIME               SetWakeupTime;

  //
  // Virtual Memory Services
  //
  EFI_SET_VIRTUAL_ADDRESS_MAP       SetVirtualAddressMap;
  EFI_CONVERT_POINTER               ConvertPointer;

  //
  // Variable Services
  //
  EFI_GET_VARIABLE                  GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME        GetNextVariableName;
  EFI_SET_VARIABLE                  SetVariable;

  //
  // Miscellaneous Services
  //
  EFI_GET_NEXT_HIGH_MONO_COUNT      GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM                  ResetSystem;

  //
  // UEFI 2.0 Capsule Services
  //
  EFI_UPDATE_CAPSULE                UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES    QueryCapsuleCapabilities;

  //
  // Miscellaneous UEFI 2.0 Service
  //
  EFI_QUERY_VARIABLE_INFO           QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

#define EFI_BOOT_SERVICES_SIGNATURE  SIGNATURE_64 ('B','O','O','T','S','E','R','V')
#define EFI_BOOT_SERVICES_REVISION   EFI_SPECIFICATION_VERSION

///
/// EFI Boot Services Table.
///
typedef struct {
  ///
  /// The table header for the EFI Boot Services Table.
  ///
  EFI_TABLE_HEADER                              Hdr;

  //
  // Task Priority Services
  //
  EFI_RAISE_TPL                                 RaiseTPL;
  EFI_RESTORE_TPL                               RestoreTPL;

  //
  // Memory Services
  //
  EFI_ALLOCATE_PAGES                            AllocatePages;
  EFI_FREE_PAGES                                FreePages;
  EFI_GET_MEMORY_MAP                            GetMemoryMap;
  EFI_ALLOCATE_POOL                             AllocatePool;
  EFI_FREE_POOL                                 FreePool;

  //
  // Event & Timer Services
  //
  EFI_CREATE_EVENT                              CreateEvent;
  EFI_SET_TIMER                                 SetTimer;
  EFI_WAIT_FOR_EVENT                            WaitForEvent;
  EFI_SIGNAL_EVENT                              SignalEvent;
  EFI_CLOSE_EVENT                               CloseEvent;
  EFI_CHECK_EVENT                               CheckEvent;

  //
  // Protocol Handler Services
  //
  EFI_INSTALL_PROTOCOL_INTERFACE                InstallProtocolInterface;
  EFI_REINSTALL_PROTOCOL_INTERFACE              ReinstallProtocolInterface;
  EFI_UNINSTALL_PROTOCOL_INTERFACE              UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL                           HandleProtocol;
  VOID                                          *Reserved;
  EFI_REGISTER_PROTOCOL_NOTIFY                  RegisterProtocolNotify;
  EFI_LOCATE_HANDLE                             LocateHandle;
  EFI_LOCATE_DEVICE_PATH                        LocateDevicePath;
  EFI_INSTALL_CONFIGURATION_TABLE               InstallConfigurationTable;

  //
  // Image Services
  //
  EFI_IMAGE_LOAD                                LoadImage;
  EFI_IMAGE_START                               StartImage;
  EFI_EXIT                                      Exit;
  EFI_IMAGE_UNLOAD                              UnloadImage;
  EFI_EXIT_BOOT_SERVICES                        ExitBootServices;

  //
  // Miscellaneous Services
  //
  EFI_GET_NEXT_MONOTONIC_COUNT                  GetNextMonotonicCount;
  EFI_STALL                                     Stall;
  EFI_SET_WATCHDOG_TIMER                        SetWatchdogTimer;

  //
  // DriverSupport Services
  //
  EFI_CONNECT_CONTROLLER                        ConnectController;
  EFI_DISCONNECT_CONTROLLER                     DisconnectController;

  //
  // Open and Close Protocol Services
  //
  EFI_OPEN_PROTOCOL                             OpenProtocol;
  EFI_CLOSE_PROTOCOL                            CloseProtocol;
  EFI_OPEN_PROTOCOL_INFORMATION                 OpenProtocolInformation;

  //
  // Library Services
  //
  EFI_PROTOCOLS_PER_HANDLE                      ProtocolsPerHandle;
  EFI_LOCATE_HANDLE_BUFFER                      LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL                           LocateProtocol;
  EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES      InstallMultipleProtocolInterfaces;
  EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES    UninstallMultipleProtocolInterfaces;

  //
  // 32-bit CRC Services
  //
  EFI_CALCULATE_CRC32                           CalculateCrc32;

  //
  // Miscellaneous Services
  //
  EFI_COPY_MEM                                  CopyMem;
  EFI_SET_MEM                                   SetMem;
  EFI_CREATE_EVENT_EX                           CreateEventEx;
} EFI_BOOT_SERVICES;

///
/// Contains a set of GUID/pointer pairs comprised of the ConfigurationTable field in the
/// EFI System Table.
///
typedef struct {
  ///
  /// The 128-bit GUID value that uniquely identifies the system configuration table.
  ///
  EFI_GUID    VendorGuid;
  ///
  /// A pointer to the table associated with VendorGuid.
  ///
  VOID        *VendorTable;
} EFI_CONFIGURATION_TABLE;

///
/// EFI System Table
///
typedef struct {
  ///
  /// The table header for the EFI System Table.
  ///
  EFI_TABLE_HEADER                   Hdr;
  ///
  /// A pointer to a null terminated string that identifies the vendor
  /// that produces the system firmware for the platform.
  ///
  CHAR16                             *FirmwareVendor;
  ///
  /// A firmware vendor specific value that identifies the revision
  /// of the system firmware for the platform.
  ///
  UINT32                             FirmwareRevision;
  ///
  /// The handle for the active console input device. This handle must support
  /// EFI_SIMPLE_TEXT_INPUT_PROTOCOL and EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
  ///
  EFI_HANDLE                         ConsoleInHandle;
  ///
  /// A pointer to the EFI_SIMPLE_TEXT_INPUT_PROTOCOL interface that is
  /// associated with ConsoleInHandle.
  ///
  EFI_SIMPLE_TEXT_INPUT_PROTOCOL     *ConIn;
  ///
  /// The handle for the active console output device.
  ///
  EFI_HANDLE                         ConsoleOutHandle;
  ///
  /// A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface
  /// that is associated with ConsoleOutHandle.
  ///
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *ConOut;
  ///
  /// The handle for the active standard error console device.
  /// This handle must support the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.
  ///
  EFI_HANDLE                         StandardErrorHandle;
  ///
  /// A pointer to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL interface
  /// that is associated with StandardErrorHandle.
  ///
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *StdErr;
  ///
  /// A pointer to the EFI Runtime Services Table.
  ///
  EFI_RUNTIME_SERVICES               *RuntimeServices;
  ///
  /// A pointer to the EFI Boot Services Table.
  ///
  EFI_BOOT_SERVICES                  *BootServices;
  ///
  /// The number of system configuration tables in the buffer ConfigurationTable.
  ///
  UINTN                              NumberOfTableEntries;
  ///
  /// A pointer to the system configuration tables.
  /// The number of entries in the table is NumberOfTableEntries.
  ///
  EFI_CONFIGURATION_TABLE            *ConfigurationTable;
} EFI_SYSTEM_TABLE;

/**
  This is the declaration of an EFI image entry point. This entry point is
  the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
  both device drivers and bus drivers.

  @param[in]  ImageHandle       The firmware allocated handle for the UEFI image.
  @param[in]  SystemTable       A pointer to the EFI System Table.

  @retval EFI_SUCCESS           The operation completed successfully.
  @retval Others                An unexpected error occurred.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_IMAGE_ENTRY_POINT)(
  IN  EFI_HANDLE                   ImageHandle,
  IN  EFI_SYSTEM_TABLE             *SystemTable
  );

用NDB将下面的UEFI的Shell命令跟踪观察学习一遍,对于熟悉UEFI将是有帮助的:

作者:朱博渊  创建时间:2024-04-14 15:47
最后编辑:朱博渊  更新时间:2024-11-15 17:44