浅谈pTOC指针

什么是TOC?

TOC :Table Of Content

TOC的定义: ROMHDR *const volatible pTOC=(ROMHDR *)-1;

    // Get replaced by romloader with real address.

现在关注一下ROMHDR的结构体:

 

typedef struct ROMHDR {

       ULONG  dllfirst;

       ULONG  dlllast;

       ULONG  physfirst;

       ULONG  physlast;

       ULONG  nummods;

       ULONG  ulRAMStart;

       ULONG  ulRAMFree;

       ULONG  ulRAMEnd;

       ULONG  ulCopyEntries;

       ULONG  ulCopyOffset;

       ULONG  ulProfilLen;

       ULONG  ulProfileOffset;

       ULONG  numfiles;

       ULONG  ulKernlFlags;

 

       ULONG  ulFSRamPercent;

       ULONG  ulDrivglobStart;

       ULONG  ulDrivgloblen;

       ULONG  usCPUType;

       ULONG  usMiscFlags; //miscellaneous flags

       PVOID   pExtensions;

       ULONG  ulTrackingStart;

       ULONG  ulTrackinglen;

}ROMHDR; 

 

在eboot的bootloadermain函数中有ROMHDR * volatile const pTOC = (ROMHDR *)-1;

Bootloader在启动之后主要作用就是拷贝内核到指定地址的ram中去,而boot代码之所以知道需要拷贝哪些代码或数据段到目标地址,是因为它根据一个约定的数据结构来拷贝的,这个数据结构就是ROMHDR。它是在产生ROM image的时候由OS linker来填充的.

 

// Search for a valid ROMHDR.  This callback looks for sections that
// are 8 bytes long and that contain a "CECE" signature.  It then
// enumerates all sections looking for one whose offset matches the
// offset following the "CECE" signature.  That will be the ROMHDR
// itself.
HeaderCallbackCode FindROMHDR(unsigned __int8 *RomImage, DWORD FileSize, const CESectionHeader *pSection)
{
 CESectionHeader sectionHeaderLocal;
 if ( !safe_copy((void*)&sectionHeaderLocal, (void *)pSection, sizeof(CESectionHeader) ))
 {
  return Error_StopEnumerating;
 }
 if (sectionHeaderLocal.fSectionSize != 8) {
  return ContinueEnumerating;
 }
 unsigned __int32 ContentsLocal[2];
 if ( !safe_copy((void*)&ContentsLocal[0], (void *)&pSection[1], sizeof(ContentsLocal) ))
 {
  return Error_StopEnumerating;
 }
 if (ContentsLocal[0] != 0x43454345) {
  return ContinueEnumerating;
 }
 ROMHDRAddress = ContentsLocal[1];
 pROMHDR = NULL;
 if (ForEachSectionHeader(RomImage, FileSize, FindROMHDRFromAddress)) {
  // Enumerating completed successfully.  Now... did we find a ROMHDR for our pSection?
  if (pROMHDR) {
   return Success_StopEnumerating;
  } else {
   return ContinueEnumerating;
  }
 }
 return Error_StopEnumerating;
}
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值