imgtools/romtools/rombuild/r_obey.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_OBEY_H__
       
    20 #define __R_OBEY_H__
       
    21 
       
    22 #define __REFERENCE_CAPABILITY_NAMES__
       
    23 
       
    24 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
    25 #include <fstream>
       
    26 #else //!__MSVCDOTNET__
       
    27 #include <fstream.h>
       
    28 #endif //__MSVCDOTNET__
       
    29 
       
    30 #include "r_rom.h"
       
    31 #include "r_areaset.h"
       
    32 #include <e32capability.h>
       
    33 
       
    34 #ifdef _L
       
    35 #undef _L
       
    36 #endif
       
    37 
       
    38 #include <vector>
       
    39 
       
    40 const TUint32 KNumWords=16;
       
    41 //
       
    42 const TInt KDefaultRomSize=0x400000;
       
    43 const TInt KDefaultRomLinearBase=0x50000000;
       
    44 const TInt KDefaultRomAlign=0x1000;
       
    45 const TUint32 KDefaultDataRunAddress = 0x400000;
       
    46 //
       
    47 
       
    48 typedef std::string String;
       
    49 typedef std::vector<String> StringVector;
       
    50 
       
    51 enum EFileAttribute
       
    52 	{
       
    53 	EAttributeStackReserve,
       
    54 	EAttributeStack,
       
    55 	EAttributeReloc,
       
    56 	EAttributeCodeAlign,
       
    57 	EAttributeDataAlign,
       
    58 	EAttributeFixed,
       
    59 	EAttributeAtt,
       
    60 	EAttributePriority,
       
    61 	EAttributePatched,
       
    62 	EAttributeUid1,
       
    63 	EAttributeUid2,
       
    64 	EAttributeUid3,
       
    65 	EAttributeHeapMin,
       
    66 	EAttributeHeapMax,
       
    67 	EAttributeHidden,
       
    68 	EAttributeKeepIAT,
       
    69 	EAttributeArea,
       
    70 	EAttributeProcessSpecific,
       
    71 	EAttributeCapability,
       
    72 	EAttributePreferred,
       
    73 	EAttributeUnpaged,
       
    74 	EAttributePaged,
       
    75 	EAttributeUnpagedCode,
       
    76 	EAttributePagedCode,
       
    77 	EAttributeUnpagedData,
       
    78 	EAttributePagedData,
       
    79 	};
       
    80 enum EKeyword 
       
    81 	{
       
    82 	EKeywordNone=0,	// backwards compatibility, but now ignored
       
    83 	EKeywordFile,
       
    84 	EKeywordData,
       
    85 	EKeywordPrimary,
       
    86 	EKeywordSecondary,
       
    87 	EKeywordVariant,
       
    88 	EKeywordExtension,
       
    89 	EKeywordDevice,
       
    90 	EKeywordDll,
       
    91 	EKeywordFileCompress,
       
    92 	EKeywordFileUncompress,
       
    93 	EKeywordArea,
       
    94 	EKeywordAlign,
       
    95 	EKeywordUnicode,
       
    96 	EKeywordAscii,
       
    97 	EKeywordSingleKernel,
       
    98 	EKeywordMultiKernel,
       
    99 	EKeywordBootBinary,
       
   100 	EKeywordRomName,
       
   101 	EKeywordRomSize,
       
   102 	EKeywordRomLinearBase,
       
   103 	EKeywordRomAlign,
       
   104 	EKeywordRomChecksum,
       
   105 	EKeywordKernelDataAddress,
       
   106 	EKeywordKernelHeapMin,
       
   107 	EKeywordKernelHeapMax,
       
   108 	EKeywordDataAddress,
       
   109 	EKeywordDllDataTop,
       
   110 	EKeywordDefaultStackReserve,
       
   111 	EKeywordVersion,
       
   112 	EKeywordLanguages,
       
   113 	EKeywordHardware,
       
   114 	EKeywordRomNameOdd,
       
   115 	EKeywordRomNameEven,
       
   116 	EKeywordSRecordFileName,
       
   117 	EKeywordSRecordBase,
       
   118 	EKeywordTrace,
       
   119 	EKeywordKernelTrace,
       
   120 	EKeywordBTrace,
       
   121 	EKeywordBTraceMode,
       
   122 	EKeywordBTraceBuffer,
       
   123 	EKeywordCollapse,
       
   124 	EKeywordTime,
       
   125 	EKeywordSection,
       
   126 	EKeywordExtensionRom,
       
   127 	EKeywordKernelRomName,
       
   128 	EKeywordAlias,
       
   129 	EKeywordHide,
       
   130 	EKeywordRename,
       
   131 	EKeywordDebugPort,
       
   132 	EKeywordCompress,
       
   133 	EKeywordMemModel,
       
   134 	EKeywordNoWrapper,
       
   135 	EKeywordEpocWrapper,
       
   136 	EKeywordCoffWrapper,
       
   137 	EKeywordPlatSecEnforcement,
       
   138 	EKeywordPlatSecDiagnostics,
       
   139 	EKeywordPlatSecProcessIsolation,
       
   140 	EKeywordPlatSecEnforceSysBin,
       
   141 	EKeywordPlatSecDisabledCaps,
       
   142 	EKeywordPagingPolicy,
       
   143 	EKeywordCodePagingPolicy,
       
   144 	EKeywordDataPagingPolicy,
       
   145 	EKeywordPagingOverride,
       
   146 	EKeywordCodePagingOverride,
       
   147 	EKeywordDataPagingOverride,
       
   148 	EKeywordDemandPagingConfig,
       
   149 	EKeywordPagedRom,
       
   150 	EKeywordPatchDllData,
       
   151 	EKeywordExecutableCompressionMethodNone,
       
   152 	EKeywordExecutableCompressionMethodInflate,
       
   153 	EKeywordExecutableCompressionMethodBytePair,
       
   154 	EKeywordCoreImage,
       
   155 	EKeywordKernelConfig,
       
   156 	EKeywordMaxUnpagedMemSize,
       
   157 	EKeywordHardwareConfigRepositoryData ,
       
   158 	};
       
   159 enum TCollapseMode
       
   160 	{
       
   161 	ECollapseNone=0,
       
   162 	ECollapseImportThunksOnly=1,
       
   163 	ECollapseImportThunksAndVtables=2,
       
   164 	ECollapseAllChainBranches=3,
       
   165 	};
       
   166 
       
   167 struct ObeyFileKeyword
       
   168 	{
       
   169 	const char* iKeyword;
       
   170 	size_t iKeywordLength;
       
   171 	TInt iPass;
       
   172 	TInt iNumArgs;		// -ve means >= number
       
   173 	enum EKeyword iKeywordEnum;
       
   174 	const char* iHelpText;
       
   175 	};
       
   176 
       
   177 struct FileAttributeKeyword
       
   178 	{
       
   179 	const char* iKeyword;
       
   180 	size_t iKeywordLength;
       
   181 	TInt iIsFileAttribute;
       
   182 	TInt iNumArgs;
       
   183 	enum EFileAttribute iAttributeEnum;
       
   184 	const char* iHelpText;
       
   185 	};
       
   186 
       
   187 class ObeyFileReader
       
   188 	{
       
   189 public:
       
   190 	ObeyFileReader(TText *aFileName);
       
   191 	~ObeyFileReader();
       
   192 
       
   193 	static void KeywordHelp();
       
   194 
       
   195 	TBool Open();
       
   196 	void Mark();
       
   197 	void MarkNext();
       
   198 	void Rewind();
       
   199 
       
   200 	TInt NextLine(TInt aPass, enum EKeyword& aKeyword);
       
   201 	TInt NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, TText*& aArg);
       
   202 
       
   203 	void CopyWord(TInt aIndex, TText*& aString);				// allocate copy of nth word
       
   204 	TInt Count() { return iNumWords;}				// number of words on current line
       
   205 	char* Word(TInt aIndex) { return (char*)iWord[aIndex]; }	// return nth word as char*
       
   206 	TText* Text(TInt aIndex) { return iWord[aIndex]; }			// return nth word as TText*
       
   207 	char* Suffix() { return (char*)iSuffix; }			// return unmatched suffix of word[0]
       
   208 	TInt CurrentLine() { return iCurrentLine;}				// number of words on current line
       
   209 
       
   210 	TInt ProcessAlign(TInt& aAlign);
       
   211 	void ProcessLanguages(TInt64& aLanguageMask);
       
   212 	void ProcessTime(TInt64& aTime);
       
   213 
       
   214 	static void TimeNow(TInt64& aTime);
       
   215 private:
       
   216 	TInt ReadAndParseLine();
       
   217 	TInt SetLineLengthBuffer();
       
   218 	TInt Parse();
       
   219 	inline TBool IsGap(char ch); 
       
   220 
       
   221 	static const ObeyFileKeyword iKeywords[];
       
   222 	static const FileAttributeKeyword iAttributeKeywords[];
       
   223 	static TInt64 iTimeNow;
       
   224 
       
   225 private:
       
   226 	FILE* iObeyFile;
       
   227 	long iMark;
       
   228 	TInt iMarkLine;
       
   229 	long iCurrentMark;
       
   230 	TInt iCurrentLine;
       
   231 	TInt imaxLength;
       
   232 	TText* iFileName;
       
   233 	TInt iNumWords;
       
   234 	TText* iWord[KNumWords];
       
   235 	TText* iSuffix;
       
   236 	TText* iLine;
       
   237 	};
       
   238 
       
   239 class CPatchDataProcessor;
       
   240 class DllDataEntry;
       
   241 
       
   242 class CObeyFile
       
   243 	{
       
   244 public:
       
   245 	TText *iRomFileName;
       
   246 	TText *iRomOddFileName;
       
   247 	TText *iRomEvenFileName;
       
   248 	TText *iSRecordFileName;
       
   249 	TText *iBootFileName;
       
   250 	TText *iKernelRomName;
       
   251 	TInt iRomSize;
       
   252 	TUint32 iRomLinearBase;
       
   253 	TUint32 iRomAlign;
       
   254 	TUint32 iKernDataRunAddress;
       
   255 	TUint32 iDataRunAddress;
       
   256 	TUint32 iKernelLimit;
       
   257 	TUint32 iKernHeapMin;
       
   258 	TUint32 iKernHeapMax;
       
   259 	TUint32 iSectionStart;
       
   260 	TInt iSectionPosition;
       
   261 	TVersion iVersion;
       
   262 	TUint32 iCheckSum;
       
   263 	TInt iNumberOfPeFiles;
       
   264 	TInt iNumberOfDataFiles;
       
   265 	TInt iNumberOfPrimaries;
       
   266 	TInt iNumberOfExtensions;
       
   267 	TInt iNumberOfVariants;
       
   268 	TInt iNumberOfDevices;
       
   269 	TInt iNumberOfHCRDataFiles ;
       
   270 	TUint iAllVariantsMask[256];
       
   271 	TRomBuilderEntry** iPrimaries;
       
   272 	TRomBuilderEntry** iVariants;
       
   273 	TRomBuilderEntry** iExtensions;
       
   274 	TRomBuilderEntry** iDevices;
       
   275 	TInt64 iLanguage;
       
   276 	TUint32 iHardware;
       
   277 	TInt64 iTime;
       
   278 	TMemModel iMemModel;
       
   279 	TInt iPageSize;
       
   280 	TInt iChunkSize;
       
   281 	TInt iVirtualAllocSize;
       
   282 	TKernelModel iKernelModel;
       
   283 	TInt iCollapseMode;
       
   284 	TUint32 iSRecordBase;
       
   285 	TInt iCurrentSectionNumber;
       
   286 	TInt iDefaultStackReserve;
       
   287 	TUint32 iTraceMask[KNumTraceMaskWords];			// Pass through to the kernel tracemask
       
   288 	TUint32 iInitialBTraceFilter[8];
       
   289 	TInt iInitialBTraceBuffer;
       
   290 	TInt iInitialBTraceMode;
       
   291 	TUint32 iDebugPort;
       
   292 	TBool iDebugPortParsed;
       
   293 	TRomNode* iRootDirectory;
       
   294 	TUint32 iDllDataTop;
       
   295 	TUint32 iKernelConfigFlags;
       
   296 	TBool iPagingPolicyParsed;
       
   297 	TBool iCodePagingPolicyParsed;
       
   298 	TBool iDataPagingPolicyParsed;
       
   299 	TBool iPagingOverrideParsed;
       
   300 	TBool iCodePagingOverrideParsed;
       
   301 	TBool iDataPagingOverrideParsed;
       
   302 	SCapabilitySet iPlatSecDisabledCaps;
       
   303 	TBool iPlatSecDisabledCapsParsed;
       
   304 	TInt iMaxUnpagedMemSize;		// Max unpaged memory size, 0 = no limits
       
   305 private:
       
   306 	ObeyFileReader& iReader;
       
   307 	TInt iMissingFiles;
       
   308 	TRomNode* iLastExecutable;
       
   309 	AreaSet iAreaSet;
       
   310 
       
   311 	TRomBuilderEntry* iFirstFile;
       
   312 	TRomBuilderEntry** iNextFilePtrPtr;
       
   313 	TRomBuilderEntry* iCurrentFile;
       
   314 	TRomBuilderEntry* iLastVariantFile;
       
   315 	DllDataEntry* iFirstDllDataEntry;
       
   316 	TBool iUpdatedMaxUnpagedMemSize;		// ETure = iMaxUnpagedMemSize has been set
       
   317 
       
   318 public:
       
   319 	CObeyFile(ObeyFileReader& aReader);
       
   320 	~CObeyFile();
       
   321 	void Release();
       
   322 	TInt ProcessKernelRom();
       
   323 	TInt ProcessExtensionRom(MRomImage*& aKernelRom);
       
   324 	TRomBuilderEntry *FirstFile();
       
   325 	TRomBuilderEntry *NextFile();
       
   326 	const AreaSet& SetArea() const ; 
       
   327  	DllDataEntry* GetFirstDllDataEntry() const;
       
   328 	void SetFirstDllDataEntry(DllDataEntry* aDllDataEntry);
       
   329 
       
   330 	int SkipToExtension();
       
   331 	TText* ProcessCoreImage();
       
   332 
       
   333 private:
       
   334 	TBool CheckHardwareVariants();
       
   335 	TBool ProcessFile(TInt aAlign, enum EKeyword aKeyword);
       
   336 	TBool ProcessRenaming(enum EKeyword aKeyword);
       
   337 	TBool ProcessKeyword(enum EKeyword aKeyword);
       
   338 	TBool ParsePatchDllData();
       
   339 	void ProcessExtensionKeyword(enum EKeyword aKeyword);
       
   340 	TInt ParseFileAttributes(TRomNode* aNode, TRomBuilderEntry* aFile);
       
   341 	TInt ParseSection();
       
   342 	TUint32 ParseVariant();
       
   343 	TBool GotKeyVariables();
       
   344 	TBool GotExtensionVariables(MRomImage*& aRom);
       
   345 	TBool GetNextBitOfFileName(TText **epocEndPtr);
       
   346 	TText *IsValidFilePath(TText *aPath);
       
   347 	void AddFile(TRomBuilderEntry* aFile);
       
   348 
       
   349 	// Area-related methods
       
   350 	TBool CreateDefaultArea();
       
   351 	TBool ParseAreaKeyword();
       
   352 	TBool ParseAreaAttribute(const TText* aArg, TInt aLineNumber, const Area*& aArea);
       
   353 	TBool AddAreaAndHandleError(const char* aName, TLinAddr aDestBaseAddr, TUint aLength, TInt aLineNumber = -1);
       
   354 
       
   355 public:
       
   356 	CPatchDataProcessor* iPatchData;	
       
   357 	void SplitPatchDataStatement(StringVector& aPatchDataTokens);	
       
   358 	};
       
   359 
       
   360 
       
   361 inline const AreaSet& CObeyFile::SetArea() const
       
   362 	{
       
   363 	return iAreaSet;
       
   364 	}
       
   365 
       
   366 #endif