gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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/logging.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 *
54 {
55  if (((const ecoff_filehdr *)ifd->data())->f_magic == ECOFF_MAGIC_ALPHA)
56  return new EcoffObject(ifd);
57  else
58  return nullptr;
59 }
60 
61 namespace
62 {
63 
64 EcoffObjectFormat ecoffObjectFormat;
65 
66 } // anonymous namespace
67 
68 
70 {
71  execHdr = (const ecoff_exechdr *)imageData->data();
72  fileHdr = &(execHdr->f);
73  aoutHdr = &(execHdr->a);
74 
75  entry = aoutHdr->entry;
76  // it's Alpha ECOFF
77  arch = Alpha;
78  opSys = Tru64;
79 }
80 
83 {
84  MemoryImage image({
85  { "text", aoutHdr->text_start, imageData,
87  { "data", aoutHdr->data_start, imageData,
89  { "bss", aoutHdr->bss_start, aoutHdr->bsize }
90  });
91 
92  for (auto M5_VAR_USED &seg: image.segments())
93  DPRINTFR(Loader, "%s\n", seg);
94 
95  return image;
96 }
97 
98 bool
100  Addr addr_mask)
101 {
102  bool retval = loadGlobalSymbols(symtab, base, offset, addr_mask);
103  retval = retval && loadLocalSymbols(symtab, base, offset, addr_mask);
104  return retval;
105 }
106 
107 bool
109  Addr addr_mask)
110 {
111  if (!symtab)
112  return false;
113 
115  warn("loadGlobalSymbols: wrong magic on %s\n", imageData->filename());
116  return false;
117  }
118 
119  auto *syms = (const ecoff_symhdr *)(imageData->data() + fileHdr->f_symptr);
120  if (syms->magic != magicSym2) {
121  warn("loadGlobalSymbols: bad symbol header magic on %s\n",
122  imageData->filename());
123  return false;
124  }
125 
126  auto *ext_syms = (const ecoff_extsym *)(
127  imageData->data() + syms->cbExtOffset);
128 
129  auto *ext_strings =
130  (const char *)(imageData->data() + syms->cbSsExtOffset);
131  for (int i = 0; i < syms->iextMax; i++) {
132  const ecoff_sym *entry = &(ext_syms[i].asym);
133  if (entry->iss != -1)
134  symtab->insert(entry->value, ext_strings + entry->iss);
135  }
136 
137  return true;
138 }
139 
140 bool
142  Addr addr_mask)
143 {
144  if (!symtab)
145  return false;
146 
148  warn("loadGlobalSymbols: wrong magic on %s\n", imageData->filename());
149  return false;
150  }
151 
152  auto *syms = (const ecoff_symhdr *)(imageData->data() + fileHdr->f_symptr);
153  if (syms->magic != magicSym2) {
154  warn("loadGlobalSymbols: bad symbol header magic on %s\n",
155  imageData->filename());
156  return false;
157  }
158 
159  auto *local_syms =
160  (const ecoff_sym *)(imageData->data() + syms->cbSymOffset);
161  auto *local_strings = (const char *)(imageData->data() + syms->cbSsOffset);
162  auto *fdesc = (const ecoff_fdr *)(imageData->data() + syms->cbFdOffset);
163 
164  for (int i = 0; i < syms->ifdMax; i++) {
165  auto *entry = (const ecoff_sym *)(local_syms + fdesc[i].isymBase);
166  auto *strings = (const char *)(local_strings + fdesc[i].issBase);
167  for (int j = 0; j < fdesc[i].csym; j++) {
168  if (entry[j].st == stGlobal || entry[j].st == stProc)
169  if (entry[j].iss != -1)
170  symtab->insert(entry[j].value, strings + entry[j].iss);
171  }
172  }
173 
174  for (int i = 0; i < syms->isymMax; i++) {
175  const ecoff_sym *entry = &(local_syms[i]);
176  if (entry->st == stProc)
177  symtab->insert(entry->value, local_strings + entry->iss);
178  }
179 
180  return true;
181 }
Bitfield< 7 > i
unsigned st
Definition: coff_sym.h:244
coff_ulong f_symptr
Definition: exec_ecoff.h:46
#define stGlobal
bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr addr_mask=MaxAddr) override
ImageFileDataPtr imageData
Definition: image_file.hh:44
EcoffObject(ImageFileDataPtr ifd)
Definition: ecoff_object.cc:69
ObjectFile * load(ImageFileDataPtr data) override
Definition: ecoff_object.cc:53
struct ecoff_aouthdr a
Definition: exec_ecoff.h:81
#define ECOFF_MAGIC_ALPHA
Definition: ecoff_machdep.h:59
Bitfield< 23, 0 > offset
Definition: types.hh:154
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
#define ECOFF_DATOFF(ep)
Definition: exec_ecoff.h:102
MemoryImage buildImage() const override
Definition: ecoff_object.cc:82
coff_ulong entry
Definition: exec_ecoff.h:59
coff_ulong text_start
Definition: exec_ecoff.h:60
coff_ulong dsize
Definition: exec_ecoff.h:57
#define magicSym2
Definition: coff_symconst.h:70
OpSys opSys
Definition: object_file.hh:76
Bitfield< 51, 12 > base
Definition: pagetable.hh:142
coff_ulong bss_start
Definition: exec_ecoff.h:62
ECOFF_PAD coff_ulong tsize
Definition: exec_ecoff.h:56
bool insert(Addr address, std::string symbol)
Definition: symtab.cc:55
coff_ulong bsize
Definition: exec_ecoff.h:58
const ecoff_aouthdr * aoutHdr
Definition: ecoff_object.hh:52
Bitfield< 2, 0 > seg
Definition: types.hh:84
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
Bitfield< 24 > j
struct ecoff_filehdr f
Definition: exec_ecoff.h:80
#define ECOFF_TXTOFF(ep)
Definition: exec_ecoff.h:97
bool loadAllSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr addr_mask=MaxAddr) override
Definition: ecoff_object.cc:99
Bitfield< 31, 28 > st
const ecoff_exechdr * execHdr
Definition: ecoff_object.hh:50
coff_int iss
Definition: coff_sym.h:243
std::shared_ptr< ImageFileData > ImageFileDataPtr
#define warn(...)
Definition: logging.hh:212
static const int NumArgumentRegs M5_VAR_USED
Definition: process.cc:84
coff_ushort f_magic
Definition: exec_ecoff.h:43
const ecoff_filehdr * fileHdr
Definition: ecoff_object.hh:51
#define stProc
bool loadLocalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr addr_mask=MaxAddr) override
coff_ulong data_start
Definition: exec_ecoff.h:61
coff_long value
Definition: coff_sym.h:242
#define DPRINTFR(...)
Definition: trace.hh:231

Generated on Fri Feb 28 2020 16:26:58 for gem5 by doxygen 1.8.13