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/mem_object.hh"
60 #include "mem/port.hh"
61 #include "params/System.hh"
65 class FSTranslatingPortProxy;
74 class System : public MemObject
79 * Private class for the system port which is only used as a
80 * master for debug access and for non-structural entities that do
81 * not have a port of their own.
83 class SystemPort : public Port
88 * Create a system port with a name and an owner.
90 SystemPort(const std::string &_name, MemObject *_owner)
93 bool recvTiming(PacketPtr pkt)
94 { panic("SystemPort does not receive timing!\n"); return false; }
95 Tick recvAtomic(PacketPtr pkt)
96 { panic("SystemPort does not receive atomic!\n"); return 0; }
97 void recvFunctional(PacketPtr pkt)
98 { panic("SystemPort does not receive functional!\n"); }
101 * The system port is a master port connected to a single
102 * slave and thus do not care about what ranges the slave
103 * covers (as there is nothing to choose from).
105 void recvRangeChange() { }
109 SystemPort _systemPort;
114 * After all objects have been created and all ports are
115 * connected, check that the system port is connected.
120 * Get a pointer to the system port that can be used by
121 * non-structural simulation objects like processes or threads, or
122 * external entities like loaders and debuggers, etc, to access
125 * @return a pointer to the system port we own
127 Port* getSystemPort() { return &_systemPort; }
130 * Additional function to return the Port of a memory object.
132 Port *getPort(const std::string &if_name, int idx = -1);
134 static const char *MemoryModeStrings[3];
143 /** Change the memory mode of the system. This should only be called by the
145 * @param mode Mode to change to (atomic/timing)
147 void setMemoryMode(Enums::MemoryMode mode);
149 PhysicalMemory *physmem;
150 PCEventQueue pcEventQueue;
152 std::vector<ThreadContext *> threadContexts;
155 ThreadContext *getThreadContext(ThreadID tid)
157 return threadContexts[tid];
162 assert(_numContexts == (int)threadContexts.size());
166 /** Return number of running (non-halted) thread contexts in
167 * system. These threads could be Active or Suspended. */
168 int numRunningContexts();
170 /** List to store ranges of memories in this system */
171 AddrRangeList memRanges;
173 /** check if an address points to valid system memory
174 * and thus we can fetch instructions out of it
176 bool isMemory(const Addr addr) const;
182 /** Port to physical memory used for writing object files into ram at
184 PortProxy* physProxy;
185 FSTranslatingPortProxy* virtProxy;
187 /** kernel symbol table */
188 SymbolTable *kernelSymtab;
190 /** Object pointer for the kernel code */
193 /** Begining of kernel code */
196 /** End of kernel code */
199 /** Entry point in the kernel to start at */
202 /** Mask that should be anded for binary/symbol loading.
203 * This allows one two different OS requirements for the same ISA to be
204 * handled. Some OSes are compiled for a virtual address and need to be
205 * loaded into physical memory that starts at address 0, while other
206 * bare metal tools generate images that start at address 0.
214 uint64_t allocatePID()
219 /** Amount of physical memory that is still free */
222 /** Amount of physical memory that exists */
226 Enums::MemoryMode memoryMode;
227 uint64_t workItemsBegin;
228 uint64_t workItemsEnd;
230 std::vector<bool> activeCpus;
233 virtual void regStats();
235 * Called by pseudo_inst to track the number of work items started by this
241 return ++workItemsBegin;
245 * Called by pseudo_inst to track the number of work items completed by
251 return ++workItemsEnd;
255 * Called by pseudo_inst to mark the cpus actively executing work items.
256 * Returns the total number of cpus that have executed work item begin or
260 markWorkItem(int index)
263 assert(index < activeCpus.size());
264 activeCpus[index] = true;
265 for (std::vector<bool>::iterator i = activeCpus.begin();
266 i < activeCpus.end(); i++) {
272 inline void workItemBegin(uint32_t tid, uint32_t workid)
274 std::pair<uint32_t,uint32_t> p(tid, workid);
275 lastWorkItemStarted[p] = curTick();
278 void workItemEnd(uint32_t tid, uint32_t workid);
281 * Fix up an address used to match PCs for hooking simulator
282 * events on to target function executions. See comment in
283 * system.cc for details.
285 virtual Addr fixFuncEventAddr(Addr addr)
287 panic("Base fixFuncEventAddr not implemented.\n");
291 * Add a function-based event to the given function, to be looked
292 * up in the specified symbol table.
295 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
297 Addr addr = 0; // initialize only to avoid compiler warning
299 if (symtab->findAddress(lbl, addr)) {
300 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
307 /** Add a function-based event to kernel code. */
309 T *addKernelFuncEvent(const char *lbl)
311 return addFuncEvent<T>(kernelSymtab, lbl);
315 std::vector<BaseRemoteGDB *> remoteGDB;
316 std::vector<GDBListener *> gdbListen;
320 typedef SystemParams Params;
331 const Params *params() const { return (const Params *)_params; }
336 * Returns the addess the kernel starts at.
337 * @return address the kernel starts at
339 Addr getKernelStart() const { return kernelStart; }
342 * Returns the addess the kernel ends at.
343 * @return address the kernel ends at
345 Addr getKernelEnd() const { return kernelEnd; }
348 * Returns the addess the entry point to the kernel code.
349 * @return entry point of the kernel code
351 Addr getKernelEntry() const { return kernelEntry; }
353 /// Allocate npages contiguous unused physical pages
354 /// @return Starting address of first page
355 Addr allocPhysPages(int npages);
357 int registerThreadContext(ThreadContext *tc, int assigned=-1);
358 void replaceThreadContext(ThreadContext *tc, int context_id);
360 void serialize(std::ostream &os);
361 void unserialize(Checkpoint *cp, const std::string §ion);
362 virtual void resume();
365 Counter totalNumInsts;
366 EventQueue instEventQueue;
367 std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted;
368 std::map<uint32_t, Stats::Histogram*> workItemStats;
370 ////////////////////////////////////////////
372 // STATIC GLOBAL SYSTEM LIST
374 ////////////////////////////////////////////
376 static std::vector<System *> systemList;
377 static int numSystemsRunning;
379 static void printSystems();
384 #endif // __SYSTEM_HH__