2 * Copyright (c) 2003-2006 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.
28 * Authors: Steve Reinhardt
34 #include "arch/isa_traits.hh"
35 #include "arch/remote_gdb.hh"
36 #include "arch/utility.hh"
37 #include "base/loader/object_file.hh"
38 #include "base/loader/symtab.hh"
39 #include "base/trace.hh"
40 #include "cpu/thread_context.hh"
41 #include "mem/mem_object.hh"
42 #include "mem/physical.hh"
43 #include "sim/builder.hh"
44 #include "sim/byteswap.hh"
45 #include "sim/system.hh"
47 #include "arch/vtophys.hh"
48 #include "kern/kernel_stats.hh"
52 using namespace TheISA
;
54 vector
<System
*> System::systemList
;
56 int System::numSystemsRunning
= 0;
58 System::System(Params
*p
)
59 : SimObject(p
->name
), physmem(p
->physmem
), numcpus(0),
61 init_param(p
->init_param
),
62 functionalPort(p
->name
+ "-fport"),
63 virtPort(p
->name
+ "-vport"),
67 memoryMode(p
->mem_mode
), _params(p
)
69 // add self to global system list
70 systemList
.push_back(this);
73 kernelSymtab
= new SymbolTable
;
74 debugSymbolTable
= new SymbolTable
;
78 * Get a functional port to memory
81 mem_port
= physmem
->getPort("functional");
82 functionalPort
.setPeer(mem_port
);
83 mem_port
->setPeer(&functionalPort
);
85 mem_port
= physmem
->getPort("functional");
86 virtPort
.setPeer(mem_port
);
87 mem_port
->setPeer(&virtPort
);
91 * Load the kernel code into memory
93 if (params()->kernel_path
== "") {
94 warn("No kernel set for full system simulation. Assuming you know what"
95 " you're doing...\n");
98 kernel
= createObjectFile(params()->kernel_path
);
100 fatal("Could not load kernel file %s", params()->kernel_path
);
102 // Load program sections into memory
103 kernel
->loadSections(&functionalPort
, LoadAddrMask
);
105 // setup entry points
106 kernelStart
= kernel
->textBase();
107 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
108 kernelEntry
= kernel
->entryPoint();
111 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
112 panic("could not load kernel symbols\n");
114 if (!kernel
->loadLocalSymbols(kernelSymtab
))
115 panic("could not load kernel local symbols\n");
117 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
118 panic("could not load kernel symbols\n");
120 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
121 panic("could not load kernel local symbols\n");
123 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
124 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
125 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
126 DPRINTF(Loader
, "Kernel loaded...\n");
128 #endif // FULL_SYSTEM
130 // increment the number of running systms
140 panic("System::fixFuncEventAddr needs to be rewritten "
141 "to work with syscall emulation");
142 #endif // FULL_SYSTEM}
146 int rgdb_enable
= true;
149 System::setMemoryMode(MemoryMode mode
)
151 assert(getState() == Drained
);
155 bool System::breakpoint()
157 if (remoteGDB
.size())
158 return remoteGDB
[0]->breakpoint();
163 System::registerThreadContext(ThreadContext
*tc
, int id
)
166 for (id
= 0; id
< threadContexts
.size(); id
++) {
167 if (!threadContexts
[id
])
172 if (threadContexts
.size() <= id
)
173 threadContexts
.resize(id
+ 1);
175 if (threadContexts
[id
])
176 panic("Cannot have two CPUs with the same id (%d)\n", id
);
178 threadContexts
[id
] = tc
;
182 RemoteGDB
*rgdb
= new RemoteGDB(this, tc
);
183 GDBListener
*gdbl
= new GDBListener(rgdb
, 7000 + id
);
186 * Uncommenting this line waits for a remote debugger to
187 * connect to the simulator before continuing.
189 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
192 if (remoteGDB
.size() <= id
) {
193 remoteGDB
.resize(id
+ 1);
196 remoteGDB
[id
] = rgdb
;
206 for (i
= 0; i
< threadContexts
.size(); i
++)
207 TheISA::startupCPU(threadContexts
[i
], i
);
211 System::replaceThreadContext(ThreadContext
*tc
, int id
)
213 if (id
>= threadContexts
.size()) {
214 panic("replaceThreadContext: bad id, %d >= %d\n",
215 id
, threadContexts
.size());
218 threadContexts
[id
] = tc
;
219 if (id
< remoteGDB
.size())
220 remoteGDB
[id
]->replaceThreadContext(tc
);
227 Addr return_addr
= page_ptr
<< LogVMPageSize
;
229 if (return_addr
>= physmem
->size())
230 fatal("Out of memory, please increase size of physical memory.");
236 System::serialize(ostream
&os
)
239 kernelSymtab
->serialize("kernel_symtab", os
);
240 #endif // FULL_SYSTEM
245 System::unserialize(Checkpoint
*cp
, const string
§ion
)
248 kernelSymtab
->unserialize("kernel_symtab", cp
, section
);
249 #endif // FULL_SYSTEM
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
;
266 System::printSystems();
269 const char *System::MemoryModeStrings
[3] = {"invalid", "atomic",
274 // In full system mode, only derived classes (e.g. AlphaLinuxSystem)
275 // can be created directly.
277 DEFINE_SIM_OBJECT_CLASS_NAME("System", System
)
281 BEGIN_DECLARE_SIM_OBJECT_PARAMS(System
)
283 SimObjectParam
<PhysicalMemory
*> physmem
;
284 SimpleEnumParam
<System::MemoryMode
> mem_mode
;
286 END_DECLARE_SIM_OBJECT_PARAMS(System
)
288 BEGIN_INIT_SIM_OBJECT_PARAMS(System
)
290 INIT_PARAM(physmem
, "physical memory"),
291 INIT_ENUM_PARAM(mem_mode
, "Memory Mode, (1=atomic, 2=timing)",
292 System::MemoryModeStrings
)
294 END_INIT_SIM_OBJECT_PARAMS(System
)
296 CREATE_SIM_OBJECT(System
)
298 System::Params
*p
= new System::Params
;
299 p
->name
= getInstanceName();
300 p
->physmem
= physmem
;
301 p
->mem_mode
= mem_mode
;
302 return new System(p
);
305 REGISTER_SIM_OBJECT("System", System
)