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