system.cc (3536:89aa06409e4d) system.cc (3812:eaa215123a26)
1/*
2 * Copyright (c) 2003-2006 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 * Authors: Steve Reinhardt
29 * Lisa Hsu
30 * Nathan Binkert
31 * Ali Saidi
32 */
33
34#include "arch/isa_traits.hh"
35#include "base/loader/object_file.hh"
36#include "base/loader/symtab.hh"
37#include "base/trace.hh"
38#include "cpu/thread_context.hh"
39#include "mem/mem_object.hh"
40#include "mem/physical.hh"
41#include "sim/builder.hh"
42#include "sim/byteswap.hh"
43#include "sim/system.hh"
44#if FULL_SYSTEM
45#include "arch/vtophys.hh"
46#include "arch/remote_gdb.hh"
47#include "kern/kernel_stats.hh"
48#endif
49
50using namespace std;
51using namespace TheISA;
52
53vector<System *> System::systemList;
54
55int System::numSystemsRunning = 0;
56
57System::System(Params *p)
58 : SimObject(p->name), physmem(p->physmem), numcpus(0),
59#if FULL_SYSTEM
60 init_param(p->init_param),
61 functionalPort(p->name + "-fport"),
62 virtPort(p->name + "-vport"),
63#else
64 page_ptr(0),
65#endif
66 memoryMode(p->mem_mode), _params(p)
67{
68 // add self to global system list
69 systemList.push_back(this);
70
71#if FULL_SYSTEM
72 kernelSymtab = new SymbolTable;
73 debugSymbolTable = new SymbolTable;
74
75
76 /**
77 * Get a functional port to memory
78 */
79 Port *mem_port;
80 mem_port = physmem->getPort("functional");
81 functionalPort.setPeer(mem_port);
82 mem_port->setPeer(&functionalPort);
83
84 mem_port = physmem->getPort("functional");
85 virtPort.setPeer(mem_port);
86 mem_port->setPeer(&virtPort);
87
88
89 /**
90 * Load the kernel code into memory
91 */
1/*
2 * Copyright (c) 2003-2006 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 * Authors: Steve Reinhardt
29 * Lisa Hsu
30 * Nathan Binkert
31 * Ali Saidi
32 */
33
34#include "arch/isa_traits.hh"
35#include "base/loader/object_file.hh"
36#include "base/loader/symtab.hh"
37#include "base/trace.hh"
38#include "cpu/thread_context.hh"
39#include "mem/mem_object.hh"
40#include "mem/physical.hh"
41#include "sim/builder.hh"
42#include "sim/byteswap.hh"
43#include "sim/system.hh"
44#if FULL_SYSTEM
45#include "arch/vtophys.hh"
46#include "arch/remote_gdb.hh"
47#include "kern/kernel_stats.hh"
48#endif
49
50using namespace std;
51using namespace TheISA;
52
53vector<System *> System::systemList;
54
55int System::numSystemsRunning = 0;
56
57System::System(Params *p)
58 : SimObject(p->name), physmem(p->physmem), numcpus(0),
59#if FULL_SYSTEM
60 init_param(p->init_param),
61 functionalPort(p->name + "-fport"),
62 virtPort(p->name + "-vport"),
63#else
64 page_ptr(0),
65#endif
66 memoryMode(p->mem_mode), _params(p)
67{
68 // add self to global system list
69 systemList.push_back(this);
70
71#if FULL_SYSTEM
72 kernelSymtab = new SymbolTable;
73 debugSymbolTable = new SymbolTable;
74
75
76 /**
77 * Get a functional port to memory
78 */
79 Port *mem_port;
80 mem_port = physmem->getPort("functional");
81 functionalPort.setPeer(mem_port);
82 mem_port->setPeer(&functionalPort);
83
84 mem_port = physmem->getPort("functional");
85 virtPort.setPeer(mem_port);
86 mem_port->setPeer(&virtPort);
87
88
89 /**
90 * Load the kernel code into memory
91 */
92 // Load kernel code
93 kernel = createObjectFile(params()->kernel_path);
94 if (kernel == NULL)
95 fatal("Could not load kernel file %s", params()->kernel_path);
92 if (params()->kernel_path == "") {
93 warn("No kernel set for full system simulation. Assuming you know what"
94 " you're doing...\n");
95 } else {
96 // Load kernel code
97 kernel = createObjectFile(params()->kernel_path);
98 if (kernel == NULL)
99 fatal("Could not load kernel file %s", params()->kernel_path);
96
100
97 // Load program sections into memory
98 kernel->loadSections(&functionalPort, LoadAddrMask);
101 // Load program sections into memory
102 kernel->loadSections(&functionalPort, LoadAddrMask);
99
103
100 // setup entry points
101 kernelStart = kernel->textBase();
102 kernelEnd = kernel->bssBase() + kernel->bssSize();
103 kernelEntry = kernel->entryPoint();
104 // setup entry points
105 kernelStart = kernel->textBase();
106 kernelEnd = kernel->bssBase() + kernel->bssSize();
107 kernelEntry = kernel->entryPoint();
104
108
105 // load symbols
106 if (!kernel->loadGlobalSymbols(kernelSymtab))
107 panic("could not load kernel symbols\n");
109 // load symbols
110 if (!kernel->loadGlobalSymbols(kernelSymtab))
111 panic("could not load kernel symbols\n");
108
112
109 if (!kernel->loadLocalSymbols(kernelSymtab))
110 panic("could not load kernel local symbols\n");
113 if (!kernel->loadLocalSymbols(kernelSymtab))
114 panic("could not load kernel local symbols\n");
111
115
112 if (!kernel->loadGlobalSymbols(debugSymbolTable))
113 panic("could not load kernel symbols\n");
116 if (!kernel->loadGlobalSymbols(debugSymbolTable))
117 panic("could not load kernel symbols\n");
114
118
115 if (!kernel->loadLocalSymbols(debugSymbolTable))
116 panic("could not load kernel local symbols\n");
119 if (!kernel->loadLocalSymbols(debugSymbolTable))
120 panic("could not load kernel local symbols\n");
117
121
118 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
119 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd);
120 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry);
121 DPRINTF(Loader, "Kernel loaded...\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");
126 }
122#endif // FULL_SYSTEM
123
124 // increment the number of running systms
125 numSystemsRunning++;
126}
127
128System::~System()
129{
130#if FULL_SYSTEM
131 delete kernelSymtab;
132 delete kernel;
133#else
134 panic("System::fixFuncEventAddr needs to be rewritten "
135 "to work with syscall emulation");
136#endif // FULL_SYSTEM}
137}
138
139#if FULL_SYSTEM
140
141
142int rgdb_wait = -1;
143
144#endif // FULL_SYSTEM
145
146
147void
148System::setMemoryMode(MemoryMode mode)
149{
150 assert(getState() == Drained);
151 memoryMode = mode;
152}
153
154int
155System::registerThreadContext(ThreadContext *tc, int id)
156{
157 if (id == -1) {
158 for (id = 0; id < threadContexts.size(); id++) {
159 if (!threadContexts[id])
160 break;
161 }
162 }
163
164 if (threadContexts.size() <= id)
165 threadContexts.resize(id + 1);
166
167 if (threadContexts[id])
168 panic("Cannot have two CPUs with the same id (%d)\n", id);
169
170 threadContexts[id] = tc;
171 numcpus++;
172
173#if FULL_SYSTEM
174 RemoteGDB *rgdb = new RemoteGDB(this, tc);
175 GDBListener *gdbl = new GDBListener(rgdb, 7000 + id);
176 gdbl->listen();
177 /**
178 * Uncommenting this line waits for a remote debugger to connect
179 * to the simulator before continuing.
180 */
181 if (rgdb_wait != -1 && rgdb_wait == id)
182 gdbl->accept();
183
184 if (remoteGDB.size() <= id) {
185 remoteGDB.resize(id + 1);
186 }
187
188 remoteGDB[id] = rgdb;
189#endif // FULL_SYSTEM
190
191 return id;
192}
193
194void
195System::startup()
196{
197 int i;
198 for (i = 0; i < threadContexts.size(); i++)
199 threadContexts[i]->activate(0);
200}
201
202void
203System::replaceThreadContext(ThreadContext *tc, int id)
204{
205 if (id >= threadContexts.size()) {
206 panic("replaceThreadContext: bad id, %d >= %d\n",
207 id, threadContexts.size());
208 }
209
210 threadContexts[id] = tc;
211#if FULL_SYSTEM
212 remoteGDB[id]->replaceThreadContext(tc);
213#endif // FULL_SYSTEM
214}
215
216#if !FULL_SYSTEM
217Addr
218System::new_page()
219{
220 Addr return_addr = page_ptr << LogVMPageSize;
221 ++page_ptr;
222 if (return_addr >= physmem->size())
223 fatal("Out of memory, please increase size of physical memory.");
224 return return_addr;
225}
226#endif
227
228void
229System::serialize(ostream &os)
230{
231#if FULL_SYSTEM
232 kernelSymtab->serialize("kernel_symtab", os);
233#endif // FULL_SYSTEM
234}
235
236
237void
238System::unserialize(Checkpoint *cp, const string &section)
239{
240#if FULL_SYSTEM
241 kernelSymtab->unserialize("kernel_symtab", cp, section);
242#endif // FULL_SYSTEM
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
256void
257printSystems()
258{
259 System::printSystems();
260}
261
262const char *System::MemoryModeStrings[3] = {"invalid", "atomic",
263 "timing"};
264
265#if FULL_SYSTEM
266
267// In full system mode, only derived classes (e.g. AlphaLinuxSystem)
268// can be created directly.
269
270DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
271
272#else
273
274BEGIN_DECLARE_SIM_OBJECT_PARAMS(System)
275
276 SimObjectParam<PhysicalMemory *> physmem;
277 SimpleEnumParam<System::MemoryMode> mem_mode;
278
279END_DECLARE_SIM_OBJECT_PARAMS(System)
280
281BEGIN_INIT_SIM_OBJECT_PARAMS(System)
282
283 INIT_PARAM(physmem, "physical memory"),
284 INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
285 System::MemoryModeStrings)
286
287END_INIT_SIM_OBJECT_PARAMS(System)
288
289CREATE_SIM_OBJECT(System)
290{
291 System::Params *p = new System::Params;
292 p->name = getInstanceName();
293 p->physmem = physmem;
294 p->mem_mode = mem_mode;
295 return new System(p);
296}
297
298REGISTER_SIM_OBJECT("System", System)
299
300#endif
127#endif // FULL_SYSTEM
128
129 // increment the number of running systms
130 numSystemsRunning++;
131}
132
133System::~System()
134{
135#if FULL_SYSTEM
136 delete kernelSymtab;
137 delete kernel;
138#else
139 panic("System::fixFuncEventAddr needs to be rewritten "
140 "to work with syscall emulation");
141#endif // FULL_SYSTEM}
142}
143
144#if FULL_SYSTEM
145
146
147int rgdb_wait = -1;
148
149#endif // FULL_SYSTEM
150
151
152void
153System::setMemoryMode(MemoryMode mode)
154{
155 assert(getState() == Drained);
156 memoryMode = mode;
157}
158
159int
160System::registerThreadContext(ThreadContext *tc, int id)
161{
162 if (id == -1) {
163 for (id = 0; id < threadContexts.size(); id++) {
164 if (!threadContexts[id])
165 break;
166 }
167 }
168
169 if (threadContexts.size() <= id)
170 threadContexts.resize(id + 1);
171
172 if (threadContexts[id])
173 panic("Cannot have two CPUs with the same id (%d)\n", id);
174
175 threadContexts[id] = tc;
176 numcpus++;
177
178#if FULL_SYSTEM
179 RemoteGDB *rgdb = new RemoteGDB(this, tc);
180 GDBListener *gdbl = new GDBListener(rgdb, 7000 + id);
181 gdbl->listen();
182 /**
183 * Uncommenting this line waits for a remote debugger to connect
184 * to the simulator before continuing.
185 */
186 if (rgdb_wait != -1 && rgdb_wait == id)
187 gdbl->accept();
188
189 if (remoteGDB.size() <= id) {
190 remoteGDB.resize(id + 1);
191 }
192
193 remoteGDB[id] = rgdb;
194#endif // FULL_SYSTEM
195
196 return id;
197}
198
199void
200System::startup()
201{
202 int i;
203 for (i = 0; i < threadContexts.size(); i++)
204 threadContexts[i]->activate(0);
205}
206
207void
208System::replaceThreadContext(ThreadContext *tc, int id)
209{
210 if (id >= threadContexts.size()) {
211 panic("replaceThreadContext: bad id, %d >= %d\n",
212 id, threadContexts.size());
213 }
214
215 threadContexts[id] = tc;
216#if FULL_SYSTEM
217 remoteGDB[id]->replaceThreadContext(tc);
218#endif // FULL_SYSTEM
219}
220
221#if !FULL_SYSTEM
222Addr
223System::new_page()
224{
225 Addr return_addr = page_ptr << LogVMPageSize;
226 ++page_ptr;
227 if (return_addr >= physmem->size())
228 fatal("Out of memory, please increase size of physical memory.");
229 return return_addr;
230}
231#endif
232
233void
234System::serialize(ostream &os)
235{
236#if FULL_SYSTEM
237 kernelSymtab->serialize("kernel_symtab", os);
238#endif // FULL_SYSTEM
239}
240
241
242void
243System::unserialize(Checkpoint *cp, const string &section)
244{
245#if FULL_SYSTEM
246 kernelSymtab->unserialize("kernel_symtab", cp, section);
247#endif // FULL_SYSTEM
248}
249
250void
251System::printSystems()
252{
253 vector<System *>::iterator i = systemList.begin();
254 vector<System *>::iterator end = systemList.end();
255 for (; i != end; ++i) {
256 System *sys = *i;
257 cerr << "System " << sys->name() << ": " << hex << sys << endl;
258 }
259}
260
261void
262printSystems()
263{
264 System::printSystems();
265}
266
267const char *System::MemoryModeStrings[3] = {"invalid", "atomic",
268 "timing"};
269
270#if FULL_SYSTEM
271
272// In full system mode, only derived classes (e.g. AlphaLinuxSystem)
273// can be created directly.
274
275DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
276
277#else
278
279BEGIN_DECLARE_SIM_OBJECT_PARAMS(System)
280
281 SimObjectParam<PhysicalMemory *> physmem;
282 SimpleEnumParam<System::MemoryMode> mem_mode;
283
284END_DECLARE_SIM_OBJECT_PARAMS(System)
285
286BEGIN_INIT_SIM_OBJECT_PARAMS(System)
287
288 INIT_PARAM(physmem, "physical memory"),
289 INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
290 System::MemoryModeStrings)
291
292END_INIT_SIM_OBJECT_PARAMS(System)
293
294CREATE_SIM_OBJECT(System)
295{
296 System::Params *p = new System::Params;
297 p->name = getInstanceName();
298 p->physmem = physmem;
299 p->mem_mode = mem_mode;
300 return new System(p);
301}
302
303REGISTER_SIM_OBJECT("System", System)
304
305#endif