object_file.hh revision 2420
12SN/A/*
21762SN/A * Copyright (c) 2002-2004 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282760Sbinkertn@umich.edu
292760Sbinkertn@umich.edu#ifndef __OBJECT_FILE_HH__
302665Ssaidi@eecs.umich.edu#define __OBJECT_FILE_HH__
312SN/A
322SN/A#include "targetarch/isa_traits.hh"	// for Addr
338229Snate@binkert.org
342SN/Aclass TranslatingPort;
35363SN/Aclass SymbolTable;
362SN/A
378229Snate@binkert.orgclass ObjectFile
382SN/A{
392SN/A  public:
402SN/A
412SN/A    enum Arch {
422SN/A        UnknownArch,
43363SN/A        Alpha
4456SN/A    };
451388SN/A
46217SN/A    enum OpSys {
47363SN/A        UnknownOpSys,
4856SN/A        Tru64,
4956SN/A        Linux
5056SN/A    };
511638SN/A
5256SN/A  protected:
532SN/A    const std::string filename;
542356SN/A    int descriptor;
552356SN/A    uint8_t *fileData;
562356SN/A    size_t len;
572SN/A
582SN/A    Arch  arch;
594000Ssaidi@eecs.umich.edu    OpSys opSys;
604000Ssaidi@eecs.umich.edu
614762Snate@binkert.org    ObjectFile(const std::string &_filename, int _fd,
624762Snate@binkert.org               size_t _len, uint8_t *_data,
634762Snate@binkert.org               Arch _arch, OpSys _opSys);
644762Snate@binkert.org
654762Snate@binkert.org  public:
664762Snate@binkert.org    virtual ~ObjectFile();
674762Snate@binkert.org
684762Snate@binkert.org    void close();
694762Snate@binkert.org
704762Snate@binkert.org    virtual bool loadSections(TranslatingPort *memPort, bool loadPhys = false);
714762Snate@binkert.org    virtual bool loadGlobalSymbols(SymbolTable *symtab) = 0;
724762Snate@binkert.org    virtual bool loadLocalSymbols(SymbolTable *symtab) = 0;
734762Snate@binkert.org
744762Snate@binkert.org    Arch  getArch()  const { return arch; }
754762Snate@binkert.org    OpSys getOpSys() const { return opSys; }
764762Snate@binkert.org
774762Snate@binkert.org  protected:
784762Snate@binkert.org
794762Snate@binkert.org    struct Section {
804762Snate@binkert.org        Addr     baseAddr;
814762Snate@binkert.org        uint8_t *fileImage;
824762Snate@binkert.org        size_t   size;
834762Snate@binkert.org    };
844762Snate@binkert.org
854762Snate@binkert.org    Addr entry;
864762Snate@binkert.org    Addr globalPtr;
874762Snate@binkert.org
884762Snate@binkert.org    Section text;
894762Snate@binkert.org    Section data;
907494Ssteve.reinhardt@amd.com    Section bss;
917494Ssteve.reinhardt@amd.com
927494Ssteve.reinhardt@amd.com    bool loadSection(Section *sec, TranslatingPort *memPort, bool loadPhys);
937494Ssteve.reinhardt@amd.com
947494Ssteve.reinhardt@amd.com  public:
957494Ssteve.reinhardt@amd.com    Addr entryPoint() const { return entry; }
967494Ssteve.reinhardt@amd.com    Addr globalPointer() const { return globalPtr; }
977494Ssteve.reinhardt@amd.com
987490Ssteve.reinhardt@amd.com    Addr textBase() const { return text.baseAddr; }
994762Snate@binkert.org    Addr dataBase() const { return data.baseAddr; }
1004762Snate@binkert.org    Addr bssBase() const { return bss.baseAddr; }
1014762Snate@binkert.org
1024762Snate@binkert.org    size_t textSize() const { return text.size; }
1034762Snate@binkert.org    size_t dataSize() const { return data.size; }
1044762Snate@binkert.org    size_t bssSize() const { return bss.size; }
1054762Snate@binkert.org};
1064762Snate@binkert.org
1074762Snate@binkert.orgObjectFile *createObjectFile(const std::string &fname);
1084762Snate@binkert.org
1094762Snate@binkert.org
1104762Snate@binkert.org#endif // __OBJECT_FILE_HH__
1114762Snate@binkert.org