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/aout_object.hh"
33 #include "mem/functional_mem/functional_memory.hh"
34 #include "base/loader/symtab.hh"
36 #include "base/trace.hh" // for DPRINTF
38 #include "base/loader/exec_aout.h"
43 AoutObject::tryFile(const string
&fname
, int fd
, size_t len
, uint8_t *data
)
45 if (!N_BADMAG(*(aout_exechdr
*)data
)) {
46 // right now this is only used for Alpha PAL code
47 return new AoutObject(fname
, fd
, len
, data
,
48 ObjectFile::Alpha
, ObjectFile::UnknownOpSys
);
56 AoutObject::AoutObject(const string
&_filename
, int _fd
,
57 size_t _len
, uint8_t *_data
,
58 Arch _arch
, OpSys _opSys
)
59 : ObjectFile(_filename
, _fd
, _len
, _data
, _arch
, _opSys
)
61 execHdr
= (aout_exechdr
*)fileData
;
63 entry
= execHdr
->entry
;
65 text
.baseAddr
= N_TXTADDR(*execHdr
);
66 text
.size
= execHdr
->tsize
;
68 data
.baseAddr
= N_DATADDR(*execHdr
);
69 data
.size
= execHdr
->dsize
;
71 bss
.baseAddr
= N_BSSADDR(*execHdr
);
72 bss
.size
= execHdr
->bsize
;
74 DPRINTFR(Loader
, "text: 0x%x %d\ndata: 0x%x %d\nbss: 0x%x %d\n",
75 text
.baseAddr
, text
.size
, data
.baseAddr
, data
.size
,
76 bss
.baseAddr
, bss
.size
);
81 AoutObject::loadSections(FunctionalMemory
*mem
, bool loadPhys
)
83 Addr textAddr
= text
.baseAddr
;
84 Addr dataAddr
= data
.baseAddr
;
87 textAddr
&= (ULL(1) << 40) - 1;
88 dataAddr
&= (ULL(1) << 40) - 1;
91 // Since we don't really have an MMU and all memory is
92 // zero-filled, there's no need to set up the BSS segment.
94 mem
->prot_write(textAddr
, fileData
+ N_TXTOFF(*execHdr
), text
.size
);
96 mem
->prot_write(dataAddr
, fileData
+ N_DATOFF(*execHdr
), data
.size
);
103 AoutObject::loadGlobalSymbols(SymbolTable
*symtab
)
105 // a.out symbols not supported yet
110 AoutObject::loadLocalSymbols(SymbolTable
*symtab
)
112 // a.out symbols not supported yet