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