X86: Fix the expected size of the immediate offset in MOV_MI.
[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(ThreadID tid)
93 {
94 return threadContexts[tid];
95 }
96
97 int numContexts()
98 {
99 assert(_numContexts == (int)threadContexts.size());
100 return _numContexts;
101 }
102
103 /** Return number of running (non-halted) thread contexts in
104 * system. These threads could be Active or Suspended. */
105 int numRunningContexts();
106
107 #if FULL_SYSTEM
108 Platform *platform;
109 uint64_t init_param;
110
111 /** Port to physical memory used for writing object files into ram at
112 * boot.*/
113 FunctionalPort functionalPort;
114 VirtualPort virtPort;
115
116 /** kernel symbol table */
117 SymbolTable *kernelSymtab;
118
119 /** Object pointer for the kernel code */
120 ObjectFile *kernel;
121
122 /** Begining of kernel code */
123 Addr kernelStart;
124
125 /** End of kernel code */
126 Addr kernelEnd;
127
128 /** Entry point in the kernel to start at */
129 Addr kernelEntry;
130
131 #else
132
133 int page_ptr;
134
135 protected:
136 uint64_t next_PID;
137
138 public:
139 uint64_t allocatePID()
140 {
141 return next_PID++;
142 }
143
144 /** Amount of physical memory that is still free */
145 Addr freeMemSize();
146
147 /** Amount of physical memory that exists */
148 Addr memSize();
149
150
151 #endif // FULL_SYSTEM
152
153 protected:
154 Enums::MemoryMode memoryMode;
155
156 #if FULL_SYSTEM
157 /**
158 * Fix up an address used to match PCs for hooking simulator
159 * events on to target function executions. See comment in
160 * system.cc for details.
161 */
162 virtual Addr fixFuncEventAddr(Addr addr) = 0;
163
164 /**
165 * Add a function-based event to the given function, to be looked
166 * up in the specified symbol table.
167 */
168 template <class T>
169 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
170 {
171 Addr addr = 0; // initialize only to avoid compiler warning
172
173 if (symtab->findAddress(lbl, addr)) {
174 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
175 return ev;
176 }
177
178 return NULL;
179 }
180
181 /** Add a function-based event to kernel code. */
182 template <class T>
183 T *addKernelFuncEvent(const char *lbl)
184 {
185 return addFuncEvent<T>(kernelSymtab, lbl);
186 }
187
188 #endif
189 public:
190 std::vector<TheISA::RemoteGDB *> remoteGDB;
191 std::vector<GDBListener *> gdbListen;
192 bool breakpoint();
193
194 public:
195 typedef SystemParams Params;
196
197 protected:
198 Params *_params;
199
200 public:
201 System(Params *p);
202 ~System();
203
204 void startup();
205
206 const Params *params() const { return (const Params *)_params; }
207
208 public:
209
210 #if FULL_SYSTEM
211 /**
212 * Returns the addess the kernel starts at.
213 * @return address the kernel starts at
214 */
215 Addr getKernelStart() const { return kernelStart; }
216
217 /**
218 * Returns the addess the kernel ends at.
219 * @return address the kernel ends at
220 */
221 Addr getKernelEnd() const { return kernelEnd; }
222
223 /**
224 * Returns the addess the entry point to the kernel code.
225 * @return entry point of the kernel code
226 */
227 Addr getKernelEntry() const { return kernelEntry; }
228
229 #else
230
231 Addr new_page();
232
233 #endif // FULL_SYSTEM
234
235 int registerThreadContext(ThreadContext *tc, int assigned=-1);
236 void replaceThreadContext(ThreadContext *tc, int context_id);
237
238 void serialize(std::ostream &os);
239 void unserialize(Checkpoint *cp, const std::string &section);
240
241 public:
242 ////////////////////////////////////////////
243 //
244 // STATIC GLOBAL SYSTEM LIST
245 //
246 ////////////////////////////////////////////
247
248 static std::vector<System *> systemList;
249 static int numSystemsRunning;
250
251 static void printSystems();
252
253
254 };
255
256 #endif // __SYSTEM_HH__