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