浅谈pTOC指针(转载)

来源:互联网 发布:天庭淘宝店 txt 编辑:程序博客网 时间:2024/05/17 09:02

转载http://blog.csdn.net/yjy889/archive/2009/07/06/4326558.aspx

什么是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;
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yjy889/archive/2009/07/06/4326558.aspx