📄 c-loader9.html
字号:
* * load<i class="textVariable">Omf</i>FmtInit - initialize the OMF loader * * This routine initializes the correct relocator unit for the current target * CPU. * * RETURNS: OK or ERROR. */ STATUS load<i class="textVariable">Omf</i>FmtInit (void) { /* OMF relocs routines ( + 1 for the optionnal SegInit routine) */ DYNLK_FUNC relocDllFv[NB_MANDATORY_RELOC_RTNS + 1]; relocDllFv[0].name = (char *)tgtSegRelocatorRtnNameGet(); relocDllFv[1].name = (char *)tgtModuleVerifyRtnNameGet(); relocDllFv[2].name = (char *)tgtRelocInitRtnNameGet(); /* Link the relocator */ if (loadRelocLink( relocDllFv, NB_MANDATORY_RELOC_RTNS+1) != OK) { return ERROR; } /* relocation routine pointer */ <i class="textVariable">omf</i>RelSegRtn = (FUNCPTR) relocDllFv[0].func; /* module verification routine */ <i class="textVariable">omf</i>ModuleVerify = (FUNCPTR) relocDllFv[1].func; /* if an Init routine exists for this relocator, run it */ if (relocDllFv[2].func != NULL) (*relocDllFv[2].func)(); return (OK); }</a></b></pre></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85408"><b class="routine"><i class="routine">load</i></b><i class="term">Omf</i><b class="routine"><i class="routine">FmtCheck</i></b><b>( )</b></a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85409"> </a>This routine is the second entry point; it checks the file format.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85410">STATUS load<i class="term">Omf</i>FmtCheck (int moduleFd, BOOL * pFormatIsKnown);</a></b></pre></dl><dd><p class="Body"><a name="85411"> </a>The input parameter is:</p></dl><dl class="margin"><dd><div class="Item"><a name="85412"> </a><b class="symbol_lc">int moduleFd</b></div><dl class="margin"><dd><div class="Indent"><a name="85418"> </a>The file descriptor of the module object.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="85419"> </a>The output parameter is:</p></dl><dl class="margin"><dd><div class="Item"><a name="85420"> </a><b class="symbol_UC">BOOL </b><b class="symbol_lc">* pFormatIsKnown</b></div><dl class="margin"><dd><div class="Indent"><a name="85421"> </a>A pointer to a boolean that holds the answer.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="85422"> </a>The return value is:</p></dl><dl class="margin"><dd><div class="Item"><a name="85423"> </a><b class="symbol_UC">STATUS</b> </div><dl class="margin"><dd><div class="Indent"><a name="85424"> </a><b class="symbol_UC">OK </b>or <b class="symbol_UC">ERROR</b>. </div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="85425"> </a>The target server calls <b class="routine"><i class="routine">load</i></b><i class="term">Omf</i><b class="routine"><i class="routine">FmtCheck</i></b><b>( )</b> during initialization to determine if a file is in the appropriate format for the loader. Files submitted to this routine should be core files only. (See <a href="c-loader9.html#85089"><i class="title">3.9.2 Installing a Shared-Library Manager</i></a>.) Note that in this example, the first four bytes in the object module are arbitrarily considered a magic number.</p></dl></dl><h4 class="EntityTitle"><a name="85429"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 3-3: <b class="routine"><i class="routine">load</i></b><i class="term">Omf</i><b class="routine"><i class="routine">FmtCheck</i></b><b>( )</b> </font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="86688">/************************************************************************ * * load<i class="term">Omf</i>FmtCheck - see if the object file is in a known format * * This routine contains the heuristic required to determine if the object * file belongs to the OMF handled by this OMF reader, and is intended for * the appropriate target architecture. * * RETURNS: OK or ERROR if file cannot be read. */ STATUS load<i class="term">Omf</i>FmtCheck ( int moduleFd, /* module object descriptor */ BOOL * pFormatIsKnown /* hold the answer */ ) { UINT32 magicNumber; /* OMF magic number */ BOOL swap; /* not used here */ /* Get the magic number */ if (read (moduleFd, (char *)&magicNumber, 4) != 4) return (ERROR); /* Check the module format */ if (load<i class="term">Omf</i>ModuleIsOk (magicNumber, &swap)) *pFormatIsKnown = TRUE; else *pFormatIsKnown = FALSE; return (OK); }</a></b></pre></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85441"><b class="routine"><i class="routine">load</i></b><i class="term">Omf</i><b class="routine"><i class="routine">FmtManage</i></b><b>( )</b> </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85442"> </a>This routine is the third and main entry point; it carries out the load process.</p><dl class="margin"><dd><pre class="Code2"><b><a name="85443">STATUS load<i class="term">Omf</i>FmtManage (char * pObjMod, int loadFlag, void ** ppText, void ** ppData, void ** ppBss, SYMTAB_ID symTbl, MODULE_ID moduleId, SEG_INFO *pSeg);</a></b></pre></dl><dd><p class="Body"><a name="85446"> </a>The input parameters are:</p></dl><dl class="margin"><dd><div class="Item"><a name="85447"> </a><b class="symbol_lc">char * pObjMode</b> </div><dl class="margin"><dd><div class="Indent"><a name="85448"> </a>A pointer to the beginning of the object-module copy in memory.</div><br></dl><dd><div class="Item"><a name="85449"> </a><b class="symbol_lc">int loadFlag</b> </div><dl class="margin"><dd><div class="Indent"><a name="85450"> </a>The loader option(s). See <b class="file">loadlib.h</b> for the definition of all macros associated with the options.</div><br></dl><dd><div class="Item"><a name="85451"> </a><b class="symbol_UC">SYMTAB_ID</b><b class="symbol_lc"> symTbl</b> </div><dl class="margin"><dd><div class="Indent"><a name="85452"> </a>The target symbol table. This is actually a pointer to a <b class="symbol_UC">SYMTAB</b> structure. See <b class="file">symlib.h</b> for a description of this structure.</div><br></dl><dd><div class="Item"><a name="85453"> </a><b class="symbol_UC">MODULE_ID</b><b class="symbol_lc"> moduleId</b> </div><dl class="margin"><dd><div class="Indent"><a name="85454"> </a>A pointer to the object-module descriptor (<b class="symbol_UC">MODULE</b> structure). See <b class="file">module.h</b> for a description of this structure.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="85455"> </a>The input-output parameters are:</p></dl><dl class="margin"><dd><div class="Item"><a name="85456"> </a><b class="symbol_lc">void ** ppText</b> </div><dl class="margin"><dd><div class="Indent"><a name="85457"> </a>Holds the required address where the text segment must be stored, or <b class="symbol_UC">NULL</b> if no special address is required. When the routine returns, it is set with the final address of the text segment (which may or may not have changed).</div><br></dl><dd><div class="Item"><a name="85458"> </a><b class="symbol_lc">void ** ppData</b> </div><dl class="margin"><dd><div class="Indent"><a name="85459"> </a>Holds the required address for the data segment, or <b class="symbol_UC">NULL</b>. It returns the final address of the data segment.</div><br></dl><dd><div class="Item"><a name="85460"> </a><b class="symbol_lc">void ** ppBss</b> </div><dl class="margin"><dd><div class="Indent"><a name="85461"> </a>Holds the required address for the <i class="term">bss </i>segment, or <b class="symbol_UC">NULL</b>. It returns the final address of the <i class="term">bss </i>segment.</div><br></dl><dd><div class="Item"><a name="85462"> </a><b class="symbol_UC">SEG_INFO </b><b>* </b><b class="symbol_lc">pSeg</b> </div><dl class="margin"><dd><div class="Indent"><a name="85463"> </a>A pointer to a structure that holds all information about segments required to process the object file. See <b class="file">loadLib.h </b>for a description of the <b class="symbol_UC">SEG_INFO</b> structure.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="85464"> </a>The return value is:</p></dl><dl class="margin"><dd><div class="Item"><a name="85465"> </a><b class="symbol_UC">STATUS</b> <b class="symbol_UC"></b></div><dl class="margin"><dd><div class="Indent"><a name="85466"> </a><b class="symbol_UC">OK </b>or <b class="symbol_UC">ERROR</b>. </div><br></dl></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="88651"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>When no address is required (<b class="symbol_UC">NULL</b> pointers are given), the value <b class="symbol_UC">LOAD_NO_ADDRESS </b>is assigned to the fields pAddrText, pAddrData, and pAddrBss of the <b class="symbol_UC">SEG_INFO</b> structure.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="85476"> </a>The steps taken by <b class="routine"><i class="routine">load</i></b><i class="term">Omf</i><b class="routine"><i class="routine">FmtManage</i></b><b>( )</b> are summarized below and in <a href="c-loader9.html#85514">Example 3-4</a>. The steps flagged with (*) are described in more detail in later code examples.</p></dl><dl class="margin"><p><ol class="List"><li value="1."><a name="85480"> </a>Check the loader options for consistency.</li></ol></p><p><ol class="List"><li value="2."><a name="85481"> </a>Check whether the host and target byte orders are identical. (*)</li></ol></p><p><ol class="List"><li value="3."><a name="85482"> </a>Read in the module headers. (*)</li></ol></p><p><ol class="List"><li value="4."><a name="85483"> </a>Determine the final size of the three segments: text, data, <i class="term">bss. </i>(*)</li></ol></p><p><ol class="List"><li value="5."><a name="85484"> </a>Read in the module symbol table and string table. (*)</li></ol></p><p><ol class="List"><li value="6."><a name="85485"> </a>Determine the compiler signature and publish the builder. (*)</li></ol></p><p><ol class="List"><li value="7."><a name="85486"> </a>Allocate memory for the segments, if required.</li></ol></p><p><ol class="List"><li value="8."><a name="85487"> </a>Read in the various module sections. (*)</li></ol></p><p><ol class="List"><li value="9."><a name="85488"> </a>Check that the core-file checksum and the target-text-section checksum match.</li></ol></p><p><ol class="List"><li value="10."><a name="85489"> </a>Process the module symbol table. (*)</li></ol></p><p><ol class="List"><li value="11."><a name="85490"> </a>Relocate the text and data segments, if required. (*)</li></ol></p><p><ol class="List"><li value="12."><a name="85491"> </a>Download text and data segments, if required. (*)</li></ol></p><p><ol class="List"><li value="13."><a name="85492"> </a>Apply virtual memory protection and cache update, if required.</li></ol></p></dl><dd> <p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="88686"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>If the loader calls <b class="routine"><i class="routine">loadOutputToFile</i></b><b>( )</b>, it does not download the module to the target memory. It returns with a <b class="routine"><i class="routine">loadOutputToFile</i></b><b>( )</b><b class="routine"><i class="routine"> </i></b>status code instead. This facility allows automated testing without live hardware.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dd> <p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="86541"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>Even for a fully linked file, the <b class="symbol_UC">SEG_INFO</b> structure must be filled in because it is used for module management, core file verification, and cache and virtual memory management. If a fully linked file holds several text, data, and <i class="term">bss </i>sections, for instance, one of each type should be chosen as representative and the information loaded into the <b class="symbol_UC">SEG_INFO</b> structure.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -