object_file.hh revision 8706
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, 556691Stjones1@inf.ed.ac.uk Arm, 567095Sgblack@eecs.umich.edu Thumb, 576691Stjones1@inf.ed.ac.uk Power 58360SN/A }; 59360SN/A 60360SN/A enum OpSys { 61360SN/A UnknownOpSys, 62360SN/A Tru64, 632207SN/A Linux, 646392Ssaidi@eecs.umich.edu Solaris, 656392Ssaidi@eecs.umich.edu LinuxArmOABI 66360SN/A }; 67360SN/A 682SN/A protected: 6912SN/A const std::string filename; 702SN/A int descriptor; 7112SN/A uint8_t *fileData; 722SN/A size_t len; 732SN/A 74360SN/A Arch arch; 75360SN/A OpSys opSys; 76360SN/A 7712SN/A ObjectFile(const std::string &_filename, int _fd, 78360SN/A 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 868706Sandreas.hansson@arm.com virtual bool loadSections(PortProxy *memProxy, Addr addrMask = 872520SN/A std::numeric_limits<Addr>::max()); 883812Ssaidi@eecs.umich.edu virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask = 893812Ssaidi@eecs.umich.edu std::numeric_limits<Addr>::max()) = 0; 903812Ssaidi@eecs.umich.edu virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask = 913812Ssaidi@eecs.umich.edu std::numeric_limits<Addr>::max()) = 0; 922SN/A 935070Ssaidi@eecs.umich.edu virtual bool isDynamic() { return false; } 945070Ssaidi@eecs.umich.edu virtual bool hasTLS() { return false; } 953917Ssaidi@eecs.umich.edu 96360SN/A Arch getArch() const { return arch; } 97360SN/A OpSys getOpSys() const { return opSys; } 98360SN/A 992SN/A protected: 1002SN/A 10112SN/A struct Section { 1022420SN/A Addr baseAddr; 1032420SN/A uint8_t *fileImage; 1042420SN/A size_t size; 10512SN/A }; 10612SN/A 10712SN/A Addr entry; 10812SN/A Addr globalPtr; 10912SN/A 11012SN/A Section text; 11112SN/A Section data; 11212SN/A Section bss; 1132SN/A 1148706Sandreas.hansson@arm.com bool loadSection(Section *sec, PortProxy* memProxy, Addr addrMask); 1152472SN/A void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; } 1162420SN/A 1172SN/A public: 11812SN/A Addr entryPoint() const { return entry; } 1192472SN/A 12012SN/A Addr globalPointer() const { return globalPtr; } 1212SN/A 12212SN/A Addr textBase() const { return text.baseAddr; } 12312SN/A Addr dataBase() const { return data.baseAddr; } 12412SN/A Addr bssBase() const { return bss.baseAddr; } 12512SN/A 12612SN/A size_t textSize() const { return text.size; } 12712SN/A size_t dataSize() const { return data.size; } 12812SN/A size_t bssSize() const { return bss.size; } 1293584Ssaidi@eecs.umich.edu 1303584Ssaidi@eecs.umich.edu void setTextBase(Addr a) { text.baseAddr = a; } 1312SN/A}; 1322SN/A 1333584Ssaidi@eecs.umich.eduObjectFile *createObjectFile(const std::string &fname, bool raw = false); 1342SN/A 1352SN/A 1362SN/A#endif // __OBJECT_FILE_HH__ 137