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