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 "config/full_system.hh"
57 #include "cpu/pc_event.hh"
58 #include "enums/MemoryMode.hh"
59 #include "mem/mem_object.hh"
60 #include "mem/port.hh"
61 #include "params/System.hh"
64 #include "kern/system_events.hh"
75 class FSTranslatingPortProxy;
80 class System : public MemObject
85 * Private class for the system port which is only used as a
86 * master for debug access and for non-structural entities that do
87 * not have a port of their own.
89 class SystemPort : public Port
94 * Create a system port with a name and an owner.
96 SystemPort(const std::string &_name, MemObject *_owner)
99 bool recvTiming(PacketPtr pkt)
100 { panic("SystemPort does not receive timing!\n"); return false; }
101 Tick recvAtomic(PacketPtr pkt)
102 { panic("SystemPort does not receive atomic!\n"); return 0; }
103 void recvFunctional(PacketPtr pkt)
104 { panic("SystemPort does not receive functional!\n"); }
105 void recvStatusChange(Status status) { }
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.
218 uint64_t allocatePID()
223 /** Amount of physical memory that is still free */
226 /** Amount of physical memory that exists */
230 #endif // FULL_SYSTEM
233 Enums::MemoryMode memoryMode;
234 uint64_t workItemsBegin;
235 uint64_t workItemsEnd;
237 std::vector<bool> activeCpus;
240 virtual void regStats();
242 * Called by pseudo_inst to track the number of work items started by this
248 return ++workItemsBegin;
252 * Called by pseudo_inst to track the number of work items completed by
258 return ++workItemsEnd;
262 * Called by pseudo_inst to mark the cpus actively executing work items.
263 * Returns the total number of cpus that have executed work item begin or
267 markWorkItem(int index)
270 assert(index < activeCpus.size());
271 activeCpus[index] = true;
272 for (std::vector<bool>::iterator i = activeCpus.begin();
273 i < activeCpus.end(); i++) {
279 inline void workItemBegin(uint32_t tid, uint32_t workid)
281 std::pair<uint32_t,uint32_t> p(tid, workid);
282 lastWorkItemStarted[p] = curTick();
285 void workItemEnd(uint32_t tid, uint32_t workid);
289 * Fix up an address used to match PCs for hooking simulator
290 * events on to target function executions. See comment in
291 * system.cc for details.
293 virtual Addr fixFuncEventAddr(Addr addr) = 0;
296 * Add a function-based event to the given function, to be looked
297 * up in the specified symbol table.
300 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
302 Addr addr = 0; // initialize only to avoid compiler warning
304 if (symtab->findAddress(lbl, addr)) {
305 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
312 /** Add a function-based event to kernel code. */
314 T *addKernelFuncEvent(const char *lbl)
316 return addFuncEvent<T>(kernelSymtab, lbl);
321 std::vector<BaseRemoteGDB *> remoteGDB;
322 std::vector<GDBListener *> gdbListen;
326 typedef SystemParams Params;
337 const Params *params() const { return (const Params *)_params; }
343 * Returns the addess the kernel starts at.
344 * @return address the kernel starts at
346 Addr getKernelStart() const { return kernelStart; }
349 * Returns the addess the kernel ends at.
350 * @return address the kernel ends at
352 Addr getKernelEnd() const { return kernelEnd; }
355 * Returns the addess the entry point to the kernel code.
356 * @return entry point of the kernel code
358 Addr getKernelEntry() const { return kernelEntry; }
362 /// Allocate npages contiguous unused physical pages
363 /// @return Starting address of first page
364 Addr allocPhysPages(int npages);
366 #endif // FULL_SYSTEM
368 int registerThreadContext(ThreadContext *tc, int assigned=-1);
369 void replaceThreadContext(ThreadContext *tc, int context_id);
371 void serialize(std::ostream &os);
372 void unserialize(Checkpoint *cp, const std::string §ion);
373 virtual void resume();
376 Counter totalNumInsts;
377 EventQueue instEventQueue;
378 std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted;
379 std::map<uint32_t, Stats::Histogram*> workItemStats;
381 ////////////////////////////////////////////
383 // STATIC GLOBAL SYSTEM LIST
385 ////////////////////////////////////////////
387 static std::vector<System *> systemList;
388 static int numSystemsRunning;
390 static void printSystems();
395 #endif // __SYSTEM_HH__