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