system.cc revision 1074
1/*
2 * Copyright (c) 2002-2004 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 "base/loader/object_file.hh"
30#include "base/loader/symtab.hh"
31#include "base/remote_gdb.hh"
32#include "cpu/exec_context.hh"
33#include "kern/kernel_stats.hh"
34#include "mem/functional_mem/memory_control.hh"
35#include "mem/functional_mem/physical_memory.hh"
36#include "targetarch/vtophys.hh"
37#include "sim/param.hh"
38#include "sim/system.hh"
39#include "base/trace.hh"
40
41using namespace std;
42
43vector<System *> System::systemList;
44
45int System::numSystemsRunning = 0;
46
47extern SymbolTable *debugSymbolTable;
48
49System::System(Params *p)
50    : SimObject(p->name), memctrl(p->memctrl), physmem(p->physmem),
51      init_param(p->init_param), params(p)
52{
53    // add self to global system list
54    systemList.push_back(this);
55
56    kernelSymtab = new SymbolTable;
57    consoleSymtab = new SymbolTable;
58    debugSymbolTable = new SymbolTable;
59
60    /**
61     * Load the kernel, pal, and console code into memory
62     */
63    // Load kernel code
64    kernel = createObjectFile(params->kernel_path);
65    if (kernel == NULL)
66        fatal("Could not load kernel file %s", params->kernel_path);
67
68    // Load Console Code
69    console = createObjectFile(params->console_path);
70    if (console == NULL)
71        fatal("Could not load console file %s", params->console_path);
72
73    // Load pal file
74    pal = createObjectFile(params->palcode);
75    if (pal == NULL)
76        fatal("Could not load PALcode file %s", params->palcode);
77
78
79    // Load program sections into memory
80    pal->loadSections(physmem, true);
81    console->loadSections(physmem, true);
82    kernel->loadSections(physmem, true);
83
84    // setup entry points
85    kernelStart = kernel->textBase();
86    kernelEnd = kernel->bssBase() + kernel->bssSize();
87    kernelEntry = kernel->entryPoint();
88
89    // load symbols
90    if (!kernel->loadGlobalSymbols(kernelSymtab))
91        panic("could not load kernel symbols\n");
92
93    if (!kernel->loadLocalSymbols(kernelSymtab))
94        panic("could not load kernel local symbols\n");
95
96    if (!console->loadGlobalSymbols(consoleSymtab))
97        panic("could not load console symbols\n");
98
99     if (!kernel->loadGlobalSymbols(debugSymbolTable))
100        panic("could not load kernel symbols\n");
101
102    if (!kernel->loadLocalSymbols(debugSymbolTable))
103        panic("could not load kernel local symbols\n");
104
105    if (!console->loadGlobalSymbols(debugSymbolTable))
106        panic("could not load console symbols\n");
107
108    if (!pal->loadGlobalSymbols(debugSymbolTable))
109        panic("could not load pal symbols\n");
110
111    if (!pal->loadLocalSymbols(debugSymbolTable))
112        panic("could not load pal symbols\n");
113
114
115    DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
116    DPRINTF(Loader, "Kernel end   = %#x\n", kernelEnd);
117    DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry);
118    DPRINTF(Loader, "Kernel loaded...\n");
119
120    Addr addr = 0;
121#ifdef DEBUG
122    consolePanicEvent = new BreakPCEvent(&pcEventQueue, "console panic");
123    if (consoleSymtab->findAddress("panic", addr))
124        consolePanicEvent->schedule(addr);
125#endif
126
127    /**
128     * Copy the osflags (kernel arguments) into the consoles
129     * memory. (Presently Linux does not use the console service
130     * routine to get these command line arguments, but Tru64 and
131     * others do.)
132     */
133    if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
134        Addr paddr = vtophys(physmem, addr);
135        char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t));
136
137        if (osflags)
138              strcpy(osflags, params->boot_osflags.c_str());
139    }
140
141    /**
142     * Set the hardware reset parameter block system type and revision
143     * information to Tsunami.
144     */
145    if (consoleSymtab->findAddress("xxm_rpb", addr)) {
146        Addr paddr = vtophys(physmem, addr);
147        char *hwrpb = (char *)physmem->dma_addr(paddr, sizeof(uint64_t));
148
149        if (!hwrpb)
150            panic("could not translate hwrpb addr\n");
151
152        *(uint64_t*)(hwrpb+0x50) = params->system_type;
153        *(uint64_t*)(hwrpb+0x58) = params->system_rev;
154    } else
155        panic("could not find hwrpb\n");
156
157    // increment the number of running systms
158    numSystemsRunning++;
159
160    kernelBinning = new Kernel::Binning(this);
161}
162
163System::~System()
164{
165    delete kernelSymtab;
166    delete consoleSymtab;
167    delete kernel;
168    delete console;
169    delete pal;
170
171    delete kernelBinning;
172
173#ifdef DEBUG
174    delete consolePanicEvent;
175#endif
176}
177
178bool
179System::breakpoint()
180{
181    return remoteGDB[0]->trap(ALPHA_KENTRY_INT);
182}
183
184int
185System::registerExecContext(ExecContext *xc)
186{
187    int xcIndex = execContexts.size();
188    execContexts.push_back(xc);
189
190    if (xcIndex == 0) {
191        // activate with zero delay so that we start ticking right
192        // away on cycle 0
193        xc->activate(0);
194    }
195
196    RemoteGDB *rgdb = new RemoteGDB(this, xc);
197    GDBListener *gdbl = new GDBListener(rgdb, 7000 + xcIndex);
198    gdbl->listen();
199    /**
200     * Uncommenting this line waits for a remote debugger to connect
201     * to the simulator before continuing.
202     */
203    //gdbl->accept();
204
205    if (remoteGDB.size() <= xcIndex) {
206        remoteGDB.resize(xcIndex+1);
207    }
208
209    remoteGDB[xcIndex] = rgdb;
210
211    return xcIndex;
212}
213
214void
215System::replaceExecContext(ExecContext *xc, int xcIndex)
216{
217    if (xcIndex >= execContexts.size()) {
218        panic("replaceExecContext: bad xcIndex, %d >= %d\n",
219              xcIndex, execContexts.size());
220    }
221
222    execContexts[xcIndex] = xc;
223    remoteGDB[xcIndex]->replaceExecContext(xc);
224}
225
226void
227System::regStats()
228{
229    kernelBinning->regStats(name() + ".kern");
230}
231
232void
233System::serialize(ostream &os)
234{
235    kernelBinning->serialize(os);
236}
237
238
239void
240System::unserialize(Checkpoint *cp, const string &section)
241{
242    kernelBinning->unserialize(cp, section);
243}
244
245void
246System::printSystems()
247{
248    vector<System *>::iterator i = systemList.begin();
249    vector<System *>::iterator end = systemList.end();
250    for (; i != end; ++i) {
251        System *sys = *i;
252        cerr << "System " << sys->name() << ": " << hex << sys << endl;
253    }
254}
255
256extern "C"
257void
258printSystems()
259{
260    System::printSystems();
261}
262
263DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
264
265