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