]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/GenFvMap/GenFvMap.cpp
Retiring the ANT/JAVA build and removing the older EDK II packages that required...
[mirror_edk2.git] / Tools / CCode / Source / GenFvMap / GenFvMap.cpp
diff --git a/Tools/CCode/Source/GenFvMap/GenFvMap.cpp b/Tools/CCode/Source/GenFvMap/GenFvMap.cpp
deleted file mode 100644 (file)
index 27a2180..0000000
+++ /dev/null
@@ -1,666 +0,0 @@
-//****************************************************************************\r
-//**\r
-//**  Copyright  (C) 2006 Intel Corporation. All rights reserved.\r
-//**\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
-//** from the company.\r
-//**\r
-//****************************************************************************\r
-#include <cstdio>\r
-#include <iostream>\r
-#include <fstream>\r
-#include <iomanip>\r
-#include <stdexcept>\r
-#include <set>\r
-#include <string>\r
-#include <sstream>\r
-#include <vector>\r
-#include <map>\r
-#include <algorithm>\r
-using namespace std;\r
-\r
-#include "ProcessorBind.h"\r
-\r
-class putUINT64\r
-{\r
-public:\r
-    putUINT64(UINT64 ullVal) : m_ull(ullVal) {}\r
-    putUINT64(const putUINT64& r) : m_ull(r.m_ull) {}\r
-\r
-    template <class _E, class _Tr>\r
-    friend basic_ostream<_E, _Tr>& operator << (basic_ostream<_E, _Tr>&, putUINT64);\r
-\r
-private:\r
-    UINT64 m_ull;\r
-};\r
-\r
-template <class _E, class _Tr>\r
-basic_ostream<_E, _Tr>& operator << (basic_ostream<_E, _Tr>& os, putUINT64 ull)\r
-{\r
-    static const char cDigits[] = "0123456789abcdef";\r
-\r
-    UINT64 base = 10;\r
-    if (os.flags() & ios_base::hex)\r
-        base = 16;\r
-    else if (os.flags() & ios_base::oct)\r
-        base = 8;\r
-\r
-    ostringstream ostr;\r
-    UINT64 ullVal = ull.m_ull;\r
-    while (ullVal != 0)\r
-    {\r
-        ostr << cDigits[ullVal % base];\r
-        ullVal /= base;\r
-    }\r
-\r
-    string s1(ostr.str());\r
-    string s2(s1.rbegin(), s1.rend());\r
-    return os << s2;\r
-}\r
-\r
-class getUINT64\r
-{\r
-public:\r
-    getUINT64(UINT64& ullVal) : m_ull(ullVal) {}\r
-    getUINT64(const getUINT64& r) : m_ull(r.m_ull) {}\r
-\r
-    template <class _E, class _Tr>\r
-    friend basic_istream<_E, _Tr>& operator >> (basic_istream<_E, _Tr>&, getUINT64);\r
-\r
-private:\r
-    UINT64& m_ull;\r
-\r
-private:\r
-    getUINT64& operator = (const getUINT64&);\r
-};\r
-\r
-template <class _E, class _Tr>\r
-basic_istream<_E, _Tr>& operator >> (basic_istream<_E, _Tr>& is, getUINT64 ull)\r
-{\r
-    string strBuf;\r
-    is >> strBuf;\r
-\r
-    UINT64 base = 10;\r
-    if (is.flags() & ios_base::hex)\r
-        base = 16;\r
-    else if (is.flags() & ios_base::oct)\r
-        base = 8;\r
-\r
-    UINT64 ullVal = 0;\r
-    for (string::iterator i = strBuf.begin(); i != strBuf.end(); i++)\r
-    {\r
-        if (*i <= '9' && *i >= '0')\r
-            *i -= '0';\r
-        else if (*i <= 'F' && *i >= 'A')\r
-            *i -= 'A' - '\x0a';\r
-        else if (*i <= 'f' && *i >= 'a')\r
-            *i -= 'a' - '\x0a';\r
-        else throw runtime_error("Invalid number format");\r
-\r
-        ullVal = ullVal * base + *i;\r
-    }\r
-    ull.m_ull = ullVal;\r
-    return is;\r
-}\r
-\r
-class EMemoryLeak : public logic_error\r
-{\r
-public:\r
-    EMemoryLeak() : logic_error("Memory leak detected") {}\r
-};\r
-\r
-class EInvalidGuidString : public invalid_argument\r
-{\r
-public:\r
-    EInvalidGuidString() : invalid_argument("Unexpected format of GUID string") {}\r
-};\r
-\r
-class ELogFileError : public logic_error\r
-{\r
-public:\r
-    ELogFileError(const string& strMsg) : logic_error(strMsg) {}\r
-};\r
-\r
-class EDuplicatedFfsFile : public ELogFileError\r
-{\r
-public:\r
-    EDuplicatedFfsFile() : ELogFileError("Duplicated FFS found in LOG file") {}\r
-};\r
-\r
-class EUnexpectedLogFileToken : public ELogFileError\r
-{\r
-public:\r
-    EUnexpectedLogFileToken() : ELogFileError("Unexpected LOG file token") {}\r
-};\r
-\r
-class EFileNotFound : public invalid_argument\r
-{\r
-public:\r
-    EFileNotFound(const string& strFName) : invalid_argument("File not found - " + strFName) {}\r
-};\r
-\r
-class EUnexpectedMapFile : public logic_error\r
-{\r
-public:\r
-    EUnexpectedMapFile(const string& strKeyWord) : logic_error("Unexpected map file format - " + strKeyWord) {}\r
-};\r
-\r
-class EUsage : public invalid_argument\r
-{\r
-public:\r
-    EUsage() : invalid_argument("Usage: GenFvMap <FV.LOG> <FV.INF> <FV.MAP>") {}\r
-};\r
-\r
-template <class T>\r
-class CMemoryLeakChecker : public set<T*>\r
-{\r
-protected:\r
-    CMemoryLeakChecker()\r
-    {\r
-    }\r
-\r
-public:\r
-    virtual ~CMemoryLeakChecker();\r
-    static CMemoryLeakChecker<T>& GetInstance();\r
-\r
-private:\r
-    CMemoryLeakChecker(const CMemoryLeakChecker<T>&);\r
-};\r
-\r
-template <class T>\r
-CMemoryLeakChecker<T>::~CMemoryLeakChecker()\r
-{\r
-    if (!CMemoryLeakChecker<T>::empty())\r
-        throw EMemoryLeak();\r
-}\r
-\r
-template <class T>\r
-CMemoryLeakChecker<T>& CMemoryLeakChecker<T>::GetInstance()\r
-{\r
-    static CMemoryLeakChecker<T> s_instance;\r
-    return s_instance;\r
-}\r
-\r
-class CObjRoot\r
-{\r
-protected:\r
-    CObjRoot()\r
-    {\r
-#ifdef _CHK_MEM_LEAK\r
-        CMemoryLeakChecker<CObjRoot>::GetInstance().insert(this);\r
-#endif\r
-    }\r
-\r
-public:\r
-    virtual ~CObjRoot()\r
-    {\r
-#ifdef _CHK_MEM_LEAK\r
-        CMemoryLeakChecker<CObjRoot>::GetInstance().erase(this);\r
-#endif\r
-    }\r
-\r
-private:\r
-    CObjRoot(const CObjRoot&);\r
-};\r
-\r
-class CIdentity : public CObjRoot\r
-{\r
-public:\r
-    CIdentity(const string&);\r
-    operator string (void) const;\r
-\r
-    bool operator < (const CIdentity& id) const\r
-    {\r
-        return memcmp(this, &id, sizeof(*this)) < 0;\r
-    }\r
-\r
-    CIdentity() : ulD1(0), wD2(0), wD3(0), wD4(0), ullD5(0)\r
-    {\r
-    }\r
-\r
-    CIdentity(const CIdentity& r) : ulD1(r.ulD1), wD2(r.wD2), wD3(r.wD3), wD4(r.wD4), ullD5(r.ullD5)\r
-    {\r
-    }\r
-\r
-    template <class _E, class _Tr>\r
-    basic_istream<_E, _Tr>& ReadId(basic_istream<_E, _Tr>&);\r
-    template <class _E, class _Tr>\r
-    basic_ostream<_E, _Tr>& WriteId(basic_ostream<_E, _Tr>&);\r
-\r
-    template <class _E, class _Tr>\r
-    friend basic_istream<_E, _Tr>& operator >> (basic_istream<_E, _Tr>&, CIdentity&);\r
-    template <class _E, class _Tr>\r
-    friend basic_ostream<_E, _Tr>& operator << (basic_ostream<_E, _Tr>&, CIdentity);\r
-\r
-private:\r
-    UINT32 ulD1;\r
-    UINT16 wD2, wD3, wD4;\r
-    UINT64 ullD5;\r
-};\r
-\r
-CIdentity::CIdentity(const string& strGuid)\r
-{\r
-    try\r
-    {\r
-        string str(strGuid);\r
-        str.erase(0, str.find_first_not_of(" {"));\r
-        str.resize(str.find_last_not_of(" }") + 1);\r
-        str[str.find('-')] = ' ';\r
-        str[str.find('-')] = ' ';\r
-        str[str.find('-')] = ' ';\r
-        str[str.find('-')] = ' ';\r
-\r
-        istringstream is(str);\r
-        is >> hex >> ulD1 >> wD2 >> wD3 >> wD4 >> getUINT64(ullD5);\r
-    }\r
-    catch (const exception&)\r
-    {\r
-        throw EInvalidGuidString();\r
-    }\r
-}\r
-\r
-CIdentity::operator string(void) const\r
-{\r
-    ostringstream os;\r
-    os << hex << setfill('0')\r
-        << setw(8) << ulD1 << '-'\r
-        << setw(4) << wD2 << '-'\r
-        << setw(4) << wD3 << '-'\r
-        << setw(4) << wD4 << '-'\r
-        << setw(12) << putUINT64(ullD5);\r
-    return os.str();\r
-}\r
-\r
-template <class _E, class _Tr>\r
-basic_istream<_E, _Tr>& CIdentity::ReadId(basic_istream<_E, _Tr>& is)\r
-{\r
-    string str;\r
-    if (!!(is >> str))\r
-        *this = CIdentity(str);\r
-    return is;\r
-}\r
-\r
-template <class _E, class _Tr>\r
-basic_ostream<_E, _Tr>& CIdentity::WriteId(basic_ostream<_E, _Tr>& os)\r
-{\r
-    return os << (string)(*this);\r
-}\r
-\r
-template <class _E, class _Tr>\r
-basic_istream<_E, _Tr>& operator >> (basic_istream<_E, _Tr>& is, CIdentity& id)\r
-{\r
-    return id.ReadId(is);\r
-}\r
-\r
-template <class _E, class _Tr>\r
-basic_ostream<_E, _Tr>& operator << (basic_ostream<_E, _Tr>& os, CIdentity id)\r
-{\r
-    return id.WriteId(os);\r
-}\r
-\r
-template <class T>\r
-class IVectorContainerByReference : virtual public CObjRoot, public vector<T*>\r
-{\r
-};\r
-\r
-template <class T>\r
-class IMapContainer : virtual public CObjRoot, public map<CIdentity, T>\r
-{\r
-};\r
-\r
-struct ISymbol : virtual public CObjRoot\r
-{\r
-    string strAddress;\r
-    string strName;\r
-    string strFrom;\r
-    UINT64 ullRva;\r
-    bool bStatic;\r
-    bool bFunction;\r
-    virtual void Relocate(UINT64)=0;\r
-};\r
-\r
-class IModule : public IVectorContainerByReference<ISymbol>\r
-{\r
-public:\r
-    string strName;\r
-    CIdentity id;\r
-    virtual UINT64 BaseAddress(void) const=0;\r
-    virtual UINT64 BaseAddress(UINT64)=0;\r
-    virtual const ISymbol *EntryPoint(void) const=0;\r
-};\r
-\r
-class IFirmwareVolume : public IVectorContainerByReference<IModule>\r
-{\r
-};\r
-\r
-class IMapFileSet : public IMapContainer<istream*>\r
-{\r
-};\r
-\r
-class IFfsSet : public IMapContainer<UINT64>\r
-{\r
-};\r
-\r
-class CFfsSetFromLogFile : public IFfsSet\r
-{\r
-public:\r
-    CFfsSetFromLogFile(const string&);\r
-};\r
-\r
-CFfsSetFromLogFile::CFfsSetFromLogFile(const string& strFName)\r
-{\r
-    ifstream ifs(strFName.c_str());\r
-    if (!ifs)\r
-        throw EFileNotFound(strFName);\r
-\r
-    CIdentity ffsId;\r
-    while (!!ffsId.ReadId(ifs))\r
-    {\r
-        UINT64 ullBase;\r
-        if (!(ifs >> hex >> getUINT64(ullBase)))\r
-            throw EUnexpectedLogFileToken();\r
-        if (!insert(value_type(ffsId, ullBase)).second)\r
-            throw EDuplicatedFfsFile();\r
-    }\r
-}\r
-\r
-class CMapFileSetFromInfFile : public IMapFileSet\r
-{\r
-public:\r
-    CMapFileSetFromInfFile(const string&);\r
-    ~CMapFileSetFromInfFile();\r
-};\r
-\r
-CMapFileSetFromInfFile::CMapFileSetFromInfFile(const string& strFName)\r
-{\r
-    static const char cszEfiFileName[] = "EFI_FILE_NAME";\r
-\r
-    ifstream ifs(strFName.c_str());\r
-    if (!ifs)\r
-        throw EFileNotFound(strFName);\r
-\r
-    string strFile;\r
-    getline(ifs, strFile, ifstream::traits_type::to_char_type(ifstream::traits_type::eof()));\r
-    strFile.erase(0, strFile.find("[files]"));\r
-\r
-    istringstream is(strFile);\r
-    string strTmp;\r
-    while (!!getline(is, strTmp))\r
-    {\r
-        string::size_type pos = strTmp.find(cszEfiFileName);\r
-        if (pos == string::npos)\r
-            continue;\r
-\r
-        strTmp.erase(0, strTmp.find_first_not_of(" =", pos + sizeof(cszEfiFileName) - 1));\r
-        pos = strTmp.find_last_of("\\/");\r
-        string strId(\r
-            strTmp.begin() + pos + 1,\r
-            strTmp.begin() + strTmp.find('-', strTmp.find('-', strTmp.find('-', strTmp.find('-', strTmp.find('-') + 1) + 1) + 1) + 1)\r
-            );\r
-        strTmp.erase(pos + 1, strId.length() + 1);\r
-        strTmp.replace(strTmp.rfind('.'), string::npos, ".map");\r
-\r
-        istream *ifmaps = new ifstream(strTmp.c_str());\r
-        if (ifmaps && !!*ifmaps &&\r
-            !insert(value_type(CIdentity(strId), ifmaps)).second)\r
-                throw EDuplicatedFfsFile();\r
-    }\r
-}\r
-\r
-CMapFileSetFromInfFile::~CMapFileSetFromInfFile()\r
-{\r
-    for (iterator i = begin(); i != end(); i++)\r
-        delete i->second;\r
-}\r
-\r
-class CSymbolFromString : public ISymbol\r
-{\r
-public:\r
-    CSymbolFromString(const string&, bool = false);\r
-    void Relocate(UINT64);\r
-};\r
-\r
-CSymbolFromString::CSymbolFromString(const string& strSymbol, bool b)\r
-{\r
-    bStatic = b;\r
-\r
-    istringstream is(strSymbol);\r
-    is >> strAddress >> strName >> hex >> getUINT64(ullRva) >> strFrom;\r
-    if (strFrom == "f")\r
-    {\r
-        bFunction = true;\r
-        is >> strFrom;\r
-    }\r
-    else bFunction = false;\r
-    if (!is)\r
-        throw EUnexpectedMapFile("Symbol line format");\r
-}\r
-\r
-void CSymbolFromString::Relocate(UINT64 ullDelta)\r
-{\r
-    if (ullRva > 0)\r
-        ullRva += ullDelta;\r
-}\r
-\r
-class CModuleFromMap : public IModule\r
-{\r
-public:\r
-    CModuleFromMap(istream&);\r
-    ~CModuleFromMap();\r
-\r
-    UINT64 BaseAddress() const;\r
-    UINT64 BaseAddress(UINT64);\r
-    const ISymbol *EntryPoint() const;\r
-\r
-private:\r
-    UINT64 m_ullLoadAddress;\r
-    iterator m_iEntryPoint;\r
-\r
-    static pair<string, string::size_type> FindToken(istream&, const string&);\r
-};\r
-\r
-pair<string, string::size_type> CModuleFromMap::FindToken(istream& is, const string& strToken)\r
-{\r
-    for (string strTmp; !!getline(is, strTmp);)\r
-    {\r
-        string::size_type pos = strTmp.find(strToken);\r
-        if (pos != string::npos)\r
-            return pair<string, string::size_type>(strTmp, pos);\r
-    }\r
-    throw EUnexpectedMapFile(strToken);\r
-}\r
-\r
-CModuleFromMap::CModuleFromMap(istream& imaps)\r
-{\r
-    static const char cszLoadAddr[] = "Preferred load address is";\r
-    static const char cszGlobal[] = "Address";\r
-    static const char cszEntryPoint[] = "entry point at";\r
-    static const char cszStatic[] = "Static symbols";\r
-\r
-    pair<string, string::size_type> pairTmp;\r
-    istringstream iss;\r
-\r
-    getline(imaps, strName);\r
-    strName.erase(0, strName.find_first_not_of(' '));\r
-\r
-    pairTmp = FindToken(imaps, cszLoadAddr);\r
-    iss.str(pairTmp.first.substr(pairTmp.second + sizeof(cszLoadAddr) - 1));\r
-    iss >> getUINT64(m_ullLoadAddress);\r
-\r
-    pairTmp = FindToken(imaps, cszGlobal);\r
-    while (!!getline(imaps, pairTmp.first) &&\r
-            pairTmp.first.find(cszEntryPoint) == string::npos)\r
-        if (pairTmp.first.find_first_not_of(' ') != string::npos)\r
-            push_back(new CSymbolFromString(pairTmp.first));\r
-\r
-    iss.str(pairTmp.first.substr(pairTmp.first.find(cszEntryPoint) + sizeof(cszEntryPoint) - 1));\r
-    iss.clear();\r
-    string strEntryPoint;\r
-    iss >> strEntryPoint;\r
-\r
-    pairTmp = FindToken(imaps, cszStatic);\r
-    if (pairTmp.second)\r
-        while (!!getline(imaps, pairTmp.first))\r
-            if (pairTmp.first.find_first_not_of(' ') != string::npos)\r
-                push_back(new CSymbolFromString(pairTmp.first, true));\r
-\r
-    for (m_iEntryPoint = begin();\r
-         m_iEntryPoint != end() && (*m_iEntryPoint)->strAddress != strEntryPoint;\r
-         m_iEntryPoint++);\r
-    if (m_iEntryPoint == end())\r
-        throw EUnexpectedMapFile("Entry point not found");\r
-}\r
-\r
-CModuleFromMap::~CModuleFromMap()\r
-{\r
-    for (iterator i = begin(); i != end(); i++)\r
-        delete *i;\r
-}\r
-\r
-UINT64 CModuleFromMap::BaseAddress(void) const\r
-{\r
-    return m_ullLoadAddress;\r
-}\r
-\r
-UINT64 CModuleFromMap::BaseAddress(UINT64 ullNewBase)\r
-{\r
-    ullNewBase -= m_ullLoadAddress;\r
-    for (iterator i = begin(); i != end(); i++)\r
-        (*i)->Relocate(ullNewBase);\r
-    m_ullLoadAddress += ullNewBase;\r
-    return m_ullLoadAddress - ullNewBase;\r
-}\r
-\r
-const ISymbol *CModuleFromMap::EntryPoint(void) const\r
-{\r
-    return *m_iEntryPoint;\r
-}\r
-\r
-class CFvMap : public IFirmwareVolume\r
-{\r
-public:\r
-    CFvMap(IFfsSet*, IMapFileSet*);\r
-    ~CFvMap();\r
-\r
-private:\r
-    CFvMap(const CFvMap&);\r
-};\r
-\r
-CFvMap::CFvMap(IFfsSet *pFfsSet, IMapFileSet *pMapSet)\r
-{\r
-    for (IFfsSet::iterator i = pFfsSet->begin(); i != pFfsSet->end(); i++)\r
-    {\r
-        IMapFileSet::iterator j = pMapSet->find(i->first);\r
-        if (j != pMapSet->end())\r
-        {\r
-            IModule *pModule = new CModuleFromMap(*j->second);\r
-            pModule->id = i->first;\r
-            pModule->BaseAddress(i->second);\r
-            push_back(pModule);\r
-        }\r
-    }\r
-}\r
-\r
-CFvMap::~CFvMap()\r
-{\r
-    for (iterator i = begin(); i != end(); i++)\r
-        delete *i;\r
-}\r
-\r
-class CFvMapGenerator : public CObjRoot\r
-{\r
-public:\r
-    CFvMapGenerator(const IFirmwareVolume *pFv) : m_pFv(pFv) {}\r
-    CFvMapGenerator(const CFvMapGenerator& r) : m_pFv(r.m_pFv) {}\r
-\r
-    template <class _E, class _Tr>\r
-    friend basic_ostream<_E, _Tr>& operator << (basic_ostream<_E, _Tr>&, CFvMapGenerator);\r
-\r
-private:\r
-    static bool Less(const IModule*, const IModule*);\r
-\r
-private:\r
-    const IFirmwareVolume *m_pFv;\r
-};\r
-\r
-template <class _E, class _Tr>\r
-basic_ostream<_E, _Tr>& operator << (basic_ostream<_E, _Tr>& os, CFvMapGenerator fvMapFmt)\r
-{\r
-    vector<IModule*> rgMods(fvMapFmt.m_pFv->begin(), fvMapFmt.m_pFv->end());\r
-    sort(rgMods.begin(), rgMods.end(), CFvMapGenerator::Less);\r
-    for (vector<IModule*>::iterator i = rgMods.begin(); i != rgMods.end(); i++)\r
-    {\r
-        os << (*i)->strName << hex << " (BaseAddress=" << putUINT64((*i)->BaseAddress());\r
-        os << ", EntryPoint=" << hex << putUINT64((*i)->EntryPoint()->ullRva);\r
-        os << ", GUID=";\r
-        (*i)->id.WriteId(os);\r
-        os << ")" << endl << endl;\r
-\r
-        for (IModule::iterator j = (*i)->begin(); j != (*i)->end(); j++)\r
-        {\r
-            os << hex << "  " << setw(16) << setfill('0') << putUINT64((*j)->ullRva);\r
-            os << ((*j)->bFunction ? " F" : "  ")\r
-                << ((*j)->bStatic ? "S " : "  ")\r
-                << (*j)->strName << endl;\r
-        }\r
-\r
-        os << endl << endl;\r
-    }\r
-    return os;\r
-}\r
-\r
-bool CFvMapGenerator::Less(const IModule *pModL, const IModule *pModR)\r
-{\r
-    return pModL->BaseAddress() < pModR->BaseAddress();\r
-}\r
-\r
-class CApplication : public CObjRoot\r
-{\r
-public:\r
-    CApplication(int, char**);\r
-    int Run(void);\r
-\r
-private:\r
-    char **m_ppszArg;\r
-private:\r
-    CApplication(const CApplication&);\r
-};\r
-\r
-CApplication::CApplication(int cArg, char *ppszArg[])\r
-: m_ppszArg(ppszArg)\r
-{\r
-    if (cArg != 4)\r
-        throw EUsage();\r
-}\r
-\r
-int CApplication::Run(void)\r
-{\r
-    CFfsSetFromLogFile ffsSet(m_ppszArg[1]);\r
-    CMapFileSetFromInfFile mapSet(m_ppszArg[2]);\r
-    ofstream ofs(m_ppszArg[3]);\r
-    CFvMap fvMap(&ffsSet, &mapSet);\r
-    ofs << CFvMapGenerator(&fvMap);\r
-    return 0;\r
-}\r
-\r
-int main(int argc, char *argv[])\r
-{\r
-    try\r
-    {\r
-        CApplication app(argc, argv);\r
-        return app.Run();\r
-    }\r
-    catch (const exception& e)\r
-    {\r
-        cerr << e.what() << endl;\r
-        return -1;\r
-    }\r
-}\r
-\r
-#ifdef _DDK3790x1830_WORKAROUND\r
-extern "C" void __fastcall __security_check_cookie(int)\r
-{\r
-}\r
-#endif\r