\r
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) {\r
//\r
- // The PE/COFF loader can support loading image types that can be executed. \r
- // If we loaded an image type that we can not execute return EFI_UNSUPORTED. \r
+ // The PE/COFF loader can support loading image types that can be executed.\r
+ // If we loaded an image type that we can not execute return EFI_UNSUPORTED.\r
//\r
return EFI_UNSUPPORTED;\r
}\r
// If the image relocations have not been stripped, then load at any address.\r
// Otherwise load at the address at which it was linked.\r
//\r
- Status = CoreAllocatePages (\r
- (Image->ImageContext.RelocationsStripped) ? AllocateAddress : AllocateAnyPages,\r
- Image->ImageContext.ImageCodeMemoryType,\r
- Image->NumberOfPages,\r
- &Image->ImageContext.ImageAddress\r
- );\r
+ // Memory below 1MB should be treated reserved for CSM and there should be\r
+ // no modules whose preferred load addresses are below 1MB.\r
+ //\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {\r
+ Status = CoreAllocatePages (\r
+ AllocateAddress,\r
+ Image->ImageContext.ImageCodeMemoryType,\r
+ Image->NumberOfPages,\r
+ &Image->ImageContext.ImageAddress\r
+ );\r
+ }\r
+ if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {\r
+ Status = CoreAllocatePages (\r
+ AllocateAnyPages,\r
+ Image->ImageContext.ImageCodeMemoryType,\r
+ Image->NumberOfPages,\r
+ &Image->ImageContext.ImageAddress\r
+ );\r
+ }\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
DstBufAlocated = TRUE;\r
-\r
} else {\r
//\r
// Caller provided the destination buffer\r
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);\r
}\r
}\r
- \r
+\r
//\r
// Fill in the entry point of the image if it is available\r
//\r
//\r
\r
DEBUG_CODE_BEGIN ();\r
- \r
+\r
UINTN Index;\r
UINTN StartIndex;\r
CHAR8 EfiFileName[256];\r
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));\r
}\r
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r
- \r
+\r
DEBUG_CODE_END ();\r
\r
return EFI_SUCCESS;\r
//\r
// Free memory.\r
//\r
- \r
+\r
if (DstBufAlocated) {\r
CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);\r
}\r
- \r
+\r
if (Image->ImageContext.FixupData != NULL) {\r
CoreFreePool (Image->ImageContext.FixupData);\r
}\r
\r
SetJumpFlag = SetJump (Image->JumpContext);\r
//\r
- // The initial call to SetJump() must always return 0. \r
- // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump(). \r
+ // The initial call to SetJump() must always return 0.\r
+ // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().\r
//\r
if (!SetJumpFlag) {\r
//\r
}\r
CoreFreePool (Image->RuntimeData);\r
}\r
- \r
+\r
//\r
// Free the Image from memory\r
//\r
//****************************************************************************\r
//**\r
-//** Copyright (C) 2006 Intel Corporation. All rights reserved. \r
+//** Copyright (C) 2006 Intel Corporation. All rights reserved.\r
//**\r
-//** The information and source code contained herein is the exclusive \r
+//** The information and source code contained herein is the exclusive\r
//** property of Intel Corporation and may not be disclosed, examined\r
-//** or reproduced in whole or in part without explicit written authorization \r
+//** or reproduced in whole or in part without explicit written authorization\r
//** from the company.\r
//**\r
//****************************************************************************\r
\r
bool operator < (const CIdentity&) const;\r
friend istream& operator >> (istream&, CIdentity&);\r
+ friend ostream& operator << (ostream&, const CIdentity&);\r
\r
static const string::size_type s_nIdStrLen;\r
\r
return is;\r
}\r
\r
+ostream& operator << (ostream& os, const CIdentity& idRight)\r
+{\r
+ return os << hex << setfill('0')\r
+ << setw(8) << (unsigned long)(idRight.m_ullId[0] >> 32) << '-'\r
+ << setw(4) << (unsigned short)(idRight.m_ullId[0] >> 16) << '-'\r
+ << setw(4) << (unsigned short)idRight.m_ullId[0] << '-'\r
+ << setw(4) << (unsigned short)(idRight.m_ullId[1] >> 48) << '-'\r
+ << setw(12) << (idRight.m_ullId[1] & 0xffffffffffff);\r
+}\r
+\r
class CInputFile : public CObjRoot\r
{\r
protected:\r
return m_is;\r
}\r
\r
-class CIdAddressMap : public CInputFile, public map<CIdentity, ulonglong_t>\r
+class CIdAddressPathMap : public CInputFile, public map<CIdentity, pair<ulonglong_t, string> >\r
{\r
public:\r
- CIdAddressMap(istream&);\r
+ CIdAddressPathMap(istream&);\r
};\r
\r
-CIdAddressMap::CIdAddressMap(istream& is)\r
+CIdAddressPathMap::CIdAddressPathMap(istream& is)\r
: CInputFile(is)\r
{\r
- CIdentity id;\r
- ulonglong_t ullBase;\r
-\r
- while (!!(m_is >> hex >> id >> ullBase))\r
- if (!insert(value_type(id, ullBase)).second)\r
+ key_type k;\r
+ mapped_type m;\r
+ while (!!(m_is >> hex >> k >> m.first) && !!GetLine(m.second))\r
+ if (!insert(value_type(k, m)).second)\r
throw runtime_error(__FUNCTION__ ": Duplicated files");\r
}\r
\r
-class CIdPathMap : public CInputFile, public map<CIdentity, string>\r
-{\r
-public:\r
- CIdPathMap(istream&);\r
-};\r
-\r
-CIdPathMap::CIdPathMap(istream& is)\r
-: CInputFile(is)\r
-{\r
- static const char cszFileSec[] = "[files]";\r
- static const char cszFfsFile[] = "EFI_FILE_NAME";\r
-\r
- string strALine;\r
-\r
- // Find the [files] section\r
- while (!!GetLine(strALine) && strALine.compare(0, sizeof(cszFileSec) - 1, cszFileSec));\r
-\r
- // m_is error means no FFS files listed in this INF file\r
- if (!m_is)\r
- return;\r
-\r
- // Parse FFS files one by one\r
- while (!!GetLine(strALine))\r
- {\r
- // Test if this begins a new section\r
- if (strALine[0] == '[')\r
- break;\r
-\r
- // Is it a line of FFS file?\r
- if (strALine.compare(0, sizeof(cszFfsFile) - 1, cszFfsFile))\r
- continue;\r
-\r
- string::size_type pos = strALine.find_first_not_of(' ', sizeof(cszFfsFile) - 1);\r
- if (pos == string::npos || strALine[pos] != '=')\r
- throw runtime_error(__FUNCTION__ ": Invalid FV INF format");\r
- pos = strALine.find_first_not_of(' ', pos + 1);\r
- if (pos == string::npos)\r
- throw runtime_error(__FUNCTION__ ": Incomplete line");\r
-\r
- strALine.erase(0, pos);\r
- pos = strALine.rfind('\\');\r
- if (pos == string::npos)\r
- pos = 0;\r
- else pos++;\r
-\r
- CIdentity id(strALine.substr(pos, CIdentity::s_nIdStrLen));\r
- if (!insert(value_type(id, strALine)).second)\r
- throw runtime_error(__FUNCTION__ ": Duplicated FFS files");\r
- }\r
-}\r
-\r
class CSymbol : public CObjRoot\r
{\r
public:\r
os << hex << setw(16) << setfill('0') << symbol.m_ullRva << setw(0);\r
os << ' ' << (symbol.m_bFunction ? 'F' : ' ')\r
<< (symbol.m_bStatic ? 'S' : ' ') << ' ';\r
- return os << symbol.m_strName << endl;\r
+ return os << symbol.m_strName;\r
}\r
\r
class CMapFile : public CInputFile, public list<CSymbol>\r
CMapFile(const string&);\r
\r
void SetLoadAddress(ulonglong_t);\r
- friend ostream& operator << (ostream&, const CMapFile&);\r
\r
string m_strModuleName;\r
ulonglong_t m_ullLoadAddr;\r
void CMapFile::SetLoadAddress(ulonglong_t ullLoadAddr)\r
{\r
for (iterator i = begin(); i != end(); i++)\r
- if (i->m_ullRva != 0)\r
+ if (i->m_ullRva >= m_ullLoadAddr)\r
i->m_ullRva += ullLoadAddr - m_ullLoadAddr;\r
m_ullLoadAddr = ullLoadAddr;\r
}\r
\r
-ostream& operator << (ostream& os, const CMapFile& mapFile)\r
-{\r
- CMapFile::const_iterator i = mapFile.begin();\r
- while (i != mapFile.end() && i->m_strAddress != mapFile.m_strEntryPoint)\r
- i++;\r
- if (i == mapFile.end())\r
- throw runtime_error(\r
- __FUNCTION__ ": Entry point not found for module " +\r
- mapFile.m_strModuleName);\r
-\r
- os << endl << hex\r
- << mapFile.m_strModuleName << " (EP=" << i->m_ullRva\r
- << ", BA=" << mapFile.m_ullLoadAddr << ')' << endl\r
- << endl;\r
-\r
- for (i = mapFile.begin(); i != mapFile.end(); i++)\r
- os << " " << *i;\r
-\r
- return os << endl;\r
-}\r
-\r
class COutputFile : public CObjRoot\r
{\r
protected:\r
class CFvMapFile : public CObjRoot, public map<CIdentity, CMapFile*>\r
{\r
public:\r
- CFvMapFile(const CIdAddressMap&, const CIdPathMap&);\r
+ CFvMapFile(const CIdAddressPathMap&);\r
~CFvMapFile(void);\r
\r
friend ostream& operator << (ostream&, const CFvMapFile&);\r
void Cleanup(void);\r
};\r
\r
-CFvMapFile::CFvMapFile(const CIdAddressMap& idAddr, const CIdPathMap& idPath)\r
+CFvMapFile::CFvMapFile(const CIdAddressPathMap& idAddrPath)\r
{\r
- for (CIdAddressMap::const_iterator i = idAddr.begin(); i != idAddr.end(); i++)\r
+ for (CIdAddressPathMap::const_iterator i = idAddrPath.begin(); i != idAddrPath.end(); i++)\r
{\r
- CIdPathMap::const_iterator j = idPath.find(i->first);\r
- if (j == idPath.end())\r
- throw runtime_error(__FUNCTION__ ": Map file not found");\r
-\r
- try\r
- {\r
- pair<iterator, bool> k = insert(value_type(i->first,\r
- new CMapFile(j->second.substr(0, j->second.rfind('.')) + ".map")));\r
- if (!k.second)\r
- throw logic_error(__FUNCTION__ ": Duplicated file found in rebase log");\r
+ if (i->second.second == "*")\r
+ continue;\r
\r
- k.first->second->SetLoadAddress(i->second);\r
- }\r
- catch (const runtime_error& e)\r
- {\r
- cerr << e.what() << endl;\r
- }\r
+ pair<iterator, bool> r = insert(value_type(i->first,\r
+ new CMapFile(i->second.second.substr(0, i->second.second.rfind('.')) + ".map")));\r
+ r.first->second->SetLoadAddress(i->second.first);\r
}\r
}\r
\r
ostream& operator << (ostream& os, const CFvMapFile& fvMap)\r
{\r
for (CFvMapFile::const_iterator i = fvMap.begin(); !!os && i != fvMap.end(); i++)\r
- os << *i->second;\r
+ {\r
+ CMapFile::const_iterator j = i->second->begin();\r
+ while (j != i->second->end() && j->m_strAddress != i->second->m_strEntryPoint) j++;\r
+ if (j == i->second->end())\r
+ throw runtime_error(\r
+ __FUNCTION__ ":Entry point not found for module " +\r
+ i->second->m_strModuleName);\r
+\r
+ os << hex\r
+ << i->second->m_strModuleName\r
+ << " (EP=" << j->m_ullRva\r
+ << ", BA=" << i->second->m_ullLoadAddr\r
+ << ", GUID=" << i->first\r
+ << ")" << endl << endl;\r
+\r
+ for (j = i->second->begin(); j != i->second->end(); j++)\r
+ os << " " << *j << endl;\r
+\r
+ os << endl << endl;\r
+ }\r
+\r
return os;\r
}\r
\r
static const char s_szUsage[];\r
};\r
\r
-const char CGenFvMapUsage::s_szUsage[] = "Usage: GenFvMap <LOG> <INF> <MAP>";\r
+const char CGenFvMapUsage::s_szUsage[] = "Usage: GenFvMap <LOG> <MAP>";\r
\r
class CGenFvMapApp : public CObjRoot\r
{\r
: m_cArgc(cArgc)\r
, m_ppszArgv(ppszArgv)\r
{\r
- if (cArgc != 4)\r
+ if (cArgc != 3)\r
throw CGenFvMapUsage();\r
}\r
\r
int CGenFvMapApp::Run(void)\r
{\r
ifstream isLog(m_ppszArgv[1]);\r
- ifstream isInf(m_ppszArgv[2]);\r
-\r
- CIdAddressMap idAddress(isLog);\r
- CIdPathMap idPath(isInf);\r
-\r
- CFvMapFile fvMap(idAddress, idPath);\r
+ CIdAddressPathMap idAddrPath(isLog);\r
+ CFvMapFile fvMap(idAddrPath);\r
\r
- ofstream osMap(m_ppszArgv[3], ios_base::out | ios_base::trunc);\r
+ ofstream osMap(m_ppszArgv[2], ios_base::out | ios_base::trunc);\r
osMap << fvMap;\r
\r
if (!osMap)\r