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