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