gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ecoff_object.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Steve Reinhardt
29  */
30 
32 
33 #include <string>
34 
35 #include "base/loader/symtab.hh"
36 #include "base/misc.hh"
37 #include "base/trace.hh"
38 #include "base/types.hh"
39 #include "debug/Loader.hh"
40 
41 // Only alpha will be able to load ecoff files for now.
42 // base/types.hh and ecoff_machdep.h must be before the other .h files
43 // because they are are gathered from other code bases and require some
44 // typedefs from those files.
46 #include "base/loader/coff_sym.h"
48 #include "base/loader/exec_ecoff.h"
49 
50 using namespace std;
51 
52 ObjectFile *
53 EcoffObject::tryFile(const string &fname, size_t len, uint8_t *data)
54 {
55  if (((ecoff_filehdr *)data)->f_magic == ECOFF_MAGIC_ALPHA) {
56  // it's Alpha ECOFF
57  return new EcoffObject(fname, len, data,
59  }
60  else {
61  return NULL;
62  }
63 }
64 
65 
66 EcoffObject::EcoffObject(const string &_filename, size_t _len, uint8_t *_data,
67  Arch _arch, OpSys _opSys)
68  : ObjectFile(_filename, _len, _data, _arch, _opSys)
69 {
71  fileHdr = &(execHdr->f);
72  aoutHdr = &(execHdr->a);
73 
74  entry = aoutHdr->entry;
75 
79 
83 
85  bss.size = aoutHdr->bsize;
86  bss.fileImage = NULL;
87 
88  DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
90  bss.baseAddr, bss.size);
91 }
92 
93 bool
95  Addr addr_mask)
96 {
97  bool retval = loadGlobalSymbols(symtab, base, offset, addr_mask);
98  retval = retval && loadLocalSymbols(symtab, base, offset, addr_mask);
99  return retval;
100 }
101 
102 bool
104  Addr addr_mask)
105 {
106  if (!symtab)
107  return false;
108 
110  warn("loadGlobalSymbols: wrong magic on %s\n", filename);
111  return false;
112  }
113 
115  if (syms->magic != magicSym2) {
116  warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename);
117  return false;
118  }
119 
120  ecoff_extsym *ext_syms = (ecoff_extsym *)(fileData + syms->cbExtOffset);
121 
122  char *ext_strings = (char *)(fileData + syms->cbSsExtOffset);
123  for (int i = 0; i < syms->iextMax; i++) {
124  ecoff_sym *entry = &(ext_syms[i].asym);
125  if (entry->iss != -1)
126  symtab->insert(entry->value, ext_strings + entry->iss);
127  }
128 
129  return true;
130 }
131 
132 bool
134  Addr addr_mask)
135 {
136  if (!symtab)
137  return false;
138 
140  warn("loadGlobalSymbols: wrong magic on %s\n", filename);
141  return false;
142  }
143 
145  if (syms->magic != magicSym2) {
146  warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename);
147  return false;
148  }
149 
150  ecoff_sym *local_syms = (ecoff_sym *)(fileData + syms->cbSymOffset);
151  char *local_strings = (char *)(fileData + syms->cbSsOffset);
152  ecoff_fdr *fdesc = (ecoff_fdr *)(fileData + syms->cbFdOffset);
153 
154  for (int i = 0; i < syms->ifdMax; i++) {
155  ecoff_sym *entry = (ecoff_sym *)(local_syms + fdesc[i].isymBase);
156  char *strings = (char *)(local_strings + fdesc[i].issBase);
157  for (int j = 0; j < fdesc[i].csym; j++) {
158  if (entry[j].st == stGlobal || entry[j].st == stProc)
159  if (entry[j].iss != -1)
160  symtab->insert(entry[j].value, strings + entry[j].iss);
161  }
162  }
163 
164  for (int i = 0; i < syms->isymMax; i++) {
165  ecoff_sym *entry = &(local_syms[i]);
166  if (entry->st == stProc)
167  symtab->insert(entry->value, local_strings + entry->iss);
168  }
169 
170  return true;
171 }
Bitfield< 7 > i
Definition: miscregs.hh:1378
unsigned st
Definition: coff_sym.h:270
coff_addr cbSymOffset
Definition: coff_sym.h:117
coff_ulong f_symptr
Definition: exec_ecoff.h:44
#define stGlobal
coff_int iextMax
Definition: coff_sym.h:112
struct ecoff_aouthdr a
Definition: exec_ecoff.h:79
#define ECOFF_MAGIC_ALPHA
Definition: ecoff_machdep.h:59
Bitfield< 23, 0 > offset
Definition: types.hh:149
#define ECOFF_DATOFF(ep)
Definition: exec_ecoff.h:100
coff_ulong entry
Definition: exec_ecoff.h:57
const char data[]
Definition: circlebuf.cc:43
coff_ulong text_start
Definition: exec_ecoff.h:58
#define warn(...)
Definition: misc.hh:219
static ObjectFile * tryFile(const std::string &fname, size_t len, uint8_t *data)
Definition: ecoff_object.cc:53
coff_int csym
Definition: coff_sym.h:155
coff_ulong dsize
Definition: exec_ecoff.h:55
#define magicSym2
Definition: coff_symconst.h:70
ecoff_exechdr * execHdr
Definition: ecoff_object.hh:44
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
coff_ulong bss_start
Definition: exec_ecoff.h:60
ECOFF_PAD coff_ulong tsize
Definition: exec_ecoff.h:54
coff_addr cbSsOffset
Definition: coff_sym.h:120
const std::string filename
Definition: object_file.hh:73
ecoff_aouthdr * aoutHdr
Definition: ecoff_object.hh:46
bool insert(Addr address, std::string symbol)
Definition: symtab.cc:55
coff_ulong bsize
Definition: exec_ecoff.h:56
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ecoff_filehdr * fileHdr
Definition: ecoff_object.hh:45
Bitfield< 24 > j
Definition: miscregs.hh:1369
struct ecoff_filehdr f
Definition: exec_ecoff.h:78
coff_short magic
Definition: coff_sym.h:100
#define ECOFF_TXTOFF(ep)
Definition: exec_ecoff.h:95
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr addr_mask=maxAddr)
uint8_t * fileData
Definition: object_file.hh:74
Bitfield< 11 > st
Definition: miscregs.hh:1509
coff_addr cbFdOffset
Definition: coff_sym.h:122
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
coff_int iss
Definition: coff_sym.h:269
coff_int ifdMax
Definition: coff_sym.h:110
virtual bool loadAllSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr addr_mask=maxAddr)
Definition: ecoff_object.cc:94
coff_addr cbSsExtOffset
Definition: coff_sym.h:121
coff_addr cbExtOffset
Definition: coff_sym.h:124
coff_int isymMax
Definition: coff_sym.h:105
Section data
Definition: object_file.hh:126
Section bss
Definition: object_file.hh:127
Section text
Definition: object_file.hh:125
coff_ushort f_magic
Definition: exec_ecoff.h:41
EcoffObject(const std::string &_filename, size_t _len, uint8_t *_data, Arch _arch, OpSys _opSys)
Definition: ecoff_object.cc:66
#define stProc
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr addr_mask=maxAddr)
coff_ulong data_start
Definition: exec_ecoff.h:59
coff_long value
Definition: coff_sym.h:268
#define DPRINTFR(...)
Definition: trace.hh:214

Generated on Fri Jun 9 2017 13:03:41 for gem5 by doxygen 1.8.6