2 * Copyright (c) 2012 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) 2002-2005 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
53 #include "base/loader/symtab.hh"
54 #include "base/misc.hh"
55 #include "base/statistics.hh"
56 #include "cpu/pc_event.hh"
57 #include "enums/MemoryMode.hh"
58 #include "kern/system_events.hh"
59 #include "mem/fs_translating_port_proxy.hh"
60 #include "mem/mem_object.hh"
61 #include "mem/port.hh"
62 #include "mem/physical.hh"
63 #include "params/System.hh"
72 class System : public MemObject
77 * Private class for the system port which is only used as a
78 * master for debug access and for non-structural entities that do
79 * not have a port of their own.
81 class SystemPort : public MasterPort
86 * Create a system port with a name and an owner.
88 SystemPort(const std::string &_name, MemObject *_owner)
89 : MasterPort(_name, _owner)
91 bool recvTimingResp(PacketPtr pkt)
92 { panic("SystemPort does not receive timing!\n"); return false; }
94 { panic("SystemPort does not expect retry!\n"); }
97 SystemPort _systemPort;
102 * After all objects have been created and all ports are
103 * connected, check that the system port is connected.
108 * Get a reference to the system port that can be used by
109 * non-structural simulation objects like processes or threads, or
110 * external entities like loaders and debuggers, etc, to access
113 * @return a reference to the system port we own
115 MasterPort& getSystemPort() { return _systemPort; }
118 * Additional function to return the Port of a memory object.
120 BaseMasterPort& getMasterPort(const std::string &if_name,
121 PortID idx = InvalidPortID);
123 static const char *MemoryModeStrings[3];
132 /** Change the memory mode of the system. This should only be called by the
134 * @param mode Mode to change to (atomic/timing)
136 void setMemoryMode(Enums::MemoryMode mode);
138 PCEventQueue pcEventQueue;
140 std::vector<ThreadContext *> threadContexts;
143 ThreadContext *getThreadContext(ThreadID tid)
145 return threadContexts[tid];
150 assert(_numContexts == (int)threadContexts.size());
154 /** Return number of running (non-halted) thread contexts in
155 * system. These threads could be Active or Suspended. */
156 int numRunningContexts();
162 /** Port to physical memory used for writing object files into ram at
165 FSTranslatingPortProxy virtProxy;
167 /** kernel symbol table */
168 SymbolTable *kernelSymtab;
170 /** Object pointer for the kernel code */
173 /** Begining of kernel code */
176 /** End of kernel code */
179 /** Entry point in the kernel to start at */
182 /** Mask that should be anded for binary/symbol loading.
183 * This allows one two different OS requirements for the same ISA to be
184 * handled. Some OSes are compiled for a virtual address and need to be
185 * loaded into physical memory that starts at address 0, while other
186 * bare metal tools generate images that start at address 0.
194 uint64_t allocatePID()
199 /** Get a pointer to access the physical memory of the system */
200 PhysicalMemory& getPhysMem() { return physmem; }
202 /** Amount of physical memory that is still free */
203 Addr freeMemSize() const;
205 /** Amount of physical memory that exists */
206 Addr memSize() const;
209 * Check if a physical address is within a range of a memory that
210 * is part of the global address map.
212 * @param addr A physical address
213 * @return Whether the address corresponds to a memory
215 bool isMemAddr(Addr addr) const;
219 PhysicalMemory physmem;
221 Enums::MemoryMode memoryMode;
222 uint64_t workItemsBegin;
223 uint64_t workItemsEnd;
225 std::vector<bool> activeCpus;
227 /** This array is a per-sytem list of all devices capable of issuing a
228 * memory system request and an associated string for each master id.
229 * It's used to uniquely id any master in the system by name for things
230 * like cache statistics.
232 std::vector<std::string> masterIds;
236 /** Request an id used to create a request object in the system. All objects
237 * that intend to issues requests into the memory system must request an id
238 * in the init() phase of startup. All master ids must be fixed by the
239 * regStats() phase that immediately preceeds it. This allows objects in the
240 * memory system to understand how many masters may exist and
241 * appropriately name the bins of their per-master stats before the stats
244 MasterID getMasterId(std::string req_name);
246 /** Get the name of an object for a given request id.
248 std::string getMasterName(MasterID master_id);
250 /** Get the number of masters registered in the system */
251 MasterID maxMasters()
253 return masterIds.size();
256 virtual void regStats();
258 * Called by pseudo_inst to track the number of work items started by this
264 return ++workItemsBegin;
268 * Called by pseudo_inst to track the number of work items completed by
274 return ++workItemsEnd;
278 * Called by pseudo_inst to mark the cpus actively executing work items.
279 * Returns the total number of cpus that have executed work item begin or
283 markWorkItem(int index)
286 assert(index < activeCpus.size());
287 activeCpus[index] = true;
288 for (std::vector<bool>::iterator i = activeCpus.begin();
289 i < activeCpus.end(); i++) {
295 inline void workItemBegin(uint32_t tid, uint32_t workid)
297 std::pair<uint32_t,uint32_t> p(tid, workid);
298 lastWorkItemStarted[p] = curTick();
301 void workItemEnd(uint32_t tid, uint32_t workid);
304 * Fix up an address used to match PCs for hooking simulator
305 * events on to target function executions. See comment in
306 * system.cc for details.
308 virtual Addr fixFuncEventAddr(Addr addr)
310 panic("Base fixFuncEventAddr not implemented.\n");
314 * Add a function-based event to the given function, to be looked
315 * up in the specified symbol table.
318 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
320 Addr addr = 0; // initialize only to avoid compiler warning
322 if (symtab->findAddress(lbl, addr)) {
323 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
330 /** Add a function-based event to kernel code. */
332 T *addKernelFuncEvent(const char *lbl)
334 return addFuncEvent<T>(kernelSymtab, lbl);
338 std::vector<BaseRemoteGDB *> remoteGDB;
339 std::vector<GDBListener *> gdbListen;
343 typedef SystemParams Params;
354 const Params *params() const { return (const Params *)_params; }
359 * Returns the addess the kernel starts at.
360 * @return address the kernel starts at
362 Addr getKernelStart() const { return kernelStart; }
365 * Returns the addess the kernel ends at.
366 * @return address the kernel ends at
368 Addr getKernelEnd() const { return kernelEnd; }
371 * Returns the addess the entry point to the kernel code.
372 * @return entry point of the kernel code
374 Addr getKernelEntry() const { return kernelEntry; }
376 /// Allocate npages contiguous unused physical pages
377 /// @return Starting address of first page
378 Addr allocPhysPages(int npages);
380 int registerThreadContext(ThreadContext *tc, int assigned=-1);
381 void replaceThreadContext(ThreadContext *tc, int context_id);
383 void serialize(std::ostream &os);
384 void unserialize(Checkpoint *cp, const std::string §ion);
385 virtual void resume();
388 Counter totalNumInsts;
389 EventQueue instEventQueue;
390 std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted;
391 std::map<uint32_t, Stats::Histogram*> workItemStats;
393 ////////////////////////////////////////////
395 // STATIC GLOBAL SYSTEM LIST
397 ////////////////////////////////////////////
399 static std::vector<System *> systemList;
400 static int numSystemsRunning;
402 static void printSystems();
404 // For futex system call
405 std::map<uint64_t, std::list<ThreadContext *> * > futexMap;
410 * If needed, serialize additional symbol table entries for a
411 * specific subclass of this sytem. Currently this is used by
414 * @param os stream to serialize to
416 virtual void serializeSymtab(std::ostream &os) {}
419 * If needed, unserialize additional symbol table entries for a
420 * specific subclass of this system.
422 * @param cp checkpoint to unserialize from
423 * @param section relevant section in the checkpoint
425 virtual void unserializeSymtab(Checkpoint *cp,
426 const std::string §ion) {}
430 #endif // __SYSTEM_HH__