system.cc revision 1070
1/* 2 * Copyright (c) 2002-2004 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 29#include "base/loader/object_file.hh" 30#include "base/loader/symtab.hh" 31#include "base/remote_gdb.hh" 32#include "cpu/exec_context.hh" 33#include "kern/kernel_stats.hh" 34#include "mem/functional_mem/memory_control.hh" 35#include "mem/functional_mem/physical_memory.hh" 36#include "targetarch/vtophys.hh" 37#include "sim/param.hh" 38#include "sim/system.hh" 39#include "base/trace.hh" 40 41using namespace std; 42 43vector<System *> System::systemList; 44 45int System::numSystemsRunning = 0; 46 47extern SymbolTable *debugSymbolTable; 48 49System::System(Params *p) 50 : SimObject(p->name), memctrl(p->memctrl), physmem(p->physmem), 51 init_param(p->init_param), params(p) 52{ 53 // add self to global system list 54 systemList.push_back(this); 55 56 kernelSymtab = new SymbolTable; 57 consoleSymtab = new SymbolTable; 58 debugSymbolTable = kernelSymtab; 59 60 /** 61 * Load the kernel, pal, and console code into memory 62 */ 63 // Load kernel code 64 kernel = createObjectFile(params->kernel_path); 65 if (kernel == NULL) 66 fatal("Could not load kernel file %s", params->kernel_path); 67 68 // Load Console Code 69 console = createObjectFile(params->console_path); 70 if (console == NULL) 71 fatal("Could not load console file %s", params->console_path); 72 73 // Load pal file 74 pal = createObjectFile(params->palcode); 75 if (pal == NULL) 76 fatal("Could not load PALcode file %s", params->palcode); 77 78 79 // Load program sections into memory 80 pal->loadSections(physmem, true); 81 console->loadSections(physmem, true); 82 kernel->loadSections(physmem, true); 83 84 // setup entry points 85 kernelStart = kernel->textBase(); 86 kernelEnd = kernel->bssBase() + kernel->bssSize(); 87 kernelEntry = kernel->entryPoint(); 88 89 // load symbols 90 if (!kernel->loadGlobalSymbols(kernelSymtab)) 91 panic("could not load kernel symbols\n"); 92 debugSymbolTable = kernelSymtab; 93 94 if (!kernel->loadLocalSymbols(kernelSymtab)) 95 panic("could not load kernel local symbols\n"); 96 97 if (!console->loadGlobalSymbols(consoleSymtab)) 98 panic("could not load console symbols\n"); 99 100 DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 101 DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 102 DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 103 DPRINTF(Loader, "Kernel loaded...\n"); 104 105 Addr addr = 0; 106#ifdef DEBUG 107 consolePanicEvent = new BreakPCEvent(&pcEventQueue, "console panic"); 108 if (consoleSymtab->findAddress("panic", addr)) 109 consolePanicEvent->schedule(addr); 110#endif 111 112 /** 113 * Copy the osflags (kernel arguments) into the consoles 114 * memory. (Presently Linux does not use the console service 115 * routine to get these command line arguments, but Tru64 and 116 * others do.) 117 */ 118 if (consoleSymtab->findAddress("env_booted_osflags", addr)) { 119 Addr paddr = vtophys(physmem, addr); 120 char *osflags = (char *)physmem->dma_addr(paddr, sizeof(uint32_t)); 121 122 if (osflags) 123 strcpy(osflags, params->boot_osflags.c_str()); 124 } 125 126 /** 127 * Set the hardware reset parameter block system type and revision 128 * information to Tsunami. 129 */ 130 if (consoleSymtab->findAddress("xxm_rpb", addr)) { 131 Addr paddr = vtophys(physmem, addr); 132 char *hwrpb = (char *)physmem->dma_addr(paddr, sizeof(uint64_t)); 133 134 if (!hwrpb) 135 panic("could not translate hwrpb addr\n"); 136 137 *(uint64_t*)(hwrpb+0x50) = params->system_type; 138 *(uint64_t*)(hwrpb+0x58) = params->system_rev; 139 } else 140 panic("could not find hwrpb\n"); 141 142 // increment the number of running systms 143 numSystemsRunning++; 144 145 kernelBinning = new Kernel::Binning(this); 146} 147 148System::~System() 149{ 150 delete kernelSymtab; 151 delete consoleSymtab; 152 delete kernel; 153 delete console; 154 delete pal; 155 156 delete kernelBinning; 157 158#ifdef DEBUG 159 delete consolePanicEvent; 160#endif 161} 162 163bool 164System::breakpoint() 165{ 166 return remoteGDB[0]->trap(ALPHA_KENTRY_INT); 167} 168 169int 170System::registerExecContext(ExecContext *xc) 171{ 172 int xcIndex = execContexts.size(); 173 execContexts.push_back(xc); 174 175 if (xcIndex == 0) { 176 // activate with zero delay so that we start ticking right 177 // away on cycle 0 178 xc->activate(0); 179 } 180 181 RemoteGDB *rgdb = new RemoteGDB(this, xc); 182 GDBListener *gdbl = new GDBListener(rgdb, 7000 + xcIndex); 183 gdbl->listen(); 184 /** 185 * Uncommenting this line waits for a remote debugger to connect 186 * to the simulator before continuing. 187 */ 188 //gdbl->accept(); 189 190 if (remoteGDB.size() <= xcIndex) { 191 remoteGDB.resize(xcIndex+1); 192 } 193 194 remoteGDB[xcIndex] = rgdb; 195 196 return xcIndex; 197} 198 199void 200System::replaceExecContext(ExecContext *xc, int xcIndex) 201{ 202 if (xcIndex >= execContexts.size()) { 203 panic("replaceExecContext: bad xcIndex, %d >= %d\n", 204 xcIndex, execContexts.size()); 205 } 206 207 execContexts[xcIndex] = xc; 208 remoteGDB[xcIndex]->replaceExecContext(xc); 209} 210 211void 212System::regStats() 213{ 214 kernelBinning->regStats(name() + ".kern"); 215} 216 217void 218System::serialize(ostream &os) 219{ 220 kernelBinning->serialize(os); 221} 222 223 224void 225System::unserialize(Checkpoint *cp, const string §ion) 226{ 227 kernelBinning->unserialize(cp, section); 228} 229 230void 231System::printSystems() 232{ 233 vector<System *>::iterator i = systemList.begin(); 234 vector<System *>::iterator end = systemList.end(); 235 for (; i != end; ++i) { 236 System *sys = *i; 237 cerr << "System " << sys->name() << ": " << hex << sys << endl; 238 } 239} 240 241extern "C" 242void 243printSystems() 244{ 245 System::printSystems(); 246} 247 248DEFINE_SIM_OBJECT_CLASS_NAME("System", System) 249 250