object_file.hh revision 2472
16019Shines@cs.fsu.edu/*
26019Shines@cs.fsu.edu * Copyright (c) 2002-2004 The Regents of The University of Michigan
310037SARM gem5 Developers * All rights reserved.
47100Sgblack@eecs.umich.edu *
57100Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
67100Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
77100Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
87100Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
97100Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
107100Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
117100Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
127100Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
137100Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
147100Sgblack@eecs.umich.edu * this software without specific prior written permission.
156019Shines@cs.fsu.edu *
166019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276019Shines@cs.fsu.edu */
286019Shines@cs.fsu.edu
296019Shines@cs.fsu.edu#ifndef __OBJECT_FILE_HH__
306019Shines@cs.fsu.edu#define __OBJECT_FILE_HH__
316019Shines@cs.fsu.edu
326019Shines@cs.fsu.edu#include <string>
336019Shines@cs.fsu.edu
346019Shines@cs.fsu.edu#include "sim/host.hh"	// for Addr
356019Shines@cs.fsu.edu
366019Shines@cs.fsu.educlass TranslatingPort;
376019Shines@cs.fsu.educlass SymbolTable;
386019Shines@cs.fsu.edu
396019Shines@cs.fsu.educlass ObjectFile
406019Shines@cs.fsu.edu{
416019Shines@cs.fsu.edu  public:
426757SAli.Saidi@ARM.com
436019Shines@cs.fsu.edu    enum Arch {
446019Shines@cs.fsu.edu        UnknownArch,
456019Shines@cs.fsu.edu        Alpha,
466019Shines@cs.fsu.edu        SPARC,
476019Shines@cs.fsu.edu        Mips
486019Shines@cs.fsu.edu    };
496019Shines@cs.fsu.edu
509022Sgblack@eecs.umich.edu    enum OpSys {
516019Shines@cs.fsu.edu        UnknownOpSys,
5210037SARM gem5 Developers        Tru64,
5310037SARM gem5 Developers        Linux,
547170Sgblack@eecs.umich.edu        Solaris
556253Sgblack@eecs.umich.edu    };
5610037SARM gem5 Developers
577202Sgblack@eecs.umich.edu  protected:
5810037SARM gem5 Developers    const std::string filename;
596253Sgblack@eecs.umich.edu    int descriptor;
6010611SAndreas.Sandberg@ARM.com    uint8_t *fileData;
616253Sgblack@eecs.umich.edu    size_t len;
627396Sgblack@eecs.umich.edu
6310037SARM gem5 Developers    Arch  arch;
648745Sgblack@eecs.umich.edu    OpSys opSys;
657405SAli.Saidi@ARM.com
6610461SAndreas.Sandberg@ARM.com    ObjectFile(const std::string &_filename, int _fd,
678782Sgblack@eecs.umich.edu               size_t _len, uint8_t *_data,
688782Sgblack@eecs.umich.edu               Arch _arch, OpSys _opSys);
698782Sgblack@eecs.umich.edu
7010810Sbr@bsdpad.com  public:
7110810Sbr@bsdpad.com    virtual ~ObjectFile();
7210810Sbr@bsdpad.com
737259Sgblack@eecs.umich.edu    void close();
748757Sgblack@eecs.umich.edu
7510461SAndreas.Sandberg@ARM.com    virtual bool loadSections(TranslatingPort *memPort, bool loadPhys = false);
768782Sgblack@eecs.umich.edu    virtual bool loadGlobalSymbols(SymbolTable *symtab) = 0;
778757Sgblack@eecs.umich.edu    virtual bool loadLocalSymbols(SymbolTable *symtab) = 0;
788777Sgblack@eecs.umich.edu
798782Sgblack@eecs.umich.edu    Arch  getArch()  const { return arch; }
808756Sgblack@eecs.umich.edu    OpSys getOpSys() const { return opSys; }
8110037SARM gem5 Developers
8210037SARM gem5 Developers  protected:
836019Shines@cs.fsu.edu
846757SAli.Saidi@ARM.com    struct Section {
858757Sgblack@eecs.umich.edu        Addr     baseAddr;
866019Shines@cs.fsu.edu        uint8_t *fileImage;
878745Sgblack@eecs.umich.edu        size_t   size;
889384SAndreas.Sandberg@arm.com    };
896397Sgblack@eecs.umich.edu
908782Sgblack@eecs.umich.edu    Addr entry;
916019Shines@cs.fsu.edu    Addr globalPtr;
9210461SAndreas.Sandberg@ARM.com
936397Sgblack@eecs.umich.edu    Section text;
948335Snate@binkert.org    Section data;
959023Sgblack@eecs.umich.edu    Section bss;
969023Sgblack@eecs.umich.edu
9710461SAndreas.Sandberg@ARM.com    bool loadSection(Section *sec, TranslatingPort *memPort, bool loadPhys);
988335Snate@binkert.org    void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; }
996019Shines@cs.fsu.edu
10010196SCurtis.Dunham@arm.com  public:
10110196SCurtis.Dunham@arm.com    Addr entryPoint() const { return entry; }
102
103    Addr globalPointer() const { return globalPtr; }
104
105    Addr textBase() const { return text.baseAddr; }
106    Addr dataBase() const { return data.baseAddr; }
107    Addr bssBase() const { return bss.baseAddr; }
108
109    size_t textSize() const { return text.size; }
110    size_t dataSize() const { return data.size; }
111    size_t bssSize() const { return bss.size; }
112};
113
114ObjectFile *createObjectFile(const std::string &fname);
115
116
117#endif // __OBJECT_FILE_HH__
118