2 * Copyright (c) 2011 ARM Limited
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.
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.
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.
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.
41 * Authors: Steve Reinhardt
48 #include "arch/isa_traits.hh"
49 #include "arch/remote_gdb.hh"
50 #include "arch/utility.hh"
51 #include "base/loader/object_file.hh"
52 #include "base/loader/symtab.hh"
53 #include "base/trace.hh"
54 #include "config/full_system.hh"
55 #include "config/the_isa.hh"
56 #include "cpu/thread_context.hh"
57 #include "debug/Loader.hh"
58 #include "debug/WorkItems.hh"
59 #include "mem/mem_object.hh"
60 #include "mem/physical.hh"
61 #include "sim/byteswap.hh"
62 #include "sim/debug.hh"
63 #include "sim/system.hh"
66 #include "arch/vtophys.hh"
67 #include "kern/kernel_stats.hh"
68 #include "mem/vport.hh"
70 #include "params/System.hh"
74 using namespace TheISA
;
76 vector
<System
*> System::systemList
;
78 int System::numSystemsRunning
= 0;
80 System::System(Params
*p
)
81 : SimObject(p
), physmem(p
->physmem
), _numContexts(0),
83 init_param(p
->init_param
),
84 loadAddrMask(p
->load_addr_mask
),
89 memoryMode(p
->mem_mode
),
92 numWorkIds(p
->num_work_ids
),
95 instEventQueue("system instruction-based event queue")
97 // add self to global system list
98 systemList
.push_back(this);
100 /** Keep track of all memories we can execute code out of
103 for (int x
= 0; x
< p
->memories
.size(); x
++) {
106 memRanges
.push_back(RangeSize(p
->memories
[x
]->start(),
107 p
->memories
[x
]->size()));
111 kernelSymtab
= new SymbolTable
;
112 if (!debugSymbolTable
)
113 debugSymbolTable
= new SymbolTable
;
117 * Get a functional port to memory
120 functionalPort
= new FunctionalPort(name() + "-fport");
121 mem_port
= physmem
->getPort("functional");
122 functionalPort
->setPeer(mem_port
);
123 mem_port
->setPeer(functionalPort
);
125 virtPort
= new VirtualPort(name() + "-fport");
126 mem_port
= physmem
->getPort("functional");
127 virtPort
->setPeer(mem_port
);
128 mem_port
->setPeer(virtPort
);
132 * Load the kernel code into memory
134 if (params()->kernel
== "") {
135 inform("No kernel set for full system simulation. Assuming you know what"
136 " you're doing...\n");
139 kernel
= createObjectFile(params()->kernel
);
140 inform("kernel located at: %s", params()->kernel
);
143 fatal("Could not load kernel file %s", params()->kernel
);
145 // Load program sections into memory
146 kernel
->loadSections(functionalPort
, loadAddrMask
);
148 // setup entry points
149 kernelStart
= kernel
->textBase();
150 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
151 kernelEntry
= kernel
->entryPoint();
154 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
155 fatal("could not load kernel symbols\n");
157 if (!kernel
->loadLocalSymbols(kernelSymtab
))
158 fatal("could not load kernel local symbols\n");
160 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
161 fatal("could not load kernel symbols\n");
163 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
164 fatal("could not load kernel local symbols\n");
166 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
167 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
168 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
169 DPRINTF(Loader
, "Kernel loaded...\n");
171 #endif // FULL_SYSTEM
173 // increment the number of running systms
185 panic("System::fixFuncEventAddr needs to be rewritten "
186 "to work with syscall emulation");
187 #endif // FULL_SYSTEM}
189 for (uint32_t j
= 0; j
< numWorkIds
; j
++)
190 delete workItemStats
[j
];
194 System::setMemoryMode(Enums::MemoryMode mode
)
196 assert(getState() == Drained
);
200 bool System::breakpoint()
202 if (remoteGDB
.size())
203 return remoteGDB
[0]->breakpoint();
208 * Setting rgdb_wait to a positive integer waits for a remote debugger to
209 * connect to that context ID before continuing. This should really
210 be a parameter on the CPU object or something...
215 System::registerThreadContext(ThreadContext
*tc
, int assigned
)
218 if (assigned
== -1) {
219 for (id
= 0; id
< threadContexts
.size(); id
++) {
220 if (!threadContexts
[id
])
224 if (threadContexts
.size() <= id
)
225 threadContexts
.resize(id
+ 1);
227 if (threadContexts
.size() <= assigned
)
228 threadContexts
.resize(assigned
+ 1);
232 if (threadContexts
[id
])
233 fatal("Cannot have two CPUs with the same id (%d)\n", id
);
235 threadContexts
[id
] = tc
;
238 int port
= getRemoteGDBPort();
240 RemoteGDB
*rgdb
= new RemoteGDB(this, tc
);
241 GDBListener
*gdbl
= new GDBListener(rgdb
, port
+ id
);
244 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
247 if (remoteGDB
.size() <= id
) {
248 remoteGDB
.resize(id
+ 1);
251 remoteGDB
[id
] = rgdb
;
254 activeCpus
.push_back(false);
260 System::numRunningContexts()
263 for (int i
= 0; i
< _numContexts
; ++i
) {
264 if (threadContexts
[i
]->status() != ThreadContext::Halted
)
275 for (i
= 0; i
< threadContexts
.size(); i
++)
276 TheISA::startupCPU(threadContexts
[i
], i
);
281 System::replaceThreadContext(ThreadContext
*tc
, int context_id
)
283 if (context_id
>= threadContexts
.size()) {
284 panic("replaceThreadContext: bad id, %d >= %d\n",
285 context_id
, threadContexts
.size());
288 threadContexts
[context_id
] = tc
;
289 if (context_id
< remoteGDB
.size())
290 remoteGDB
[context_id
]->replaceThreadContext(tc
);
295 System::allocPhysPages(int npages
)
297 Addr return_addr
= pagePtr
<< LogVMPageSize
;
299 if (return_addr
>= physmem
->size())
300 fatal("Out of memory, please increase size of physical memory.");
307 return physmem
->size();
311 System::freeMemSize()
313 return physmem
->size() - (pagePtr
<< LogVMPageSize
);
319 System::isMemory(const Addr addr
) const
321 std::list
<Range
<Addr
> >::const_iterator i
;
322 for (i
= memRanges
.begin(); i
!= memRanges
.end(); i
++) {
337 System::serialize(ostream
&os
)
340 kernelSymtab
->serialize("kernel_symtab", os
);
341 #else // !FULL_SYSTEM
342 SERIALIZE_SCALAR(pagePtr
);
343 SERIALIZE_SCALAR(nextPID
);
349 System::unserialize(Checkpoint
*cp
, const string
§ion
)
352 kernelSymtab
->unserialize("kernel_symtab", cp
, section
);
353 #else // !FULL_SYSTEM
354 UNSERIALIZE_SCALAR(pagePtr
);
355 UNSERIALIZE_SCALAR(nextPID
);
362 for (uint32_t j
= 0; j
< numWorkIds
; j
++) {
363 workItemStats
[j
] = new Stats::Histogram();
364 stringstream namestr
;
365 ccprintf(namestr
, "work_item_type%d", j
);
366 workItemStats
[j
]->init(20)
367 .name(name() + "." + namestr
.str())
368 .desc("Run time stat for" + namestr
.str())
369 .prereq(*workItemStats
[j
]);
374 System::workItemEnd(uint32_t tid
, uint32_t workid
)
376 std::pair
<uint32_t,uint32_t> p(tid
, workid
);
377 if (!lastWorkItemStarted
.count(p
))
380 Tick samp
= curTick() - lastWorkItemStarted
[p
];
381 DPRINTF(WorkItems
, "Work item end: %d\t%d\t%lld\n", tid
, workid
, samp
);
383 if (workid
>= numWorkIds
)
384 fatal("Got workid greater than specified in system configuration\n");
386 workItemStats
[workid
]->sample(samp
);
387 lastWorkItemStarted
.erase(p
);
391 System::printSystems()
393 vector
<System
*>::iterator i
= systemList
.begin();
394 vector
<System
*>::iterator end
= systemList
.end();
395 for (; i
!= end
; ++i
) {
397 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
404 System::printSystems();
407 const char *System::MemoryModeStrings
[3] = {"invalid", "atomic",
413 SystemParams::create()
415 return new System(this);