imgtools/romtools/rombuild/r_areaset.h
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 2000-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 * Area-related API
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef __R_AREASET_H__
       
    21 #define __R_AREASET_H__
       
    22 
       
    23 #include <assert.h>
       
    24 #include <string.h>
       
    25 #include <stdlib.h>
       
    26 #include <assert.h>
       
    27 #include <iostream>
       
    28 #include <string>
       
    29 #include <vector>
       
    30 #include <map>
       
    31 #include <fstream>
       
    32 
       
    33 #include <e32std.h>
       
    34 #include <e32rom.h>				// TLinAddr
       
    35 
       
    36 typedef std::vector<std::string> TStringList;
       
    37 struct DepInfo
       
    38 {
       
    39 public:
       
    40 	TBool dependOthers;
       
    41 	TBool beenDepended;
       
    42 	int index;
       
    43 	std::string portName;
       
    44 	TStringList depFilesList;
       
    45 	DepInfo()
       
    46 	{
       
    47 		dependOthers = EFalse;
       
    48 		beenDepended = EFalse;
       
    49 		index = -1;
       
    50 	}
       
    51 };
       
    52 typedef std::map<std::string, DepInfo> TDepInfoList;
       
    53 
       
    54 class TRomBuilderEntry;
       
    55 
       
    56 /**
       
    57  A zone of memory in which files are stored.
       
    58 
       
    59  Areas (except the default one - see below) are relocated from ROM to
       
    60  RAM at boot time.
       
    61 
       
    62  When created an area is given a "destination base address" (the start
       
    63  of the area in RAM) and a maximum size.
       
    64 
       
    65  During processing the "source base address" (the start of the area in
       
    66  ROM) is set once and the area is extended each time a file is
       
    67  processed by setting repeatedly the "source limit address" (the top
       
    68  of the area in ROM).
       
    69 
       
    70  The default area contains files that don't need relocation.  So its
       
    71  "source base address" and "destination base address" are the same.
       
    72 
       
    73  @private 
       
    74 */
       
    75 
       
    76 class Area
       
    77 	{
       
    78 public:
       
    79 	~Area();
       
    80 
       
    81 	const char* Name() const;
       
    82 
       
    83 	void SetSrcBaseAddr(TLinAddr aSrcBaseAddr);
       
    84 	TLinAddr SrcBaseAddr() const;
       
    85 
       
    86 	TBool ExtendSrcLimitAddr(TLinAddr aSrcLimitAddr, TUint& aOverflow);
       
    87 	TLinAddr SrcLimitAddr() const;
       
    88 	
       
    89 	TLinAddr DestBaseAddr() const;
       
    90 
       
    91 	TUint MaxSize() const;
       
    92 	TUint UsedSize() const;
       
    93 
       
    94 	TBool IsDefault() const;
       
    95 
       
    96 	void AddFile(TRomBuilderEntry* aFile);
       
    97 
       
    98 	TInt SortFilesForPagedRom();
       
    99 private:
       
   100 	// only AreaSet can create areas
       
   101 	Area(const char* aName, TLinAddr aDestBaseAddr, TUint aMaxSize, Area* aNext=0);
       
   102 	void ReleaseAllFiles();
       
   103 	void WriteDependenceGraph();
       
   104 public:
       
   105 	TRomBuilderEntry* iFirstPagedCode; // For PagedRom only
       
   106 private:
       
   107 	const char* iName;
       
   108 	TLinAddr iDestBaseAddr;
       
   109 	TLinAddr iSrcBaseAddr;
       
   110 	TLinAddr iSrcLimitAddr;
       
   111 	TUint iMaxSize;
       
   112 
       
   113 	TBool iIsDefault;
       
   114 
       
   115 	TRomBuilderEntry* iFiles;
       
   116 	TRomBuilderEntry** iNextFilePtrPtr;
       
   117 
       
   118 	Area* iNextArea;
       
   119 
       
   120 	friend class AreaSet;
       
   121 	friend class FilesInAreaIterator;
       
   122 	friend class NonDefaultAreasIterator;
       
   123 	};
       
   124 
       
   125 
       
   126 inline  const char* Area::Name() const
       
   127 	{
       
   128 	return iName;
       
   129 	}
       
   130 
       
   131 
       
   132 inline void Area::SetSrcBaseAddr(TLinAddr aSrcBaseAddr)
       
   133 	{
       
   134 	// setting allowed only once
       
   135 	assert(iSrcBaseAddr == 0);	
       
   136 	assert(aSrcBaseAddr != 0);
       
   137 
       
   138 	iSrcLimitAddr = iSrcBaseAddr = aSrcBaseAddr;
       
   139 	}
       
   140 
       
   141 
       
   142 inline TLinAddr Area::SrcBaseAddr() const
       
   143 	{
       
   144 	// must have been set before
       
   145 	assert(iSrcBaseAddr != 0);
       
   146 	return iSrcBaseAddr;
       
   147 	}
       
   148 
       
   149 
       
   150 inline TLinAddr Area::SrcLimitAddr() const
       
   151 	{
       
   152 	// must have been set before
       
   153 	assert(iSrcBaseAddr != 0);
       
   154 	return iSrcLimitAddr;
       
   155 	}
       
   156 
       
   157 
       
   158 inline TLinAddr Area::DestBaseAddr() const
       
   159 	{
       
   160 	return iDestBaseAddr;
       
   161 	}
       
   162 
       
   163 
       
   164 inline TUint Area::MaxSize() const
       
   165 	{
       
   166 	return iMaxSize;
       
   167 	}
       
   168 
       
   169 
       
   170 inline TUint Area::UsedSize() const
       
   171 	{
       
   172 	return iSrcLimitAddr-iSrcBaseAddr;
       
   173 	}
       
   174 
       
   175 
       
   176 inline TBool Area::IsDefault() const
       
   177 	{
       
   178 	return iIsDefault;
       
   179 	}
       
   180 
       
   181 
       
   182 ////////////////////////////////////////////////////////////////////////
       
   183 
       
   184 class TRomBuilderEntry;
       
   185 
       
   186 /**
       
   187  Iterate over every file in a given area.
       
   188 
       
   189  Files are iterated in the order in which they have been appended to
       
   190  the area.  
       
   191  
       
   192  @private
       
   193 */
       
   194 
       
   195 class FilesInAreaIterator
       
   196 	{
       
   197 public:
       
   198 	FilesInAreaIterator(const Area& aArea);
       
   199 
       
   200 	TBool IsDone() const;
       
   201 	TRomBuilderEntry* Current() const;
       
   202 	void GoToNext();
       
   203 
       
   204 private:
       
   205 	TRomBuilderEntry* iCurrentFile;
       
   206 	};
       
   207 
       
   208 
       
   209 inline FilesInAreaIterator::FilesInAreaIterator(const Area& aArea)
       
   210 	: iCurrentFile(aArea.iFiles)
       
   211 	{
       
   212 	}
       
   213 
       
   214 inline TBool FilesInAreaIterator::IsDone() const
       
   215 	{
       
   216 	return iCurrentFile == 0;
       
   217 	}
       
   218 
       
   219 inline TRomBuilderEntry* FilesInAreaIterator::Current() const
       
   220 	{
       
   221 	return iCurrentFile;
       
   222 	}
       
   223 
       
   224 ////////////////////////////////////////////////////////////////////////
       
   225 
       
   226 /**
       
   227  Set of areas indexed by name.
       
   228 
       
   229  There can be only one default area identified by its name
       
   230  (KDefaultAreaName).
       
   231 
       
   232  @private 
       
   233 */
       
   234 
       
   235 class AreaSet
       
   236 	{
       
   237 public:
       
   238 	enum TAddResult
       
   239 		{ 
       
   240 		EAdded,
       
   241 		EOverlap,
       
   242 		EDuplicateName,
       
   243 		EOverflow,
       
   244 		};
       
   245 
       
   246 public:
       
   247 	AreaSet();
       
   248 	~AreaSet();
       
   249 
       
   250 	TAddResult AddArea(const char* aName, TLinAddr aDestBaseAddr, TUint aMaxSize, const char*& aOverlappingArea);
       
   251 	void ReleaseAllAreas();
       
   252 
       
   253 	Area* FindByName(const char* aName) const;
       
   254 	TInt Count() const;
       
   255 	Area* DefaultArea() const;
       
   256 
       
   257 private:
       
   258 	Area* iNonDefaultAreas;
       
   259 	Area* iDefaultArea;
       
   260 	TInt iAreaCount;
       
   261 
       
   262 public:
       
   263 	static const char KDefaultAreaName[];
       
   264 
       
   265 	friend class NonDefaultAreasIterator;
       
   266 	};
       
   267 
       
   268 
       
   269 inline TInt AreaSet::Count() const
       
   270 	{
       
   271 	return iAreaCount;
       
   272 	}
       
   273 
       
   274 
       
   275 inline Area* AreaSet::DefaultArea() const
       
   276 	{
       
   277 	return iDefaultArea;
       
   278 	}
       
   279 
       
   280 
       
   281 ////////////////////////////////////////////////////////////////////////
       
   282 
       
   283 
       
   284 /**
       
   285 
       
   286  Iterate over every non-default area of a given area set.
       
   287 
       
   288  @private
       
   289 */
       
   290 
       
   291 class NonDefaultAreasIterator
       
   292 	{
       
   293 public:
       
   294 	NonDefaultAreasIterator(const AreaSet& aAreaSet);
       
   295 
       
   296 	TBool IsDone() const;
       
   297 	Area& Current() const;
       
   298 	void GoToNext();
       
   299 
       
   300 private:
       
   301 	Area* iCurrentArea;
       
   302 	};
       
   303 
       
   304 inline NonDefaultAreasIterator::NonDefaultAreasIterator(const AreaSet& aAreaSet)
       
   305 	: iCurrentArea(aAreaSet.iNonDefaultAreas)
       
   306 	{
       
   307 	}
       
   308 
       
   309 inline TBool NonDefaultAreasIterator::IsDone() const
       
   310 	{
       
   311 	return iCurrentArea == 0;
       
   312 	}
       
   313 
       
   314 inline Area& NonDefaultAreasIterator::Current() const
       
   315 	{
       
   316 	assert(iCurrentArea != 0);
       
   317 	return *iCurrentArea;
       
   318 	}
       
   319 
       
   320 #endif // __R_AREASET_H__