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