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