system.hh (4997:e7380529bd2d) system.hh (5712:199d31b47f7b)
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
53class BaseCPU;
54class ThreadContext;
55class ObjectFile;
56class PhysicalMemory;
57
58#if FULL_SYSTEM
59class Platform;
60#endif
61class GDBListener;
62namespace TheISA
63{
64 class RemoteGDB;
65}
66
67class 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 numcpus;
91
92 int getNumCPUs()
93 {
94 if (numcpus != threadContexts.size())
95 panic("cpu array not fully populated!");
96
97 return numcpus;
98 }
99
100#if FULL_SYSTEM
101 Platform *platform;
102 uint64_t init_param;
103
104 /** Port to physical memory used for writing object files into ram at
105 * boot.*/
106 FunctionalPort functionalPort;
107 VirtualPort virtPort;
108
109 /** kernel symbol table */
110 SymbolTable *kernelSymtab;
111
112 /** Object pointer for the kernel code */
113 ObjectFile *kernel;
114
115 /** Begining of kernel code */
116 Addr kernelStart;
117
118 /** End of kernel code */
119 Addr kernelEnd;
120
121 /** Entry point in the kernel to start at */
122 Addr kernelEntry;
123
124#else
125
126 int page_ptr;
127
128 protected:
129 uint64_t next_PID;
130
131 public:
132 uint64_t allocatePID()
133 {
134 return next_PID++;
135 }
136
137
138#endif // FULL_SYSTEM
139
140 protected:
141 Enums::MemoryMode memoryMode;
142
143#if FULL_SYSTEM
144 /**
145 * Fix up an address used to match PCs for hooking simulator
146 * events on to target function executions. See comment in
147 * system.cc for details.
148 */
149 virtual Addr fixFuncEventAddr(Addr addr) = 0;
150
151 /**
152 * Add a function-based event to the given function, to be looked
153 * up in the specified symbol table.
154 */
155 template <class T>
156 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
157 {
158 Addr addr = 0; // initialize only to avoid compiler warning
159
160 if (symtab->findAddress(lbl, addr)) {
161 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
162 return ev;
163 }
164
165 return NULL;
166 }
167
168 /** Add a function-based event to kernel code. */
169 template <class T>
170 T *addKernelFuncEvent(const char *lbl)
171 {
172 return addFuncEvent<T>(kernelSymtab, lbl);
173 }
174
175#endif
176 public:
177 std::vector<TheISA::RemoteGDB *> remoteGDB;
178 std::vector<GDBListener *> gdbListen;
179 bool breakpoint();
180
181 public:
182 typedef SystemParams Params;
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
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
53class BaseCPU;
54class ThreadContext;
55class ObjectFile;
56class PhysicalMemory;
57
58#if FULL_SYSTEM
59class Platform;
60#endif
61class GDBListener;
62namespace TheISA
63{
64 class RemoteGDB;
65}
66
67class 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 numcpus;
91
92 int getNumCPUs()
93 {
94 if (numcpus != threadContexts.size())
95 panic("cpu array not fully populated!");
96
97 return numcpus;
98 }
99
100#if FULL_SYSTEM
101 Platform *platform;
102 uint64_t init_param;
103
104 /** Port to physical memory used for writing object files into ram at
105 * boot.*/
106 FunctionalPort functionalPort;
107 VirtualPort virtPort;
108
109 /** kernel symbol table */
110 SymbolTable *kernelSymtab;
111
112 /** Object pointer for the kernel code */
113 ObjectFile *kernel;
114
115 /** Begining of kernel code */
116 Addr kernelStart;
117
118 /** End of kernel code */
119 Addr kernelEnd;
120
121 /** Entry point in the kernel to start at */
122 Addr kernelEntry;
123
124#else
125
126 int page_ptr;
127
128 protected:
129 uint64_t next_PID;
130
131 public:
132 uint64_t allocatePID()
133 {
134 return next_PID++;
135 }
136
137
138#endif // FULL_SYSTEM
139
140 protected:
141 Enums::MemoryMode memoryMode;
142
143#if FULL_SYSTEM
144 /**
145 * Fix up an address used to match PCs for hooking simulator
146 * events on to target function executions. See comment in
147 * system.cc for details.
148 */
149 virtual Addr fixFuncEventAddr(Addr addr) = 0;
150
151 /**
152 * Add a function-based event to the given function, to be looked
153 * up in the specified symbol table.
154 */
155 template <class T>
156 T *addFuncEvent(SymbolTable *symtab, const char *lbl)
157 {
158 Addr addr = 0; // initialize only to avoid compiler warning
159
160 if (symtab->findAddress(lbl, addr)) {
161 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
162 return ev;
163 }
164
165 return NULL;
166 }
167
168 /** Add a function-based event to kernel code. */
169 template <class T>
170 T *addKernelFuncEvent(const char *lbl)
171 {
172 return addFuncEvent<T>(kernelSymtab, lbl);
173 }
174
175#endif
176 public:
177 std::vector<TheISA::RemoteGDB *> remoteGDB;
178 std::vector<GDBListener *> gdbListen;
179 bool breakpoint();
180
181 public:
182 typedef SystemParams Params;
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);
222 int registerThreadContext(ThreadContext *tc);
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__
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__