2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * Copyright (c) 2011 Regents of the University of California
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Authors: Steve Reinhardt
41 #include "base/loader/symtab.hh"
42 #include "base/misc.hh"
43 #include "base/statistics.hh"
44 #include "config/full_system.hh"
45 #include "cpu/pc_event.hh"
46 #include "enums/MemoryMode.hh"
47 #include "mem/port.hh"
48 #include "params/System.hh"
49 #include "sim/sim_object.hh"
52 #include "kern/system_events.hh"
68 class System : public SimObject
72 static const char *MemoryModeStrings[3];
81 /** Change the memory mode of the system. This should only be called by the
83 * @param mode Mode to change to (atomic/timing)
85 void setMemoryMode(Enums::MemoryMode mode);
87 PhysicalMemory *physmem;
88 PCEventQueue pcEventQueue;
90 std::vector<ThreadContext *> threadContexts;
93 ThreadContext *getThreadContext(ThreadID tid)
95 return threadContexts[tid];
100 assert(_numContexts == (int)threadContexts.size());
104 /** Return number of running (non-halted) thread contexts in
105 * system. These threads could be Active or Suspended. */
106 int numRunningContexts();
108 /** List to store ranges of memories in this system */
109 AddrRangeList memRanges;
111 /** check if an address points to valid system memory
112 * and thus we can fetch instructions out of it
114 bool isMemory(const Addr addr) const;
121 /** Port to physical memory used for writing object files into ram at
123 FunctionalPort *functionalPort;
124 VirtualPort *virtPort;
126 /** kernel symbol table */
127 SymbolTable *kernelSymtab;
129 /** Object pointer for the kernel code */
132 /** Begining of kernel code */
135 /** End of kernel code */
138 /** Entry point in the kernel to start at */
141 /** Mask that should be anded for binary/symbol loading.
142 * This allows one two different OS requirements for the same ISA to be
143 * handled. Some OSes are compiled for a virtual address and need to be
144 * loaded into physical memory that starts at address 0, while other
145 * bare metal tools generate images that start at address 0.
149 #endif // FULL_SYSTEM
155 uint64_t allocatePID()
160 /** Amount of physical memory that is still free */
163 /** Amount of physical memory that exists */
167 Enums::MemoryMode memoryMode;
168 uint64_t workItemsBegin;
169 uint64_t workItemsEnd;
170 std::vector<bool> activeCpus;
174 * Called by pseudo_inst to track the number of work items started by this
180 return ++workItemsBegin;
184 * Called by pseudo_inst to track the number of work items completed by
190 return ++workItemsEnd;
194 * Called by pseudo_inst to mark the cpus actively executing work items.
195 * Returns the total number of cpus that have executed work item begin or
199 markWorkItem(int index)
202 assert(index < activeCpus.size());
203 activeCpus[index] = true;
204 for (std::vector<bool>::iterator i = activeCpus.begin();
205 i < activeCpus.end(); i++) {
213 * Fix up an address used to match PCs for hooking simulator
214 * events on to target function executions. See comment in
215 * system.cc for details.
217 virtual Addr fixFuncEventAddr(Addr addr) = 0;
220 * Add a function-based event to the given function, to be looked
221 * up in the specified symbol table.
224 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
226 Addr addr = 0; // initialize only to avoid compiler warning
228 if (symtab->findAddress(lbl, addr)) {
229 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
236 /** Add a function-based event to kernel code. */
238 T *addKernelFuncEvent(const char *lbl)
240 return addFuncEvent<T>(kernelSymtab, lbl);
245 std::vector<BaseRemoteGDB *> remoteGDB;
246 std::vector<GDBListener *> gdbListen;
250 typedef SystemParams Params;
261 const Params *params() const { return (const Params *)_params; }
267 * Returns the addess the kernel starts at.
268 * @return address the kernel starts at
270 Addr getKernelStart() const { return kernelStart; }
273 * Returns the addess the kernel ends at.
274 * @return address the kernel ends at
276 Addr getKernelEnd() const { return kernelEnd; }
279 * Returns the addess the entry point to the kernel code.
280 * @return entry point of the kernel code
282 Addr getKernelEntry() const { return kernelEntry; }
288 int registerThreadContext(ThreadContext *tc, int assigned=-1);
289 void replaceThreadContext(ThreadContext *tc, int context_id);
291 void serialize(std::ostream &os);
292 void unserialize(Checkpoint *cp, const std::string §ion);
293 virtual void resume();
296 Counter totalNumInsts;
297 EventQueue instEventQueue;
299 ////////////////////////////////////////////
301 // STATIC GLOBAL SYSTEM LIST
303 ////////////////////////////////////////////
305 static std::vector<System *> systemList;
306 static int numSystemsRunning;
308 static void printSystems();
313 #endif // __SYSTEM_HH__