remove duplicate profile event code that is already in
[gem5.git] / sim / system.hh
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __SYSTEM_HH__
30 #define __SYSTEM_HH__
31
32 #include <string>
33 #include <vector>
34
35 #include "base/statistics.hh"
36 #include "base/loader/symtab.hh"
37 #include "cpu/pc_event.hh"
38 #include "kern/system_events.hh"
39 #include "sim/sim_object.hh"
40
41 class BaseCPU;
42 class ExecContext;
43 class GDBListener;
44 class MemoryController;
45 class ObjectFile;
46 class PhysicalMemory;
47 class Platform;
48 class RemoteGDB;
49 namespace Kernel { class Binning; }
50
51 class System : public SimObject
52 {
53 public:
54 MemoryController *memctrl;
55 PhysicalMemory *physmem;
56 Platform *platform;
57 PCEventQueue pcEventQueue;
58 uint64_t init_param;
59
60 std::vector<ExecContext *> execContexts;
61 int numcpus;
62
63 int getNumCPUs()
64 {
65 if (numcpus != execContexts.size())
66 panic("cpu array not fully populated!");
67
68 return numcpus;
69 }
70
71 /** kernel symbol table */
72 SymbolTable *kernelSymtab;
73
74 /** console symbol table */
75 SymbolTable *consoleSymtab;
76
77 /** pal symbol table */
78 SymbolTable *palSymtab;
79
80 /** all symbols table */
81 SymbolTable *allSymtab;
82
83 /** Object pointer for the kernel code */
84 ObjectFile *kernel;
85
86 /** Object pointer for the console code */
87 ObjectFile *console;
88
89 /** Object pointer for the PAL code */
90 ObjectFile *pal;
91
92 /** Begining of kernel code */
93 Addr kernelStart;
94
95 /** End of kernel code */
96 Addr kernelEnd;
97
98 /** Entry point in the kernel to start at */
99 Addr kernelEntry;
100
101 Kernel::Binning *kernelBinning;
102
103 #ifdef DEBUG
104 /** Event to halt the simulator if the console calls panic() */
105 BreakPCEvent *consolePanicEvent;
106 #endif
107
108 protected:
109
110 /**
111 * Fix up an address used to match PCs for hooking simulator
112 * events on to target function executions. See comment in
113 * system.cc for details.
114 */
115 Addr fixFuncEventAddr(Addr addr);
116
117 /**
118 * Add a function-based event to the given function, to be looked
119 * up in the specified symbol table.
120 */
121 template <class T>
122 T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
123 {
124 Addr addr = 0; // initialize only to avoid compiler warning
125
126 if (symtab->findAddress(lbl, addr)) {
127 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
128 return ev;
129 }
130
131 return NULL;
132 }
133
134 /** Add a function-based event to kernel code. */
135 template <class T>
136 T *System::addKernelFuncEvent(const char *lbl)
137 {
138 return addFuncEvent<T>(kernelSymtab, lbl);
139 }
140
141 /** Add a function-based event to PALcode. */
142 template <class T>
143 T *System::addPalFuncEvent(const char *lbl)
144 {
145 return addFuncEvent<T>(palSymtab, lbl);
146 }
147
148 /** Add a function-based event to the console code. */
149 template <class T>
150 T *System::addConsoleFuncEvent(const char *lbl)
151 {
152 return addFuncEvent<T>(consoleSymtab, lbl);
153 }
154
155 public:
156 std::vector<RemoteGDB *> remoteGDB;
157 std::vector<GDBListener *> gdbListen;
158 bool breakpoint();
159
160 public:
161 struct Params
162 {
163 std::string name;
164 Tick boot_cpu_frequency;
165 MemoryController *memctrl;
166 PhysicalMemory *physmem;
167 uint64_t init_param;
168 bool bin;
169 std::vector<std::string> binned_fns;
170 bool bin_int;
171
172 std::string kernel_path;
173 std::string console_path;
174 std::string palcode;
175 std::string boot_osflags;
176
177 std::string readfile;
178 uint64_t system_type;
179 uint64_t system_rev;
180 };
181 Params *params;
182
183 System(Params *p);
184 ~System();
185
186 void startup();
187
188 public:
189 /**
190 * Set the m5AlphaAccess pointer in the console
191 */
192 void setAlphaAccess(Addr access);
193
194 /**
195 * Returns the addess the kernel starts at.
196 * @return address the kernel starts at
197 */
198 Addr getKernelStart() const { return kernelStart; }
199
200 /**
201 * Returns the addess the kernel ends at.
202 * @return address the kernel ends at
203 */
204 Addr getKernelEnd() const { return kernelEnd; }
205
206 /**
207 * Returns the addess the entry point to the kernel code.
208 * @return entry point of the kernel code
209 */
210 Addr getKernelEntry() const { return kernelEntry; }
211
212 int registerExecContext(ExecContext *xc, int xcIndex);
213 void replaceExecContext(ExecContext *xc, int xcIndex);
214
215 void regStats();
216 void serialize(std::ostream &os);
217 void unserialize(Checkpoint *cp, const std::string &section);
218
219 public:
220 ////////////////////////////////////////////
221 //
222 // STATIC GLOBAL SYSTEM LIST
223 //
224 ////////////////////////////////////////////
225
226 static std::vector<System *> systemList;
227 static int numSystemsRunning;
228
229 static void printSystems();
230 };
231
232 #endif // __SYSTEM_HH__