什么是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来填充的.
// 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*)§ionHeaderLocal, (void *)pSection, sizeof(CESectionHeader) ))
{
return Error_StopEnumerating;
}
return ContinueEnumerating;
}
if ( !safe_copy((void*)&ContentsLocal[0], (void *)&pSection[1], sizeof(ContentsLocal) ))
{
return Error_StopEnumerating;
}
return ContinueEnumerating;
}
pROMHDR = NULL;
// Enumerating completed successfully. Now... did we find a ROMHDR for our pSection?
if (pROMHDR) {
return Success_StopEnumerating;
} else {
return ContinueEnumerating;
}
}
return Error_StopEnumerating;
}