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;
120 /** Port to physical memory used for writing object files into ram at
122 FunctionalPort *functionalPort;
123 VirtualPort *virtPort;
125 /** kernel symbol table */
126 SymbolTable *kernelSymtab;
128 /** Object pointer for the kernel code */
131 /** Begining of kernel code */
134 /** End of kernel code */
137 /** Entry point in the kernel to start at */
140 /** Mask that should be anded for binary/symbol loading.
141 * This allows one two different OS requirements for the same ISA to be
142 * handled. Some OSes are compiled for a virtual address and need to be
143 * loaded into physical memory that starts at address 0, while other
144 * bare metal tools generate images that start at address 0.
156 uint64_t allocatePID()
161 /** Amount of physical memory that is still free */
164 /** Amount of physical memory that exists */
168 #endif // FULL_SYSTEM
171 Enums::MemoryMode memoryMode;
172 uint64_t workItemsBegin;
173 uint64_t workItemsEnd;
174 std::vector<bool> activeCpus;
178 * Called by pseudo_inst to track the number of work items started by this
184 return ++workItemsBegin;
188 * Called by pseudo_inst to track the number of work items completed by
194 return ++workItemsEnd;
198 * Called by pseudo_inst to mark the cpus actively executing work items.
199 * Returns the total number of cpus that have executed work item begin or
203 markWorkItem(int index)
206 assert(index < activeCpus.size());
207 activeCpus[index] = true;
208 for (std::vector<bool>::iterator i = activeCpus.begin();
209 i < activeCpus.end(); i++) {
217 * Fix up an address used to match PCs for hooking simulator
218 * events on to target function executions. See comment in
219 * system.cc for details.
221 virtual Addr fixFuncEventAddr(Addr addr) = 0;
224 * Add a function-based event to the given function, to be looked
225 * up in the specified symbol table.
228 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
230 Addr addr = 0; // initialize only to avoid compiler warning
232 if (symtab->findAddress(lbl, addr)) {
233 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
240 /** Add a function-based event to kernel code. */
242 T *addKernelFuncEvent(const char *lbl)
244 return addFuncEvent<T>(kernelSymtab, lbl);
249 std::vector<BaseRemoteGDB *> remoteGDB;
250 std::vector<GDBListener *> gdbListen;
254 typedef SystemParams Params;
265 const Params *params() const { return (const Params *)_params; }
271 * Returns the addess the kernel starts at.
272 * @return address the kernel starts at
274 Addr getKernelStart() const { return kernelStart; }
277 * Returns the addess the kernel ends at.
278 * @return address the kernel ends at
280 Addr getKernelEnd() const { return kernelEnd; }
283 * Returns the addess the entry point to the kernel code.
284 * @return entry point of the kernel code
286 Addr getKernelEntry() const { return kernelEntry; }
290 /// Allocate npages contiguous unused physical pages
291 /// @return Starting address of first page
292 Addr allocPhysPages(int npages);
294 #endif // FULL_SYSTEM
296 int registerThreadContext(ThreadContext *tc, int assigned=-1);
297 void replaceThreadContext(ThreadContext *tc, int context_id);
299 void serialize(std::ostream &os);
300 void unserialize(Checkpoint *cp, const std::string §ion);
301 virtual void resume();
304 Counter totalNumInsts;
305 EventQueue instEventQueue;
307 ////////////////////////////////////////////
309 // STATIC GLOBAL SYSTEM LIST
311 ////////////////////////////////////////////
313 static std::vector<System *> systemList;
314 static int numSystemsRunning;
316 static void printSystems();
321 #endif // __SYSTEM_HH__