ecoff_object.cc (3812:eaa215123a26) ecoff_object.cc (5543:3af77710f397)
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
31#include <string>
32
33#include "base/loader/ecoff_object.hh"
34#include "base/misc.hh"
35#include "base/loader/symtab.hh"
36
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
31#include <string>
32
33#include "base/loader/ecoff_object.hh"
34#include "base/misc.hh"
35#include "base/loader/symtab.hh"
36
37#include "base/trace.hh" // for DPRINTF
37#include "base/trace.hh" // for DPRINTF
38
39#include "base/loader/exec_ecoff.h"
40#include "base/loader/coff_sym.h"
41#include "base/loader/coff_symconst.h"
42
43using namespace std;
44
45ObjectFile *
46EcoffObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
47{
48 if (((ecoff_filehdr *)data)->f_magic == ECOFF_MAGIC_ALPHA) {
49 // it's Alpha ECOFF
50 return new EcoffObject(fname, fd, len, data,
51 ObjectFile::Alpha, ObjectFile::Tru64);
52 }
53 else {
54 return NULL;
55 }
56}
57
58
59EcoffObject::EcoffObject(const string &_filename, int _fd,
60 size_t _len, uint8_t *_data,
61 Arch _arch, OpSys _opSys)
62 : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
63{
64 execHdr = (ecoff_exechdr *)fileData;
65 fileHdr = &(execHdr->f);
66 aoutHdr = &(execHdr->a);
67
68 entry = aoutHdr->entry;
69
70 text.baseAddr = aoutHdr->text_start;
71 text.size = aoutHdr->tsize;
72 text.fileImage = fileData + ECOFF_TXTOFF(execHdr);
73
74 data.baseAddr = aoutHdr->data_start;
75 data.size = aoutHdr->dsize;
76 data.fileImage = fileData + ECOFF_DATOFF(execHdr);
77
78 bss.baseAddr = aoutHdr->bss_start;
79 bss.size = aoutHdr->bsize;
80 bss.fileImage = NULL;
81
82 DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
83 text.baseAddr, text.size, data.baseAddr, data.size,
84 bss.baseAddr, bss.size);
85}
86
87
88bool
89EcoffObject::loadGlobalSymbols(SymbolTable *symtab, Addr addrMask)
90{
91 if (!symtab)
92 return false;
93
94 if (fileHdr->f_magic != ECOFF_MAGIC_ALPHA) {
95 warn("loadGlobalSymbols: wrong magic on %s\n", filename);
96 return false;
97 }
98
99 ecoff_symhdr *syms = (ecoff_symhdr *)(fileData + fileHdr->f_symptr);
100 if (syms->magic != magicSym2) {
101 warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename);
102 return false;
103 }
104
105 ecoff_extsym *ext_syms = (ecoff_extsym *)(fileData + syms->cbExtOffset);
106
107 char *ext_strings = (char *)(fileData + syms->cbSsExtOffset);
108 for (int i = 0; i < syms->iextMax; i++) {
109 ecoff_sym *entry = &(ext_syms[i].asym);
110 if (entry->iss != -1)
111 symtab->insert(entry->value, ext_strings + entry->iss);
112 }
113
114 return true;
115}
116
117bool
118EcoffObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
119{
120 if (!symtab)
121 return false;
122
123 if (fileHdr->f_magic != ECOFF_MAGIC_ALPHA) {
124 warn("loadGlobalSymbols: wrong magic on %s\n", filename);
125 return false;
126 }
127
128 ecoff_symhdr *syms = (ecoff_symhdr *)(fileData + fileHdr->f_symptr);
129 if (syms->magic != magicSym2) {
130 warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename);
131 return false;
132 }
133
134 ecoff_sym *local_syms = (ecoff_sym *)(fileData + syms->cbSymOffset);
135 char *local_strings = (char *)(fileData + syms->cbSsOffset);
136 ecoff_fdr *fdesc = (ecoff_fdr *)(fileData + syms->cbFdOffset);
137
138 for (int i = 0; i < syms->ifdMax; i++) {
139 ecoff_sym *entry = (ecoff_sym *)(local_syms + fdesc[i].isymBase);
140 char *strings = (char *)(local_strings + fdesc[i].issBase);
141 for (int j = 0; j < fdesc[i].csym; j++) {
142 if (entry[j].st == stGlobal || entry[j].st == stProc)
143 if (entry[j].iss != -1)
144 symtab->insert(entry[j].value, strings + entry[j].iss);
145 }
146 }
147
148 for (int i = 0; i < syms->isymMax; i++) {
149 ecoff_sym *entry = &(local_syms[i]);
150 if (entry->st == stProc)
151 symtab->insert(entry->value, local_strings + entry->iss);
152 }
153
154 return true;
155}
38
39#include "base/loader/exec_ecoff.h"
40#include "base/loader/coff_sym.h"
41#include "base/loader/coff_symconst.h"
42
43using namespace std;
44
45ObjectFile *
46EcoffObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
47{
48 if (((ecoff_filehdr *)data)->f_magic == ECOFF_MAGIC_ALPHA) {
49 // it's Alpha ECOFF
50 return new EcoffObject(fname, fd, len, data,
51 ObjectFile::Alpha, ObjectFile::Tru64);
52 }
53 else {
54 return NULL;
55 }
56}
57
58
59EcoffObject::EcoffObject(const string &_filename, int _fd,
60 size_t _len, uint8_t *_data,
61 Arch _arch, OpSys _opSys)
62 : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys)
63{
64 execHdr = (ecoff_exechdr *)fileData;
65 fileHdr = &(execHdr->f);
66 aoutHdr = &(execHdr->a);
67
68 entry = aoutHdr->entry;
69
70 text.baseAddr = aoutHdr->text_start;
71 text.size = aoutHdr->tsize;
72 text.fileImage = fileData + ECOFF_TXTOFF(execHdr);
73
74 data.baseAddr = aoutHdr->data_start;
75 data.size = aoutHdr->dsize;
76 data.fileImage = fileData + ECOFF_DATOFF(execHdr);
77
78 bss.baseAddr = aoutHdr->bss_start;
79 bss.size = aoutHdr->bsize;
80 bss.fileImage = NULL;
81
82 DPRINTFR(Loader, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
83 text.baseAddr, text.size, data.baseAddr, data.size,
84 bss.baseAddr, bss.size);
85}
86
87
88bool
89EcoffObject::loadGlobalSymbols(SymbolTable *symtab, Addr addrMask)
90{
91 if (!symtab)
92 return false;
93
94 if (fileHdr->f_magic != ECOFF_MAGIC_ALPHA) {
95 warn("loadGlobalSymbols: wrong magic on %s\n", filename);
96 return false;
97 }
98
99 ecoff_symhdr *syms = (ecoff_symhdr *)(fileData + fileHdr->f_symptr);
100 if (syms->magic != magicSym2) {
101 warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename);
102 return false;
103 }
104
105 ecoff_extsym *ext_syms = (ecoff_extsym *)(fileData + syms->cbExtOffset);
106
107 char *ext_strings = (char *)(fileData + syms->cbSsExtOffset);
108 for (int i = 0; i < syms->iextMax; i++) {
109 ecoff_sym *entry = &(ext_syms[i].asym);
110 if (entry->iss != -1)
111 symtab->insert(entry->value, ext_strings + entry->iss);
112 }
113
114 return true;
115}
116
117bool
118EcoffObject::loadLocalSymbols(SymbolTable *symtab, Addr addrMask)
119{
120 if (!symtab)
121 return false;
122
123 if (fileHdr->f_magic != ECOFF_MAGIC_ALPHA) {
124 warn("loadGlobalSymbols: wrong magic on %s\n", filename);
125 return false;
126 }
127
128 ecoff_symhdr *syms = (ecoff_symhdr *)(fileData + fileHdr->f_symptr);
129 if (syms->magic != magicSym2) {
130 warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename);
131 return false;
132 }
133
134 ecoff_sym *local_syms = (ecoff_sym *)(fileData + syms->cbSymOffset);
135 char *local_strings = (char *)(fileData + syms->cbSsOffset);
136 ecoff_fdr *fdesc = (ecoff_fdr *)(fileData + syms->cbFdOffset);
137
138 for (int i = 0; i < syms->ifdMax; i++) {
139 ecoff_sym *entry = (ecoff_sym *)(local_syms + fdesc[i].isymBase);
140 char *strings = (char *)(local_strings + fdesc[i].issBase);
141 for (int j = 0; j < fdesc[i].csym; j++) {
142 if (entry[j].st == stGlobal || entry[j].st == stProc)
143 if (entry[j].iss != -1)
144 symtab->insert(entry[j].value, strings + entry[j].iss);
145 }
146 }
147
148 for (int i = 0; i < syms->isymMax; i++) {
149 ecoff_sym *entry = &(local_syms[i]);
150 if (entry->st == stProc)
151 symtab->insert(entry->value, local_strings + entry->iss);
152 }
153
154 return true;
155}