system.cc revision 1074
16657Snate@binkert.org/*
26657Snate@binkert.org * Copyright (c) 2002-2004 The Regents of The University of Michigan
310972Sdavid.hashe@amd.com * All rights reserved.
46657Snate@binkert.org *
56657Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66657Snate@binkert.org * modification, are permitted provided that the following conditions are
76657Snate@binkert.org * met: redistributions of source code must retain the above copyright
86657Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96657Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116657Snate@binkert.org * documentation and/or other materials provided with the distribution;
126657Snate@binkert.org * neither the name of the copyright holders nor the names of its
136657Snate@binkert.org * contributors may be used to endorse or promote products derived from
146657Snate@binkert.org * this software without specific prior written permission.
156657Snate@binkert.org *
166657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276657Snate@binkert.org */
286657Snate@binkert.org
296657Snate@binkert.org#include "base/loader/object_file.hh"
306657Snate@binkert.org#include "base/loader/symtab.hh"
316657Snate@binkert.org#include "base/remote_gdb.hh"
326657Snate@binkert.org#include "cpu/exec_context.hh"
336657Snate@binkert.org#include "kern/kernel_stats.hh"
346657Snate@binkert.org#include "mem/functional_mem/memory_control.hh"
356657Snate@binkert.org#include "mem/functional_mem/physical_memory.hh"
366657Snate@binkert.org#include "targetarch/vtophys.hh"
376657Snate@binkert.org#include "sim/param.hh"
386657Snate@binkert.org#include "sim/system.hh"
396657Snate@binkert.org#include "base/trace.hh"
406657Snate@binkert.org
416657Snate@binkert.orgusing namespace std;
426657Snate@binkert.org
436657Snate@binkert.orgvector<System *> System::systemList;
446657Snate@binkert.org
456657Snate@binkert.orgint System::numSystemsRunning = 0;
466657Snate@binkert.org
476657Snate@binkert.orgextern SymbolTable *debugSymbolTable;
486657Snate@binkert.org
496657Snate@binkert.orgSystem::System(Params *p)
506657Snate@binkert.org    : SimObject(p->name), memctrl(p->memctrl), physmem(p->physmem),
516657Snate@binkert.org      init_param(p->init_param), params(p)
526657Snate@binkert.org{
536657Snate@binkert.org    // add self to global system list
546657Snate@binkert.org    systemList.push_back(this);
556657Snate@binkert.org
566657Snate@binkert.org    kernelSymtab = new SymbolTable;
576657Snate@binkert.org    consoleSymtab = new SymbolTable;
586657Snate@binkert.org    debugSymbolTable = new SymbolTable;
596657Snate@binkert.org
606657Snate@binkert.org    /**
616657Snate@binkert.org     * Load the kernel, pal, and console code into memory
626657Snate@binkert.org     */
636657Snate@binkert.org    // Load kernel code
646657Snate@binkert.org    kernel = createObjectFile(params->kernel_path);
656657Snate@binkert.org    if (kernel == NULL)
666657Snate@binkert.org        fatal("Could not load kernel file %s", params->kernel_path);
676657Snate@binkert.org
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