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 "config/full_system.hh"
42 #include "config/the_isa.hh"
43 #include "mem/mem_object.hh"
44 #include "mem/physical.hh"
45 #include "sim/byteswap.hh"
46 #include "sim/system.hh"
47 #include "sim/debug.hh"
50 #include "arch/vtophys.hh"
51 #include "kern/kernel_stats.hh"
52 #include "mem/vport.hh"
54 #include "params/System.hh"
58 using namespace TheISA
;
60 vector
<System
*> System::systemList
;
62 int System::numSystemsRunning
= 0;
64 System::System(Params
*p
)
65 : SimObject(p
), physmem(p
->physmem
), _numContexts(0),
67 init_param(p
->init_param
),
68 loadAddrMask(p
->load_addr_mask
),
73 memoryMode(p
->mem_mode
), _params(p
)
75 // add self to global system list
76 systemList
.push_back(this);
79 kernelSymtab
= new SymbolTable
;
80 if (!debugSymbolTable
)
81 debugSymbolTable
= new SymbolTable
;
85 * Get a functional port to memory
88 functionalPort
= new FunctionalPort(name() + "-fport");
89 mem_port
= physmem
->getPort("functional");
90 functionalPort
->setPeer(mem_port
);
91 mem_port
->setPeer(functionalPort
);
93 virtPort
= new VirtualPort(name() + "-fport");
94 mem_port
= physmem
->getPort("functional");
95 virtPort
->setPeer(mem_port
);
96 mem_port
->setPeer(virtPort
);
100 * Load the kernel code into memory
102 if (params()->kernel
== "") {
103 inform("No kernel set for full system simulation. Assuming you know what"
104 " you're doing...\n");
107 kernel
= createObjectFile(params()->kernel
);
108 inform("kernel located at: %s", params()->kernel
);
111 fatal("Could not load kernel file %s", params()->kernel
);
113 // Load program sections into memory
114 kernel
->loadSections(functionalPort
, loadAddrMask
);
116 // setup entry points
117 kernelStart
= kernel
->textBase();
118 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
119 kernelEntry
= kernel
->entryPoint();
122 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
123 fatal("could not load kernel symbols\n");
125 if (!kernel
->loadLocalSymbols(kernelSymtab
))
126 fatal("could not load kernel local symbols\n");
128 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
129 fatal("could not load kernel symbols\n");
131 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
132 fatal("could not load kernel local symbols\n");
134 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
135 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
136 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
137 DPRINTF(Loader
, "Kernel loaded...\n");
139 #endif // FULL_SYSTEM
141 // increment the number of running systms
151 panic("System::fixFuncEventAddr needs to be rewritten "
152 "to work with syscall emulation");
153 #endif // FULL_SYSTEM}
157 System::setMemoryMode(Enums::MemoryMode mode
)
159 assert(getState() == Drained
);
163 bool System::breakpoint()
165 if (remoteGDB
.size())
166 return remoteGDB
[0]->breakpoint();
171 * Setting rgdb_wait to a positive integer waits for a remote debugger to
172 * connect to that context ID before continuing. This should really
173 be a parameter on the CPU object or something...
178 System::registerThreadContext(ThreadContext
*tc
, int assigned
)
181 if (assigned
== -1) {
182 for (id
= 0; id
< threadContexts
.size(); id
++) {
183 if (!threadContexts
[id
])
187 if (threadContexts
.size() <= id
)
188 threadContexts
.resize(id
+ 1);
190 if (threadContexts
.size() <= assigned
)
191 threadContexts
.resize(assigned
+ 1);
195 if (threadContexts
[id
])
196 fatal("Cannot have two CPUs with the same id (%d)\n", id
);
198 threadContexts
[id
] = tc
;
201 int port
= getRemoteGDBPort();
203 RemoteGDB
*rgdb
= new RemoteGDB(this, tc
);
204 GDBListener
*gdbl
= new GDBListener(rgdb
, port
+ id
);
207 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
210 if (remoteGDB
.size() <= id
) {
211 remoteGDB
.resize(id
+ 1);
214 remoteGDB
[id
] = rgdb
;
221 System::numRunningContexts()
224 for (int i
= 0; i
< _numContexts
; ++i
) {
225 if (threadContexts
[i
]->status() != ThreadContext::Halted
)
236 for (i
= 0; i
< threadContexts
.size(); i
++)
237 TheISA::startupCPU(threadContexts
[i
], i
);
242 System::replaceThreadContext(ThreadContext
*tc
, int context_id
)
244 if (context_id
>= threadContexts
.size()) {
245 panic("replaceThreadContext: bad id, %d >= %d\n",
246 context_id
, threadContexts
.size());
249 threadContexts
[context_id
] = tc
;
250 if (context_id
< remoteGDB
.size())
251 remoteGDB
[context_id
]->replaceThreadContext(tc
);
258 Addr return_addr
= page_ptr
<< LogVMPageSize
;
260 if (return_addr
>= physmem
->size())
261 fatal("Out of memory, please increase size of physical memory.");
268 return physmem
->size();
272 System::freeMemSize()
274 return physmem
->size() - (page_ptr
<< LogVMPageSize
);
280 System::serialize(ostream
&os
)
283 kernelSymtab
->serialize("kernel_symtab", os
);
284 #else // !FULL_SYSTEM
285 SERIALIZE_SCALAR(page_ptr
);
291 System::unserialize(Checkpoint
*cp
, const string
§ion
)
294 kernelSymtab
->unserialize("kernel_symtab", cp
, section
);
295 #else // !FULL_SYSTEM
296 UNSERIALIZE_SCALAR(page_ptr
);
301 System::printSystems()
303 vector
<System
*>::iterator i
= systemList
.begin();
304 vector
<System
*>::iterator end
= systemList
.end();
305 for (; i
!= end
; ++i
) {
307 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
314 System::printSystems();
317 const char *System::MemoryModeStrings
[3] = {"invalid", "atomic",
323 SystemParams::create()
325 return new System(this);