object_file.hh revision 4155
13900Ssaidi@eecs.umich.edu/*
22632Sstever@eecs.umich.edu * Copyright (c) 2002-2004 The Regents of The University of Michigan
32632Sstever@eecs.umich.edu * All rights reserved.
42632Sstever@eecs.umich.edu *
52632Sstever@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
62632Sstever@eecs.umich.edu * modification, are permitted provided that the following conditions are
72632Sstever@eecs.umich.edu * met: redistributions of source code must retain the above copyright
82632Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
92632Sstever@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
102632Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
112632Sstever@eecs.umich.edu * documentation and/or other materials provided with the distribution;
122632Sstever@eecs.umich.edu * neither the name of the copyright holders nor the names of its
132632Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from
142632Sstever@eecs.umich.edu * this software without specific prior written permission.
152632Sstever@eecs.umich.edu *
162632Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172632Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182632Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192632Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202632Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212632Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222632Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232632Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242632Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252632Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262632Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272632Sstever@eecs.umich.edu *
282632Sstever@eecs.umich.edu * Authors: Nathan Binkert
292632Sstever@eecs.umich.edu *          Steve Reinhardt
302632Sstever@eecs.umich.edu */
312022SN/A
322022SN/A#ifndef __OBJECT_FILE_HH__
332022SN/A#define __OBJECT_FILE_HH__
342022SN/A
352022SN/A#include <limits>
362469SN/A#include <string>
372469SN/A
382469SN/A#include "sim/host.hh"	// for Addr
392469SN/A
402516SN/Aclass Port;
412516SN/Aclass SymbolTable;
422944Sgblack@eecs.umich.edu
432482SN/Aclass ObjectFile
443598Sgblack@eecs.umich.edu{
453056Sgblack@eecs.umich.edu  public:
462469SN/A
473056Sgblack@eecs.umich.edu    enum Arch {
483056Sgblack@eecs.umich.edu        UnknownArch,
493056Sgblack@eecs.umich.edu        Alpha,
503598Sgblack@eecs.umich.edu        SPARC64,
512516SN/A        SPARC32,
523056Sgblack@eecs.umich.edu        Mips,
533598Sgblack@eecs.umich.edu        X86
543056Sgblack@eecs.umich.edu    };
553056Sgblack@eecs.umich.edu
563056Sgblack@eecs.umich.edu    enum OpSys {
573056Sgblack@eecs.umich.edu        UnknownOpSys,
583056Sgblack@eecs.umich.edu        Tru64,
593056Sgblack@eecs.umich.edu        Linux,
603056Sgblack@eecs.umich.edu        Solaris
613598Sgblack@eecs.umich.edu    };
623056Sgblack@eecs.umich.edu
633056Sgblack@eecs.umich.edu  protected:
643598Sgblack@eecs.umich.edu    const std::string filename;
653056Sgblack@eecs.umich.edu    int descriptor;
663056Sgblack@eecs.umich.edu    uint8_t *fileData;
673056Sgblack@eecs.umich.edu    size_t len;
683056Sgblack@eecs.umich.edu
693056Sgblack@eecs.umich.edu    Arch  arch;
703056Sgblack@eecs.umich.edu    OpSys opSys;
713056Sgblack@eecs.umich.edu
723056Sgblack@eecs.umich.edu    ObjectFile(const std::string &_filename, int _fd,
733056Sgblack@eecs.umich.edu               size_t _len, uint8_t *_data,
743056Sgblack@eecs.umich.edu               Arch _arch, OpSys _opSys);
753056Sgblack@eecs.umich.edu
763056Sgblack@eecs.umich.edu  public:
773056Sgblack@eecs.umich.edu    virtual ~ObjectFile();
783056Sgblack@eecs.umich.edu
793056Sgblack@eecs.umich.edu    void close();
803056Sgblack@eecs.umich.edu
813056Sgblack@eecs.umich.edu    virtual bool loadSections(Port *memPort, Addr addrMask =
823056Sgblack@eecs.umich.edu            std::numeric_limits<Addr>::max());
833056Sgblack@eecs.umich.edu    virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask =
842482SN/A            std::numeric_limits<Addr>::max()) = 0;
853598Sgblack@eecs.umich.edu    virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
863598Sgblack@eecs.umich.edu            std::numeric_limits<Addr>::max()) = 0;
873598Sgblack@eecs.umich.edu
883598Sgblack@eecs.umich.edu    virtual bool  isDynamic();
893598Sgblack@eecs.umich.edu
903598Sgblack@eecs.umich.edu    Arch  getArch()  const { return arch; }
913598Sgblack@eecs.umich.edu    OpSys getOpSys() const { return opSys; }
923598Sgblack@eecs.umich.edu
933598Sgblack@eecs.umich.edu  protected:
943598Sgblack@eecs.umich.edu
953598Sgblack@eecs.umich.edu    struct Section {
963598Sgblack@eecs.umich.edu        Addr     baseAddr;
973598Sgblack@eecs.umich.edu        uint8_t *fileImage;
983598Sgblack@eecs.umich.edu        size_t   size;
993598Sgblack@eecs.umich.edu    };
1003598Sgblack@eecs.umich.edu
1013598Sgblack@eecs.umich.edu    Addr entry;
1023598Sgblack@eecs.umich.edu    Addr globalPtr;
1033598Sgblack@eecs.umich.edu
1043598Sgblack@eecs.umich.edu    Section text;
1053598Sgblack@eecs.umich.edu    Section data;
1063598Sgblack@eecs.umich.edu    Section bss;
1073598Sgblack@eecs.umich.edu
1083598Sgblack@eecs.umich.edu    bool loadSection(Section *sec, Port *memPort, Addr addrMask);
1093598Sgblack@eecs.umich.edu    void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; }
1103598Sgblack@eecs.umich.edu
1113598Sgblack@eecs.umich.edu  public:
1123598Sgblack@eecs.umich.edu    Addr entryPoint() const { return entry; }
1133598Sgblack@eecs.umich.edu
1143598Sgblack@eecs.umich.edu    Addr globalPointer() const { return globalPtr; }
1153598Sgblack@eecs.umich.edu
1163598Sgblack@eecs.umich.edu    Addr textBase() const { return text.baseAddr; }
1172516SN/A    Addr dataBase() const { return data.baseAddr; }
1182516SN/A    Addr bssBase() const { return bss.baseAddr; }
1192516SN/A
1202516SN/A    size_t textSize() const { return text.size; }
1212482SN/A    size_t dataSize() const { return data.size; }
1222482SN/A    size_t bssSize() const { return bss.size; }
1232591SN/A
1242516SN/A    void setTextBase(Addr a) { text.baseAddr = a; }
1252580SN/A};
1262580SN/A
1272482SN/AObjectFile *createObjectFile(const std::string &fname, bool raw = false);
1282482SN/A
1292591SN/A
1302516SN/A#endif // __OBJECT_FILE_HH__
1312580SN/A