2 * Copyright (c) 2002-2005 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/memory_control.hh"
35 #include "mem/functional/physical.hh"
36 #include "targetarch/vtophys.hh"
37 #include "sim/builder.hh"
38 #include "sim/system.hh"
39 #include "base/trace.hh"
43 vector
<System
*> System::systemList
;
45 int System::numSystemsRunning
= 0;
47 System::System(Params
*p
)
48 : SimObject(p
->name
), memctrl(p
->memctrl
), physmem(p
->physmem
),
49 init_param(p
->init_param
), numcpus(0), params(p
)
51 // add self to global system list
52 systemList
.push_back(this);
54 kernelSymtab
= new SymbolTable
;
55 consoleSymtab
= new SymbolTable
;
56 palSymtab
= new SymbolTable
;
57 debugSymbolTable
= new SymbolTable
;
60 * Load the kernel, pal, and console code into memory
63 kernel
= createObjectFile(params
->kernel_path
);
65 fatal("Could not load kernel file %s", params
->kernel_path
);
68 console
= createObjectFile(params
->console_path
);
70 fatal("Could not load console file %s", params
->console_path
);
73 pal
= createObjectFile(params
->palcode
);
75 fatal("Could not load PALcode file %s", params
->palcode
);
78 // Load program sections into memory
79 pal
->loadSections(physmem
, true);
80 console
->loadSections(physmem
, true);
81 kernel
->loadSections(physmem
, true);
84 kernelStart
= kernel
->textBase();
85 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
86 kernelEntry
= kernel
->entryPoint();
89 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
90 panic("could not load kernel symbols\n");
92 if (!kernel
->loadLocalSymbols(kernelSymtab
))
93 panic("could not load kernel local symbols\n");
95 if (!console
->loadGlobalSymbols(consoleSymtab
))
96 panic("could not load console symbols\n");
98 if (!pal
->loadGlobalSymbols(palSymtab
))
99 panic("could not load pal symbols\n");
101 if (!pal
->loadLocalSymbols(palSymtab
))
102 panic("could not load pal symbols\n");
104 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
105 panic("could not load kernel symbols\n");
107 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
108 panic("could not load kernel local symbols\n");
110 if (!console
->loadGlobalSymbols(debugSymbolTable
))
111 panic("could not load console symbols\n");
113 if (!pal
->loadGlobalSymbols(debugSymbolTable
))
114 panic("could not load pal symbols\n");
116 if (!pal
->loadLocalSymbols(debugSymbolTable
))
117 panic("could not load pal symbols\n");
120 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
121 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
122 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
123 DPRINTF(Loader
, "Kernel loaded...\n");
127 consolePanicEvent
= new BreakPCEvent(&pcEventQueue
, "console panic");
128 if (consoleSymtab
->findAddress("panic", addr
))
129 consolePanicEvent
->schedule(addr
);
133 * Copy the osflags (kernel arguments) into the consoles
134 * memory. (Presently Linux does not use the console service
135 * routine to get these command line arguments, but Tru64 and
138 if (consoleSymtab
->findAddress("env_booted_osflags", addr
)) {
139 Addr paddr
= vtophys(physmem
, addr
);
140 char *osflags
= (char *)physmem
->dma_addr(paddr
, sizeof(uint32_t));
143 strcpy(osflags
, params
->boot_osflags
.c_str());
147 * Set the hardware reset parameter block system type and revision
148 * information to Tsunami.
150 if (consoleSymtab
->findAddress("m5_rpb", addr
)) {
151 Addr paddr
= vtophys(physmem
, addr
);
152 char *hwrpb
= (char *)physmem
->dma_addr(paddr
, sizeof(uint64_t));
155 panic("could not translate hwrpb addr\n");
157 *(uint64_t*)(hwrpb
+0x50) = htog(params
->system_type
);
158 *(uint64_t*)(hwrpb
+0x58) = htog(params
->system_rev
);
160 panic("could not find hwrpb\n");
162 // increment the number of running systms
165 kernelBinning
= new Kernel::Binning(this);
171 delete consoleSymtab
;
176 delete kernelBinning
;
179 delete consolePanicEvent
;
184 System::setAlphaAccess(Addr access
)
187 if (consoleSymtab
->findAddress("m5AlphaAccess", addr
)) {
188 Addr paddr
= vtophys(physmem
, addr
);
189 uint64_t *m5AlphaAccess
=
190 (uint64_t *)physmem
->dma_addr(paddr
, sizeof(uint64_t));
193 panic("could not translate m5AlphaAccess addr\n");
195 *m5AlphaAccess
= htog(EV5::Phys2K0Seg(access
));
197 panic("could not find m5AlphaAccess\n");
203 return remoteGDB
[0]->trap(ALPHA_KENTRY_INT
);
209 System::registerExecContext(ExecContext
*xc
, int id
)
212 for (id
= 0; id
< execContexts
.size(); id
++) {
213 if (!execContexts
[id
])
218 if (execContexts
.size() <= id
)
219 execContexts
.resize(id
+ 1);
221 if (execContexts
[id
])
222 panic("Cannot have two CPUs with the same id (%d)\n", id
);
224 execContexts
[id
] = xc
;
227 RemoteGDB
*rgdb
= new RemoteGDB(this, xc
);
228 GDBListener
*gdbl
= new GDBListener(rgdb
, 7000 + id
);
231 * Uncommenting this line waits for a remote debugger to connect
232 * to the simulator before continuing.
234 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
237 if (remoteGDB
.size() <= id
) {
238 remoteGDB
.resize(id
+ 1);
241 remoteGDB
[id
] = rgdb
;
249 if (!execContexts
.empty()) {
250 // activate with zero delay so that we start ticking right
252 execContexts
[0]->activate(0);
257 System::replaceExecContext(ExecContext
*xc
, int id
)
259 if (id
>= execContexts
.size()) {
260 panic("replaceExecContext: bad id, %d >= %d\n",
261 id
, execContexts
.size());
264 execContexts
[id
] = xc
;
265 remoteGDB
[id
]->replaceExecContext(xc
);
271 kernelBinning
->regStats(name() + ".kern");
275 System::serialize(ostream
&os
)
277 kernelBinning
->serialize(os
);
282 System::unserialize(Checkpoint
*cp
, const string
§ion
)
284 kernelBinning
->unserialize(cp
, section
);
288 System::printSystems()
290 vector
<System
*>::iterator i
= systemList
.begin();
291 vector
<System
*>::iterator end
= systemList
.end();
292 for (; i
!= end
; ++i
) {
294 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
302 System::printSystems();
305 BEGIN_DECLARE_SIM_OBJECT_PARAMS(System
)
307 Param
<Tick
> boot_cpu_frequency
;
308 SimObjectParam
<MemoryController
*> memctrl
;
309 SimObjectParam
<PhysicalMemory
*> physmem
;
311 Param
<string
> kernel
;
312 Param
<string
> console
;
315 Param
<string
> boot_osflags
;
316 Param
<string
> readfile
;
317 Param
<unsigned int> init_param
;
319 Param
<uint64_t> system_type
;
320 Param
<uint64_t> system_rev
;
323 VectorParam
<string
> binned_fns
;
326 END_DECLARE_SIM_OBJECT_PARAMS(System
)
328 BEGIN_INIT_SIM_OBJECT_PARAMS(System
)
330 INIT_PARAM(boot_cpu_frequency
, "Frequency of the boot CPU"),
331 INIT_PARAM(memctrl
, "memory controller"),
332 INIT_PARAM(physmem
, "phsyical memory"),
333 INIT_PARAM(kernel
, "file that contains the kernel code"),
334 INIT_PARAM(console
, "file that contains the console code"),
335 INIT_PARAM(pal
, "file that contains palcode"),
336 INIT_PARAM_DFLT(boot_osflags
, "flags to pass to the kernel during boot",
338 INIT_PARAM_DFLT(readfile
, "file to read startup script from", ""),
339 INIT_PARAM_DFLT(init_param
, "numerical value to pass into simulator", 0),
340 INIT_PARAM_DFLT(system_type
, "Type of system we are emulating", 34),
341 INIT_PARAM_DFLT(system_rev
, "Revision of system we are emulating", 1<<10),
342 INIT_PARAM_DFLT(bin
, "is this system to be binned", false),
343 INIT_PARAM(binned_fns
, "functions to be broken down and binned"),
344 INIT_PARAM_DFLT(bin_int
, "is interrupt code binned seperately?", true)
346 END_INIT_SIM_OBJECT_PARAMS(System
)
348 CREATE_SIM_OBJECT(System
)
350 System::Params
*p
= new System::Params
;
351 p
->name
= getInstanceName();
352 p
->boot_cpu_frequency
= boot_cpu_frequency
;
353 p
->memctrl
= memctrl
;
354 p
->physmem
= physmem
;
355 p
->kernel_path
= kernel
;
356 p
->console_path
= console
;
358 p
->boot_osflags
= boot_osflags
;
359 p
->init_param
= init_param
;
360 p
->readfile
= readfile
;
361 p
->system_type
= system_type
;
362 p
->system_rev
= system_rev
;
364 p
->binned_fns
= binned_fns
;
365 p
->bin_int
= bin_int
;
366 return new System(p
);
369 REGISTER_SIM_OBJECT("System", System
)