object_file.hh revision 2519
11689SN/A/* 21689SN/A * Copyright (c) 2002-2004 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 291689SN/A#ifndef __OBJECT_FILE_HH__ 301689SN/A#define __OBJECT_FILE_HH__ 312325SN/A 322325SN/A#include <string> 331060SN/A 341060SN/A#include "sim/host.hh" // for Addr 351060SN/A 362292SN/Aclass Port; 372292SN/Aclass SymbolTable; 381681SN/A 391060SN/Aclass ObjectFile 402669Sktlim@umich.edu{ 411060SN/A public: 421060SN/A 431858SN/A enum Arch { 442325SN/A UnknownArch, 451717SN/A Alpha, 462683Sktlim@umich.edu SPARC, 471717SN/A Mips 481717SN/A }; 492292SN/A 502292SN/A enum OpSys { 511060SN/A UnknownOpSys, 521060SN/A Tru64, 532316SN/A Linux, 542316SN/A Solaris 552680Sktlim@umich.edu }; 562669Sktlim@umich.edu 571060SN/A protected: 581060SN/A const std::string filename; 591060SN/A int descriptor; 601060SN/A uint8_t *fileData; 611060SN/A size_t len; 621060SN/A 631464SN/A Arch arch; 641061SN/A OpSys opSys; 652292SN/A 662292SN/A ObjectFile(const std::string &_filename, int _fd, 672292SN/A size_t _len, uint8_t *_data, 682632Sstever@eecs.umich.edu Arch _arch, OpSys _opSys); 692669Sktlim@umich.edu 701681SN/A public: 711685SN/A virtual ~ObjectFile(); 721681SN/A 731060SN/A void close(); 741060SN/A 752348SN/A virtual bool loadSections(Port *memPort, bool loadPhys = false); 762348SN/A virtual bool loadGlobalSymbols(SymbolTable *symtab) = 0; 772348SN/A virtual bool loadLocalSymbols(SymbolTable *symtab) = 0; 782348SN/A 792348SN/A Arch getArch() const { return arch; } 801060SN/A OpSys getOpSys() const { return opSys; } 811755SN/A 821060SN/A protected: 831060SN/A 842669Sktlim@umich.edu struct Section { 852669Sktlim@umich.edu Addr baseAddr; 862669Sktlim@umich.edu uint8_t *fileImage; 872325SN/A size_t size; 881060SN/A }; 891060SN/A 901061SN/A Addr entry; 911060SN/A Addr globalPtr; 922292SN/A 932292SN/A Section text; 942292SN/A Section data; 952292SN/A Section bss; 961060SN/A 971060SN/A bool loadSection(Section *sec, Port *memPort, bool loadPhys); 981060SN/A void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; } 991060SN/A 1001060SN/A public: 1012307SN/A Addr entryPoint() const { return entry; } 1022307SN/A 1031060SN/A Addr globalPointer() const { return globalPtr; } 1041060SN/A 1052292SN/A Addr textBase() const { return text.baseAddr; } 1061060SN/A Addr dataBase() const { return data.baseAddr; } 1071060SN/A Addr bssBase() const { return bss.baseAddr; } 1081060SN/A 1091060SN/A size_t textSize() const { return text.size; } 1101060SN/A size_t dataSize() const { return data.size; } 1111060SN/A size_t bssSize() const { return bss.size; } 1122292SN/A}; 1131755SN/A 1141060SN/AObjectFile *createObjectFile(const std::string &fname); 1151060SN/A 1162292SN/A 1171755SN/A#endif // __OBJECT_FILE_HH__ 1182292SN/A