aout_object.cc revision 360
1/*
2 * Copyright (c) 2003 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
29#include <string>
30
31#include "base/loader/aout_object.hh"
32
33#include "mem/functional_mem/functional_memory.hh"
34#include "base/loader/symtab.hh"
35
36#include "base/trace.hh"	// for DPRINTF
37
38#include "base/loader/exec_aout.h"
39
40using namespace std;
41
42ObjectFile *
43AoutObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
44{
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);
49    }
50    else {
51        return NULL;
52    }
53}
54
55
56AoutObject::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)
60{
61    execHdr = (aout_exechdr *)fileData;
62
63    entry = execHdr->entry;
64
65    text.baseAddr = N_TXTADDR(*execHdr);
66    text.size = execHdr->tsize;
67
68    data.baseAddr = N_DATADDR(*execHdr);
69    data.size = execHdr->dsize;
70
71    bss.baseAddr = N_BSSADDR(*execHdr);
72    bss.size = execHdr->bsize;
73
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);
77}
78
79
80bool
81AoutObject::loadSections(FunctionalMemory *mem, bool loadPhys)
82{
83    Addr textAddr = text.baseAddr;
84    Addr dataAddr = data.baseAddr;
85
86    if (loadPhys) {
87        textAddr &= (ULL(1) << 40) - 1;
88        dataAddr &= (ULL(1) << 40) - 1;
89    }
90
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.
93    if (text.size != 0)
94        mem->prot_write(textAddr, fileData + N_TXTOFF(*execHdr), text.size);
95    if (data.size != 0)
96        mem->prot_write(dataAddr, fileData + N_DATOFF(*execHdr), data.size);
97
98    return true;
99}
100
101
102bool
103AoutObject::loadGlobalSymbols(SymbolTable *symtab)
104{
105    // a.out symbols not supported yet
106    return false;
107}
108
109bool
110AoutObject::loadLocalSymbols(SymbolTable *symtab)
111{
112    // a.out symbols not supported yet
113    return false;
114}
115