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 "ecoff_object.hh"
33 #include "functional_memory.hh"
36 #include "trace.hh" // for DPRINTF
38 #include "exec_ecoff.h"
40 #include "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
);
57 EcoffObject::EcoffObject(const string
&_filename
, int _fd
,
58 size_t _len
, uint8_t *_data
)
59 : ObjectFile(_filename
, _fd
, _len
, _data
)
61 execHdr
= (ecoff_exechdr
*)fileData
;
62 fileHdr
= &(execHdr
->f
);
63 aoutHdr
= &(execHdr
->a
);
65 entry
= aoutHdr
->entry
;
67 text
.baseAddr
= aoutHdr
->text_start
;
68 text
.size
= aoutHdr
->tsize
;
70 data
.baseAddr
= aoutHdr
->data_start
;
71 data
.size
= aoutHdr
->dsize
;
73 bss
.baseAddr
= aoutHdr
->bss_start
;
74 bss
.size
= aoutHdr
->bsize
;
76 DPRINTFR(Loader
, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
77 text
.baseAddr
, text
.size
, data
.baseAddr
, data
.size
,
78 bss
.baseAddr
, bss
.size
);
83 EcoffObject::loadSections(FunctionalMemory
*mem
, bool loadPhys
)
85 Addr textAddr
= text
.baseAddr
;
86 Addr dataAddr
= data
.baseAddr
;
89 textAddr
&= (ULL(1) << 40) - 1;
90 dataAddr
&= (ULL(1) << 40) - 1;
93 // Since we don't really have an MMU and all memory is
94 // zero-filled, there's no need to set up the BSS segment.
95 mem
->prot_write(textAddr
, fileData
+ ECOFF_TXTOFF(execHdr
), text
.size
);
96 mem
->prot_write(dataAddr
, fileData
+ ECOFF_DATOFF(execHdr
), data
.size
);
103 EcoffObject::loadGlobalSymbols(SymbolTable
*symtab
)
108 if (fileHdr
->f_magic
!= ECOFF_MAGIC_ALPHA
) {
109 cprintf("wrong magic\n");
113 ecoff_symhdr
*syms
= (ecoff_symhdr
*)(fileData
+ fileHdr
->f_symptr
);
114 if (syms
->magic
!= magicSym2
) {
115 cprintf("bad symbol header magic\n");
119 ecoff_extsym
*ext_syms
= (ecoff_extsym
*)(fileData
+ syms
->cbExtOffset
);
121 char *ext_strings
= (char *)(fileData
+ syms
->cbSsExtOffset
);
122 for (int i
= 0; i
< syms
->iextMax
; i
++) {
123 ecoff_sym
*entry
= &(ext_syms
[i
].asym
);
124 if (entry
->iss
!= -1)
125 symtab
->insert(entry
->value
, ext_strings
+ entry
->iss
);
132 EcoffObject::loadLocalSymbols(SymbolTable
*symtab
)
137 if (fileHdr
->f_magic
!= ECOFF_MAGIC_ALPHA
) {
138 cprintf("wrong magic\n");
142 ecoff_symhdr
*syms
= (ecoff_symhdr
*)(fileData
+ fileHdr
->f_symptr
);
143 if (syms
->magic
!= magicSym2
) {
144 cprintf("bad symbol header magic\n");
148 ecoff_sym
*local_syms
= (ecoff_sym
*)(fileData
+ syms
->cbSymOffset
);
149 char *local_strings
= (char *)(fileData
+ syms
->cbSsOffset
);
150 ecoff_fdr
*fdesc
= (ecoff_fdr
*)(fileData
+ syms
->cbFdOffset
);
152 for (int i
= 0; i
< syms
->ifdMax
; i
++) {
153 ecoff_sym
*entry
= (ecoff_sym
*)(local_syms
+ fdesc
[i
].isymBase
);
154 char *strings
= (char *)(local_strings
+ fdesc
[i
].issBase
);
155 for (int j
= 0; j
< fdesc
[i
].csym
; j
++) {
156 if (entry
[j
].st
== stGlobal
|| entry
[j
].st
== stProc
)
157 if (entry
[j
].iss
!= -1)
158 symtab
->insert(entry
[j
].value
, strings
+ entry
[j
].iss
);
162 for (int i
= 0; i
< syms
->isymMax
; i
++) {
163 ecoff_sym
*entry
= &(local_syms
[i
]);
164 if (entry
->st
== stProc
)
165 symtab
->insert(entry
->value
, local_strings
+ entry
->iss
);