bloggerads

2015年6月16日 星期二

UEFI : SEC Phase Code Trace

UEFI 架構只有SEC這個phase因為是machine dependent而且cache/memory尚未初始化,所以剛開始是組合語言寫的,最主要就是做以下這幾件事:
  1. 切32位元(或64位元)flat mode
  2. Cache As Ram (在Flat32.asm中jump到CacheAsRam函數的位址)
  3. 找BFV(Boot Firmware Volume), BFV指的是存放PEI Foundation/PEIMs的FV
  4. 找到以C寫的SEC phase entry point
  5. 跳到以C code寫的SEC point (SecStartup),最後Transfer the control to the PEI core
VOID
EFIAPI
SecStartup (
  IN UINT32    SizeOfRam,
  IN UINT32    TempRamBase,
  IN VOID      *BootFirmwareVolume
  )
{
   ...
}


從上電的reset vector, trace Code如下:

進入點為 UefiCpuPkg\ResetVector\Vtf0\Ia16\ResetVectorVtf0.asm


;; Reset Vector
;
; This is where the processor will begin execution
;
    nop
    nop
    jmp     short EarlyBspInitReal16


接著跳到Init16.asm再跳到Main.asm裡面Main16這個位址


Main16:
      OneTimeCall EarlyInit16
      ;
      ; Transition the processor from 16-bit real mode to 32-bit flat mode
      ;
      OneTimeCall TransitionFromReal16To32BitFlat
BITS    32
      ;
      ; Search for the Boot Firmware Volume (BFV)
      ;
      OneTimeCall Flat32SearchForBfvBase
      ;
      ; EBP - Start of BFV
      ;
      ;
      ; Search for the SEC entry point
      ;
      OneTimeCall Flat32SearchForSecEntryPoint
      ;
      ; ESI - SEC Core entry point
      ; EBP - Start of BFV
      ;
%ifdef ARCH_IA32
      ;
      ; Restore initial EAX value into the EAX register
      ;
      mov     eax, esp
      ;
      ; Jump to the 32-bit SEC entry point
      ;
      jmp     esi
()


沒有留言:

張貼留言