Merge ktlim@zizzer:/bk/newmem
[gem5.git] / src / 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 * Authors: Steve Reinhardt
29 * Lisa Hsu
30 * Nathan Binkert
31 */
32
33 #ifndef __SYSTEM_HH__
34 #define __SYSTEM_HH__
35
36 #include <string>
37 #include <vector>
38
39 #include "base/loader/symtab.hh"
40 #include "base/misc.hh"
41 #include "base/statistics.hh"
42 #include "cpu/pc_event.hh"
43 #include "mem/port.hh"
44 #include "sim/sim_object.hh"
45 #if FULL_SYSTEM
46 #include "kern/system_events.hh"
47 #include "mem/vport.hh"
48 #endif
49
50 class BaseCPU;
51 class ThreadContext;
52 class ObjectFile;
53 class PhysicalMemory;
54
55 #if FULL_SYSTEM
56 class Platform;
57 class GDBListener;
58 class RemoteGDB;
59 #endif
60
61 class System : public SimObject
62 {
63 public:
64 enum MemoryMode {
65 Invalid=0,
66 Atomic,
67 Timing
68 };
69
70 static const char *MemoryModeStrings[3];
71
72
73 MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; }
74
75 /** Change the memory mode of the system. This should only be called by the
76 * python!!
77 * @param mode Mode to change to (atomic/timing)
78 */
79 void setMemoryMode(MemoryMode mode);
80
81 PhysicalMemory *physmem;
82 PCEventQueue pcEventQueue;
83
84 std::vector<ThreadContext *> threadContexts;
85 int numcpus;
86
87 int getNumCPUs()
88 {
89 if (numcpus != threadContexts.size())
90 panic("cpu array not fully populated!");
91
92 return numcpus;
93 }
94
95 #if FULL_SYSTEM
96 Platform *platform;
97 uint64_t init_param;
98
99 /** Port to physical memory used for writing object files into ram at
100 * boot.*/
101 FunctionalPort functionalPort;
102 VirtualPort virtPort;
103
104 /** kernel symbol table */
105 SymbolTable *kernelSymtab;
106
107 /** Object pointer for the kernel code */
108 ObjectFile *kernel;
109
110 /** Begining of kernel code */
111 Addr kernelStart;
112
113 /** End of kernel code */
114 Addr kernelEnd;
115
116 /** Entry point in the kernel to start at */
117 Addr kernelEntry;
118
119 #else
120
121 int page_ptr;
122
123
124 #endif // FULL_SYSTEM
125
126 protected:
127
128 MemoryMode memoryMode;
129
130 #if FULL_SYSTEM
131 /**
132 * Fix up an address used to match PCs for hooking simulator
133 * events on to target function executions. See comment in
134 * system.cc for details.
135 */
136 virtual Addr fixFuncEventAddr(Addr addr) = 0;
137
138 /**
139 * Add a function-based event to the given function, to be looked
140 * up in the specified symbol table.
141 */
142 template <class T>
143 T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
144 {
145 Addr addr = 0; // initialize only to avoid compiler warning
146
147 if (symtab->findAddress(lbl, addr)) {
148 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
149 return ev;
150 }
151
152 return NULL;
153 }
154
155 /** Add a function-based event to kernel code. */
156 template <class T>
157 T *System::addKernelFuncEvent(const char *lbl)
158 {
159 return addFuncEvent<T>(kernelSymtab, lbl);
160 }
161
162 #endif
163 public:
164 #if FULL_SYSTEM
165 std::vector<RemoteGDB *> remoteGDB;
166 std::vector<GDBListener *> gdbListen;
167 virtual bool breakpoint() = 0;
168 #endif // FULL_SYSTEM
169
170 public:
171 struct Params
172 {
173 std::string name;
174 PhysicalMemory *physmem;
175 MemoryMode mem_mode;
176
177 #if FULL_SYSTEM
178 Tick boot_cpu_frequency;
179 std::string boot_osflags;
180 uint64_t init_param;
181
182 std::string kernel_path;
183 std::string readfile;
184 #endif
185 };
186
187 protected:
188 Params *_params;
189
190 public:
191 System(Params *p);
192 ~System();
193
194 void startup();
195
196 const Params *params() const { return (const Params *)_params; }
197
198 public:
199
200 #if FULL_SYSTEM
201 /**
202 * Returns the addess the kernel starts at.
203 * @return address the kernel starts at
204 */
205 Addr getKernelStart() const { return kernelStart; }
206
207 /**
208 * Returns the addess the kernel ends at.
209 * @return address the kernel ends at
210 */
211 Addr getKernelEnd() const { return kernelEnd; }
212
213 /**
214 * Returns the addess the entry point to the kernel code.
215 * @return entry point of the kernel code
216 */
217 Addr getKernelEntry() const { return kernelEntry; }
218
219 #else
220
221 Addr new_page();
222
223 #endif // FULL_SYSTEM
224
225 int registerThreadContext(ThreadContext *tc, int tcIndex);
226 void replaceThreadContext(ThreadContext *tc, int tcIndex);
227
228 void serialize(std::ostream &os);
229 void unserialize(Checkpoint *cp, const std::string &section);
230
231 public:
232 ////////////////////////////////////////////
233 //
234 // STATIC GLOBAL SYSTEM LIST
235 //
236 ////////////////////////////////////////////
237
238 static std::vector<System *> systemList;
239 static int numSystemsRunning;
240
241 static void printSystems();
242
243
244 };
245
246 #endif // __SYSTEM_HH__