1/* 2 * Copyright (c) 2003-2006 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 * Authors: Steve Reinhardt 29 * Lisa Hsu 30 * Nathan Binkert 31 * Ali Saidi 32 */ 33 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" 48 49#if FULL_SYSTEM 50#include "arch/vtophys.hh" 51#include "kern/kernel_stats.hh" 52#else 53#include "params/System.hh" 54#endif 55 56using namespace std; 57using namespace TheISA; 58 59vector<System *> System::systemList; 60 61int System::numSystemsRunning = 0; 62 63System::System(Params *p) 64 : SimObject(p), physmem(p->physmem), _numContexts(0), 65#if FULL_SYSTEM 66 init_param(p->init_param), 67 functionalPort(p->name + "-fport"), 68 virtPort(p->name + "-vport"),
| 1/* 2 * Copyright (c) 2003-2006 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 * Authors: Steve Reinhardt 29 * Lisa Hsu 30 * Nathan Binkert 31 * Ali Saidi 32 */ 33 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" 48 49#if FULL_SYSTEM 50#include "arch/vtophys.hh" 51#include "kern/kernel_stats.hh" 52#else 53#include "params/System.hh" 54#endif 55 56using namespace std; 57using namespace TheISA; 58 59vector<System *> System::systemList; 60 61int System::numSystemsRunning = 0; 62 63System::System(Params *p) 64 : SimObject(p), physmem(p->physmem), _numContexts(0), 65#if FULL_SYSTEM 66 init_param(p->init_param), 67 functionalPort(p->name + "-fport"), 68 virtPort(p->name + "-vport"),
|
| 69 loadAddrMask(p->load_addr_mask),
|
69#else 70 page_ptr(0), 71 next_PID(0), 72#endif 73 memoryMode(p->mem_mode), _params(p) 74{ 75 // add self to global system list 76 systemList.push_back(this); 77 78#if FULL_SYSTEM 79 kernelSymtab = new SymbolTable; 80 if (!debugSymbolTable) 81 debugSymbolTable = new SymbolTable; 82 83 84 /** 85 * Get a functional port to memory 86 */ 87 Port *mem_port; 88 mem_port = physmem->getPort("functional"); 89 functionalPort.setPeer(mem_port); 90 mem_port->setPeer(&functionalPort); 91 92 mem_port = physmem->getPort("functional"); 93 virtPort.setPeer(mem_port); 94 mem_port->setPeer(&virtPort); 95 96 97 /** 98 * Load the kernel code into memory 99 */ 100 if (params()->kernel == "") { 101 inform("No kernel set for full system simulation. Assuming you know what" 102 " you're doing...\n"); 103 } else { 104 // Load kernel code 105 kernel = createObjectFile(params()->kernel); 106 inform("kernel located at: %s", params()->kernel); 107 108 if (kernel == NULL) 109 fatal("Could not load kernel file %s", params()->kernel); 110 111 // Load program sections into memory
| 70#else 71 page_ptr(0), 72 next_PID(0), 73#endif 74 memoryMode(p->mem_mode), _params(p) 75{ 76 // add self to global system list 77 systemList.push_back(this); 78 79#if FULL_SYSTEM 80 kernelSymtab = new SymbolTable; 81 if (!debugSymbolTable) 82 debugSymbolTable = new SymbolTable; 83 84 85 /** 86 * Get a functional port to memory 87 */ 88 Port *mem_port; 89 mem_port = physmem->getPort("functional"); 90 functionalPort.setPeer(mem_port); 91 mem_port->setPeer(&functionalPort); 92 93 mem_port = physmem->getPort("functional"); 94 virtPort.setPeer(mem_port); 95 mem_port->setPeer(&virtPort); 96 97 98 /** 99 * Load the kernel code into memory 100 */ 101 if (params()->kernel == "") { 102 inform("No kernel set for full system simulation. Assuming you know what" 103 " you're doing...\n"); 104 } else { 105 // Load kernel code 106 kernel = createObjectFile(params()->kernel); 107 inform("kernel located at: %s", params()->kernel); 108 109 if (kernel == NULL) 110 fatal("Could not load kernel file %s", params()->kernel); 111 112 // Load program sections into memory
|
112 kernel->loadSections(&functionalPort, LoadAddrMask);
| 113 kernel->loadSections(&functionalPort, loadAddrMask);
|
113 114 // setup entry points 115 kernelStart = kernel->textBase(); 116 kernelEnd = kernel->bssBase() + kernel->bssSize(); 117 kernelEntry = kernel->entryPoint(); 118 119 // load symbols 120 if (!kernel->loadGlobalSymbols(kernelSymtab)) 121 fatal("could not load kernel symbols\n"); 122 123 if (!kernel->loadLocalSymbols(kernelSymtab)) 124 fatal("could not load kernel local symbols\n"); 125 126 if (!kernel->loadGlobalSymbols(debugSymbolTable)) 127 fatal("could not load kernel symbols\n"); 128 129 if (!kernel->loadLocalSymbols(debugSymbolTable)) 130 fatal("could not load kernel local symbols\n"); 131 132 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 133 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 134 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 135 DPRINTF(Loader, "Kernel loaded...\n"); 136 } 137#endif // FULL_SYSTEM 138 139 // increment the number of running systms 140 numSystemsRunning++; 141} 142 143System::~System() 144{ 145#if FULL_SYSTEM 146 delete kernelSymtab; 147 delete kernel; 148#else 149 panic("System::fixFuncEventAddr needs to be rewritten " 150 "to work with syscall emulation"); 151#endif // FULL_SYSTEM} 152} 153 154void 155System::setMemoryMode(Enums::MemoryMode mode) 156{ 157 assert(getState() == Drained); 158 memoryMode = mode; 159} 160 161bool System::breakpoint() 162{ 163 if (remoteGDB.size()) 164 return remoteGDB[0]->breakpoint(); 165 return false; 166} 167 168/** 169 * Setting rgdb_wait to a positive integer waits for a remote debugger to 170 * connect to that context ID before continuing. This should really 171 be a parameter on the CPU object or something... 172 */ 173int rgdb_wait = -1; 174 175int 176System::registerThreadContext(ThreadContext *tc, int assigned) 177{ 178 int id; 179 if (assigned == -1) { 180 for (id = 0; id < threadContexts.size(); id++) { 181 if (!threadContexts[id]) 182 break; 183 } 184 185 if (threadContexts.size() <= id) 186 threadContexts.resize(id + 1); 187 } else { 188 if (threadContexts.size() <= assigned) 189 threadContexts.resize(assigned + 1); 190 id = assigned; 191 } 192 193 if (threadContexts[id]) 194 fatal("Cannot have two CPUs with the same id (%d)\n", id); 195 196 threadContexts[id] = tc; 197 _numContexts++; 198 199 int port = getRemoteGDBPort(); 200 if (port) { 201 RemoteGDB *rgdb = new RemoteGDB(this, tc); 202 GDBListener *gdbl = new GDBListener(rgdb, port + id); 203 gdbl->listen(); 204 205 if (rgdb_wait != -1 && rgdb_wait == id) 206 gdbl->accept(); 207 208 if (remoteGDB.size() <= id) { 209 remoteGDB.resize(id + 1); 210 } 211 212 remoteGDB[id] = rgdb; 213 } 214 215 return id; 216} 217 218int 219System::numRunningContexts() 220{ 221 int running = 0; 222 for (int i = 0; i < _numContexts; ++i) { 223 if (threadContexts[i]->status() != ThreadContext::Halted) 224 ++running; 225 } 226 return running; 227} 228 229void 230System::startup() 231{ 232#if FULL_SYSTEM 233 int i; 234 for (i = 0; i < threadContexts.size(); i++) 235 TheISA::startupCPU(threadContexts[i], i); 236#endif 237} 238 239void 240System::replaceThreadContext(ThreadContext *tc, int context_id) 241{ 242 if (context_id >= threadContexts.size()) { 243 panic("replaceThreadContext: bad id, %d >= %d\n", 244 context_id, threadContexts.size()); 245 } 246 247 threadContexts[context_id] = tc; 248 if (context_id < remoteGDB.size()) 249 remoteGDB[context_id]->replaceThreadContext(tc); 250} 251 252#if !FULL_SYSTEM 253Addr 254System::new_page() 255{ 256 Addr return_addr = page_ptr << LogVMPageSize; 257 ++page_ptr; 258 if (return_addr >= physmem->size()) 259 fatal("Out of memory, please increase size of physical memory."); 260 return return_addr; 261} 262 263Addr 264System::memSize() 265{ 266 return physmem->size(); 267} 268 269Addr 270System::freeMemSize() 271{ 272 return physmem->size() - (page_ptr << LogVMPageSize); 273} 274 275#endif 276 277void 278System::serialize(ostream &os) 279{ 280#if FULL_SYSTEM 281 kernelSymtab->serialize("kernel_symtab", os); 282#else // !FULL_SYSTEM 283 SERIALIZE_SCALAR(page_ptr); 284#endif 285} 286 287 288void 289System::unserialize(Checkpoint *cp, const string §ion) 290{ 291#if FULL_SYSTEM 292 kernelSymtab->unserialize("kernel_symtab", cp, section); 293#else // !FULL_SYSTEM 294 UNSERIALIZE_SCALAR(page_ptr); 295#endif 296} 297 298void 299System::printSystems() 300{ 301 vector<System *>::iterator i = systemList.begin(); 302 vector<System *>::iterator end = systemList.end(); 303 for (; i != end; ++i) { 304 System *sys = *i; 305 cerr << "System " << sys->name() << ": " << hex << sys << endl; 306 } 307} 308 309void 310printSystems() 311{ 312 System::printSystems(); 313} 314 315const char *System::MemoryModeStrings[3] = {"invalid", "atomic", 316 "timing"}; 317 318#if !FULL_SYSTEM 319 320System * 321SystemParams::create() 322{ 323 return new System(this); 324} 325 326#endif
| 114 115 // setup entry points 116 kernelStart = kernel->textBase(); 117 kernelEnd = kernel->bssBase() + kernel->bssSize(); 118 kernelEntry = kernel->entryPoint(); 119 120 // load symbols 121 if (!kernel->loadGlobalSymbols(kernelSymtab)) 122 fatal("could not load kernel symbols\n"); 123 124 if (!kernel->loadLocalSymbols(kernelSymtab)) 125 fatal("could not load kernel local symbols\n"); 126 127 if (!kernel->loadGlobalSymbols(debugSymbolTable)) 128 fatal("could not load kernel symbols\n"); 129 130 if (!kernel->loadLocalSymbols(debugSymbolTable)) 131 fatal("could not load kernel local symbols\n"); 132 133 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 134 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 135 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 136 DPRINTF(Loader, "Kernel loaded...\n"); 137 } 138#endif // FULL_SYSTEM 139 140 // increment the number of running systms 141 numSystemsRunning++; 142} 143 144System::~System() 145{ 146#if FULL_SYSTEM 147 delete kernelSymtab; 148 delete kernel; 149#else 150 panic("System::fixFuncEventAddr needs to be rewritten " 151 "to work with syscall emulation"); 152#endif // FULL_SYSTEM} 153} 154 155void 156System::setMemoryMode(Enums::MemoryMode mode) 157{ 158 assert(getState() == Drained); 159 memoryMode = mode; 160} 161 162bool System::breakpoint() 163{ 164 if (remoteGDB.size()) 165 return remoteGDB[0]->breakpoint(); 166 return false; 167} 168 169/** 170 * Setting rgdb_wait to a positive integer waits for a remote debugger to 171 * connect to that context ID before continuing. This should really 172 be a parameter on the CPU object or something... 173 */ 174int rgdb_wait = -1; 175 176int 177System::registerThreadContext(ThreadContext *tc, int assigned) 178{ 179 int id; 180 if (assigned == -1) { 181 for (id = 0; id < threadContexts.size(); id++) { 182 if (!threadContexts[id]) 183 break; 184 } 185 186 if (threadContexts.size() <= id) 187 threadContexts.resize(id + 1); 188 } else { 189 if (threadContexts.size() <= assigned) 190 threadContexts.resize(assigned + 1); 191 id = assigned; 192 } 193 194 if (threadContexts[id]) 195 fatal("Cannot have two CPUs with the same id (%d)\n", id); 196 197 threadContexts[id] = tc; 198 _numContexts++; 199 200 int port = getRemoteGDBPort(); 201 if (port) { 202 RemoteGDB *rgdb = new RemoteGDB(this, tc); 203 GDBListener *gdbl = new GDBListener(rgdb, port + id); 204 gdbl->listen(); 205 206 if (rgdb_wait != -1 && rgdb_wait == id) 207 gdbl->accept(); 208 209 if (remoteGDB.size() <= id) { 210 remoteGDB.resize(id + 1); 211 } 212 213 remoteGDB[id] = rgdb; 214 } 215 216 return id; 217} 218 219int 220System::numRunningContexts() 221{ 222 int running = 0; 223 for (int i = 0; i < _numContexts; ++i) { 224 if (threadContexts[i]->status() != ThreadContext::Halted) 225 ++running; 226 } 227 return running; 228} 229 230void 231System::startup() 232{ 233#if FULL_SYSTEM 234 int i; 235 for (i = 0; i < threadContexts.size(); i++) 236 TheISA::startupCPU(threadContexts[i], i); 237#endif 238} 239 240void 241System::replaceThreadContext(ThreadContext *tc, int context_id) 242{ 243 if (context_id >= threadContexts.size()) { 244 panic("replaceThreadContext: bad id, %d >= %d\n", 245 context_id, threadContexts.size()); 246 } 247 248 threadContexts[context_id] = tc; 249 if (context_id < remoteGDB.size()) 250 remoteGDB[context_id]->replaceThreadContext(tc); 251} 252 253#if !FULL_SYSTEM 254Addr 255System::new_page() 256{ 257 Addr return_addr = page_ptr << LogVMPageSize; 258 ++page_ptr; 259 if (return_addr >= physmem->size()) 260 fatal("Out of memory, please increase size of physical memory."); 261 return return_addr; 262} 263 264Addr 265System::memSize() 266{ 267 return physmem->size(); 268} 269 270Addr 271System::freeMemSize() 272{ 273 return physmem->size() - (page_ptr << LogVMPageSize); 274} 275 276#endif 277 278void 279System::serialize(ostream &os) 280{ 281#if FULL_SYSTEM 282 kernelSymtab->serialize("kernel_symtab", os); 283#else // !FULL_SYSTEM 284 SERIALIZE_SCALAR(page_ptr); 285#endif 286} 287 288 289void 290System::unserialize(Checkpoint *cp, const string §ion) 291{ 292#if FULL_SYSTEM 293 kernelSymtab->unserialize("kernel_symtab", cp, section); 294#else // !FULL_SYSTEM 295 UNSERIALIZE_SCALAR(page_ptr); 296#endif 297} 298 299void 300System::printSystems() 301{ 302 vector<System *>::iterator i = systemList.begin(); 303 vector<System *>::iterator end = systemList.end(); 304 for (; i != end; ++i) { 305 System *sys = *i; 306 cerr << "System " << sys->name() << ": " << hex << sys << endl; 307 } 308} 309 310void 311printSystems() 312{ 313 System::printSystems(); 314} 315 316const char *System::MemoryModeStrings[3] = {"invalid", "atomic", 317 "timing"}; 318 319#if !FULL_SYSTEM 320 321System * 322SystemParams::create() 323{ 324 return new System(this); 325} 326 327#endif
|