summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524>2006-12-31 09:55:05 +0000
committerbxing <bxing@6f19259b-4bc3-4df7-8a09-765794883524>2006-12-31 09:55:05 +0000
commita3ab2a47d9ecb2295802726fd17f048c14519aab (patch)
tree43346ac9424cadf70f85dd4fb2a858eb40f6ce92
parent8733430b83565480540d1d890986cbf22c54db0d (diff)
downloadedk2-platforms-a3ab2a47d9ecb2295802726fd17f048c14519aab.tar.xz
Integrated FV memory map into R9
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2158 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--EdkModulePkg/Core/Dxe/Image/Image.c47
-rw-r--r--Tools/CCode/Source/GenFvMap/GenFvMap.cpp172
-rw-r--r--Tools/CCode/Source/GenFvMap/build.xml1
-rw-r--r--Tools/CCode/Source/PeiRebase/PeiRebaseExe.c18
4 files changed, 100 insertions, 138 deletions
diff --git a/EdkModulePkg/Core/Dxe/Image/Image.c b/EdkModulePkg/Core/Dxe/Image/Image.c
index 4e6bd0843e..9a2723765d 100644
--- a/EdkModulePkg/Core/Dxe/Image/Image.c
+++ b/EdkModulePkg/Core/Dxe/Image/Image.c
@@ -219,8 +219,8 @@ Returns:
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) {
//
- // The PE/COFF loader can support loading image types that can be executed.
- // If we loaded an image type that we can not execute return EFI_UNSUPORTED.
+ // The PE/COFF loader can support loading image types that can be executed.
+ // If we loaded an image type that we can not execute return EFI_UNSUPORTED.
//
return EFI_UNSUPPORTED;
}
@@ -247,17 +247,30 @@ Returns:
// If the image relocations have not been stripped, then load at any address.
// Otherwise load at the address at which it was linked.
//
- Status = CoreAllocatePages (
- (Image->ImageContext.RelocationsStripped) ? AllocateAddress : AllocateAnyPages,
- Image->ImageContext.ImageCodeMemoryType,
- Image->NumberOfPages,
- &Image->ImageContext.ImageAddress
- );
+ // Memory below 1MB should be treated reserved for CSM and there should be
+ // no modules whose preferred load addresses are below 1MB.
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {
+ Status = CoreAllocatePages (
+ AllocateAddress,
+ Image->ImageContext.ImageCodeMemoryType,
+ Image->NumberOfPages,
+ &Image->ImageContext.ImageAddress
+ );
+ }
+ if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {
+ Status = CoreAllocatePages (
+ AllocateAnyPages,
+ Image->ImageContext.ImageCodeMemoryType,
+ Image->NumberOfPages,
+ &Image->ImageContext.ImageAddress
+ );
+ }
if (EFI_ERROR (Status)) {
return Status;
}
DstBufAlocated = TRUE;
-
} else {
//
// Caller provided the destination buffer
@@ -394,7 +407,7 @@ Returns:
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);
}
}
-
+
//
// Fill in the entry point of the image if it is available
//
@@ -407,7 +420,7 @@ Returns:
//
DEBUG_CODE_BEGIN ();
-
+
UINTN Index;
UINTN StartIndex;
CHAR8 EfiFileName[256];
@@ -439,7 +452,7 @@ Returns:
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
}
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));
-
+
DEBUG_CODE_END ();
return EFI_SUCCESS;
@@ -449,11 +462,11 @@ Done:
//
// Free memory.
//
-
+
if (DstBufAlocated) {
CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
}
-
+
if (Image->ImageContext.FixupData != NULL) {
CoreFreePool (Image->ImageContext.FixupData);
}
@@ -927,8 +940,8 @@ Returns:
SetJumpFlag = SetJump (Image->JumpContext);
//
- // The initial call to SetJump() must always return 0.
- // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().
+ // The initial call to SetJump() must always return 0.
+ // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().
//
if (!SetJumpFlag) {
//
@@ -1142,7 +1155,7 @@ Returns:
}
CoreFreePool (Image->RuntimeData);
}
-
+
//
// Free the Image from memory
//
diff --git a/Tools/CCode/Source/GenFvMap/GenFvMap.cpp b/Tools/CCode/Source/GenFvMap/GenFvMap.cpp
index 4a8c726785..0ff5bd07ee 100644
--- a/Tools/CCode/Source/GenFvMap/GenFvMap.cpp
+++ b/Tools/CCode/Source/GenFvMap/GenFvMap.cpp
@@ -1,10 +1,10 @@
//****************************************************************************
//**
-//** Copyright (C) 2006 Intel Corporation. All rights reserved.
+//** Copyright (C) 2006 Intel Corporation. All rights reserved.
//**
-//** The information and source code contained herein is the exclusive
+//** The information and source code contained herein is the exclusive
//** property of Intel Corporation and may not be disclosed, examined
-//** or reproduced in whole or in part without explicit written authorization
+//** or reproduced in whole or in part without explicit written authorization
//** from the company.
//**
//****************************************************************************
@@ -78,6 +78,7 @@ public:
bool operator < (const CIdentity&) const;
friend istream& operator >> (istream&, CIdentity&);
+ friend ostream& operator << (ostream&, const CIdentity&);
static const string::size_type s_nIdStrLen;
@@ -134,6 +135,16 @@ istream& operator >> (istream& is, CIdentity& idRight)
return is;
}
+ostream& operator << (ostream& os, const CIdentity& idRight)
+{
+ return os << hex << setfill('0')
+ << setw(8) << (unsigned long)(idRight.m_ullId[0] >> 32) << '-'
+ << setw(4) << (unsigned short)(idRight.m_ullId[0] >> 16) << '-'
+ << setw(4) << (unsigned short)idRight.m_ullId[0] << '-'
+ << setw(4) << (unsigned short)(idRight.m_ullId[1] >> 48) << '-'
+ << setw(12) << (idRight.m_ullId[1] & 0xffffffffffff);
+}
+
class CInputFile : public CObjRoot
{
protected:
@@ -183,74 +194,22 @@ istream& CInputFile::GetLine(string& strALine)
return m_is;
}
-class CIdAddressMap : public CInputFile, public map<CIdentity, ulonglong_t>
+class CIdAddressPathMap : public CInputFile, public map<CIdentity, pair<ulonglong_t, string> >
{
public:
- CIdAddressMap(istream&);
+ CIdAddressPathMap(istream&);
};
-CIdAddressMap::CIdAddressMap(istream& is)
+CIdAddressPathMap::CIdAddressPathMap(istream& is)
: CInputFile(is)
{
- CIdentity id;
- ulonglong_t ullBase;
-
- while (!!(m_is >> hex >> id >> ullBase))
- if (!insert(value_type(id, ullBase)).second)
+ key_type k;
+ mapped_type m;
+ while (!!(m_is >> hex >> k >> m.first) && !!GetLine(m.second))
+ if (!insert(value_type(k, m)).second)
throw runtime_error(__FUNCTION__ ": Duplicated files");
}
-class CIdPathMap : public CInputFile, public map<CIdentity, string>
-{
-public:
- CIdPathMap(istream&);
-};
-
-CIdPathMap::CIdPathMap(istream& is)
-: CInputFile(is)
-{
- static const char cszFileSec[] = "[files]";
- static const char cszFfsFile[] = "EFI_FILE_NAME";
-
- string strALine;
-
- // Find the [files] section
- while (!!GetLine(strALine) && strALine.compare(0, sizeof(cszFileSec) - 1, cszFileSec));
-
- // m_is error means no FFS files listed in this INF file
- if (!m_is)
- return;
-
- // Parse FFS files one by one
- while (!!GetLine(strALine))
- {
- // Test if this begins a new section
- if (strALine[0] == '[')
- break;
-
- // Is it a line of FFS file?
- if (strALine.compare(0, sizeof(cszFfsFile) - 1, cszFfsFile))
- continue;
-
- string::size_type pos = strALine.find_first_not_of(' ', sizeof(cszFfsFile) - 1);
- if (pos == string::npos || strALine[pos] != '=')
- throw runtime_error(__FUNCTION__ ": Invalid FV INF format");
- pos = strALine.find_first_not_of(' ', pos + 1);
- if (pos == string::npos)
- throw runtime_error(__FUNCTION__ ": Incomplete line");
-
- strALine.erase(0, pos);
- pos = strALine.rfind('\\');
- if (pos == string::npos)
- pos = 0;
- else pos++;
-
- CIdentity id(strALine.substr(pos, CIdentity::s_nIdStrLen));
- if (!insert(value_type(id, strALine)).second)
- throw runtime_error(__FUNCTION__ ": Duplicated FFS files");
- }
-}
-
class CSymbol : public CObjRoot
{
public:
@@ -286,7 +245,7 @@ ostream& operator << (ostream& os, const CSymbol& symbol)
os << hex << setw(16) << setfill('0') << symbol.m_ullRva << setw(0);
os << ' ' << (symbol.m_bFunction ? 'F' : ' ')
<< (symbol.m_bStatic ? 'S' : ' ') << ' ';
- return os << symbol.m_strName << endl;
+ return os << symbol.m_strName;
}
class CMapFile : public CInputFile, public list<CSymbol>
@@ -295,7 +254,6 @@ public:
CMapFile(const string&);
void SetLoadAddress(ulonglong_t);
- friend ostream& operator << (ostream&, const CMapFile&);
string m_strModuleName;
ulonglong_t m_ullLoadAddr;
@@ -344,32 +302,11 @@ CMapFile::CMapFile(const string& strFName)
void CMapFile::SetLoadAddress(ulonglong_t ullLoadAddr)
{
for (iterator i = begin(); i != end(); i++)
- if (i->m_ullRva != 0)
+ if (i->m_ullRva >= m_ullLoadAddr)
i->m_ullRva += ullLoadAddr - m_ullLoadAddr;
m_ullLoadAddr = ullLoadAddr;
}
-ostream& operator << (ostream& os, const CMapFile& mapFile)
-{
- CMapFile::const_iterator i = mapFile.begin();
- while (i != mapFile.end() && i->m_strAddress != mapFile.m_strEntryPoint)
- i++;
- if (i == mapFile.end())
- throw runtime_error(
- __FUNCTION__ ": Entry point not found for module " +
- mapFile.m_strModuleName);
-
- os << endl << hex
- << mapFile.m_strModuleName << " (EP=" << i->m_ullRva
- << ", BA=" << mapFile.m_ullLoadAddr << ')' << endl
- << endl;
-
- for (i = mapFile.begin(); i != mapFile.end(); i++)
- os << " " << *i;
-
- return os << endl;
-}
-
class COutputFile : public CObjRoot
{
protected:
@@ -384,7 +321,7 @@ private:
class CFvMapFile : public CObjRoot, public map<CIdentity, CMapFile*>
{
public:
- CFvMapFile(const CIdAddressMap&, const CIdPathMap&);
+ CFvMapFile(const CIdAddressPathMap&);
~CFvMapFile(void);
friend ostream& operator << (ostream&, const CFvMapFile&);
@@ -393,27 +330,16 @@ private:
void Cleanup(void);
};
-CFvMapFile::CFvMapFile(const CIdAddressMap& idAddr, const CIdPathMap& idPath)
+CFvMapFile::CFvMapFile(const CIdAddressPathMap& idAddrPath)
{
- for (CIdAddressMap::const_iterator i = idAddr.begin(); i != idAddr.end(); i++)
+ for (CIdAddressPathMap::const_iterator i = idAddrPath.begin(); i != idAddrPath.end(); i++)
{
- CIdPathMap::const_iterator j = idPath.find(i->first);
- if (j == idPath.end())
- throw runtime_error(__FUNCTION__ ": Map file not found");
-
- try
- {
- pair<iterator, bool> k = insert(value_type(i->first,
- new CMapFile(j->second.substr(0, j->second.rfind('.')) + ".map")));
- if (!k.second)
- throw logic_error(__FUNCTION__ ": Duplicated file found in rebase log");
+ if (i->second.second == "*")
+ continue;
- k.first->second->SetLoadAddress(i->second);
- }
- catch (const runtime_error& e)
- {
- cerr << e.what() << endl;
- }
+ pair<iterator, bool> r = insert(value_type(i->first,
+ new CMapFile(i->second.second.substr(0, i->second.second.rfind('.')) + ".map")));
+ r.first->second->SetLoadAddress(i->second.first);
}
}
@@ -426,7 +352,27 @@ void CFvMapFile::Cleanup(void)
ostream& operator << (ostream& os, const CFvMapFile& fvMap)
{
for (CFvMapFile::const_iterator i = fvMap.begin(); !!os && i != fvMap.end(); i++)
- os << *i->second;
+ {
+ CMapFile::const_iterator j = i->second->begin();
+ while (j != i->second->end() && j->m_strAddress != i->second->m_strEntryPoint) j++;
+ if (j == i->second->end())
+ throw runtime_error(
+ __FUNCTION__ ":Entry point not found for module " +
+ i->second->m_strModuleName);
+
+ os << hex
+ << i->second->m_strModuleName
+ << " (EP=" << j->m_ullRva
+ << ", BA=" << i->second->m_ullLoadAddr
+ << ", GUID=" << i->first
+ << ")" << endl << endl;
+
+ for (j = i->second->begin(); j != i->second->end(); j++)
+ os << " " << *j << endl;
+
+ os << endl << endl;
+ }
+
return os;
}
@@ -446,7 +392,7 @@ private:
static const char s_szUsage[];
};
-const char CGenFvMapUsage::s_szUsage[] = "Usage: GenFvMap <LOG> <INF> <MAP>";
+const char CGenFvMapUsage::s_szUsage[] = "Usage: GenFvMap <LOG> <MAP>";
class CGenFvMapApp : public CObjRoot
{
@@ -465,7 +411,7 @@ CGenFvMapApp::CGenFvMapApp(int cArgc, char *ppszArgv[])
: m_cArgc(cArgc)
, m_ppszArgv(ppszArgv)
{
- if (cArgc != 4)
+ if (cArgc != 3)
throw CGenFvMapUsage();
}
@@ -476,14 +422,10 @@ CGenFvMapApp::~CGenFvMapApp(void)
int CGenFvMapApp::Run(void)
{
ifstream isLog(m_ppszArgv[1]);
- ifstream isInf(m_ppszArgv[2]);
-
- CIdAddressMap idAddress(isLog);
- CIdPathMap idPath(isInf);
-
- CFvMapFile fvMap(idAddress, idPath);
+ CIdAddressPathMap idAddrPath(isLog);
+ CFvMapFile fvMap(idAddrPath);
- ofstream osMap(m_ppszArgv[3], ios_base::out | ios_base::trunc);
+ ofstream osMap(m_ppszArgv[2], ios_base::out | ios_base::trunc);
osMap << fvMap;
if (!osMap)
diff --git a/Tools/CCode/Source/GenFvMap/build.xml b/Tools/CCode/Source/GenFvMap/build.xml
index 6c236bf979..4d7e155591 100644
--- a/Tools/CCode/Source/GenFvMap/build.xml
+++ b/Tools/CCode/Source/GenFvMap/build.xml
@@ -40,6 +40,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
optimize="speed">
<compilerarg value="${ExtraArgus}" if="ExtraArgus" />
<compilerarg value="/EHsc" unless="GCC"/>
+ <compilerarg value="/Za" unless="GCC"/>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
diff --git a/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c b/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
index 11192c428b..7519a55e48 100644
--- a/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
+++ b/Tools/CCode/Source/PeiRebase/PeiRebaseExe.c
@@ -799,9 +799,10 @@ Returns:
//
fprintf (
LogFile,
- "%s %016I64X\n",
+ "%s %016I64X %s\n",
FileGuidString,
- ImageContext.DestinationAddress
+ ImageContext.DestinationAddress,
+ ImageContext.PdbPointer == NULL ? "*" : ImageContext.PdbPointer
);
*BaseToUpdate += EFI_SIZE_TO_PAGES (ImageContext.ImageSize) * EFI_PAGE_SIZE;
@@ -1136,8 +1137,6 @@ Returns:
GetLength (CurrentPe32Section.Pe32Section->CommonHeader.Size) - sizeof (EFI_PE32_SECTION) -
sizeof (EFI_TE_IMAGE_HEADER)
);
- free ((VOID *) MemoryImagePointer);
- free (TEBuffer);
if (FfsFile->Attributes & FFS_ATTRIB_TAIL_PRESENT) {
TailSize = sizeof (EFI_FFS_FILE_TAIL);
} else {
@@ -1171,10 +1170,17 @@ Returns:
fprintf (
LogFile,
- "%s %016I64X\n",
+ "%s %016I64X %s\n",
FileGuidString,
- ImageContext.DestinationAddress
+ ImageContext.DestinationAddress,
+ ImageContext.PdbPointer == NULL ? "*" : ImageContext.PdbPointer
);
+
+ //
+ // Free buffers
+ //
+ free ((VOID *) MemoryImagePointer);
+ free (TEBuffer);
}
return EFI_SUCCESS;