device-emulator1源代码阅读之寻找ROMHDR
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://bluefish.blog.51cto.com/214870/69180 |
这个函数是在load bin的时候用的,必须得找到ROMHDR,找到了之后才去真正load bin文件的每个sector。关于ROMHDR,相信大家应该经常见到了,在eboot的bootloadermain函数中有ROMHDR * volatile const pTOC = (ROMHDR *)-1; 这样一个语句。Bootloader在启动之后主要作用就是拷贝内核到指定地址的ram中去,而boot代码之所以知道需要拷贝哪些代码或数据段到目标地址,是因为它根据一个约定的数据结构来拷贝的,这个数据结构就是ROMHDR。它是在产生ROM image的时候由OS linker来填充的。也就是这里所说的以“CECE”开头的数据段。
// 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*)§ionHeaderLocal, (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; } 本文出自 “bluefish” 博客,请务必保留此出处http://bluefish.blog.51cto.com/214870/69180 本文出自 51CTO.COM技术博客 |


rightsoft
博客统计信息
热门文章
最新评论
友情链接