eb0655aa55a3b612ac99c466696badb27e99954d
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"
46 #include "arch/vtophys.hh"
47 #include "kern/kernel_stats.hh"
49 #include "params/System.hh"
53 using namespace TheISA
;
55 vector
<System
*> System::systemList
;
57 int System::numSystemsRunning
= 0;
59 System::System(Params
*p
)
60 : SimObject(p
->name
), physmem(p
->physmem
), numcpus(0),
62 init_param(p
->init_param
),
63 functionalPort(p
->name
+ "-fport"),
64 virtPort(p
->name
+ "-vport"),
68 memoryMode(p
->mem_mode
), _params(p
)
70 // add self to global system list
71 systemList
.push_back(this);
74 kernelSymtab
= new SymbolTable
;
75 if (!debugSymbolTable
)
76 debugSymbolTable
= new SymbolTable
;
80 * Get a functional port to memory
83 mem_port
= physmem
->getPort("functional");
84 functionalPort
.setPeer(mem_port
);
85 mem_port
->setPeer(&functionalPort
);
87 mem_port
= physmem
->getPort("functional");
88 virtPort
.setPeer(mem_port
);
89 mem_port
->setPeer(&virtPort
);
93 * Load the kernel code into memory
95 if (params()->kernel
== "") {
96 warn("No kernel set for full system simulation. Assuming you know what"
97 " you're doing...\n");
100 kernel
= createObjectFile(params()->kernel
);
102 fatal("Could not load kernel file %s", params()->kernel
);
104 // Load program sections into memory
105 kernel
->loadSections(&functionalPort
, LoadAddrMask
);
107 // setup entry points
108 kernelStart
= kernel
->textBase();
109 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
110 kernelEntry
= kernel
->entryPoint();
113 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
114 panic("could not load kernel symbols\n");
116 if (!kernel
->loadLocalSymbols(kernelSymtab
))
117 panic("could not load kernel local symbols\n");
119 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
120 panic("could not load kernel symbols\n");
122 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
123 panic("could not load kernel local symbols\n");
125 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
126 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
127 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
128 DPRINTF(Loader
, "Kernel loaded...\n");
130 #endif // FULL_SYSTEM
132 // increment the number of running systms
142 panic("System::fixFuncEventAddr needs to be rewritten "
143 "to work with syscall emulation");
144 #endif // FULL_SYSTEM}
148 int rgdb_enable
= true;
151 System::setMemoryMode(Enums::MemoryMode mode
)
153 assert(getState() == Drained
);
157 bool System::breakpoint()
159 if (remoteGDB
.size())
160 return remoteGDB
[0]->breakpoint();
165 System::registerThreadContext(ThreadContext
*tc
, int id
)
168 for (id
= 0; id
< threadContexts
.size(); id
++) {
169 if (!threadContexts
[id
])
174 if (threadContexts
.size() <= id
)
175 threadContexts
.resize(id
+ 1);
177 if (threadContexts
[id
])
178 panic("Cannot have two CPUs with the same id (%d)\n", id
);
180 threadContexts
[id
] = tc
;
184 RemoteGDB
*rgdb
= new RemoteGDB(this, tc
);
185 GDBListener
*gdbl
= new GDBListener(rgdb
, 7000 + id
);
188 * Uncommenting this line waits for a remote debugger to
189 * connect to the simulator before continuing.
191 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
194 if (remoteGDB
.size() <= id
) {
195 remoteGDB
.resize(id
+ 1);
198 remoteGDB
[id
] = rgdb
;
208 for (i
= 0; i
< threadContexts
.size(); i
++)
209 TheISA::startupCPU(threadContexts
[i
], i
);
213 System::replaceThreadContext(ThreadContext
*tc
, int id
)
215 if (id
>= threadContexts
.size()) {
216 panic("replaceThreadContext: bad id, %d >= %d\n",
217 id
, threadContexts
.size());
220 threadContexts
[id
] = tc
;
221 if (id
< remoteGDB
.size())
222 remoteGDB
[id
]->replaceThreadContext(tc
);
229 Addr return_addr
= page_ptr
<< LogVMPageSize
;
231 if (return_addr
>= physmem
->size())
232 fatal("Out of memory, please increase size of physical memory.");
238 System::serialize(ostream
&os
)
241 kernelSymtab
->serialize("kernel_symtab", os
);
242 #endif // FULL_SYSTEM
247 System::unserialize(Checkpoint
*cp
, const string
§ion
)
250 kernelSymtab
->unserialize("kernel_symtab", cp
, section
);
251 #endif // FULL_SYSTEM
255 System::printSystems()
257 vector
<System
*>::iterator i
= systemList
.begin();
258 vector
<System
*>::iterator end
= systemList
.end();
259 for (; i
!= end
; ++i
) {
261 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
268 System::printSystems();
271 const char *System::MemoryModeStrings
[3] = {"invalid", "atomic",
277 SystemParams::create()
279 System::Params
*p
= new System::Params
;
281 p
->physmem
= physmem
;
282 p
->mem_mode
= mem_mode
;
283 return new System(p
);