Do a better job of factoring out CPU model in ISA description.
[gem5.git] / sim / system.cc
1 /*
2 * Copyright (c) 2003 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
29 #include "cpu/exec_context.hh"
30 #include "targetarch/vtophys.hh"
31 #include "sim/param.hh"
32 #include "sim/system.hh"
33
34 using namespace std;
35
36 vector<System *> System::systemList;
37
38 int System::numSystemsRunning = 0;
39
40 System::System(const std::string _name,
41 const uint64_t _init_param,
42 MemoryController *_memCtrl,
43 PhysicalMemory *_physmem,
44 const bool _bin)
45 : SimObject(_name),
46 init_param(_init_param),
47 memCtrl(_memCtrl),
48 physmem(_physmem),
49 bin(_bin)
50 {
51 // add self to global system list
52 systemList.push_back(this);
53 if (bin == true) {
54 Kernel = new Statistics::MainBin("non TCPIP Kernel stats");
55 Kernel->activate();
56 User = new Statistics::MainBin("User stats");
57 } else
58 Kernel = NULL;
59 }
60
61
62 System::~System()
63 {
64 }
65
66
67 int
68 System::registerExecContext(ExecContext *xc)
69 {
70 int myIndex = execContexts.size();
71 execContexts.push_back(xc);
72 return myIndex;
73 }
74
75
76 void
77 System::replaceExecContext(int xcIndex, ExecContext *xc)
78 {
79 if (xcIndex >= execContexts.size()) {
80 panic("replaceExecContext: bad xcIndex, %d >= %d\n",
81 xcIndex, execContexts.size());
82 }
83
84 execContexts[xcIndex] = xc;
85 }
86
87
88 void
89 System::printSystems()
90 {
91 vector<System *>::iterator i = systemList.begin();
92 vector<System *>::iterator end = systemList.end();
93 for (; i != end; ++i) {
94 System *sys = *i;
95 cerr << "System " << sys->name() << ": " << hex << sys << endl;
96 }
97 }
98
99 extern "C"
100 void
101 printSystems()
102 {
103 System::printSystems();
104 }
105
106 Statistics::MainBin *
107 System::getBin(const std::string &name)
108 {
109 std::map<const std::string, Statistics::MainBin *>::const_iterator i;
110 i = fnBins.find(name);
111 if (i == fnBins.end())
112 panic("trying to getBin %s that is not on system map!", name);
113 return (*i).second;
114 }
115
116 SWContext *
117 System::findContext(Addr pcb)
118 {
119 std::map<Addr, SWContext *>::const_iterator iter;
120 iter = swCtxMap.find(pcb);
121 if (iter != swCtxMap.end()) {
122 SWContext *ctx = (*iter).second;
123 assert(ctx != NULL && "should never have a null ctx in ctxMap");
124 return ctx;
125 } else
126 return NULL;
127 }
128
129 void
130 System::serialize(std::ostream &os)
131 {
132 if (bin == true) {
133 map<const Addr, SWContext *>::const_iterator iter, end;
134 iter = swCtxMap.begin();
135 end = swCtxMap.end();
136
137 int numCtxs = swCtxMap.size();
138 SERIALIZE_SCALAR(numCtxs);
139 SWContext *ctx;
140 for (int i = 0; iter != end; ++i, ++iter) {
141 paramOut(os, csprintf("Addr[%d]",i), (*iter).first);
142 ctx = (*iter).second;
143 paramOut(os, csprintf("calls[%d]",i), ctx->calls);
144
145 stack<fnCall *> *stack = &(ctx->callStack);
146 fnCall *top;
147 int size = stack->size();
148 paramOut(os, csprintf("stacksize[%d]",i), size);
149 for (int j=0; j<size; ++j) {
150 top = stack->top();
151 paramOut(os, csprintf("ctx[%d].stackpos[%d]",i,j),
152 top->name);
153 delete top;
154 stack->pop();
155 }
156 }
157 }
158 }
159
160 void
161 System::unserialize(Checkpoint *cp, const std::string &section)
162 {
163 if (bin == true) {
164 int numCtxs;
165 UNSERIALIZE_SCALAR(numCtxs);
166
167 SWContext *ctx;
168 Addr addr;
169 int size;
170 for(int i = 0; i < numCtxs; ++i) {
171 ctx = new SWContext;
172 paramIn(cp, section, csprintf("Addr[%d]",i), addr);
173 paramIn(cp, section, csprintf("calls[%d]",i), ctx->calls);
174
175 paramIn(cp, section, csprintf("stacksize[%d]",i), size);
176
177 vector<fnCall *> calls;
178 fnCall *call;
179 for (int j = 0; j < size; ++j) {
180 call = new fnCall;
181 paramIn(cp, section, csprintf("ctx[%d].stackpos[%d]",i,j),
182 call->name);
183 call->myBin = getBin(call->name);
184 calls.push_back(call);
185 }
186
187 for (int j=size-1; j>=0; --j) {
188 ctx->callStack.push(calls[j]);
189 }
190
191 addContext(addr, ctx);
192 }
193 }
194 }
195
196 DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
197