object_file.hh revision 2472
11060SN/A/* 27944SGiacomo.Gabrielli@arm.com * Copyright (c) 2002-2004 The Regents of The University of Michigan 37944SGiacomo.Gabrielli@arm.com * All rights reserved. 47944SGiacomo.Gabrielli@arm.com * 57944SGiacomo.Gabrielli@arm.com * Redistribution and use in source and binary forms, with or without 67944SGiacomo.Gabrielli@arm.com * modification, are permitted provided that the following conditions are 77944SGiacomo.Gabrielli@arm.com * met: redistributions of source code must retain the above copyright 87944SGiacomo.Gabrielli@arm.com * notice, this list of conditions and the following disclaimer; 97944SGiacomo.Gabrielli@arm.com * redistributions in binary form must reproduce the above copyright 107944SGiacomo.Gabrielli@arm.com * notice, this list of conditions and the following disclaimer in the 117944SGiacomo.Gabrielli@arm.com * documentation and/or other materials provided with the distribution; 127944SGiacomo.Gabrielli@arm.com * neither the name of the copyright holders nor the names of its 137944SGiacomo.Gabrielli@arm.com * contributors may be used to endorse or promote products derived from 142702Sktlim@umich.edu * this software without specific prior written permission. 156973Stjones1@inf.ed.ac.uk * 161060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271060SN/A */ 281060SN/A 291060SN/A#ifndef __OBJECT_FILE_HH__ 301060SN/A#define __OBJECT_FILE_HH__ 311060SN/A 321060SN/A#include <string> 331060SN/A 341060SN/A#include "sim/host.hh" // for Addr 351060SN/A 361060SN/Aclass TranslatingPort; 371060SN/Aclass SymbolTable; 381060SN/A 391060SN/Aclass ObjectFile 402665Ssaidi@eecs.umich.edu{ 412665Ssaidi@eecs.umich.edu public: 426973Stjones1@inf.ed.ac.uk 431060SN/A enum Arch { 441060SN/A UnknownArch, 451464SN/A Alpha, 461464SN/A SPARC, 471060SN/A Mips 482731Sktlim@umich.edu }; 492292SN/A 501464SN/A enum OpSys { 518733Sgeoffrey.blake@arm.com UnknownOpSys, 521060SN/A Tru64, 537720Sgblack@eecs.umich.edu Linux, 541060SN/A Solaris 551060SN/A }; 566658Snate@binkert.org 578733Sgeoffrey.blake@arm.com protected: 583770Sgblack@eecs.umich.edu const std::string filename; 591464SN/A int descriptor; 601464SN/A uint8_t *fileData; 612669Sktlim@umich.edu size_t len; 621060SN/A 636973Stjones1@inf.ed.ac.uk Arch arch; 642669Sktlim@umich.edu OpSys opSys; 657678Sgblack@eecs.umich.edu 668817Sgblack@eecs.umich.edu ObjectFile(const std::string &_filename, int _fd, 672292SN/A size_t _len, uint8_t *_data, 686023Snate@binkert.org Arch _arch, OpSys _opSys); 691060SN/A 701060SN/A public: 711060SN/A virtual ~ObjectFile(); 721060SN/A 731060SN/A void close(); 741060SN/A 751060SN/A virtual bool loadSections(TranslatingPort *memPort, bool loadPhys = false); 761061SN/A virtual bool loadGlobalSymbols(SymbolTable *symtab) = 0; 771060SN/A virtual bool loadLocalSymbols(SymbolTable *symtab) = 0; 781060SN/A 791060SN/A Arch getArch() const { return arch; } 802733Sktlim@umich.edu OpSys getOpSys() const { return opSys; } 812733Sktlim@umich.edu 821060SN/A protected: 832292SN/A 842107SN/A struct Section { 852690Sktlim@umich.edu Addr baseAddr; 862107SN/A uint8_t *fileImage; 872690Sktlim@umich.edu size_t size; 882690Sktlim@umich.edu }; 891060SN/A 902292SN/A Addr entry; 912292SN/A Addr globalPtr; 928486Sgblack@eecs.umich.edu 932292SN/A Section text; 942292SN/A Section data; 952292SN/A Section bss; 962292SN/A 971060SN/A bool loadSection(Section *sec, TranslatingPort *memPort, bool loadPhys); 985543Ssaidi@eecs.umich.edu void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; } 995543Ssaidi@eecs.umich.edu 1001060SN/A public: 1011060SN/A Addr entryPoint() const { return entry; } 1022292SN/A 1032107SN/A Addr globalPointer() const { return globalPtr; } 1048502Sgblack@eecs.umich.edu 1051060SN/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; } 1112292SN/A size_t bssSize() const { return bss.size; } 1121060SN/A}; 1131060SN/A 1145358Sgblack@eecs.umich.eduObjectFile *createObjectFile(const std::string &fname); 1155358Sgblack@eecs.umich.edu 1165358Sgblack@eecs.umich.edu 1175358Sgblack@eecs.umich.edu#endif // __OBJECT_FILE_HH__ 1185358Sgblack@eecs.umich.edu