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