system.cc revision 1806
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com */ 2812855Sgabeblack@google.com 2912855Sgabeblack@google.com#include "base/loader/object_file.hh" 3012855Sgabeblack@google.com#include "base/loader/symtab.hh" 3112855Sgabeblack@google.com#include "base/remote_gdb.hh" 3212855Sgabeblack@google.com#include "cpu/exec_context.hh" 3312855Sgabeblack@google.com#include "kern/kernel_stats.hh" 3412855Sgabeblack@google.com#include "mem/functional/memory_control.hh" 3512855Sgabeblack@google.com#include "mem/functional/physical.hh" 3612855Sgabeblack@google.com#include "targetarch/vtophys.hh" 3712855Sgabeblack@google.com#include "sim/builder.hh" 3812855Sgabeblack@google.com#include "sim/system.hh" 3912855Sgabeblack@google.com#include "base/trace.hh" 4012855Sgabeblack@google.com 4112855Sgabeblack@google.comusing namespace std; 4212855Sgabeblack@google.com 4312855Sgabeblack@google.comvector<System *> System::systemList; 4412855Sgabeblack@google.com 4512855Sgabeblack@google.comint System::numSystemsRunning = 0; 4612855Sgabeblack@google.com 4712855Sgabeblack@google.comSystem::System(Params *p) 4812855Sgabeblack@google.com : SimObject(p->name), memctrl(p->memctrl), physmem(p->physmem), 4912855Sgabeblack@google.com init_param(p->init_param), numcpus(0), params(p) 5012855Sgabeblack@google.com{ 5112855Sgabeblack@google.com // add self to global system list 5212855Sgabeblack@google.com systemList.push_back(this); 5312855Sgabeblack@google.com 5412855Sgabeblack@google.com kernelSymtab = new SymbolTable; 5512855Sgabeblack@google.com consoleSymtab = new SymbolTable; 5612855Sgabeblack@google.com palSymtab = new SymbolTable; 5712855Sgabeblack@google.com debugSymbolTable = new SymbolTable; 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com /** 6012855Sgabeblack@google.com * Load the kernel, pal, and console code into memory 6112855Sgabeblack@google.com */ 6212855Sgabeblack@google.com // Load kernel code 6312855Sgabeblack@google.com kernel = createObjectFile(params->kernel_path); 6412855Sgabeblack@google.com if (kernel == NULL) 6512855Sgabeblack@google.com fatal("Could not load kernel file %s", params->kernel_path); 6612855Sgabeblack@google.com 6712855Sgabeblack@google.com // Load Console Code 6812855Sgabeblack@google.com console = createObjectFile(params->console_path); 6912855Sgabeblack@google.com if (console == NULL) 7012855Sgabeblack@google.com fatal("Could not load console file %s", params->console_path); 7112855Sgabeblack@google.com 7212855Sgabeblack@google.com // Load pal file 7312855Sgabeblack@google.com pal = createObjectFile(params->palcode); 7412855Sgabeblack@google.com if (pal == NULL) 7512855Sgabeblack@google.com fatal("Could not load PALcode file %s", params->palcode); 7612855Sgabeblack@google.com 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com // Load program sections into memory 7912855Sgabeblack@google.com pal->loadSections(physmem, true); 8012855Sgabeblack@google.com console->loadSections(physmem, true); 8112855Sgabeblack@google.com kernel->loadSections(physmem, true); 82 83 // setup entry points 84 kernelStart = kernel->textBase(); 85 kernelEnd = kernel->bssBase() + kernel->bssSize(); 86 kernelEntry = kernel->entryPoint(); 87 88 // load symbols 89 if (!kernel->loadGlobalSymbols(kernelSymtab)) 90 panic("could not load kernel symbols\n"); 91 92 if (!kernel->loadLocalSymbols(kernelSymtab)) 93 panic("could not load kernel local symbols\n"); 94 95 if (!console->loadGlobalSymbols(consoleSymtab)) 96 panic("could not load console symbols\n"); 97 98 if (!pal->loadGlobalSymbols(palSymtab)) 99 panic("could not load pal symbols\n"); 100 101 if (!pal->loadLocalSymbols(palSymtab)) 102 panic("could not load pal symbols\n"); 103 104 if (!kernel->loadGlobalSymbols(debugSymbolTable)) 105 panic("could not load kernel symbols\n"); 106 107 if (!kernel->loadLocalSymbols(debugSymbolTable)) 108 panic("could not load kernel local symbols\n"); 109 110 if (!console->loadGlobalSymbols(debugSymbolTable)) 111 panic("could not load console symbols\n"); 112 113 if (!pal->loadGlobalSymbols(debugSymbolTable)) 114 panic("could not load pal symbols\n"); 115 116 if (!pal->loadLocalSymbols(debugSymbolTable)) 117 panic("could not load pal symbols\n"); 118 119 120 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 121 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 122 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 123 DPRINTF(Loader, "Kernel loaded...\n"); 124 125 Addr addr = 0; 126#ifdef DEBUG 127 consolePanicEvent = new BreakPCEvent(&pcEventQueue, "console panic"); 128 if (consoleSymtab->findAddress("panic", addr)) 129 consolePanicEvent->schedule(addr); 130#endif 131 132 /** 133 * Copy the osflags (kernel arguments) into the consoles 134 * memory. (Presently Linux does not use the console service 135 * routine to get these command line arguments, but Tru64 and 136 * others do.) 137 */ 138 if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 139 Addr paddr = vtophys(physmem, addr); 140 char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t)); 141 142 if (osflags) 143 strcpy(osflags, params->boot_osflags.c_str()); 144 } 145 146 /** 147 * Set the hardware reset parameter block system type and revision 148 * information to Tsunami. 149 */ 150 if (consoleSymtab->findAddress("m5_rpb", addr)) { 151 Addr paddr = vtophys(physmem, addr); 152 char *hwrpb = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 153 154 if (!hwrpb) 155 panic("could not translate hwrpb addr\n"); 156 157 *(uint64_t*)(hwrpb+0x50) = htoa(params->system_type); 158 *(uint64_t*)(hwrpb+0x58) = htoa(params->system_rev); 159 } else 160 panic("could not find hwrpb\n"); 161 162 // increment the number of running systms 163 numSystemsRunning++; 164 165 kernelBinning = new Kernel::Binning(this); 166} 167 168System::~System() 169{ 170 delete kernelSymtab; 171 delete consoleSymtab; 172 delete kernel; 173 delete console; 174 delete pal; 175 176 delete kernelBinning; 177 178#ifdef DEBUG 179 delete consolePanicEvent; 180#endif 181} 182 183void 184System::setAlphaAccess(Addr access) 185{ 186 Addr addr = 0; 187 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) { 188 Addr paddr = vtophys(physmem, addr); 189 uint64_t *m5AlphaAccess = 190 (uint64_t *)physmem->dma_addr(paddr, sizeof(uint64_t)); 191 192 if (!m5AlphaAccess) 193 panic("could not translate m5AlphaAccess addr\n"); 194 195 *m5AlphaAccess = htoa(EV5::Phys2K0Seg(access)); 196 } else 197 panic("could not find m5AlphaAccess\n"); 198} 199 200bool 201System::breakpoint() 202{ 203 return remoteGDB[0]->trap(ALPHA_KENTRY_INT); 204} 205 206int 207System::registerExecContext(ExecContext *xc, int id) 208{ 209 if (id == -1) { 210 for (id = 0; id < execContexts.size(); id++) { 211 if (!execContexts[id]) 212 break; 213 } 214 } 215 216 if (execContexts.size() <= id) 217 execContexts.resize(id + 1); 218 219 if (execContexts[id]) 220 panic("Cannot have two CPUs with the same id (%d)\n", id); 221 222 execContexts[id] = xc; 223 numcpus++; 224 225 RemoteGDB *rgdb = new RemoteGDB(this, xc); 226 GDBListener *gdbl = new GDBListener(rgdb, 7000 + id); 227 gdbl->listen(); 228 /** 229 * Uncommenting this line waits for a remote debugger to connect 230 * to the simulator before continuing. 231 */ 232 //gdbl->accept(); 233 234 if (remoteGDB.size() <= id) { 235 remoteGDB.resize(id + 1); 236 } 237 238 remoteGDB[id] = rgdb; 239 240 return id; 241} 242 243void 244System::startup() 245{ 246 if (!execContexts.empty()) { 247 // activate with zero delay so that we start ticking right 248 // away on cycle 0 249 execContexts[0]->activate(0); 250 } 251} 252 253void 254System::replaceExecContext(ExecContext *xc, int id) 255{ 256 if (id >= execContexts.size()) { 257 panic("replaceExecContext: bad id, %d >= %d\n", 258 id, execContexts.size()); 259 } 260 261 execContexts[id] = xc; 262 remoteGDB[id]->replaceExecContext(xc); 263} 264 265void 266System::regStats() 267{ 268 kernelBinning->regStats(name() + ".kern"); 269} 270 271void 272System::serialize(ostream &os) 273{ 274 kernelBinning->serialize(os); 275} 276 277 278void 279System::unserialize(Checkpoint *cp, const string §ion) 280{ 281 kernelBinning->unserialize(cp, section); 282} 283 284void 285System::printSystems() 286{ 287 vector<System *>::iterator i = systemList.begin(); 288 vector<System *>::iterator end = systemList.end(); 289 for (; i != end; ++i) { 290 System *sys = *i; 291 cerr << "System " << sys->name() << ": " << hex << sys << endl; 292 } 293} 294 295extern "C" 296void 297printSystems() 298{ 299 System::printSystems(); 300} 301 302BEGIN_DECLARE_SIM_OBJECT_PARAMS(System) 303 304 Param<Tick> boot_cpu_frequency; 305 SimObjectParam<MemoryController *> memctrl; 306 SimObjectParam<PhysicalMemory *> physmem; 307 308 Param<string> kernel; 309 Param<string> console; 310 Param<string> pal; 311 312 Param<string> boot_osflags; 313 Param<string> readfile; 314 Param<unsigned int> init_param; 315 316 Param<uint64_t> system_type; 317 Param<uint64_t> system_rev; 318 319 Param<bool> bin; 320 VectorParam<string> binned_fns; 321 Param<bool> bin_int; 322 323END_DECLARE_SIM_OBJECT_PARAMS(System) 324 325BEGIN_INIT_SIM_OBJECT_PARAMS(System) 326 327 INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"), 328 INIT_PARAM(memctrl, "memory controller"), 329 INIT_PARAM(physmem, "phsyical memory"), 330 INIT_PARAM(kernel, "file that contains the kernel code"), 331 INIT_PARAM(console, "file that contains the console code"), 332 INIT_PARAM(pal, "file that contains palcode"), 333 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot", 334 "a"), 335 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""), 336 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0), 337 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34), 338 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10), 339 INIT_PARAM_DFLT(bin, "is this system to be binned", false), 340 INIT_PARAM(binned_fns, "functions to be broken down and binned"), 341 INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true) 342 343END_INIT_SIM_OBJECT_PARAMS(System) 344 345CREATE_SIM_OBJECT(System) 346{ 347 System::Params *p = new System::Params; 348 p->name = getInstanceName(); 349 p->boot_cpu_frequency = boot_cpu_frequency; 350 p->memctrl = memctrl; 351 p->physmem = physmem; 352 p->kernel_path = kernel; 353 p->console_path = console; 354 p->palcode = pal; 355 p->boot_osflags = boot_osflags; 356 p->init_param = init_param; 357 p->readfile = readfile; 358 p->system_type = system_type; 359 p->system_rev = system_rev; 360 p->bin = bin; 361 p->binned_fns = binned_fns; 362 p->bin_int = bin_int; 363 return new System(p); 364} 365 366REGISTER_SIM_OBJECT("System", System) 367 368