f10167bba244db1f1ba04a67598d4d264819bf88
2 * Copyright (c) 2003-2006 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.
28 * Authors: Steve Reinhardt
34 #include "arch/isa_traits.hh"
35 #include "arch/remote_gdb.hh"
36 #include "arch/utility.hh"
37 #include "base/loader/object_file.hh"
38 #include "base/loader/symtab.hh"
39 #include "base/trace.hh"
40 #include "cpu/thread_context.hh"
41 #include "mem/mem_object.hh"
42 #include "mem/physical.hh"
43 #include "sim/byteswap.hh"
44 #include "sim/system.hh"
45 #include "sim/debug.hh"
47 #include "arch/vtophys.hh"
48 #include "kern/kernel_stats.hh"
50 #include "params/System.hh"
54 using namespace TheISA
;
56 vector
<System
*> System::systemList
;
58 int System::numSystemsRunning
= 0;
60 System::System(Params
*p
)
61 : SimObject(p
), physmem(p
->physmem
), _numContexts(0),
63 init_param(p
->init_param
),
64 functionalPort(p
->name
+ "-fport"),
65 virtPort(p
->name
+ "-vport"),
70 memoryMode(p
->mem_mode
), _params(p
)
72 // add self to global system list
73 systemList
.push_back(this);
76 kernelSymtab
= new SymbolTable
;
77 if (!debugSymbolTable
)
78 debugSymbolTable
= new SymbolTable
;
82 * Get a functional port to memory
85 mem_port
= physmem
->getPort("functional");
86 functionalPort
.setPeer(mem_port
);
87 mem_port
->setPeer(&functionalPort
);
89 mem_port
= physmem
->getPort("functional");
90 virtPort
.setPeer(mem_port
);
91 mem_port
->setPeer(&virtPort
);
95 * Load the kernel code into memory
97 if (params()->kernel
== "") {
98 inform("No kernel set for full system simulation. Assuming you know what"
99 " you're doing...\n");
102 kernel
= createObjectFile(params()->kernel
);
103 inform("kernel located at: %s", params()->kernel
);
106 fatal("Could not load kernel file %s", params()->kernel
);
108 // Load program sections into memory
109 kernel
->loadSections(&functionalPort
, LoadAddrMask
);
111 // setup entry points
112 kernelStart
= kernel
->textBase();
113 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
114 kernelEntry
= kernel
->entryPoint();
117 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
118 fatal("could not load kernel symbols\n");
120 if (!kernel
->loadLocalSymbols(kernelSymtab
))
121 fatal("could not load kernel local symbols\n");
123 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
124 fatal("could not load kernel symbols\n");
126 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
127 fatal("could not load kernel local symbols\n");
129 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
130 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
131 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
132 DPRINTF(Loader
, "Kernel loaded...\n");
134 #endif // FULL_SYSTEM
136 // increment the number of running systms
146 panic("System::fixFuncEventAddr needs to be rewritten "
147 "to work with syscall emulation");
148 #endif // FULL_SYSTEM}
152 int rgdb_enable
= true;
155 System::setMemoryMode(Enums::MemoryMode mode
)
157 assert(getState() == Drained
);
161 bool System::breakpoint()
163 if (remoteGDB
.size())
164 return remoteGDB
[0]->breakpoint();
169 System::registerThreadContext(ThreadContext
*tc
, int assigned
)
172 if (assigned
== -1) {
173 for (id
= 0; id
< threadContexts
.size(); id
++) {
174 if (!threadContexts
[id
])
178 if (threadContexts
.size() <= id
)
179 threadContexts
.resize(id
+ 1);
181 if (threadContexts
.size() <= assigned
)
182 threadContexts
.resize(assigned
+ 1);
186 if (threadContexts
[id
])
187 fatal("Cannot have two CPUs with the same id (%d)\n", id
);
189 threadContexts
[id
] = tc
;
192 int port
= getRemoteGDBPort();
193 if (rgdb_enable
&& port
) {
194 RemoteGDB
*rgdb
= new RemoteGDB(this, tc
);
195 GDBListener
*gdbl
= new GDBListener(rgdb
, port
+ id
);
198 * Uncommenting this line waits for a remote debugger to
199 * connect to the simulator before continuing.
201 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
204 if (remoteGDB
.size() <= id
) {
205 remoteGDB
.resize(id
+ 1);
208 remoteGDB
[id
] = rgdb
;
215 System::numRunningContexts()
218 for (int i
= 0; i
< _numContexts
; ++i
) {
219 if (threadContexts
[i
]->status() != ThreadContext::Halted
)
230 for (i
= 0; i
< threadContexts
.size(); i
++)
231 TheISA::startupCPU(threadContexts
[i
], i
);
236 System::replaceThreadContext(ThreadContext
*tc
, int context_id
)
238 if (context_id
>= threadContexts
.size()) {
239 panic("replaceThreadContext: bad id, %d >= %d\n",
240 context_id
, threadContexts
.size());
243 threadContexts
[context_id
] = tc
;
244 if (context_id
< remoteGDB
.size())
245 remoteGDB
[context_id
]->replaceThreadContext(tc
);
252 Addr return_addr
= page_ptr
<< LogVMPageSize
;
254 if (return_addr
>= physmem
->size())
255 fatal("Out of memory, please increase size of physical memory.");
262 return physmem
->size();
266 System::freeMemSize()
268 return physmem
->size() - (page_ptr
<< LogVMPageSize
);
274 System::serialize(ostream
&os
)
277 kernelSymtab
->serialize("kernel_symtab", os
);
278 #else // !FULL_SYSTEM
279 SERIALIZE_SCALAR(page_ptr
);
285 System::unserialize(Checkpoint
*cp
, const string
§ion
)
288 kernelSymtab
->unserialize("kernel_symtab", cp
, section
);
289 #else // !FULL_SYSTEM
290 UNSERIALIZE_SCALAR(page_ptr
);
295 System::printSystems()
297 vector
<System
*>::iterator i
= systemList
.begin();
298 vector
<System
*>::iterator end
= systemList
.end();
299 for (; i
!= end
; ++i
) {
301 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
308 System::printSystems();
311 const char *System::MemoryModeStrings
[3] = {"invalid", "atomic",
317 SystemParams::create()
319 return new System(this);