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