Major improvements in the graph output code. Mostly adding more
[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 /** Object pointer for the kernel code */
81 ObjectFile *kernel;
82
83 /** Object pointer for the console code */
84 ObjectFile *console;
85
86 /** Object pointer for the PAL code */
87 ObjectFile *pal;
88
89 /** Begining of kernel code */
90 Addr kernelStart;
91
92 /** End of kernel code */
93 Addr kernelEnd;
94
95 /** Entry point in the kernel to start at */
96 Addr kernelEntry;
97
98 Kernel::Binning *kernelBinning;
99
100 #ifdef DEBUG
101 /** Event to halt the simulator if the console calls panic() */
102 BreakPCEvent *consolePanicEvent;
103 #endif
104
105 protected:
106
107 /**
108 * Fix up an address used to match PCs for hooking simulator
109 * events on to target function executions. See comment in
110 * system.cc for details.
111 */
112 Addr fixFuncEventAddr(Addr addr);
113
114 /**
115 * Add a function-based event to the given function, to be looked
116 * up in the specified symbol table.
117 */
118 template <class T>
119 T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
120 {
121 Addr addr = 0; // initialize only to avoid compiler warning
122
123 if (symtab->findAddress(lbl, addr)) {
124 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
125 return ev;
126 }
127
128 return NULL;
129 }
130
131 /** Add a function-based event to kernel code. */
132 template <class T>
133 T *System::addKernelFuncEvent(const char *lbl)
134 {
135 return addFuncEvent<T>(kernelSymtab, lbl);
136 }
137
138 /** Add a function-based event to PALcode. */
139 template <class T>
140 T *System::addPalFuncEvent(const char *lbl)
141 {
142 return addFuncEvent<T>(palSymtab, lbl);
143 }
144
145 /** Add a function-based event to the console code. */
146 template <class T>
147 T *System::addConsoleFuncEvent(const char *lbl)
148 {
149 return addFuncEvent<T>(consoleSymtab, lbl);
150 }
151
152 public:
153 std::vector<RemoteGDB *> remoteGDB;
154 std::vector<GDBListener *> gdbListen;
155 bool breakpoint();
156
157 public:
158 struct Params
159 {
160 std::string name;
161 Tick boot_cpu_frequency;
162 MemoryController *memctrl;
163 PhysicalMemory *physmem;
164 uint64_t init_param;
165 bool bin;
166 std::vector<std::string> binned_fns;
167 bool bin_int;
168
169 std::string kernel_path;
170 std::string console_path;
171 std::string palcode;
172 std::string boot_osflags;
173
174 std::string readfile;
175 uint64_t system_type;
176 uint64_t system_rev;
177 };
178 Params *params;
179
180 System(Params *p);
181 ~System();
182
183 void startup();
184
185 public:
186 /**
187 * Set the m5AlphaAccess pointer in the console
188 */
189 void setAlphaAccess(Addr access);
190
191 /**
192 * Returns the addess the kernel starts at.
193 * @return address the kernel starts at
194 */
195 Addr getKernelStart() const { return kernelStart; }
196
197 /**
198 * Returns the addess the kernel ends at.
199 * @return address the kernel ends at
200 */
201 Addr getKernelEnd() const { return kernelEnd; }
202
203 /**
204 * Returns the addess the entry point to the kernel code.
205 * @return entry point of the kernel code
206 */
207 Addr getKernelEntry() const { return kernelEntry; }
208
209 int registerExecContext(ExecContext *xc, int xcIndex);
210 void replaceExecContext(ExecContext *xc, int xcIndex);
211
212 void regStats();
213 void serialize(std::ostream &os);
214 void unserialize(Checkpoint *cp, const std::string &section);
215
216 public:
217 ////////////////////////////////////////////
218 //
219 // STATIC GLOBAL SYSTEM LIST
220 //
221 ////////////////////////////////////////////
222
223 static std::vector<System *> systemList;
224 static int numSystemsRunning;
225
226 static void printSystems();
227 };
228
229 #endif // __SYSTEM_HH__