raw_object.cc revision 3812
13584Ssaidi@eecs.umich.edu/*
23584Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
33584Ssaidi@eecs.umich.edu * All rights reserved.
43584Ssaidi@eecs.umich.edu *
53584Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
63584Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
73584Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
83584Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
93584Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
103584Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
113584Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
123584Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
133584Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
143584Ssaidi@eecs.umich.edu * this software without specific prior written permission.
153584Ssaidi@eecs.umich.edu *
163584Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173584Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183584Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193584Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203584Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213584Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223584Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233584Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243584Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253584Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263584Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273584Ssaidi@eecs.umich.edu *
283584Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
293584Ssaidi@eecs.umich.edu */
303584Ssaidi@eecs.umich.edu
313584Ssaidi@eecs.umich.edu#include "base/loader/raw_object.hh"
323603Ssaidi@eecs.umich.edu#include "base/loader/symtab.hh"
333584Ssaidi@eecs.umich.edu#include "base/trace.hh"
343584Ssaidi@eecs.umich.edu
353584Ssaidi@eecs.umich.eduObjectFile *
363584Ssaidi@eecs.umich.eduRawObject::tryFile(const std::string &fname, int fd, size_t len, uint8_t *data)
373584Ssaidi@eecs.umich.edu{
383584Ssaidi@eecs.umich.edu    return new RawObject(fname, fd, len, data, ObjectFile::UnknownArch,
393584Ssaidi@eecs.umich.edu            ObjectFile::UnknownOpSys);
403584Ssaidi@eecs.umich.edu}
413584Ssaidi@eecs.umich.edu
423584Ssaidi@eecs.umich.eduRawObject::RawObject(const std::string &_filename, int _fd, size_t _len,
433584Ssaidi@eecs.umich.edu        uint8_t *_data, Arch _arch, OpSys _opSys)
443584Ssaidi@eecs.umich.edu    : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
453584Ssaidi@eecs.umich.edu{
463584Ssaidi@eecs.umich.edu    text.baseAddr = 0;
473584Ssaidi@eecs.umich.edu    text.size = len;
483584Ssaidi@eecs.umich.edu    text.fileImage = fileData;
493584Ssaidi@eecs.umich.edu
503584Ssaidi@eecs.umich.edu    data.baseAddr = 0;
513584Ssaidi@eecs.umich.edu    data.size = 0;
523584Ssaidi@eecs.umich.edu    data.fileImage = NULL;
533584Ssaidi@eecs.umich.edu
543584Ssaidi@eecs.umich.edu    bss.baseAddr = 0;
553584Ssaidi@eecs.umich.edu    bss.size = 0;
563584Ssaidi@eecs.umich.edu    bss.fileImage = NULL;
573584Ssaidi@eecs.umich.edu
583584Ssaidi@eecs.umich.edu    DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
593584Ssaidi@eecs.umich.edu             text.baseAddr, text.size, data.baseAddr, data.size,
603584Ssaidi@eecs.umich.edu             bss.baseAddr, bss.size);
613584Ssaidi@eecs.umich.edu}
623584Ssaidi@eecs.umich.edu
633584Ssaidi@eecs.umich.edubool
643812Ssaidi@eecs.umich.eduRawObject::loadGlobalSymbols(SymbolTable *symtab, Addr addrMask)
653584Ssaidi@eecs.umich.edu{
663603Ssaidi@eecs.umich.edu    int fnameStart = filename.rfind('/',filename.size()) + 1;
673603Ssaidi@eecs.umich.edu    int extStart = filename.rfind('.',filename.size());
683812Ssaidi@eecs.umich.edu    symtab->insert(text.baseAddr & addrMask, filename.substr(fnameStart,
693603Ssaidi@eecs.umich.edu                extStart-fnameStart) + "_start");
703584Ssaidi@eecs.umich.edu    return true;
713584Ssaidi@eecs.umich.edu}
723584Ssaidi@eecs.umich.edu
733584Ssaidi@eecs.umich.edubool
743812Ssaidi@eecs.umich.eduRawObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
753584Ssaidi@eecs.umich.edu{
763603Ssaidi@eecs.umich.edu    int fnameStart = filename.rfind('/',filename.size()) + 1;
773603Ssaidi@eecs.umich.edu    int extStart = filename.rfind('.',filename.size());
783812Ssaidi@eecs.umich.edu    symtab->insert(text.baseAddr & addrMask, filename.substr(fnameStart,
793603Ssaidi@eecs.umich.edu                extStart-fnameStart) + "_start");
803584Ssaidi@eecs.umich.edu    return true;
813584Ssaidi@eecs.umich.edu}
82