Deleted Added
sdiff udiff text old ( 7914:eee5bb0fb8ea ) new ( 8460:3893d9d2c6c2 )
full compact
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * Copyright (c) 2011 Regents of the University of California
4 * All rights reserved.
5 *
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.
16 *
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.
28 *
29 * Authors: Steve Reinhardt
30 * Lisa Hsu
31 * Nathan Binkert
32 * Rick Strong
33 */
34
35#ifndef __SYSTEM_HH__
36#define __SYSTEM_HH__
37
38#include <string>
39#include <vector>
40
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"
50
51#if FULL_SYSTEM
52#include "kern/system_events.hh"
53#endif
54
55class BaseCPU;
56class ThreadContext;
57class ObjectFile;
58class PhysicalMemory;
59
60#if FULL_SYSTEM
61class Platform;
62class FunctionalPort;
63class VirtualPort;
64#endif
65class GDBListener;
66class BaseRemoteGDB;
67
68class System : public SimObject
69{
70 public:
71
72 static const char *MemoryModeStrings[3];
73
74 Enums::MemoryMode
75 getMemoryMode()
76 {
77 assert(memoryMode);
78 return memoryMode;
79 }
80
81 /** Change the memory mode of the system. This should only be called by the
82 * python!!
83 * @param mode Mode to change to (atomic/timing)
84 */
85 void setMemoryMode(Enums::MemoryMode mode);
86
87 PhysicalMemory *physmem;
88 PCEventQueue pcEventQueue;
89
90 std::vector<ThreadContext *> threadContexts;
91 int _numContexts;
92
93 ThreadContext *getThreadContext(ThreadID tid)
94 {
95 return threadContexts[tid];
96 }
97
98 int numContexts()
99 {
100 assert(_numContexts == (int)threadContexts.size());
101 return _numContexts;
102 }
103
104 /** Return number of running (non-halted) thread contexts in
105 * system. These threads could be Active or Suspended. */
106 int numRunningContexts();
107
108#if FULL_SYSTEM
109 Platform *platform;
110 uint64_t init_param;
111
112 /** Port to physical memory used for writing object files into ram at
113 * boot.*/
114 FunctionalPort *functionalPort;
115 VirtualPort *virtPort;
116
117 /** kernel symbol table */
118 SymbolTable *kernelSymtab;
119
120 /** Object pointer for the kernel code */
121 ObjectFile *kernel;
122
123 /** Begining of kernel code */
124 Addr kernelStart;
125
126 /** End of kernel code */
127 Addr kernelEnd;
128
129 /** Entry point in the kernel to start at */
130 Addr kernelEntry;
131
132 /** Mask that should be anded for binary/symbol loading.
133 * This allows one two different OS requirements for the same ISA to be
134 * handled. Some OSes are compiled for a virtual address and need to be
135 * loaded into physical memory that starts at address 0, while other
136 * bare metal tools generate images that start at address 0.
137 */
138 Addr loadAddrMask;
139
140#else
141
142 Addr pagePtr;
143
144 protected:
145 uint64_t nextPID;
146
147 public:
148 uint64_t allocatePID()
149 {
150 return nextPID++;
151 }
152
153 /** Amount of physical memory that is still free */
154 Addr freeMemSize();
155
156 /** Amount of physical memory that exists */
157 Addr memSize();
158
159
160#endif // FULL_SYSTEM
161
162 protected:
163 Enums::MemoryMode memoryMode;
164 uint64_t workItemsBegin;
165 uint64_t workItemsEnd;
166 std::vector<bool> activeCpus;
167
168 public:
169 /**
170 * Called by pseudo_inst to track the number of work items started by this
171 * system.
172 */
173 uint64_t
174 incWorkItemsBegin()
175 {
176 return ++workItemsBegin;
177 }
178
179 /**
180 * Called by pseudo_inst to track the number of work items completed by
181 * this system.
182 */
183 uint64_t
184 incWorkItemsEnd()
185 {
186 return ++workItemsEnd;
187 }
188
189 /**
190 * Called by pseudo_inst to mark the cpus actively executing work items.
191 * Returns the total number of cpus that have executed work item begin or
192 * ends.
193 */
194 int
195 markWorkItem(int index)
196 {
197 int count = 0;
198 assert(index < activeCpus.size());
199 activeCpus[index] = true;
200 for (std::vector<bool>::iterator i = activeCpus.begin();
201 i < activeCpus.end(); i++) {
202 if (*i) count++;
203 }
204 return count;
205 }
206
207#if FULL_SYSTEM
208 /**
209 * Fix up an address used to match PCs for hooking simulator
210 * events on to target function executions. See comment in
211 * system.cc for details.
212 */
213 virtual Addr fixFuncEventAddr(Addr addr) = 0;
214
215 /**
216 * Add a function-based event to the given function, to be looked
217 * up in the specified symbol table.
218 */
219 template <class T>
220 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
221 {
222 Addr addr = 0; // initialize only to avoid compiler warning
223
224 if (symtab->findAddress(lbl, addr)) {
225 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
226 return ev;
227 }
228
229 return NULL;
230 }
231
232 /** Add a function-based event to kernel code. */
233 template <class T>
234 T *addKernelFuncEvent(const char *lbl)
235 {
236 return addFuncEvent<T>(kernelSymtab, lbl);
237 }
238
239#endif
240 public:
241 std::vector<BaseRemoteGDB *> remoteGDB;
242 std::vector<GDBListener *> gdbListen;
243 bool breakpoint();
244
245 public:
246 typedef SystemParams Params;
247
248 protected:
249 Params *_params;
250
251 public:
252 System(Params *p);
253 ~System();
254
255 void initState();
256
257 const Params *params() const { return (const Params *)_params; }
258
259 public:
260
261#if FULL_SYSTEM
262 /**
263 * Returns the addess the kernel starts at.
264 * @return address the kernel starts at
265 */
266 Addr getKernelStart() const { return kernelStart; }
267
268 /**
269 * Returns the addess the kernel ends at.
270 * @return address the kernel ends at
271 */
272 Addr getKernelEnd() const { return kernelEnd; }
273
274 /**
275 * Returns the addess the entry point to the kernel code.
276 * @return entry point of the kernel code
277 */
278 Addr getKernelEntry() const { return kernelEntry; }
279
280#else
281
282 Addr new_page();
283
284#endif // FULL_SYSTEM
285
286 int registerThreadContext(ThreadContext *tc, int assigned=-1);
287 void replaceThreadContext(ThreadContext *tc, int context_id);
288
289 void serialize(std::ostream &os);
290 void unserialize(Checkpoint *cp, const std::string &section);
291 virtual void resume();
292
293 public:
294 Counter totalNumInsts;
295 EventQueue instEventQueue;
296
297 ////////////////////////////////////////////
298 //
299 // STATIC GLOBAL SYSTEM LIST
300 //
301 ////////////////////////////////////////////
302
303 static std::vector<System *> systemList;
304 static int numSystemsRunning;
305
306 static void printSystems();
307
308
309};
310
311#endif // __SYSTEM_HH__