2 * Copyright (c) 2002-2004 The Regents of The University of Michigan
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.
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.
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"
43 vector
<System
*> System::systemList
;
45 int System::numSystemsRunning
= 0;
47 extern SymbolTable
*debugSymbolTable
;
49 System::System(Params
*p
)
50 : SimObject(p
->name
), memctrl(p
->memctrl
), physmem(p
->physmem
),
51 init_param(p
->init_param
), params(p
)
53 // add self to global system list
54 systemList
.push_back(this);
56 kernelSymtab
= new SymbolTable
;
57 consoleSymtab
= new SymbolTable
;
58 palSymtab
= new SymbolTable
;
59 debugSymbolTable
= new SymbolTable
;
62 * Load the kernel, pal, and console code into memory
65 kernel
= createObjectFile(params
->kernel_path
);
67 fatal("Could not load kernel file %s", params
->kernel_path
);
70 console
= createObjectFile(params
->console_path
);
72 fatal("Could not load console file %s", params
->console_path
);
75 pal
= createObjectFile(params
->palcode
);
77 fatal("Could not load PALcode file %s", params
->palcode
);
80 // Load program sections into memory
81 pal
->loadSections(physmem
, true);
82 console
->loadSections(physmem
, true);
83 kernel
->loadSections(physmem
, true);
86 kernelStart
= kernel
->textBase();
87 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
88 kernelEntry
= kernel
->entryPoint();
91 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
92 panic("could not load kernel symbols\n");
94 if (!kernel
->loadLocalSymbols(kernelSymtab
))
95 panic("could not load kernel local symbols\n");
97 if (!console
->loadGlobalSymbols(consoleSymtab
))
98 panic("could not load console symbols\n");
100 if (!pal
->loadGlobalSymbols(palSymtab
))
101 panic("could not load pal symbols\n");
103 if (!pal
->loadLocalSymbols(palSymtab
))
104 panic("could not load pal symbols\n");
106 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
107 panic("could not load kernel symbols\n");
109 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
110 panic("could not load kernel local symbols\n");
112 if (!console
->loadGlobalSymbols(debugSymbolTable
))
113 panic("could not load console symbols\n");
115 if (!pal
->loadGlobalSymbols(debugSymbolTable
))
116 panic("could not load pal symbols\n");
118 if (!pal
->loadLocalSymbols(debugSymbolTable
))
119 panic("could not load pal symbols\n");
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");
129 consolePanicEvent
= new BreakPCEvent(&pcEventQueue
, "console panic");
130 if (consoleSymtab
->findAddress("panic", addr
))
131 consolePanicEvent
->schedule(addr
);
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
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));
145 strcpy(osflags
, params
->boot_osflags
.c_str());
149 * Set the hardware reset parameter block system type and revision
150 * information to Tsunami.
152 if (consoleSymtab
->findAddress("xxm_rpb", addr
)) {
153 Addr paddr
= vtophys(physmem
, addr
);
154 char *hwrpb
= (char *)physmem
->dma_addr(paddr
, sizeof(uint64_t));
157 panic("could not translate hwrpb addr\n");
159 *(uint64_t*)(hwrpb
+0x50) = params
->system_type
;
160 *(uint64_t*)(hwrpb
+0x58) = params
->system_rev
;
162 panic("could not find hwrpb\n");
164 // increment the number of running systms
167 kernelBinning
= new Kernel::Binning(this);
173 delete consoleSymtab
;
178 delete kernelBinning
;
181 delete consolePanicEvent
;
188 return remoteGDB
[0]->trap(ALPHA_KENTRY_INT
);
192 System::registerExecContext(ExecContext
*xc
)
194 int xcIndex
= execContexts
.size();
195 execContexts
.push_back(xc
);
198 // activate with zero delay so that we start ticking right
203 RemoteGDB
*rgdb
= new RemoteGDB(this, xc
);
204 GDBListener
*gdbl
= new GDBListener(rgdb
, 7000 + xcIndex
);
207 * Uncommenting this line waits for a remote debugger to connect
208 * to the simulator before continuing.
212 if (remoteGDB
.size() <= xcIndex
) {
213 remoteGDB
.resize(xcIndex
+1);
216 remoteGDB
[xcIndex
] = rgdb
;
222 System::replaceExecContext(ExecContext
*xc
, int xcIndex
)
224 if (xcIndex
>= execContexts
.size()) {
225 panic("replaceExecContext: bad xcIndex, %d >= %d\n",
226 xcIndex
, execContexts
.size());
229 execContexts
[xcIndex
] = xc
;
230 remoteGDB
[xcIndex
]->replaceExecContext(xc
);
236 kernelBinning
->regStats(name() + ".kern");
240 System::serialize(ostream
&os
)
242 kernelBinning
->serialize(os
);
247 System::unserialize(Checkpoint
*cp
, const string
§ion
)
249 kernelBinning
->unserialize(cp
, section
);
253 System::printSystems()
255 vector
<System
*>::iterator i
= systemList
.begin();
256 vector
<System
*>::iterator end
= systemList
.end();
257 for (; i
!= end
; ++i
) {
259 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
267 System::printSystems();
270 DEFINE_SIM_OBJECT_CLASS_NAME("System", System
)