2 * Copyright (c) 2003 The Regents of The University of Michigan
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.
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.
31 #include "base/loader/ecoff_object.hh"
33 #include "mem/functional/functional.hh"
34 #include "base/loader/symtab.hh"
36 #include "base/trace.hh" // for DPRINTF
38 #include "base/loader/exec_ecoff.h"
39 #include "base/loader/coff_sym.h"
40 #include "base/loader/coff_symconst.h"
45 EcoffObject::tryFile(const string
&fname
, int fd
, size_t len
, uint8_t *data
)
47 if (((ecoff_filehdr
*)data
)->f_magic
== ECOFF_MAGIC_ALPHA
) {
49 return new EcoffObject(fname
, fd
, len
, data
,
50 ObjectFile::Alpha
, ObjectFile::Tru64
);
58 EcoffObject::EcoffObject(const string
&_filename
, int _fd
,
59 size_t _len
, uint8_t *_data
,
60 Arch _arch
, OpSys _opSys
)
61 : ObjectFile(_filename
, _fd
, _len
, _data
, _arch
, _opSys
)
63 execHdr
= (ecoff_exechdr
*)fileData
;
64 fileHdr
= &(execHdr
->f
);
65 aoutHdr
= &(execHdr
->a
);
67 entry
= aoutHdr
->entry
;
69 text
.baseAddr
= aoutHdr
->text_start
;
70 text
.size
= aoutHdr
->tsize
;
72 data
.baseAddr
= aoutHdr
->data_start
;
73 data
.size
= aoutHdr
->dsize
;
75 bss
.baseAddr
= aoutHdr
->bss_start
;
76 bss
.size
= aoutHdr
->bsize
;
78 DPRINTFR(Loader
, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
79 text
.baseAddr
, text
.size
, data
.baseAddr
, data
.size
,
80 bss
.baseAddr
, bss
.size
);
85 EcoffObject::loadSections(FunctionalMemory
*mem
, bool loadPhys
)
87 Addr textAddr
= text
.baseAddr
;
88 Addr dataAddr
= data
.baseAddr
;
91 textAddr
&= (ULL(1) << 40) - 1;
92 dataAddr
&= (ULL(1) << 40) - 1;
95 // Since we don't really have an MMU and all memory is
96 // zero-filled, there's no need to set up the BSS segment.
97 mem
->prot_write(textAddr
, fileData
+ ECOFF_TXTOFF(execHdr
), text
.size
);
98 mem
->prot_write(dataAddr
, fileData
+ ECOFF_DATOFF(execHdr
), data
.size
);
105 EcoffObject::loadGlobalSymbols(SymbolTable
*symtab
)
110 if (fileHdr
->f_magic
!= ECOFF_MAGIC_ALPHA
) {
111 warn("loadGlobalSymbols: wrong magic on %s\n", filename
);
115 ecoff_symhdr
*syms
= (ecoff_symhdr
*)(fileData
+ fileHdr
->f_symptr
);
116 if (syms
->magic
!= magicSym2
) {
117 warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename
);
121 ecoff_extsym
*ext_syms
= (ecoff_extsym
*)(fileData
+ syms
->cbExtOffset
);
123 char *ext_strings
= (char *)(fileData
+ syms
->cbSsExtOffset
);
124 for (int i
= 0; i
< syms
->iextMax
; i
++) {
125 ecoff_sym
*entry
= &(ext_syms
[i
].asym
);
126 if (entry
->iss
!= -1)
127 symtab
->insert(entry
->value
, ext_strings
+ entry
->iss
);
134 EcoffObject::loadLocalSymbols(SymbolTable
*symtab
)
139 if (fileHdr
->f_magic
!= ECOFF_MAGIC_ALPHA
) {
140 warn("loadGlobalSymbols: wrong magic on %s\n", filename
);
144 ecoff_symhdr
*syms
= (ecoff_symhdr
*)(fileData
+ fileHdr
->f_symptr
);
145 if (syms
->magic
!= magicSym2
) {
146 warn("loadGlobalSymbols: bad symbol header magic on %s\n", filename
);
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
);
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
);
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
);