2 * Copyright (c) 2003 The Regents of The University of Michigan
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.
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.
29 #include "cpu/exec_context.hh"
30 #include "targetarch/vtophys.hh"
31 #include "sim/param.hh"
32 #include "sim/system.hh"
36 vector
<System
*> System::systemList
;
38 int System::numSystemsRunning
= 0;
40 System::System(const std::string _name
,
41 const uint64_t _init_param
,
42 MemoryController
*_memCtrl
,
43 PhysicalMemory
*_physmem
,
46 init_param(_init_param
),
51 // add self to global system list
52 systemList
.push_back(this);
54 Kernel
= new Statistics::MainBin("non TCPIP Kernel stats");
56 User
= new Statistics::MainBin("User stats");
68 System::registerExecContext(ExecContext
*xc
)
70 int myIndex
= execContexts
.size();
71 execContexts
.push_back(xc
);
77 System::replaceExecContext(int xcIndex
, ExecContext
*xc
)
79 if (xcIndex
>= execContexts
.size()) {
80 panic("replaceExecContext: bad xcIndex, %d >= %d\n",
81 xcIndex
, execContexts
.size());
84 execContexts
[xcIndex
] = xc
;
89 System::printSystems()
91 vector
<System
*>::iterator i
= systemList
.begin();
92 vector
<System
*>::iterator end
= systemList
.end();
93 for (; i
!= end
; ++i
) {
95 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
103 System::printSystems();
106 Statistics::MainBin
*
107 System::getBin(const std::string
&name
)
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
);
117 System::findContext(Addr pcb
)
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");
130 System::serialize(std::ostream
&os
)
133 map
<const Addr
, SWContext
*>::const_iterator iter
, end
;
134 iter
= swCtxMap
.begin();
135 end
= swCtxMap
.end();
137 int numCtxs
= swCtxMap
.size();
138 SERIALIZE_SCALAR(numCtxs
);
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
);
145 stack
<fnCall
*> *stack
= &(ctx
->callStack
);
147 int size
= stack
->size();
148 paramOut(os
, csprintf("stacksize[%d]",i
), size
);
149 for (int j
=0; j
<size
; ++j
) {
151 paramOut(os
, csprintf("ctx[%d].stackpos[%d]",i
,j
),
161 System::unserialize(Checkpoint
*cp
, const std::string
§ion
)
165 UNSERIALIZE_SCALAR(numCtxs
);
170 for(int i
= 0; i
< numCtxs
; ++i
) {
172 paramIn(cp
, section
, csprintf("Addr[%d]",i
), addr
);
173 paramIn(cp
, section
, csprintf("calls[%d]",i
), ctx
->calls
);
175 paramIn(cp
, section
, csprintf("stacksize[%d]",i
), size
);
177 vector
<fnCall
*> calls
;
179 for (int j
= 0; j
< size
; ++j
) {
181 paramIn(cp
, section
, csprintf("ctx[%d].stackpos[%d]",i
,j
),
183 call
->myBin
= getBin(call
->name
);
184 calls
.push_back(call
);
187 for (int j
=size
-1; j
>=0; --j
) {
188 ctx
->callStack
.push(calls
[j
]);
191 addContext(addr
, ctx
);
196 DEFINE_SIM_OBJECT_CLASS_NAME("System", System
)