object_file.hh revision 2665
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 382207SN/A#include "sim/host.hh" // for Addr 392SN/A 402519SN/Aclass Port; 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, 502207SN/A SPARC, 512472SN/A Mips 52360SN/A }; 53360SN/A 54360SN/A enum OpSys { 55360SN/A UnknownOpSys, 56360SN/A Tru64, 572207SN/A Linux, 582207SN/A Solaris 59360SN/A }; 60360SN/A 612SN/A protected: 6212SN/A const std::string filename; 632SN/A int descriptor; 6412SN/A uint8_t *fileData; 652SN/A size_t len; 662SN/A 67360SN/A Arch arch; 68360SN/A OpSys opSys; 69360SN/A 7012SN/A ObjectFile(const std::string &_filename, int _fd, 71360SN/A size_t _len, uint8_t *_data, 72360SN/A Arch _arch, OpSys _opSys); 7312SN/A 742SN/A public: 752SN/A virtual ~ObjectFile(); 762SN/A 772SN/A void close(); 782SN/A 792520SN/A virtual bool loadSections(Port *memPort, Addr addrMask = 802520SN/A std::numeric_limits<Addr>::max()); 8112SN/A virtual bool loadGlobalSymbols(SymbolTable *symtab) = 0; 8212SN/A virtual bool loadLocalSymbols(SymbolTable *symtab) = 0; 832SN/A 84360SN/A Arch getArch() const { return arch; } 85360SN/A OpSys getOpSys() const { return opSys; } 86360SN/A 872SN/A protected: 882SN/A 8912SN/A struct Section { 902420SN/A Addr baseAddr; 912420SN/A uint8_t *fileImage; 922420SN/A size_t size; 9312SN/A }; 9412SN/A 9512SN/A Addr entry; 9612SN/A Addr globalPtr; 9712SN/A 9812SN/A Section text; 9912SN/A Section data; 10012SN/A Section bss; 1012SN/A 1022520SN/A bool loadSection(Section *sec, Port *memPort, Addr addrMask); 1032472SN/A void setGlobalPointer(Addr global_ptr) { globalPtr = global_ptr; } 1042420SN/A 1052SN/A public: 10612SN/A Addr entryPoint() const { return entry; } 1072472SN/A 10812SN/A Addr globalPointer() const { return globalPtr; } 1092SN/A 11012SN/A Addr textBase() const { return text.baseAddr; } 11112SN/A Addr dataBase() const { return data.baseAddr; } 11212SN/A Addr bssBase() const { return bss.baseAddr; } 11312SN/A 11412SN/A size_t textSize() const { return text.size; } 11512SN/A size_t dataSize() const { return data.size; } 11612SN/A size_t bssSize() const { return bss.size; } 1172SN/A}; 1182SN/A 11912SN/AObjectFile *createObjectFile(const std::string &fname); 1202SN/A 1212SN/A 1222SN/A#endif // __OBJECT_FILE_HH__ 123