object_file.hh revision 10880
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 *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
292665Ssaidi@eecs.umich.edu *          Steve Reinhardt
302SN/A */
312SN/A
322SN/A#ifndef __OBJECT_FILE_HH__
332SN/A#define __OBJECT_FILE_HH__
342SN/A
352520SN/A#include <limits>
362207SN/A#include <string>
372207SN/A
386214Snate@binkert.org#include "base/types.hh"
392SN/A
408706Sandreas.hansson@arm.comclass PortProxy;
412SN/Aclass SymbolTable;
422SN/A
432SN/Aclass ObjectFile
442SN/A{
45360SN/A  public:
46360SN/A
47360SN/A    enum Arch {
48360SN/A        UnknownArch,
492207SN/A        Alpha,
504111Sgblack@eecs.umich.edu        SPARC64,
514111Sgblack@eecs.umich.edu        SPARC32,
524155Sgblack@eecs.umich.edu        Mips,
535874Sgblack@eecs.umich.edu        X86_64,
545874Sgblack@eecs.umich.edu        I386,
5510037SARM gem5 Developers        Arm64,
566691Stjones1@inf.ed.ac.uk        Arm,
577095Sgblack@eecs.umich.edu        Thumb,
586691Stjones1@inf.ed.ac.uk        Power
59360SN/A    };
60360SN/A
61360SN/A    enum OpSys {
62360SN/A        UnknownOpSys,
63360SN/A        Tru64,
642207SN/A        Linux,
656392Ssaidi@eecs.umich.edu        Solaris,
6610810Sbr@bsdpad.com        LinuxArmOABI,
6710810Sbr@bsdpad.com        FreeBSD
68360SN/A    };
69360SN/A
702SN/A  protected:
7112SN/A    const std::string filename;
7212SN/A    uint8_t *fileData;
732SN/A    size_t len;
742SN/A
75360SN/A    Arch  arch;
76360SN/A    OpSys opSys;
77360SN/A
7810880SCurtis.Dunham@arm.com    ObjectFile(const std::string &_filename, size_t _len, uint8_t *_data,
79360SN/A               Arch _arch, OpSys _opSys);
8012SN/A
812SN/A  public:
822SN/A    virtual ~ObjectFile();
832SN/A
842SN/A    void close();
852SN/A
868852Sandreas.hansson@arm.com    virtual bool loadSections(PortProxy& memProxy, Addr addrMask =
8710037SARM gem5 Developers                              std::numeric_limits<Addr>::max(),
8810037SARM gem5 Developers                              Addr offset = 0);
893812Ssaidi@eecs.umich.edu    virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask =
903812Ssaidi@eecs.umich.edu            std::numeric_limits<Addr>::max()) = 0;
913812Ssaidi@eecs.umich.edu    virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
923812Ssaidi@eecs.umich.edu            std::numeric_limits<Addr>::max()) = 0;
939641Sguodeyuan@tsinghua.org.cn    virtual bool loadWeakSymbols(SymbolTable *symtab, Addr addrMask =
949641Sguodeyuan@tsinghua.org.cn            std::numeric_limits<Addr>::max())
959641Sguodeyuan@tsinghua.org.cn    { return false; }
962SN/A
975070Ssaidi@eecs.umich.edu    virtual bool isDynamic() { return false; }
985070Ssaidi@eecs.umich.edu    virtual bool hasTLS() { return false; }
993917Ssaidi@eecs.umich.edu
100360SN/A    Arch  getArch()  const { return arch; }
101360SN/A    OpSys getOpSys() const { return opSys; }
102360SN/A
1032SN/A  protected:
1042SN/A
10512SN/A    struct Section {
1062420SN/A        Addr     baseAddr;
1072420SN/A        uint8_t *fileImage;
1082420SN/A        size_t   size;
10912SN/A    };
11012SN/A
11112SN/A    Addr entry;
11212SN/A    Addr globalPtr;
11312SN/A
11412SN/A    Section text;
11512SN/A    Section data;
11612SN/A    Section bss;
1172SN/A
11810037SARM gem5 Developers    bool loadSection(Section *sec, PortProxy& memProxy, Addr addrMask,
11910037SARM gem5 Developers                     Addr offset = 0);
1202472SN/A    void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; }
1212420SN/A
1222SN/A  public:
12312SN/A    Addr entryPoint() const { return entry; }
1242472SN/A
12512SN/A    Addr globalPointer() const { return globalPtr; }
1262SN/A
12712SN/A    Addr textBase() const { return text.baseAddr; }
12812SN/A    Addr dataBase() const { return data.baseAddr; }
12912SN/A    Addr bssBase() const { return bss.baseAddr; }
13012SN/A
13112SN/A    size_t textSize() const { return text.size; }
13212SN/A    size_t dataSize() const { return data.size; }
13312SN/A    size_t bssSize() const { return bss.size; }
1343584Ssaidi@eecs.umich.edu
1359261Sdam.sunwoo@arm.com    /* This function allows you to override the base address where
1369261Sdam.sunwoo@arm.com     * a binary is going to be loaded or set it if the binary is just a
1379261Sdam.sunwoo@arm.com     * blob that doesn't include an object header.
1389261Sdam.sunwoo@arm.com     * @param a address to load the binary/text section at
1399261Sdam.sunwoo@arm.com     */
1403584Ssaidi@eecs.umich.edu    void setTextBase(Addr a) { text.baseAddr = a; }
1412SN/A};
1422SN/A
1433584Ssaidi@eecs.umich.eduObjectFile *createObjectFile(const std::string &fname, bool raw = false);
1442SN/A
1452SN/A
1462SN/A#endif // __OBJECT_FILE_HH__
147