]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/GenFvMap/GenFvMap.cpp
Fix building error in Linux
[mirror_edk2.git] / Tools / CCode / Source / GenFvMap / GenFvMap.cpp
index 4a8c726785b79fa343c5ef9e3aa2ef6696e93261..1bd7b38f5497126e063ea212bb05d2d6a89fdb41 100644 (file)
@@ -1,18 +1,18 @@
 //****************************************************************************\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
+#include "ProcessorBind.h"\r
+#include <iostream>\r
 #include <stdexcept>\r
 #include <list>\r
 #include <map>\r
-#include <iostream>\r
 #include <iomanip>\r
 #include <fstream>\r
 #include <sstream>\r
@@ -22,7 +22,7 @@
 #include <functional>\r
 using namespace std;\r
 \r
-typedef unsigned __int64 ulonglong_t;\r
+typedef UINT64 ulonglong_t;\r
 \r
 template <class T>\r
 class CMemoryLeakChecker : public list<T*>\r
@@ -78,6 +78,7 @@ public:
 \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
@@ -134,6 +135,16 @@ istream& operator >> (istream& is, CIdentity& idRight)
     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] & 0xffffffffffffULL);\r
+}\r
+\r
 class CInputFile : public CObjRoot\r
 {\r
 protected:\r
@@ -183,74 +194,22 @@ istream& CInputFile::GetLine(string& strALine)
     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
@@ -286,7 +245,7 @@ ostream& operator << (ostream& os, const CSymbol& symbol)
     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
@@ -295,7 +254,6 @@ public:
     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
@@ -344,32 +302,11 @@ CMapFile::CMapFile(const string& strFName)
 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
@@ -384,7 +321,7 @@ private:
 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
@@ -393,27 +330,16 @@ private:
     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
@@ -426,7 +352,27 @@ void CFvMapFile::Cleanup(void)
 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
@@ -446,7 +392,7 @@ private:
     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
@@ -465,7 +411,7 @@ CGenFvMapApp::CGenFvMapApp(int cArgc, char *ppszArgv[])
 : m_cArgc(cArgc)\r
 , m_ppszArgv(ppszArgv)\r
 {\r
-    if (cArgc != 4)\r
+    if (cArgc != 3)\r
         throw CGenFvMapUsage();\r
 }\r
 \r
@@ -476,14 +422,10 @@ CGenFvMapApp::~CGenFvMapApp(void)
 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