imgtools/romtools/rombuild/r_rom.h
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __R_ROM_H__
       
    20 #define __R_ROM_H__
       
    21 
       
    22 #include "e32image.h"
       
    23 #include <e32rom.h>
       
    24 
       
    25 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
    26 #include <fstream>
       
    27 #else //!__MSVCDOTNET__
       
    28 #include <fstream.h>
       
    29 #endif //__MSVCDOTNET__
       
    30 #include <boost/thread/thread.hpp>
       
    31 #include <boost/thread/mutex.hpp>
       
    32 #include <queue>
       
    33 
       
    34 #include "h_utl.h"
       
    35 #include "r_mromimage.h"
       
    36 #include <malloc.h>
       
    37 
       
    38 
       
    39 //
       
    40 const TUint KRomWrapperSize = 0x100;
       
    41 const TUint KRomNameSize = 16;
       
    42 //
       
    43 const TUint KOverrideStack = 0x01;
       
    44 const TUint KOverrideHeapMin = 0x02;
       
    45 const TUint KOverrideHeapMax = 0x04;
       
    46 const TUint KOverrideAddress = 0x08;
       
    47 const TUint KOverrideUid1 = 0x10;
       
    48 const TUint KOverrideUid2 = 0x20;
       
    49 const TUint KOverrideUid3 = 0x40;
       
    50 const TUint KOverrideCallEntryPoint = 0x80;
       
    51 const TUint KOverrideNoCallEntryPoint = 0x100;
       
    52 const TUint KOverridePriority = 0x200;
       
    53 const TUint KOverrideStackReserve = 0x400;
       
    54 const TUint KOverrideKeepIAT = 0x800;
       
    55 const TUint KOverrideCapability = 0x1000;
       
    56 const TUint KOverrideCodeUnpaged = 0x2000;
       
    57 const TUint KOverrideCodePaged = 0x4000;
       
    58 const TUint KOverrideDataUnpaged = 0x8000;
       
    59 const TUint KOverrideDataPaged = 0x10000;
       
    60 const TUint KOverrideHCRData = 0x20000 ;
       
    61 
       
    62 enum TKernelModel {ESingleKernel, EMultipleKernels};
       
    63 enum TMemModel {E_MM_Moving, E_MM_Direct, E_MM_Multiple, E_MM_Flexible};
       
    64 
       
    65 class TRomBuilderEntry;
       
    66 class E32Rom;
       
    67 typedef queue<TRomBuilderEntry*> EntryQueue;
       
    68 
       
    69 const TUint KVariantIndependent = 0x01000000;
       
    70 
       
    71 extern TInt CompareCapabilities(const TUint32* aSubCaps, const TUint32* aSuperCaps, const char* aSubName, const char* aSuperName);
       
    72 
       
    73 class LoadImageWorker
       
    74 	{
       
    75 public:
       
    76 	static EntryQueue *m_queue;
       
    77 	static boost::mutex m_mutex;
       
    78 	static TInt m_errors;
       
    79 	static TMemModel m_memmodel;
       
    80 	LoadImageWorker(EntryQueue* aQueue, TMemModel aMemModel);
       
    81 	void operator()();
       
    82 	};
       
    83 class CompressPageWorker
       
    84 	{
       
    85 public:
       
    86 	static E32Rom* m_rom;
       
    87 	static TInt m_nextpage;
       
    88 	static TInt m_totalpages;
       
    89 	static TInt m_pagesize;
       
    90 	static boost::mutex m_mutex;
       
    91 	static TInt m_error;
       
    92 	CompressPageWorker(E32Rom* aRom, TInt aPageSize, TInt aTotalPages, TInt aNextPage);
       
    93 	void operator()();
       
    94 	};
       
    95 
       
    96 class THardwareVariant
       
    97 	{
       
    98 public:
       
    99 	enum THardwareVariantOrder
       
   100 		{
       
   101 		EUnordered=0,
       
   102 		ELess=1,
       
   103 		EEqual=2,
       
   104 		EGreater=4,
       
   105 		};
       
   106 public:
       
   107 	THardwareVariant() {iVariant=KVariantIndependent;}
       
   108 	THardwareVariant(TUint aVariant) {iVariant=aVariant;}
       
   109 	operator TUint() const {return iVariant;}
       
   110 	TBool MutuallyExclusive(THardwareVariant aHardwareVariant) const;
       
   111 	TInt Compare(THardwareVariant aHardwareVariant) const;
       
   112 	TBool operator<(THardwareVariant a) const { return ((Compare(a)&ELess)!=0); }
       
   113 	TBool operator==(THardwareVariant a) const { return ((Compare(a)&EEqual)!=0); }
       
   114 	TBool operator>(THardwareVariant a) const { return ((Compare(a)&EGreater)!=0); }
       
   115 	TBool operator<=(THardwareVariant a) const { return ((Compare(a)&(ELess|EEqual))!=0); }
       
   116 	TBool operator>=(THardwareVariant a) const { return ((Compare(a)&(EGreater|EEqual))!=0); }
       
   117 	TBool IsIndependent() const {return Layer()<=3;}
       
   118 	TBool IsCpu() const {return Parent()==3; }
       
   119 	TBool IsVariant() const;
       
   120 	TUint32 ReturnVariant() const {return iVariant;} 
       
   121 	TUint Layer() const {return iVariant>>24;}
       
   122 	TUint Parent() const {return (iVariant>>16)&0xff;}
       
   123 	TUint VMask() const {return iVariant&0xffff;}
       
   124 private:
       
   125 	TUint32 iVariant;
       
   126 	};
       
   127 
       
   128 class TRomLoad
       
   129 	{
       
   130 public:
       
   131 	TText name[KRomNameSize];
       
   132 	TText versionStr[4];
       
   133 	TText buildNumStr[4];
       
   134 	TUint romSize;
       
   135 	TUint wrapSize;
       
   136 	};
       
   137 //
       
   138 
       
   139 // representation of a relocation record for areas.
       
   140 class TReloc
       
   141 	{
       
   142 public:
       
   143 	TInt iLength;
       
   144 	TUint iSrc;
       
   145 	TUint iDest;
       
   146 	};
       
   147 
       
   148 // thing for tracking the various addresses at which to find something
       
   149 
       
   150 class TAddressRange
       
   151 	{
       
   152 public:
       
   153 	TAddressRange();
       
   154 
       
   155 	void Append(TAddressRange& aRange);
       
   156 	void Extend(TInt aOffset);
       
   157 	void Move(TInt aOffset);
       
   158 
       
   159 public:
       
   160 	TAny*	iImagePtr;			// data in the ROM image buffer
       
   161 	TUint32	iImageAddr;			// address in the ROM image 
       
   162 	TUint32 iRunAddr;			// runtime address, usually the same as the iImageAddr
       
   163 	TUint   iSize;				// size of this section
       
   164 	};
       
   165 
       
   166 
       
   167 class TImageSection : public TAddressRange
       
   168 	{
       
   169 public:
       
   170 	TImageSection() : TAddressRange(), iFilePtr(0) {}
       
   171 
       
   172 	TAny* iFilePtr;		// original data in the E32Image file
       
   173 
       
   174 	void Load() const;	// copy the file data into the image, if needed
       
   175 	};
       
   176 
       
   177 //
       
   178 const TUint KFillSize = KRomWrapperSize-sizeof(TRomLoad);
       
   179 class CObeyFile;
       
   180 class TRomLoaderHeader
       
   181 	{
       
   182 public:
       
   183 	void SetUp(CObeyFile *aObey);
       
   184 private:
       
   185 	TRomLoad r;
       
   186 	TUint8 filler[KFillSize];
       
   187 	};
       
   188 //
       
   189 class TRomBuilderEntry;
       
   190 class TRomNode;
       
   191 class TRomFile;
       
   192 class TDllFindInfo
       
   193 	{
       
   194 public:
       
   195 	TDllFindInfo(const char* aImportName, const TRomBuilderEntry* aEntry);
       
   196 	~TDllFindInfo();
       
   197 public:
       
   198 	const char* iBareName;		// filename+extension to find, not including path UID or version
       
   199 	TUint32 iUid3;				// requested UID3 - 0 if don't care
       
   200 	TUint32 iModuleVersion;		// requested version
       
   201 	TUint32 iHwVariant;			// requested hardware variant
       
   202 	};
       
   203 
       
   204 class TAutoFree
       
   205 	{
       
   206 public:
       
   207 	TAutoFree(void* aPtr) {iPtr=aPtr;}
       
   208 	~TAutoFree() {free(iPtr);}
       
   209 private:
       
   210 	void* iPtr;
       
   211 	};
       
   212 
       
   213 #define AUTO_FREE(p)	TAutoFree _auto_free_##p(p)
       
   214 
       
   215 class TModuleName
       
   216 	{
       
   217 public:
       
   218 	TModuleName(const TRomBuilderEntry* aEntry);
       
   219 	TModuleName(const TDllFindInfo& aInfo);
       
   220 	TModuleName(const TRomNode& aNode);
       
   221 	TModuleName(const TRomFile& aFile, const TRomNode* aRootDir);
       
   222 	~TModuleName();
       
   223 	operator const char* () {return iName;}
       
   224 private:
       
   225 	char* iName;
       
   226 	};
       
   227 
       
   228 // class representing a file (or directory) in the ROM
       
   229 class TRomFile
       
   230 	{
       
   231 public:
       
   232 	TRomFile();
       
   233 	~TRomFile();
       
   234 	TInt AddressFromOrdinal(TLinAddr& aEDataAddr,TLinAddr& aExport, TUint aOrdinal);
       
   235 	void Finalise(TInt aSize);
       
   236 
       
   237 	void Close() { if (--iRefCount<=0) delete this; };
       
   238 	void Open() {iRefCount++; };
       
   239 
       
   240 	TInt MarkDeps();
       
   241 	TInt FindRouteTo(TRomFile* aDest, TRomFile** aStack, TInt aIndex);
       
   242 	TRomEntry* RomEntry() const {return iRomEntry;}
       
   243 	void SetRomEntry(TRomEntry* aEntry);
       
   244 
       
   245 	TAddressRange iAddresses;
       
   246 
       
   247 	inline TRomImageHeader* RomImgHdr() const
       
   248 		{return (TRomImageHeader*)iAddresses.iImagePtr;}
       
   249 
       
   250 	TAddressRange iExportDir;
       
   251 	TRomBuilderEntry* iRbEntry;	// only until Layout stage
       
   252 	TBool iDir;
       
   253 	TBool iFinal;
       
   254 	THardwareVariant iHwvd;
       
   255 	TRomEntry* iRomEntry;		// in ROM image buffer
       
   256 	friend class FileEntry;
       
   257 
       
   258 	TInt iDataBssOffsetInExe;	// for allocating DLL data in process data section
       
   259 
       
   260 	// dependence graph
       
   261 	TInt iNumDeps;
       
   262 	TRomFile** iDeps;
       
   263 	TInt iNumPDeps;
       
   264 	TRomFile** iPDeps;
       
   265 	TInt iMark;
       
   266 	TRomFile* iAttachProcess;
       
   267 	TInt iTotalDataBss;
       
   268 
       
   269 	// Data used when computing SMP properties.
       
   270 	struct TSmpInfo
       
   271 		{
       
   272 		TSmpInfo() : isInit(0), isActive(0), isSafe(0) {}
       
   273 		bool isInit;
       
   274 		bool isActive;
       
   275 		bool isSafe;
       
   276 		} iSmpInfo;
       
   277 
       
   278 	bool ComputeSmpSafe(const TRomBuilderEntry*);
       
   279 public:
       
   280 	TUint32 Uid3() const;
       
   281 	TUint32 ModuleVersion() const;
       
   282 	THardwareVariant HardwareVariant() const;
       
   283 	TUint32 ABI() const;
       
   284 	TInt ExportDirCount() const;
       
   285 	TUint32 RomImageFlags() const;
       
   286 	TLinAddr DataBssLinearBase() const;
       
   287 	const SSecurityInfo& SecurityInfo() const;
       
   288 private:
       
   289 	TInt iRefCount;
       
   290 	};
       
   291 //
       
   292 class TRomBuilderEntry;
       
   293 class RomFileStructure;
       
   294 
       
   295 // class representing a directory entry in the ROM file system
       
   296 class TRomNode
       
   297 	{
       
   298 public:
       
   299 	TRomNode(const TText* aName, TRomBuilderEntry* aEntry=0);
       
   300 	TRomNode(const TText* aName, TRomNode* aNode);
       
   301 private:
       
   302 	TRomNode(const TRomNode& aNode);
       
   303 public:
       
   304 	~TRomNode();
       
   305 	void Destroy();
       
   306 
       
   307 	TInt SetAtt(TText *anAttWord);
       
   308 	TInt NameCpy(char* aDest); // returns the length of aDest (in UTF-16 characters for Unicode, not bytes)
       
   309 	TInt SetBareName();
       
   310 
       
   311 	TRomNode* NewSubDir(const TText* aName);
       
   312 	void AddFile(TRomNode *aChild);
       
   313 	TInt Rename(TRomNode *aOldParent, TRomNode* aNewParent, TText* aNewName);
       
   314 	TRomNode* FindInDirectory(const TText* aName);
       
   315 	TRomNode* FindInDirectory(const TText* aName, THardwareVariant aVariant , TBool aPatchDataFlag=FALSE);
       
   316 
       
   317 	TRomEntry* RomEntry() const {return iRomFile->RomEntry();}
       
   318 	void Finalise(TInt aSize);
       
   319 
       
   320 	void CountDirectory(TInt& aFileCount, TInt& aDirCount);
       
   321 	TInt ProcessDirectory(RomFileStructure* aRFS);
       
   322 
       
   323 	static void AddExecutableFile(TRomNode*& aLast, TRomNode* aNode);
       
   324 	TRomNode* FindImageFileByName(const TDllFindInfo& aInfo, TBool aPrintDiag, TBool& aFallBack);
       
   325 	TInt CheckForVersionConflicts(const TRomBuilderEntry* a);
       
   326 
       
   327 	TRomNode* CopyDirectory(TRomNode*& aLastExecutable, TRomNode* aParent);
       
   328 	TInt Alias(TRomNode* aNode, TRomNode*& aLastExecutable);
       
   329 public:
       
   330 	char* BareName() const;
       
   331 	TUint32 Uid3() const;
       
   332 	TUint32 ModuleVersion() const;
       
   333 	THardwareVariant HardwareVariant() const;
       
   334 	TUint32 ABI() const;
       
   335 	TInt FullNameLength(TBool aIgnoreHiddenAttrib = EFalse) const;
       
   336 	TInt GetFullName(char* aBuf, TBool aIgnoreHiddenAttrib = EFalse) const;
       
   337 
       
   338 	void Add(TRomNode* aChild);
       
   339 	void Remove(TRomNode* aChild);
       
   340 
       
   341 	static TInt Count;			// seed for unique identifiers
       
   342 
       
   343 	TRomNode* iSibling;
       
   344 	TRomNode* iChild;
       
   345 	TRomNode* iParent;
       
   346 	TRomNode* iNextExecutable;
       
   347 
       
   348 protected:
       
   349 	TInt iIdentifier;
       
   350 	friend class FileEntry;
       
   351 
       
   352 public:
       
   353 	TRomFile* iRomFile;
       
   354 	TText* iName;
       
   355 	char* iBareName;		// name including extension but without UID or version
       
   356 	TUint8 iAtt;
       
   357 	TBool iHidden;
       
   358 	};
       
   359 
       
   360 class E32Rom;
       
   361 class Area;
       
   362 class TRomBuilderEntry : public E32ImageFile
       
   363 	{
       
   364 public:
       
   365 	TRomBuilderEntry(const char *aFileName, TText *aName);
       
   366 	~TRomBuilderEntry();
       
   367 	TInt SetCodeAlignment(TText *aStr);
       
   368 	TInt SetDataAlignment(TText *aStr);
       
   369 	TInt SetRelocationAddress(TText *aStr);
       
   370 	TInt SetStackReserve(TText *aStr);
       
   371 	TInt SetStackSize(TText *aStr);
       
   372 	TInt SetHeapSizeMin(TText *aStr);
       
   373 	TInt SetHeapSizeMax(TText *aStr);
       
   374 	TInt SetCapability(TText *aStr);
       
   375 	TInt SetUid1(TText *aStr);
       
   376 	TInt SetUid2(TText *aStr);
       
   377 	TInt SetUid3(TText *aStr);
       
   378 	TInt SetCallEntryPoint(TBool aState);
       
   379 	TInt SetPriority(TText *aStr);
       
   380 	TInt SetAttachProcess(TText *aStr);
       
   381 	TInt OpenImageFile();
       
   382 	TInt SizeInRom();
       
   383 	void SizeInSections(TInt& aSize1, TInt& aSize2);
       
   384 	void LoadToRom();
       
   385 	TInt FixupImports(E32Rom& aRom);
       
   386 	TInt ResolveDllRefTable(E32Rom& aRom);
       
   387 	TInt BuildDependenceGraph(E32Rom& aRom);
       
   388 	TInt FindAttachProcess(E32Rom& aRom);
       
   389 	const char* GetDefaultAttachProcess();
       
   390 	void SetRomNode(TRomNode* aNode);
       
   391 	void FixupRomEntries(TInt aSize);
       
   392 	TRomEntry* RomEntry() const {return iRomNode->RomEntry(); };
       
   393 	void DisplaySize(TPrintType aWhere);
       
   394 public:
       
   395 	inline TBool Primary() const
       
   396 		{return iRomImageFlags & KRomImageFlagPrimary;}
       
   397 	inline TBool Variant() const
       
   398 		{return iRomImageFlags & KRomImageFlagVariant;}
       
   399 	inline TBool Extension() const
       
   400 		{return iRomImageFlags & KRomImageFlagExtension;}
       
   401 	inline TBool Device() const
       
   402 		{return iRomImageFlags & KRomImageFlagDevice;}
       
   403 	inline TBool Secondary() const
       
   404 		{return iRomImageFlags & KRomImageFlagSecondary;}
       
   405 	inline TBool HCRDataFile() const 
       
   406 		{ return iOverrideFlags & KOverrideHCRData ;}
       
   407 private:
       
   408 	TRomBuilderEntry();
       
   409 	TRomBuilderEntry(const TRomBuilderEntry&);
       
   410 	const TRomBuilderEntry& operator=(const TRomBuilderEntry &);
       
   411 	void Relocate();
       
   412 public:
       
   413 	TText *iName;
       
   414 	TBool iResource;
       
   415 	TBool iNonXIP;
       
   416 	TBool iPreferred;
       
   417 	TUint iCompression;
       
   418 	TBool iPatched;
       
   419 	Area* iArea;
       
   420 	TInt  iRomSectionNumber;
       
   421 	TUint iOverrideFlags;
       
   422 	TUint32 iRelocationAddress;
       
   423 	TInt iAlignment;
       
   424 	TInt iCodeAlignment;
       
   425 	TInt iDataAlignment;
       
   426 	TInt iStackSize;
       
   427 	TInt iHeapSizeMin;
       
   428 	TInt iHeapSizeMax;
       
   429 	TProcessPriority iPriority;
       
   430 	TUint iUid1;
       
   431 	TUint iUid2;
       
   432 	TUint iUid3;
       
   433 	TLinAddr iDataBssLinearBase;
       
   434 	SSecurityInfo iS;
       
   435 	char* iBareName;			// EPOC name+extension but without path or version
       
   436 	TUint32 iVersionInName;
       
   437 	TUint32 iVersionPresentInName;
       
   438 
       
   439 	THardwareVariant iHardwareVariant;
       
   440 	TUint iDataBssOffset;
       
   441 	TInt iStackReserve;
       
   442 
       
   443 	TRomImageHeader* iRomImageHeader;
       
   444 
       
   445 	TAddressRange iHeaderRange;
       
   446 	TImageSection iCodeSection;
       
   447 	TImageSection iImportAddressTableSection;
       
   448 	TImageSection iExportDirSection;
       
   449 	TImageSection iDataSection;
       
   450 	TAddressRange iDllRefTableRange;
       
   451 
       
   452 	TLinAddr**  iIATRefs;	// image addresses of pointers to IAT
       
   453 
       
   454 	TRomBuilderEntry* iNext;
       
   455 	TRomBuilderEntry* iNextInArea;
       
   456 
       
   457 	TUint32 iRomImageFlags;
       
   458 	TText* iProcessName;
       
   459 
       
   460 	// Used by the collapse routines
       
   461 	TInt iImportCount;
       
   462 	TUint32 iImportBlockStartAddress;
       
   463 	TUint32 iImportBlockEndAddress;
       
   464 	TRomNode *iRomNode;
       
   465 	};
       
   466 //
       
   467 class ImpTRomHeader	: public TRomHeader
       
   468 	{
       
   469 public:
       
   470 	void Display();
       
   471 	void SetUp(CObeyFile *aObey);
       
   472 	void CheckSum(TUint32 aTargetValue);
       
   473 	};
       
   474 //
       
   475 class COrderedFileList
       
   476 	{
       
   477 public:
       
   478 	static COrderedFileList* New(TInt aMaxFiles);
       
   479 	~COrderedFileList();
       
   480 	void Add(TRomBuilderEntry* anEntry);
       
   481 	TInt Count() {return iCount;}
       
   482 	TRomBuilderEntry* operator[](TInt anIndex) {return iOrderedFiles[anIndex];}
       
   483 private:
       
   484 	COrderedFileList(TInt aMaxFiles);
       
   485 private:
       
   486 	TInt iCount;
       
   487 	TInt iMaxFiles;
       
   488 	TRomBuilderEntry **iOrderedFiles;
       
   489 	};
       
   490 //
       
   491 class CObeyFile;
       
   492 class Area;
       
   493 class Memmap;
       
   494 class E32Rom : public MRomImage
       
   495 	{
       
   496 public:
       
   497 	E32Rom(CObeyFile *aObey);
       
   498 	~E32Rom();
       
   499 	TInt Create();
       
   500 	TInt CreateExtension(MRomImage* aKernelRom);
       
   501 	TInt Align(TInt aVal);
       
   502 	void DisplaySizes(TPrintType aWhere);
       
   503 	TInt WriteImages(TInt aHeaderType);
       
   504 	TInt Compare(char* anImage, TInt aHeaderType);
       
   505 	//
       
   506 	//
       
   507 	char *RomToActualAddress(TUint aPtr);
       
   508 	TUint ActualToRomAddress(TAny *aPtr);
       
   509 	void Display(TRomImageHeader *aHdr);
       
   510 	TRomNode* FindImageFileByName(const TDllFindInfo& aInfo, TBool aPrintDiag, TBool& aFallBack);
       
   511 	TInt CheckForVersionConflicts(const TRomBuilderEntry* a);
       
   512 	TRomNode* CopyDirectory(TRomNode*& aLastExecutable);
       
   513 
       
   514 	TRomNode* RootDirectory();
       
   515 	TText* RomFileName();
       
   516 	TUint32 RomBase();
       
   517 	TUint32 RomSize();
       
   518 	TVersion Version();
       
   519 	TInt64 Time();
       
   520 	TUint32 CheckSum();
       
   521 	TUint32 DataRunAddress();
       
   522 	TUint32 RomAlign();
       
   523 
       
   524 private:
       
   525 	void CalculateDataAddresses();
       
   526 	void CalculateDataAddress(TRomBuilderEntry *aFile);
       
   527 	char *LayoutRom(char *anAddr);
       
   528 	char *ReserveRomExceptionSearchTable(char *anAddr, TRomExceptionSearchTable*& exceptionSearchTable);
       
   529 	void ConstructRomExceptionSearchTable(TRomExceptionSearchTable* exceptionSearchTable);
       
   530 	void LayoutFile(TRomBuilderEntry*, TAddressRange& aMain, TAddressRange* aSecond, CBytePair* aBPE);
       
   531 	void NextRom(TAddressRange* aFirst, TAddressRange* aSecond);
       
   532 	TInt TranslateFiles();
       
   533 	void EnumerateVariants();
       
   534 	TUint32 AlignToChunk(TUint32 anAddr);
       
   535 	TUint32 AlignToPage(TUint32 anAddr);
       
   536 	TUint32 AllocVirtual(TUint32 aAddr,TUint aSize);
       
   537 	TInt LoadDataToRom(TRomBuilderEntry *aFile, TAddressRange& aAddress, CBytePair* aBPE);
       
   538 	void LoadFileToRom(TRomBuilderEntry *aFile);
       
   539 
       
   540 	void Write(ofstream &of, TInt aHeaderType);		// main ROM image
       
   541 	void WriteOdd(ofstream &of);					// odd halfwords
       
   542 	void WriteEven(ofstream &of);					// even halfwords
       
   543 	void WriteSRecord(ofstream &of);				// SREC or S19 format
       
   544 
       
   545 	TInt LoadContents(char*& anAddr, TRomHeader* aHeader);
       
   546 	TInt BuildDependenceGraph();
       
   547 	TInt ResolveDllRefTables();
       
   548 	TInt ResolveImports();
       
   549 	TInt CreateExportDirectory();
       
   550 	char *WriteDirectory(char *aAddr, TRomHeader* aHeader);
       
   551 	TInt WriteHeadersToRom(char *anAddr);
       
   552 	TInt RequiredSize();
       
   553 	void SetCompressionInfo(TUint aCompressionType, TUint aCompressedSize, TUint aUncompressedSize);
       
   554 	void FinaliseSectionHeader();
       
   555 	void FinaliseExtensionHeader(MRomImage* aKernelRom);
       
   556 	void DisplayExtensionHeader();
       
   557 	void SetImageAddr(TAddressRange& aSet, TAny* aPtr, TUint32 aRunOffset=0);
       
   558 	void SetImageAddr(TAddressRange& aSet, TUint aAddr, TUint32 aRunOffset=0);
       
   559 	TInt CollapseImportThunks();
       
   560 	TInt CollapseImportThunks(TRomBuilderEntry* aFile);
       
   561 	TInt CollapseBranches();
       
   562 	TInt CollapseBranches(TRomBuilderEntry* aFile);
       
   563 	TUint32 FindFinalJumpDestination(TUint32 ja);
       
   564 
       
   565 	char* AllocateRelocationTable(char* aAddr, TReloc*& aRelocTable);
       
   566 	void FillInRelocationTable(TReloc* aRelocTable);
       
   567 
       
   568 	void LinkKernelExtensions(TRomBuilderEntry* aExtArray[], TInt aExtCount);
       
   569 	void FillInCrcs();
       
   570 	void ProcessDllData();
       
   571 
       
   572 	void CreatePageIndex(char*& aAddr);
       
   573 	TInt CompressPages();
       
   574 	TInt CompressPage(SRomPageInfo& aPageInfo, TInt aOutOffset, CBytePair * aBPE);
       
   575 
       
   576 	// dependence graph
       
   577 	void UnmarkGraph(TInt aMark=0xffffffff);
       
   578 	void FindMarked(TInt aMarkMask, TInt aMark, TRomFile**& aList);
       
   579 	TInt ProcessDependencies();
       
   580 	void ListRouteTo(TRomFile* aStart, TRomFile* aDest, TInt aNDeps);
       
   581 
       
   582 	void SetSmpFlags();
       
   583 	
       
   584 	// Check if the unpaged memory size overflows. For page enabled ROM only.
       
   585 	TInt CheckUnpagedMemSize();
       
   586 	
       
   587 	// Initialize the page info prior to compression
       
   588 	TInt SetupPages();
       
   589 
       
   590 	Memmap *iImageMap;
       
   591 public:
       
   592 	char* iData;
       
   593 	TInt iSize;
       
   594 	TRomLoaderHeader *iLoaderHeader;
       
   595 	TRomHeader *iHeader;
       
   596 	TExtensionRomHeader *iExtensionRomHeader;		// NULL if not extension ROM
       
   597 	//
       
   598 	CObeyFile *iObey;
       
   599 
       
   600 	char *iSectionPtr;
       
   601 	
       
   602 	//
       
   603 	TInt iSizeUsed;
       
   604 	TInt iUncompressedSize;
       
   605 	TInt iOverhead;
       
   606 	TInt iDirectorySize;
       
   607 	TInt iImportsFixedUp;
       
   608 	TInt iBranchesFixedUp;
       
   609 	TInt iVtableEntriesFixedUp;
       
   610 	//
       
   611 	TUint32 iNextDataChunkBase;
       
   612 	TUint32 iTotalSvDataSize;
       
   613 	TUint32 iNextDllDataAddr;
       
   614 	char* iPrevPrimaryAddress;
       
   615 	char* iPrevVariantAddress;
       
   616 	COrderedFileList** iVariantFileLists;
       
   617 	TRomBuilderEntry** iPeFiles;
       
   618 	};
       
   619 
       
   620 
       
   621 #endif