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 "base/loader/object_file.hh"
36 #include "base/loader/symtab.hh"
37 #include "base/trace.hh"
38 #include "cpu/thread_context.hh"
39 #include "mem/mem_object.hh"
40 #include "mem/physical.hh"
41 #include "sim/builder.hh"
42 #include "sim/byteswap.hh"
43 #include "sim/system.hh"
45 #include "arch/vtophys.hh"
46 #include "arch/remote_gdb.hh"
47 #include "kern/kernel_stats.hh"
51 using namespace TheISA
;
53 vector
<System
*> System::systemList
;
55 int System::numSystemsRunning
= 0;
57 System::System(Params
*p
)
58 : SimObject(p
->name
), physmem(p
->physmem
), numcpus(0),
60 init_param(p
->init_param
),
61 functionalPort(p
->name
+ "-fport"),
62 virtPort(p
->name
+ "-vport"),
66 memoryMode(p
->mem_mode
), _params(p
)
68 // add self to global system list
69 systemList
.push_back(this);
72 kernelSymtab
= new SymbolTable
;
73 debugSymbolTable
= new SymbolTable
;
77 * Get a functional port to memory
80 mem_port
= physmem
->getPort("functional");
81 functionalPort
.setPeer(mem_port
);
82 mem_port
->setPeer(&functionalPort
);
84 mem_port
= physmem
->getPort("functional");
85 virtPort
.setPeer(mem_port
);
86 mem_port
->setPeer(&virtPort
);
90 * Load the kernel code into memory
92 if (params()->kernel_path
== "") {
93 warn("No kernel set for full system simulation. Assuming you know what"
94 " you're doing...\n");
97 kernel
= createObjectFile(params()->kernel_path
);
99 fatal("Could not load kernel file %s", params()->kernel_path
);
101 // Load program sections into memory
102 kernel
->loadSections(&functionalPort
, LoadAddrMask
);
104 // setup entry points
105 kernelStart
= kernel
->textBase();
106 kernelEnd
= kernel
->bssBase() + kernel
->bssSize();
107 kernelEntry
= kernel
->entryPoint();
110 if (!kernel
->loadGlobalSymbols(kernelSymtab
))
111 panic("could not load kernel symbols\n");
113 if (!kernel
->loadLocalSymbols(kernelSymtab
))
114 panic("could not load kernel local symbols\n");
116 if (!kernel
->loadGlobalSymbols(debugSymbolTable
))
117 panic("could not load kernel symbols\n");
119 if (!kernel
->loadLocalSymbols(debugSymbolTable
))
120 panic("could not load kernel local symbols\n");
122 DPRINTF(Loader
, "Kernel start = %#x\n", kernelStart
);
123 DPRINTF(Loader
, "Kernel end = %#x\n", kernelEnd
);
124 DPRINTF(Loader
, "Kernel entry = %#x\n", kernelEntry
);
125 DPRINTF(Loader
, "Kernel loaded...\n");
127 #endif // FULL_SYSTEM
129 // increment the number of running systms
139 panic("System::fixFuncEventAddr needs to be rewritten "
140 "to work with syscall emulation");
141 #endif // FULL_SYSTEM}
149 #endif // FULL_SYSTEM
153 System::setMemoryMode(MemoryMode mode
)
155 assert(getState() == Drained
);
160 System::registerThreadContext(ThreadContext
*tc
, int id
)
163 for (id
= 0; id
< threadContexts
.size(); id
++) {
164 if (!threadContexts
[id
])
169 if (threadContexts
.size() <= id
)
170 threadContexts
.resize(id
+ 1);
172 if (threadContexts
[id
])
173 panic("Cannot have two CPUs with the same id (%d)\n", id
);
175 threadContexts
[id
] = tc
;
179 RemoteGDB
*rgdb
= new RemoteGDB(this, tc
);
180 GDBListener
*gdbl
= new GDBListener(rgdb
, 7000 + id
);
183 * Uncommenting this line waits for a remote debugger to connect
184 * to the simulator before continuing.
186 if (rgdb_wait
!= -1 && rgdb_wait
== id
)
189 if (remoteGDB
.size() <= id
) {
190 remoteGDB
.resize(id
+ 1);
193 remoteGDB
[id
] = rgdb
;
194 #endif // FULL_SYSTEM
203 for (i
= 0; i
< threadContexts
.size(); i
++)
204 threadContexts
[i
]->activate(0);
208 System::replaceThreadContext(ThreadContext
*tc
, int id
)
210 if (id
>= threadContexts
.size()) {
211 panic("replaceThreadContext: bad id, %d >= %d\n",
212 id
, threadContexts
.size());
215 threadContexts
[id
] = tc
;
217 remoteGDB
[id
]->replaceThreadContext(tc
);
218 #endif // FULL_SYSTEM
225 Addr return_addr
= page_ptr
<< LogVMPageSize
;
227 if (return_addr
>= physmem
->size())
228 fatal("Out of memory, please increase size of physical memory.");
234 System::serialize(ostream
&os
)
237 kernelSymtab
->serialize("kernel_symtab", os
);
238 #endif // FULL_SYSTEM
243 System::unserialize(Checkpoint
*cp
, const string
§ion
)
246 kernelSymtab
->unserialize("kernel_symtab", cp
, section
);
247 #endif // FULL_SYSTEM
251 System::printSystems()
253 vector
<System
*>::iterator i
= systemList
.begin();
254 vector
<System
*>::iterator end
= systemList
.end();
255 for (; i
!= end
; ++i
) {
257 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
264 System::printSystems();
267 const char *System::MemoryModeStrings
[3] = {"invalid", "atomic",
272 // In full system mode, only derived classes (e.g. AlphaLinuxSystem)
273 // can be created directly.
275 DEFINE_SIM_OBJECT_CLASS_NAME("System", System
)
279 BEGIN_DECLARE_SIM_OBJECT_PARAMS(System
)
281 SimObjectParam
<PhysicalMemory
*> physmem
;
282 SimpleEnumParam
<System::MemoryMode
> mem_mode
;
284 END_DECLARE_SIM_OBJECT_PARAMS(System
)
286 BEGIN_INIT_SIM_OBJECT_PARAMS(System
)
288 INIT_PARAM(physmem
, "physical memory"),
289 INIT_ENUM_PARAM(mem_mode
, "Memory Mode, (1=atomic, 2=timing)",
290 System::MemoryModeStrings
)
292 END_INIT_SIM_OBJECT_PARAMS(System
)
294 CREATE_SIM_OBJECT(System
)
296 System::Params
*p
= new System::Params
;
297 p
->name
= getInstanceName();
298 p
->physmem
= physmem
;
299 p
->mem_mode
= mem_mode
;
300 return new System(p
);
303 REGISTER_SIM_OBJECT("System", System
)