system.cc (12122:20512f6810d7) system.cc (12262:a58c0c323e4f)
1/*
2 * Copyright (c) 2011-2014 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2003-2006 The Regents of The University of Michigan
15 * Copyright (c) 2011 Regents of the University of California
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Steve Reinhardt
42 * Lisa Hsu
43 * Nathan Binkert
44 * Ali Saidi
45 * Rick Strong
46 */
47
48#include "sim/system.hh"
49
50#include "arch/remote_gdb.hh"
51#include "arch/utility.hh"
52#include "base/loader/object_file.hh"
53#include "base/loader/symtab.hh"
54#include "base/str.hh"
55#include "base/trace.hh"
56#include "config/use_kvm.hh"
57#if USE_KVM
58#include "cpu/kvm/base.hh"
59#include "cpu/kvm/vm.hh"
60#endif
61#include "cpu/base.hh"
62#include "cpu/thread_context.hh"
63#include "debug/Loader.hh"
64#include "debug/WorkItems.hh"
65#include "mem/abstract_mem.hh"
66#include "mem/physical.hh"
67#include "params/System.hh"
68#include "sim/byteswap.hh"
69#include "sim/debug.hh"
70#include "sim/full_system.hh"
71
72/**
73 * To avoid linking errors with LTO, only include the header if we
74 * actually have a definition.
75 */
76#if THE_ISA != NULL_ISA
77#include "kern/kernel_stats.hh"
78
79#endif
80
81using namespace std;
82using namespace TheISA;
83
84vector<System *> System::systemList;
85
86int System::numSystemsRunning = 0;
87
88System::System(Params *p)
89 : MemObject(p), _systemPort("system_port", this),
90 _numContexts(0),
91 multiThread(p->multi_thread),
92 pagePtr(0),
93 init_param(p->init_param),
94 physProxy(_systemPort, p->cache_line_size),
95 kernelSymtab(nullptr),
96 kernel(nullptr),
97 loadAddrMask(p->load_addr_mask),
98 loadAddrOffset(p->load_offset),
99#if USE_KVM
100 kvmVM(p->kvm_vm),
101#else
102 kvmVM(nullptr),
103#endif
104 physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
105 memoryMode(p->mem_mode),
106 _cacheLineSize(p->cache_line_size),
107 workItemsBegin(0),
108 workItemsEnd(0),
109 numWorkIds(p->num_work_ids),
110 thermalModel(p->thermal_model),
111 _params(p),
112 totalNumInsts(0),
113 instEventQueue("system instruction-based event queue")
114{
115 // add self to global system list
116 systemList.push_back(this);
117
118#if USE_KVM
119 if (kvmVM) {
120 kvmVM->setSystem(this);
121 }
122#endif
123
124 if (FullSystem) {
125 kernelSymtab = new SymbolTable;
126 if (!debugSymbolTable)
127 debugSymbolTable = new SymbolTable;
128 }
129
130 // check if the cache line size is a value known to work
131 if (!(_cacheLineSize == 16 || _cacheLineSize == 32 ||
132 _cacheLineSize == 64 || _cacheLineSize == 128))
133 warn_once("Cache line size is neither 16, 32, 64 nor 128 bytes.\n");
134
135 // Get the generic system master IDs
136 MasterID tmp_id M5_VAR_USED;
137 tmp_id = getMasterId("writebacks");
138 assert(tmp_id == Request::wbMasterId);
139 tmp_id = getMasterId("functional");
140 assert(tmp_id == Request::funcMasterId);
141 tmp_id = getMasterId("interrupt");
142 assert(tmp_id == Request::intMasterId);
143
144 if (FullSystem) {
145 if (params()->kernel == "") {
146 inform("No kernel set for full system simulation. "
147 "Assuming you know what you're doing\n");
148 } else {
149 // Get the kernel code
150 kernel = createObjectFile(params()->kernel);
151 inform("kernel located at: %s", params()->kernel);
152
153 if (kernel == NULL)
154 fatal("Could not load kernel file %s", params()->kernel);
155
156 // setup entry points
157 kernelStart = kernel->textBase();
158 kernelEnd = kernel->bssBase() + kernel->bssSize();
159 kernelEntry = kernel->entryPoint();
160
161 // load symbols
162 if (!kernel->loadGlobalSymbols(kernelSymtab))
163 fatal("could not load kernel symbols\n");
164
165 if (!kernel->loadLocalSymbols(kernelSymtab))
166 fatal("could not load kernel local symbols\n");
167
168 if (!kernel->loadGlobalSymbols(debugSymbolTable))
169 fatal("could not load kernel symbols\n");
170
171 if (!kernel->loadLocalSymbols(debugSymbolTable))
172 fatal("could not load kernel local symbols\n");
173
174 // Loading only needs to happen once and after memory system is
175 // connected so it will happen in initState()
176 }
1/*
2 * Copyright (c) 2011-2014 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2003-2006 The Regents of The University of Michigan
15 * Copyright (c) 2011 Regents of the University of California
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Steve Reinhardt
42 * Lisa Hsu
43 * Nathan Binkert
44 * Ali Saidi
45 * Rick Strong
46 */
47
48#include "sim/system.hh"
49
50#include "arch/remote_gdb.hh"
51#include "arch/utility.hh"
52#include "base/loader/object_file.hh"
53#include "base/loader/symtab.hh"
54#include "base/str.hh"
55#include "base/trace.hh"
56#include "config/use_kvm.hh"
57#if USE_KVM
58#include "cpu/kvm/base.hh"
59#include "cpu/kvm/vm.hh"
60#endif
61#include "cpu/base.hh"
62#include "cpu/thread_context.hh"
63#include "debug/Loader.hh"
64#include "debug/WorkItems.hh"
65#include "mem/abstract_mem.hh"
66#include "mem/physical.hh"
67#include "params/System.hh"
68#include "sim/byteswap.hh"
69#include "sim/debug.hh"
70#include "sim/full_system.hh"
71
72/**
73 * To avoid linking errors with LTO, only include the header if we
74 * actually have a definition.
75 */
76#if THE_ISA != NULL_ISA
77#include "kern/kernel_stats.hh"
78
79#endif
80
81using namespace std;
82using namespace TheISA;
83
84vector<System *> System::systemList;
85
86int System::numSystemsRunning = 0;
87
88System::System(Params *p)
89 : MemObject(p), _systemPort("system_port", this),
90 _numContexts(0),
91 multiThread(p->multi_thread),
92 pagePtr(0),
93 init_param(p->init_param),
94 physProxy(_systemPort, p->cache_line_size),
95 kernelSymtab(nullptr),
96 kernel(nullptr),
97 loadAddrMask(p->load_addr_mask),
98 loadAddrOffset(p->load_offset),
99#if USE_KVM
100 kvmVM(p->kvm_vm),
101#else
102 kvmVM(nullptr),
103#endif
104 physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
105 memoryMode(p->mem_mode),
106 _cacheLineSize(p->cache_line_size),
107 workItemsBegin(0),
108 workItemsEnd(0),
109 numWorkIds(p->num_work_ids),
110 thermalModel(p->thermal_model),
111 _params(p),
112 totalNumInsts(0),
113 instEventQueue("system instruction-based event queue")
114{
115 // add self to global system list
116 systemList.push_back(this);
117
118#if USE_KVM
119 if (kvmVM) {
120 kvmVM->setSystem(this);
121 }
122#endif
123
124 if (FullSystem) {
125 kernelSymtab = new SymbolTable;
126 if (!debugSymbolTable)
127 debugSymbolTable = new SymbolTable;
128 }
129
130 // check if the cache line size is a value known to work
131 if (!(_cacheLineSize == 16 || _cacheLineSize == 32 ||
132 _cacheLineSize == 64 || _cacheLineSize == 128))
133 warn_once("Cache line size is neither 16, 32, 64 nor 128 bytes.\n");
134
135 // Get the generic system master IDs
136 MasterID tmp_id M5_VAR_USED;
137 tmp_id = getMasterId("writebacks");
138 assert(tmp_id == Request::wbMasterId);
139 tmp_id = getMasterId("functional");
140 assert(tmp_id == Request::funcMasterId);
141 tmp_id = getMasterId("interrupt");
142 assert(tmp_id == Request::intMasterId);
143
144 if (FullSystem) {
145 if (params()->kernel == "") {
146 inform("No kernel set for full system simulation. "
147 "Assuming you know what you're doing\n");
148 } else {
149 // Get the kernel code
150 kernel = createObjectFile(params()->kernel);
151 inform("kernel located at: %s", params()->kernel);
152
153 if (kernel == NULL)
154 fatal("Could not load kernel file %s", params()->kernel);
155
156 // setup entry points
157 kernelStart = kernel->textBase();
158 kernelEnd = kernel->bssBase() + kernel->bssSize();
159 kernelEntry = kernel->entryPoint();
160
161 // load symbols
162 if (!kernel->loadGlobalSymbols(kernelSymtab))
163 fatal("could not load kernel symbols\n");
164
165 if (!kernel->loadLocalSymbols(kernelSymtab))
166 fatal("could not load kernel local symbols\n");
167
168 if (!kernel->loadGlobalSymbols(debugSymbolTable))
169 fatal("could not load kernel symbols\n");
170
171 if (!kernel->loadLocalSymbols(debugSymbolTable))
172 fatal("could not load kernel local symbols\n");
173
174 // Loading only needs to happen once and after memory system is
175 // connected so it will happen in initState()
176 }
177
178 for (const auto &obj_name : p->kernel_extras) {
179 inform("Loading additional kernel object: %s", obj_name);
180 ObjectFile *obj = createObjectFile(obj_name);
181 fatal_if(!obj, "Failed to additional kernel object '%s'.\n",
182 obj_name);
183 kernelExtras.push_back(obj);
184 }
177 }
178
179 // increment the number of running systems
180 numSystemsRunning++;
181
182 // Set back pointers to the system in all memories
183 for (int x = 0; x < params()->memories.size(); x++)
184 params()->memories[x]->system(this);
185}
186
187System::~System()
188{
189 delete kernelSymtab;
190 delete kernel;
191
192 for (uint32_t j = 0; j < numWorkIds; j++)
193 delete workItemStats[j];
194}
195
196void
197System::init()
198{
199 // check that the system port is connected
200 if (!_systemPort.isConnected())
201 panic("System port on %s is not connected.\n", name());
202}
203
204BaseMasterPort&
205System::getMasterPort(const std::string &if_name, PortID idx)
206{
207 // no need to distinguish at the moment (besides checking)
208 return _systemPort;
209}
210
211void
212System::setMemoryMode(Enums::MemoryMode mode)
213{
214 assert(drainState() == DrainState::Drained);
215 memoryMode = mode;
216}
217
218bool System::breakpoint()
219{
220 if (remoteGDB.size())
221 return remoteGDB[0]->breakpoint();
222 return false;
223}
224
225ContextID
226System::registerThreadContext(ThreadContext *tc, ContextID assigned)
227{
228 int id;
229 if (assigned == InvalidContextID) {
230 for (id = 0; id < threadContexts.size(); id++) {
231 if (!threadContexts[id])
232 break;
233 }
234
235 if (threadContexts.size() <= id)
236 threadContexts.resize(id + 1);
237 } else {
238 if (threadContexts.size() <= assigned)
239 threadContexts.resize(assigned + 1);
240 id = assigned;
241 }
242
243 if (threadContexts[id])
244 fatal("Cannot have two CPUs with the same id (%d)\n", id);
245
246 threadContexts[id] = tc;
247 _numContexts++;
248
249#if THE_ISA != NULL_ISA
250 int port = getRemoteGDBPort();
251 if (port) {
252 RemoteGDB *rgdb = new RemoteGDB(this, tc);
253 GDBListener *gdbl = new GDBListener(rgdb, port + id);
254 gdbl->listen();
255
256 BaseCPU *cpu = tc->getCpuPtr();
257 if (cpu->waitForRemoteGDB()) {
258 inform("%s: Waiting for a remote GDB connection on port %d.\n",
259 cpu->name(), gdbl->getPort());
260
261 gdbl->accept();
262 }
263 if (remoteGDB.size() <= id) {
264 remoteGDB.resize(id + 1);
265 }
266
267 remoteGDB[id] = rgdb;
268 }
269#endif
270
271 activeCpus.push_back(false);
272
273 return id;
274}
275
276int
277System::numRunningContexts()
278{
279 int running = 0;
280 for (int i = 0; i < _numContexts; ++i) {
281 if (threadContexts[i]->status() != ThreadContext::Halted)
282 ++running;
283 }
284 return running;
285}
286
287void
288System::initState()
289{
290 if (FullSystem) {
291 for (int i = 0; i < threadContexts.size(); i++)
292 TheISA::startupCPU(threadContexts[i], i);
293 // Moved from the constructor to here since it relies on the
294 // address map being resolved in the interconnect
295 /**
296 * Load the kernel code into memory
297 */
298 if (params()->kernel != "") {
299 if (params()->kernel_addr_check) {
300 // Validate kernel mapping before loading binary
301 if (!(isMemAddr((kernelStart & loadAddrMask) +
302 loadAddrOffset) &&
303 isMemAddr((kernelEnd & loadAddrMask) +
304 loadAddrOffset))) {
305 fatal("Kernel is mapped to invalid location (not memory). "
306 "kernelStart 0x(%x) - kernelEnd 0x(%x) %#x:%#x\n",
307 kernelStart,
308 kernelEnd, (kernelStart & loadAddrMask) +
309 loadAddrOffset,
310 (kernelEnd & loadAddrMask) + loadAddrOffset);
311 }
312 }
313 // Load program sections into memory
314 kernel->loadSections(physProxy, loadAddrMask, loadAddrOffset);
185 }
186
187 // increment the number of running systems
188 numSystemsRunning++;
189
190 // Set back pointers to the system in all memories
191 for (int x = 0; x < params()->memories.size(); x++)
192 params()->memories[x]->system(this);
193}
194
195System::~System()
196{
197 delete kernelSymtab;
198 delete kernel;
199
200 for (uint32_t j = 0; j < numWorkIds; j++)
201 delete workItemStats[j];
202}
203
204void
205System::init()
206{
207 // check that the system port is connected
208 if (!_systemPort.isConnected())
209 panic("System port on %s is not connected.\n", name());
210}
211
212BaseMasterPort&
213System::getMasterPort(const std::string &if_name, PortID idx)
214{
215 // no need to distinguish at the moment (besides checking)
216 return _systemPort;
217}
218
219void
220System::setMemoryMode(Enums::MemoryMode mode)
221{
222 assert(drainState() == DrainState::Drained);
223 memoryMode = mode;
224}
225
226bool System::breakpoint()
227{
228 if (remoteGDB.size())
229 return remoteGDB[0]->breakpoint();
230 return false;
231}
232
233ContextID
234System::registerThreadContext(ThreadContext *tc, ContextID assigned)
235{
236 int id;
237 if (assigned == InvalidContextID) {
238 for (id = 0; id < threadContexts.size(); id++) {
239 if (!threadContexts[id])
240 break;
241 }
242
243 if (threadContexts.size() <= id)
244 threadContexts.resize(id + 1);
245 } else {
246 if (threadContexts.size() <= assigned)
247 threadContexts.resize(assigned + 1);
248 id = assigned;
249 }
250
251 if (threadContexts[id])
252 fatal("Cannot have two CPUs with the same id (%d)\n", id);
253
254 threadContexts[id] = tc;
255 _numContexts++;
256
257#if THE_ISA != NULL_ISA
258 int port = getRemoteGDBPort();
259 if (port) {
260 RemoteGDB *rgdb = new RemoteGDB(this, tc);
261 GDBListener *gdbl = new GDBListener(rgdb, port + id);
262 gdbl->listen();
263
264 BaseCPU *cpu = tc->getCpuPtr();
265 if (cpu->waitForRemoteGDB()) {
266 inform("%s: Waiting for a remote GDB connection on port %d.\n",
267 cpu->name(), gdbl->getPort());
268
269 gdbl->accept();
270 }
271 if (remoteGDB.size() <= id) {
272 remoteGDB.resize(id + 1);
273 }
274
275 remoteGDB[id] = rgdb;
276 }
277#endif
278
279 activeCpus.push_back(false);
280
281 return id;
282}
283
284int
285System::numRunningContexts()
286{
287 int running = 0;
288 for (int i = 0; i < _numContexts; ++i) {
289 if (threadContexts[i]->status() != ThreadContext::Halted)
290 ++running;
291 }
292 return running;
293}
294
295void
296System::initState()
297{
298 if (FullSystem) {
299 for (int i = 0; i < threadContexts.size(); i++)
300 TheISA::startupCPU(threadContexts[i], i);
301 // Moved from the constructor to here since it relies on the
302 // address map being resolved in the interconnect
303 /**
304 * Load the kernel code into memory
305 */
306 if (params()->kernel != "") {
307 if (params()->kernel_addr_check) {
308 // Validate kernel mapping before loading binary
309 if (!(isMemAddr((kernelStart & loadAddrMask) +
310 loadAddrOffset) &&
311 isMemAddr((kernelEnd & loadAddrMask) +
312 loadAddrOffset))) {
313 fatal("Kernel is mapped to invalid location (not memory). "
314 "kernelStart 0x(%x) - kernelEnd 0x(%x) %#x:%#x\n",
315 kernelStart,
316 kernelEnd, (kernelStart & loadAddrMask) +
317 loadAddrOffset,
318 (kernelEnd & loadAddrMask) + loadAddrOffset);
319 }
320 }
321 // Load program sections into memory
322 kernel->loadSections(physProxy, loadAddrMask, loadAddrOffset);
323 for (const auto &extra_kernel : kernelExtras) {
324 extra_kernel->loadSections(physProxy, loadAddrMask,
325 loadAddrOffset);
326 }
315
316 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
317 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd);
318 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry);
319 DPRINTF(Loader, "Kernel loaded...\n");
320 }
321 }
322}
323
324void
325System::replaceThreadContext(ThreadContext *tc, ContextID context_id)
326{
327 if (context_id >= threadContexts.size()) {
328 panic("replaceThreadContext: bad id, %d >= %d\n",
329 context_id, threadContexts.size());
330 }
331
332 threadContexts[context_id] = tc;
333 if (context_id < remoteGDB.size())
334 remoteGDB[context_id]->replaceThreadContext(tc);
335}
336
337bool
338System::validKvmEnvironment() const
339{
340#if USE_KVM
341 if (threadContexts.empty())
342 return false;
343
344 for (auto tc : threadContexts) {
345 if (dynamic_cast<BaseKvmCPU*>(tc->getCpuPtr()) == nullptr) {
346 return false;
347 }
348 }
349 return true;
350#else
351 return false;
352#endif
353}
354
355Addr
356System::allocPhysPages(int npages)
357{
358 Addr return_addr = pagePtr << PageShift;
359 pagePtr += npages;
360
361 Addr next_return_addr = pagePtr << PageShift;
362
363 AddrRange m5opRange(0xffff0000, 0xffffffff);
364 if (m5opRange.contains(next_return_addr)) {
365 warn("Reached m5ops MMIO region\n");
366 return_addr = 0xffffffff;
367 pagePtr = 0xffffffff >> PageShift;
368 }
369
370 if ((pagePtr << PageShift) > physmem.totalSize())
371 fatal("Out of memory, please increase size of physical memory.");
372 return return_addr;
373}
374
375Addr
376System::memSize() const
377{
378 return physmem.totalSize();
379}
380
381Addr
382System::freeMemSize() const
383{
384 return physmem.totalSize() - (pagePtr << PageShift);
385}
386
387bool
388System::isMemAddr(Addr addr) const
389{
390 return physmem.isMemAddr(addr);
391}
392
393void
394System::drainResume()
395{
396 totalNumInsts = 0;
397}
398
399void
400System::serialize(CheckpointOut &cp) const
401{
402 if (FullSystem)
403 kernelSymtab->serialize("kernel_symtab", cp);
404 SERIALIZE_SCALAR(pagePtr);
405 serializeSymtab(cp);
406
407 // also serialize the memories in the system
408 physmem.serializeSection(cp, "physmem");
409}
410
411
412void
413System::unserialize(CheckpointIn &cp)
414{
415 if (FullSystem)
416 kernelSymtab->unserialize("kernel_symtab", cp);
417 UNSERIALIZE_SCALAR(pagePtr);
418 unserializeSymtab(cp);
419
420 // also unserialize the memories in the system
421 physmem.unserializeSection(cp, "physmem");
422}
423
424void
425System::regStats()
426{
427 MemObject::regStats();
428
429 for (uint32_t j = 0; j < numWorkIds ; j++) {
430 workItemStats[j] = new Stats::Histogram();
431 stringstream namestr;
432 ccprintf(namestr, "work_item_type%d", j);
433 workItemStats[j]->init(20)
434 .name(name() + "." + namestr.str())
435 .desc("Run time stat for" + namestr.str())
436 .prereq(*workItemStats[j]);
437 }
438}
439
440void
441System::workItemEnd(uint32_t tid, uint32_t workid)
442{
443 std::pair<uint32_t,uint32_t> p(tid, workid);
444 if (!lastWorkItemStarted.count(p))
445 return;
446
447 Tick samp = curTick() - lastWorkItemStarted[p];
448 DPRINTF(WorkItems, "Work item end: %d\t%d\t%lld\n", tid, workid, samp);
449
450 if (workid >= numWorkIds)
451 fatal("Got workid greater than specified in system configuration\n");
452
453 workItemStats[workid]->sample(samp);
454 lastWorkItemStarted.erase(p);
455}
456
457void
458System::printSystems()
459{
460 ios::fmtflags flags(cerr.flags());
461
462 vector<System *>::iterator i = systemList.begin();
463 vector<System *>::iterator end = systemList.end();
464 for (; i != end; ++i) {
465 System *sys = *i;
466 cerr << "System " << sys->name() << ": " << hex << sys << endl;
467 }
468
469 cerr.flags(flags);
470}
471
472void
473printSystems()
474{
475 System::printSystems();
476}
477
478MasterID
479System::getMasterId(std::string master_name)
480{
481 // strip off system name if the string starts with it
482 if (startswith(master_name, name()))
483 master_name = master_name.erase(0, name().size() + 1);
484
485 // CPUs in switch_cpus ask for ids again after switching
486 for (int i = 0; i < masterIds.size(); i++) {
487 if (masterIds[i] == master_name) {
488 return i;
489 }
490 }
491
492 // Verify that the statistics haven't been enabled yet
493 // Otherwise objects will have sized their stat buckets and
494 // they will be too small
495
496 if (Stats::enabled()) {
497 fatal("Can't request a masterId after regStats(). "
498 "You must do so in init().\n");
499 }
500
501 masterIds.push_back(master_name);
502
503 return masterIds.size() - 1;
504}
505
506std::string
507System::getMasterName(MasterID master_id)
508{
509 if (master_id >= masterIds.size())
510 fatal("Invalid master_id passed to getMasterName()\n");
511
512 return masterIds[master_id];
513}
514
515System *
516SystemParams::create()
517{
518 return new System(this);
519}
327
328 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
329 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd);
330 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry);
331 DPRINTF(Loader, "Kernel loaded...\n");
332 }
333 }
334}
335
336void
337System::replaceThreadContext(ThreadContext *tc, ContextID context_id)
338{
339 if (context_id >= threadContexts.size()) {
340 panic("replaceThreadContext: bad id, %d >= %d\n",
341 context_id, threadContexts.size());
342 }
343
344 threadContexts[context_id] = tc;
345 if (context_id < remoteGDB.size())
346 remoteGDB[context_id]->replaceThreadContext(tc);
347}
348
349bool
350System::validKvmEnvironment() const
351{
352#if USE_KVM
353 if (threadContexts.empty())
354 return false;
355
356 for (auto tc : threadContexts) {
357 if (dynamic_cast<BaseKvmCPU*>(tc->getCpuPtr()) == nullptr) {
358 return false;
359 }
360 }
361 return true;
362#else
363 return false;
364#endif
365}
366
367Addr
368System::allocPhysPages(int npages)
369{
370 Addr return_addr = pagePtr << PageShift;
371 pagePtr += npages;
372
373 Addr next_return_addr = pagePtr << PageShift;
374
375 AddrRange m5opRange(0xffff0000, 0xffffffff);
376 if (m5opRange.contains(next_return_addr)) {
377 warn("Reached m5ops MMIO region\n");
378 return_addr = 0xffffffff;
379 pagePtr = 0xffffffff >> PageShift;
380 }
381
382 if ((pagePtr << PageShift) > physmem.totalSize())
383 fatal("Out of memory, please increase size of physical memory.");
384 return return_addr;
385}
386
387Addr
388System::memSize() const
389{
390 return physmem.totalSize();
391}
392
393Addr
394System::freeMemSize() const
395{
396 return physmem.totalSize() - (pagePtr << PageShift);
397}
398
399bool
400System::isMemAddr(Addr addr) const
401{
402 return physmem.isMemAddr(addr);
403}
404
405void
406System::drainResume()
407{
408 totalNumInsts = 0;
409}
410
411void
412System::serialize(CheckpointOut &cp) const
413{
414 if (FullSystem)
415 kernelSymtab->serialize("kernel_symtab", cp);
416 SERIALIZE_SCALAR(pagePtr);
417 serializeSymtab(cp);
418
419 // also serialize the memories in the system
420 physmem.serializeSection(cp, "physmem");
421}
422
423
424void
425System::unserialize(CheckpointIn &cp)
426{
427 if (FullSystem)
428 kernelSymtab->unserialize("kernel_symtab", cp);
429 UNSERIALIZE_SCALAR(pagePtr);
430 unserializeSymtab(cp);
431
432 // also unserialize the memories in the system
433 physmem.unserializeSection(cp, "physmem");
434}
435
436void
437System::regStats()
438{
439 MemObject::regStats();
440
441 for (uint32_t j = 0; j < numWorkIds ; j++) {
442 workItemStats[j] = new Stats::Histogram();
443 stringstream namestr;
444 ccprintf(namestr, "work_item_type%d", j);
445 workItemStats[j]->init(20)
446 .name(name() + "." + namestr.str())
447 .desc("Run time stat for" + namestr.str())
448 .prereq(*workItemStats[j]);
449 }
450}
451
452void
453System::workItemEnd(uint32_t tid, uint32_t workid)
454{
455 std::pair<uint32_t,uint32_t> p(tid, workid);
456 if (!lastWorkItemStarted.count(p))
457 return;
458
459 Tick samp = curTick() - lastWorkItemStarted[p];
460 DPRINTF(WorkItems, "Work item end: %d\t%d\t%lld\n", tid, workid, samp);
461
462 if (workid >= numWorkIds)
463 fatal("Got workid greater than specified in system configuration\n");
464
465 workItemStats[workid]->sample(samp);
466 lastWorkItemStarted.erase(p);
467}
468
469void
470System::printSystems()
471{
472 ios::fmtflags flags(cerr.flags());
473
474 vector<System *>::iterator i = systemList.begin();
475 vector<System *>::iterator end = systemList.end();
476 for (; i != end; ++i) {
477 System *sys = *i;
478 cerr << "System " << sys->name() << ": " << hex << sys << endl;
479 }
480
481 cerr.flags(flags);
482}
483
484void
485printSystems()
486{
487 System::printSystems();
488}
489
490MasterID
491System::getMasterId(std::string master_name)
492{
493 // strip off system name if the string starts with it
494 if (startswith(master_name, name()))
495 master_name = master_name.erase(0, name().size() + 1);
496
497 // CPUs in switch_cpus ask for ids again after switching
498 for (int i = 0; i < masterIds.size(); i++) {
499 if (masterIds[i] == master_name) {
500 return i;
501 }
502 }
503
504 // Verify that the statistics haven't been enabled yet
505 // Otherwise objects will have sized their stat buckets and
506 // they will be too small
507
508 if (Stats::enabled()) {
509 fatal("Can't request a masterId after regStats(). "
510 "You must do so in init().\n");
511 }
512
513 masterIds.push_back(master_name);
514
515 return masterIds.size() - 1;
516}
517
518std::string
519System::getMasterName(MasterID master_id)
520{
521 if (master_id >= masterIds.size())
522 fatal("Invalid master_id passed to getMasterName()\n");
523
524 return masterIds[master_id];
525}
526
527System *
528SystemParams::create()
529{
530 return new System(this);
531}