More reformatting of reference parameter declarations.
[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 #ifdef FS_MEASURE
54 if (bin == true) {
55 nonPath = new Statistics::MainBin("non TCPIP path stats");
56 nonPath->activate();
57 } else
58 nonPath = NULL;
59 #endif
60 }
61
62
63 System::~System()
64 {
65 }
66
67
68 int
69 System::registerExecContext(ExecContext *xc)
70 {
71 int myIndex = execContexts.size();
72 execContexts.push_back(xc);
73 return myIndex;
74 }
75
76
77 void
78 System::replaceExecContext(int xcIndex, ExecContext *xc)
79 {
80 if (xcIndex >= execContexts.size()) {
81 panic("replaceExecContext: bad xcIndex, %d >= %d\n",
82 xcIndex, execContexts.size());
83 }
84
85 execContexts[xcIndex] = xc;
86 }
87
88
89 void
90 System::printSystems()
91 {
92 vector<System *>::iterator i = systemList.begin();
93 vector<System *>::iterator end = systemList.end();
94 for (; i != end; ++i) {
95 System *sys = *i;
96 cerr << "System " << sys->name() << ": " << hex << sys << endl;
97 }
98 }
99
100 extern "C"
101 void
102 printSystems()
103 {
104 System::printSystems();
105 }
106
107 #ifdef FS_MEASURE
108 Statistics::MainBin *
109 System::getBin(const std::string &name)
110 {
111 std::map<const std::string, Statistics::MainBin *>::const_iterator i;
112 i = fnBins.find(name);
113 if (i == fnBins.end())
114 panic("trying to getBin that is not on system map!");
115 return (*i).second;
116 }
117
118 SWContext *
119 System::findContext(Addr pcb)
120 {
121 std::map<Addr, SWContext *>::const_iterator iter;
122 iter = swCtxMap.find(pcb);
123 if (iter != swCtxMap.end()) {
124 SWContext *ctx = (*iter).second;
125 assert(ctx != NULL && "should never have a null ctx in ctxMap");
126 return ctx;
127 } else
128 return NULL;
129 }
130 #endif //FS_MEASURE
131
132 DEFINE_SIM_OBJECT_CLASS_NAME("System", System)
133