void BootloaderMain (void) { ROMHDR *pRomHdr = NULL; // pTOC for NK image. MUST COPY IT OR CLEANBOOT may erase it DWORD dwAction, dwpToc; DWORD dwImageStart = 0, dwImageLength = 0, dwLaunchAddr = 0; BOOL bDownloaded = FALSE;
// relocate globals to RAM if (!KernelRelocate (pTOC)) { // spin forever HALT (BLERR_KERNELRELOCATE); } ********************************** static BOOL KernelRelocate (ROMHDR *const pTOC) { ULONG loop; COPYentry *cptr; if (pTOC == (ROMHDR *const) -1) { return FALSE; // spin forever! } // This is where the data sections become valid... don't read globals until after this for (loop = 0; loop < pTOC->ulCopyEntries; loop++) { cptr = (COPYentry *)(pTOC->ulCopyOffset + loop*sizeof(COPYentry)); if (cptr->ulCopyLen) memcpy((LPVOID)cptr->ulDest,(LPVOID)cptr->ulSource,cptr->ulCopyLen); if (cptr->ulCopyLen != cptr->ulDestLen) memset((LPVOID)(cptr->ulDest+cptr->ulCopyLen),0,cptr->ulDestLen-cptr->ulCopyLen); } return TRUE; } ********************************** 第一个问题:ROMHDR结构体内容分析: typedef struct ROMHDR { ULONG dllfirst; // first DLL address ULONG dlllast; // last DLL address ULONG physfirst; // first physical address ULONG physlast; // highest physical address ULONG nummods; // number of TOCentry's ULONG ulRAMStart; // start of RAM ULONG ulRAMFree; // start of RAM free space ULONG ulRAMEnd; // end of RAM ULONG ulCopyEntries; // number of copy section entries ULONG ulCopyOffset; // offset to copy section ULONG ulProfileLen; // length of PROFentries RAM ULONG ulProfileOffset; // offset to PROFentries ULONG numfiles; // number of FILES ULONG ulKernelFlags; // optional kernel flags from ROMFLAGS .bib config option ULONG ulFSRamPercent; // Percentage of RAM used for filesystem // from FSRAMPERCENT .bib config option // byte 0 = #4K chunks/Mbyte of RAM for filesystem 0-2Mbytes 0-255 // byte 1 = #4K chunks/Mbyte of RAM for filesystem 2-4Mbytes 0-255 // byte 2 = #4K chunks/Mbyte of RAM for filesystem 4-6Mbytes 0-255 // byte 3 = #4K chunks/Mbyte of RAM for filesystem > 6Mbytes 0-255
ULONG ulDrivglobStart; // device driver global starting address ULONG ulDrivglobLen; // device driver global length USHORT usCPUType; // CPU (machine) Type USHORT usMiscFlags; // Miscellaneous flags PVOID pExtensions; // pointer to ROM Header extensions ULONG ulTrackingStart; // tracking memory starting address ULONG ulTrackingLen; // tracking memory ending address } ROMHDR; |