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