Step to UEFI (122)System Table 哪里来的

很多年前,有个笑话,讲的是一个领导,水平不高,发言只能照着秘书写的稿子念。有一次开大会,传达精神,他念:“正确的思想是天上掉下来的!”此言一出,台下昏昏欲睡的人登时来了精神。只见领导翻了一页,又大声的念到“吗?”

我们编写 Shell Application 最常用的 System Table 当然也不是天上掉下来的,最近研究了一下 System Table 的来源。在【参考1】中,给出来这个是在DxeMain.c 中创建的。

以OVMF 代码为例, 在 \MdeModulePkg\Core\Dxe\DxeMain\DxeMain.c 中可以查到。为了验证,我修改代码,在整个 Table 的最后面加上一个标记。

  // Initialize Memory Services
  //
  CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);

  MemoryProfileInit (HobStart);

  //
  // Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
  // Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
  //
  //LABZDebug gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
  //LABZDebug_Start
  gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE)+4, &mEfiSystemTableTemplate);
  p=(UINT8 *)gDxeCoreST;
  *(p+sizeof (EFI_SYSTEM_TABLE))='L';
  *(p+sizeof (EFI_SYSTEM_TABLE)+1)='A';
  *(p+sizeof (EFI_SYSTEM_TABLE)+2)='B';
  *(p+sizeof (EFI_SYSTEM_TABLE)+3)='Z';
   
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "DBGMark\n"));
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "0x%x\n", p));
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "0x%x\n", p+sizeof (EFI_SYSTEM_TABLE)));	
  //LABZDebug_End
  ASSERT (gDxeCoreST != NULL);

  gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
  ASSERT (gDxeCoreRT != NULL);

 

编译BIOS 然后在 QEMU 上运行,先是查看串口输出:

st1

Install PPI: 605EA650-C65C-42E1-BA80-91A52AB618C6
CoreInitializeMemoryServices:
BaseAddress - 0x4022000 Length - 0x3F5F000 MinimalMemorySizeNeeded - 0x10F4000
DBGMark
0x7F6F010
0x7F6F058
InstallProtocolInterface: 5B1B31A1-9562-11D2-8E3F-00A0C969723B 7FBA1B0
HOBLIST address in DXE = 0x7D98010

可以看到给出来的 System Table的内存地址是 0x7F6F010。我们启动到 Shell 使用 mm 命令可以看到内存的信息,其中包括当前的 SystemTable 的地址

st2

可以看到SystemTable 的地址就是Log中输出的地址,因此上面的位置就是生成的代码。
接下来再用mem 命令直接查看内存,同样可以看到我们在内存中的标记。

st3

参考:
1. http://blog.csdn.net/jiangwei0512

《Step to UEFI (122)System Table 哪里来的》有一个想法

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注