system.cc (2716:b9114064d77a) system.cc (2720:695250d6fa42)
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 "base/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 _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);
96
97 // Load program sections into memory
98 kernel->loadSections(&functionalPort, LoadAddrMask);
99
100 // setup entry points
101 kernelStart = kernel->textBase();
102 kernelEnd = kernel->bssBase() + kernel->bssSize();
103 kernelEntry = kernel->entryPoint();
104
105 // load symbols
106 if (!kernel->loadGlobalSymbols(kernelSymtab))
107 panic("could not load kernel symbols\n");
108
109 if (!kernel->loadLocalSymbols(kernelSymtab))
110 panic("could not load kernel local symbols\n");
111
112 if (!kernel->loadGlobalSymbols(debugSymbolTable))
113 panic("could not load kernel symbols\n");
114
115 if (!kernel->loadLocalSymbols(debugSymbolTable))
116 panic("could not load kernel local symbols\n");
117
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");
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 "base/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 _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);
96
97 // Load program sections into memory
98 kernel->loadSections(&functionalPort, LoadAddrMask);
99
100 // setup entry points
101 kernelStart = kernel->textBase();
102 kernelEnd = kernel->bssBase() + kernel->bssSize();
103 kernelEntry = kernel->entryPoint();
104
105 // load symbols
106 if (!kernel->loadGlobalSymbols(kernelSymtab))
107 panic("could not load kernel symbols\n");
108
109 if (!kernel->loadLocalSymbols(kernelSymtab))
110 panic("could not load kernel local symbols\n");
111
112 if (!kernel->loadGlobalSymbols(debugSymbolTable))
113 panic("could not load kernel symbols\n");
114
115 if (!kernel->loadLocalSymbols(debugSymbolTable))
116 panic("could not load kernel local symbols\n");
117
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
123 kernelBinning = new Kernel::Binning(this);
124#endif // FULL_SYSTEM
125
126 // increment the number of running systms
127 numSystemsRunning++;
128}
129
130System::~System()
131{
132#if FULL_SYSTEM
133 delete kernelSymtab;
134 delete kernel;
135#else
136 panic("System::fixFuncEventAddr needs to be rewritten "
137 "to work with syscall emulation");
138#endif // FULL_SYSTEM}
139}
140
141#if FULL_SYSTEM
142
143
144int rgdb_wait = -1;
145
146#endif // FULL_SYSTEM
147
148int
149System::registerThreadContext(ThreadContext *tc, int id)
150{
151 if (id == -1) {
152 for (id = 0; id < threadContexts.size(); id++) {
153 if (!threadContexts[id])
154 break;
155 }
156 }
157
158 if (threadContexts.size() <= id)
159 threadContexts.resize(id + 1);
160
161 if (threadContexts[id])
162 panic("Cannot have two CPUs with the same id (%d)\n", id);
163
164 threadContexts[id] = tc;
165 numcpus++;
166
167#if FULL_SYSTEM
168 RemoteGDB *rgdb = new RemoteGDB(this, tc);
169 GDBListener *gdbl = new GDBListener(rgdb, 7000 + id);
170 gdbl->listen();
171 /**
172 * Uncommenting this line waits for a remote debugger to connect
173 * to the simulator before continuing.
174 */
175 if (rgdb_wait != -1 && rgdb_wait == id)
176 gdbl->accept();
177
178 if (remoteGDB.size() <= id) {
179 remoteGDB.resize(id + 1);
180 }
181
182 remoteGDB[id] = rgdb;
183#endif // FULL_SYSTEM
184
185 return id;
186}
187
188void
189System::startup()
190{
191 int i;
192 for (i = 0; i < threadContexts.size(); i++)
193 threadContexts[i]->activate(0);
194}
195
196void
197System::replaceThreadContext(ThreadContext *tc, int id)
198{
199 if (id >= threadContexts.size()) {
200 panic("replaceThreadContext: bad id, %d >= %d\n",
201 id, threadContexts.size());
202 }
203
204 threadContexts[id] = tc;
205#if FULL_SYSTEM
206 remoteGDB[id]->replaceThreadContext(tc);
207#endif // FULL_SYSTEM
208}
209
210#if !FULL_SYSTEM
211Addr
212System::new_page()
213{
214 Addr return_addr = page_ptr << LogVMPageSize;
215 ++page_ptr;
216 return return_addr;
217}
218#endif
219
220void
221System::serialize(ostream &os)
222{
223#if FULL_SYSTEM
224 kernelSymtab->serialize("kernel_symtab", os);
225#endif // FULL_SYSTEM
226}
227
228
229void
230System::unserialize(Checkpoint *cp, const string &section)
231{
232#if FULL_SYSTEM
233 kernelSymtab->unserialize("kernel_symtab", cp, section);
234#endif // FULL_SYSTEM
235}
236
237void
238System::printSystems()
239{
240 vector<System *>::iterator i = systemList.begin();
241 vector<System *>::iterator end = systemList.end();
242 for (; i != end; ++i) {
243 System *sys = *i;
244 cerr << "System " << sys->name() << ": " << hex << sys << endl;
245 }
246}
247
248extern "C"
249void
250printSystems()
251{
252 System::printSystems();
253}
254
255#if FULL_SYSTEM
256
257// In full system mode, only derived classes (e.g. AlphaLinuxSystem)
258// can be created directly.
259
260DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
261
262#else
263
264BEGIN_DECLARE_SIM_OBJECT_PARAMS(System)
265
266 SimObjectParam<PhysicalMemory *> physmem;
267
268END_DECLARE_SIM_OBJECT_PARAMS(System)
269
270BEGIN_INIT_SIM_OBJECT_PARAMS(System)
271
272 INIT_PARAM(physmem, "physical memory")
273
274END_INIT_SIM_OBJECT_PARAMS(System)
275
276CREATE_SIM_OBJECT(System)
277{
278 System::Params *p = new System::Params;
279 p->name = getInstanceName();
280 p->physmem = physmem;
281 return new System(p);
282}
283
284REGISTER_SIM_OBJECT("System", System)
285
286#endif
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
146int
147System::registerThreadContext(ThreadContext *tc, int id)
148{
149 if (id == -1) {
150 for (id = 0; id < threadContexts.size(); id++) {
151 if (!threadContexts[id])
152 break;
153 }
154 }
155
156 if (threadContexts.size() <= id)
157 threadContexts.resize(id + 1);
158
159 if (threadContexts[id])
160 panic("Cannot have two CPUs with the same id (%d)\n", id);
161
162 threadContexts[id] = tc;
163 numcpus++;
164
165#if FULL_SYSTEM
166 RemoteGDB *rgdb = new RemoteGDB(this, tc);
167 GDBListener *gdbl = new GDBListener(rgdb, 7000 + id);
168 gdbl->listen();
169 /**
170 * Uncommenting this line waits for a remote debugger to connect
171 * to the simulator before continuing.
172 */
173 if (rgdb_wait != -1 && rgdb_wait == id)
174 gdbl->accept();
175
176 if (remoteGDB.size() <= id) {
177 remoteGDB.resize(id + 1);
178 }
179
180 remoteGDB[id] = rgdb;
181#endif // FULL_SYSTEM
182
183 return id;
184}
185
186void
187System::startup()
188{
189 int i;
190 for (i = 0; i < threadContexts.size(); i++)
191 threadContexts[i]->activate(0);
192}
193
194void
195System::replaceThreadContext(ThreadContext *tc, int id)
196{
197 if (id >= threadContexts.size()) {
198 panic("replaceThreadContext: bad id, %d >= %d\n",
199 id, threadContexts.size());
200 }
201
202 threadContexts[id] = tc;
203#if FULL_SYSTEM
204 remoteGDB[id]->replaceThreadContext(tc);
205#endif // FULL_SYSTEM
206}
207
208#if !FULL_SYSTEM
209Addr
210System::new_page()
211{
212 Addr return_addr = page_ptr << LogVMPageSize;
213 ++page_ptr;
214 return return_addr;
215}
216#endif
217
218void
219System::serialize(ostream &os)
220{
221#if FULL_SYSTEM
222 kernelSymtab->serialize("kernel_symtab", os);
223#endif // FULL_SYSTEM
224}
225
226
227void
228System::unserialize(Checkpoint *cp, const string &section)
229{
230#if FULL_SYSTEM
231 kernelSymtab->unserialize("kernel_symtab", cp, section);
232#endif // FULL_SYSTEM
233}
234
235void
236System::printSystems()
237{
238 vector<System *>::iterator i = systemList.begin();
239 vector<System *>::iterator end = systemList.end();
240 for (; i != end; ++i) {
241 System *sys = *i;
242 cerr << "System " << sys->name() << ": " << hex << sys << endl;
243 }
244}
245
246extern "C"
247void
248printSystems()
249{
250 System::printSystems();
251}
252
253#if FULL_SYSTEM
254
255// In full system mode, only derived classes (e.g. AlphaLinuxSystem)
256// can be created directly.
257
258DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
259
260#else
261
262BEGIN_DECLARE_SIM_OBJECT_PARAMS(System)
263
264 SimObjectParam<PhysicalMemory *> physmem;
265
266END_DECLARE_SIM_OBJECT_PARAMS(System)
267
268BEGIN_INIT_SIM_OBJECT_PARAMS(System)
269
270 INIT_PARAM(physmem, "physical memory")
271
272END_INIT_SIM_OBJECT_PARAMS(System)
273
274CREATE_SIM_OBJECT(System)
275{
276 System::Params *p = new System::Params;
277 p->name = getInstanceName();
278 p->physmem = physmem;
279 return new System(p);
280}
281
282REGISTER_SIM_OBJECT("System", System)
283
284#endif