system.cc revision 4762
12689Sktlim@umich.edu/* 22689Sktlim@umich.edu * Copyright (c) 2003-2006 The Regents of The University of Michigan 32689Sktlim@umich.edu * All rights reserved. 42689Sktlim@umich.edu * 52689Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without 62689Sktlim@umich.edu * modification, are permitted provided that the following conditions are 72689Sktlim@umich.edu * met: redistributions of source code must retain the above copyright 82689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer; 92689Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright 102689Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the 112689Sktlim@umich.edu * documentation and/or other materials provided with the distribution; 122689Sktlim@umich.edu * neither the name of the copyright holders nor the names of its 132689Sktlim@umich.edu * contributors may be used to endorse or promote products derived from 142689Sktlim@umich.edu * this software without specific prior written permission. 152689Sktlim@umich.edu * 162689Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172689Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182689Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192689Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202689Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212689Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222689Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232689Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242689Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252689Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Steve Reinhardt 292689Sktlim@umich.edu * Lisa Hsu 302689Sktlim@umich.edu * Nathan Binkert 312689Sktlim@umich.edu * Ali Saidi 322689Sktlim@umich.edu */ 332689Sktlim@umich.edu 342521SN/A#include "arch/isa_traits.hh" 353960Sgblack@eecs.umich.edu#include "arch/remote_gdb.hh" 364194Ssaidi@eecs.umich.edu#include "arch/utility.hh" 371070SN/A#include "base/loader/object_file.hh" 381070SN/A#include "base/loader/symtab.hh" 392521SN/A#include "base/trace.hh" 402680Sktlim@umich.edu#include "cpu/thread_context.hh" 412521SN/A#include "mem/mem_object.hh" 422522SN/A#include "mem/physical.hh" 432037SN/A#include "sim/byteswap.hh" 4456SN/A#include "sim/system.hh" 452378SN/A#if FULL_SYSTEM 462521SN/A#include "arch/vtophys.hh" 472378SN/A#include "kern/kernel_stats.hh" 484762Snate@binkert.org#else 494762Snate@binkert.org#include "params/System.hh" 502378SN/A#endif 512SN/A 522SN/Ausing namespace std; 532107SN/Ausing namespace TheISA; 542SN/A 552SN/Avector<System *> System::systemList; 562SN/A 572SN/Aint System::numSystemsRunning = 0; 582SN/A 591070SN/ASystem::System(Params *p) 602378SN/A : SimObject(p->name), physmem(p->physmem), numcpus(0), 612378SN/A#if FULL_SYSTEM 622521SN/A init_param(p->init_param), 632640Sstever@eecs.umich.edu functionalPort(p->name + "-fport"), 642640Sstever@eecs.umich.edu virtPort(p->name + "-vport"), 652378SN/A#else 662378SN/A page_ptr(0), 672378SN/A#endif 682902Ssaidi@eecs.umich.edu memoryMode(p->mem_mode), _params(p) 692SN/A{ 701070SN/A // add self to global system list 711070SN/A systemList.push_back(this); 721070SN/A 732378SN/A#if FULL_SYSTEM 741070SN/A kernelSymtab = new SymbolTable; 751074SN/A debugSymbolTable = new SymbolTable; 761070SN/A 772520SN/A 782520SN/A /** 792520SN/A * Get a functional port to memory 802520SN/A */ 812520SN/A Port *mem_port; 822520SN/A mem_port = physmem->getPort("functional"); 832520SN/A functionalPort.setPeer(mem_port); 842520SN/A mem_port->setPeer(&functionalPort); 852520SN/A 862521SN/A mem_port = physmem->getPort("functional"); 872521SN/A virtPort.setPeer(mem_port); 882521SN/A mem_port->setPeer(&virtPort); 892521SN/A 902520SN/A 911070SN/A /** 922158SN/A * Load the kernel code into memory 931070SN/A */ 944762Snate@binkert.org if (params()->kernel == "") { 953812Ssaidi@eecs.umich.edu warn("No kernel set for full system simulation. Assuming you know what" 963812Ssaidi@eecs.umich.edu " you're doing...\n"); 973812Ssaidi@eecs.umich.edu } else { 983812Ssaidi@eecs.umich.edu // Load kernel code 994762Snate@binkert.org kernel = createObjectFile(params()->kernel); 1003812Ssaidi@eecs.umich.edu if (kernel == NULL) 1014762Snate@binkert.org fatal("Could not load kernel file %s", params()->kernel); 1021070SN/A 1033812Ssaidi@eecs.umich.edu // Load program sections into memory 1043812Ssaidi@eecs.umich.edu kernel->loadSections(&functionalPort, LoadAddrMask); 1051070SN/A 1063812Ssaidi@eecs.umich.edu // setup entry points 1073812Ssaidi@eecs.umich.edu kernelStart = kernel->textBase(); 1083812Ssaidi@eecs.umich.edu kernelEnd = kernel->bssBase() + kernel->bssSize(); 1093812Ssaidi@eecs.umich.edu kernelEntry = kernel->entryPoint(); 1101070SN/A 1113812Ssaidi@eecs.umich.edu // load symbols 1123812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(kernelSymtab)) 1133812Ssaidi@eecs.umich.edu panic("could not load kernel symbols\n"); 1141070SN/A 1153812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(kernelSymtab)) 1163812Ssaidi@eecs.umich.edu panic("could not load kernel local symbols\n"); 1171070SN/A 1183812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(debugSymbolTable)) 1193812Ssaidi@eecs.umich.edu panic("could not load kernel symbols\n"); 1201074SN/A 1213812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(debugSymbolTable)) 1223812Ssaidi@eecs.umich.edu panic("could not load kernel local symbols\n"); 1231074SN/A 1243812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 1253812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 1263812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 1273812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel loaded...\n"); 1283812Ssaidi@eecs.umich.edu } 1292378SN/A#endif // FULL_SYSTEM 1302378SN/A 1311070SN/A // increment the number of running systms 132878SN/A numSystemsRunning++; 1332SN/A} 1342SN/A 1352SN/ASystem::~System() 1362SN/A{ 1372378SN/A#if FULL_SYSTEM 1381070SN/A delete kernelSymtab; 1391070SN/A delete kernel; 1402378SN/A#else 1412378SN/A panic("System::fixFuncEventAddr needs to be rewritten " 1422378SN/A "to work with syscall emulation"); 1432378SN/A#endif // FULL_SYSTEM} 1442SN/A} 1452SN/A 1461808SN/Aint rgdb_wait = -1; 1474095Sbinkertn@umich.eduint rgdb_enable = true; 1481808SN/A 1492901Ssaidi@eecs.umich.eduvoid 1504762Snate@binkert.orgSystem::setMemoryMode(Enums::MemoryMode mode) 1512901Ssaidi@eecs.umich.edu{ 1522901Ssaidi@eecs.umich.edu assert(getState() == Drained); 1532901Ssaidi@eecs.umich.edu memoryMode = mode; 1542901Ssaidi@eecs.umich.edu} 1552901Ssaidi@eecs.umich.edu 1563960Sgblack@eecs.umich.edubool System::breakpoint() 1573960Sgblack@eecs.umich.edu{ 1584095Sbinkertn@umich.edu if (remoteGDB.size()) 1594095Sbinkertn@umich.edu return remoteGDB[0]->breakpoint(); 1604095Sbinkertn@umich.edu return false; 1613960Sgblack@eecs.umich.edu} 1623960Sgblack@eecs.umich.edu 163180SN/Aint 1642680Sktlim@umich.eduSystem::registerThreadContext(ThreadContext *tc, int id) 1652SN/A{ 1661806SN/A if (id == -1) { 1672680Sktlim@umich.edu for (id = 0; id < threadContexts.size(); id++) { 1682680Sktlim@umich.edu if (!threadContexts[id]) 1691806SN/A break; 1701806SN/A } 1711806SN/A } 1721806SN/A 1732680Sktlim@umich.edu if (threadContexts.size() <= id) 1742680Sktlim@umich.edu threadContexts.resize(id + 1); 1751806SN/A 1762680Sktlim@umich.edu if (threadContexts[id]) 1771806SN/A panic("Cannot have two CPUs with the same id (%d)\n", id); 1781806SN/A 1792680Sktlim@umich.edu threadContexts[id] = tc; 1801806SN/A numcpus++; 1811070SN/A 1824095Sbinkertn@umich.edu if (rgdb_enable) { 1834095Sbinkertn@umich.edu RemoteGDB *rgdb = new RemoteGDB(this, tc); 1844095Sbinkertn@umich.edu GDBListener *gdbl = new GDBListener(rgdb, 7000 + id); 1854095Sbinkertn@umich.edu gdbl->listen(); 1864095Sbinkertn@umich.edu /** 1874095Sbinkertn@umich.edu * Uncommenting this line waits for a remote debugger to 1884095Sbinkertn@umich.edu * connect to the simulator before continuing. 1894095Sbinkertn@umich.edu */ 1904095Sbinkertn@umich.edu if (rgdb_wait != -1 && rgdb_wait == id) 1914095Sbinkertn@umich.edu gdbl->accept(); 1921070SN/A 1934095Sbinkertn@umich.edu if (remoteGDB.size() <= id) { 1944095Sbinkertn@umich.edu remoteGDB.resize(id + 1); 1954095Sbinkertn@umich.edu } 1964095Sbinkertn@umich.edu 1974095Sbinkertn@umich.edu remoteGDB[id] = rgdb; 1981070SN/A } 1991070SN/A 2001806SN/A return id; 201180SN/A} 20275SN/A 203180SN/Avoid 2041129SN/ASystem::startup() 2051129SN/A{ 2062114SN/A int i; 2072680Sktlim@umich.edu for (i = 0; i < threadContexts.size(); i++) 2084194Ssaidi@eecs.umich.edu TheISA::startupCPU(threadContexts[i], i); 2091129SN/A} 2101129SN/A 2111129SN/Avoid 2122680Sktlim@umich.eduSystem::replaceThreadContext(ThreadContext *tc, int id) 213180SN/A{ 2142680Sktlim@umich.edu if (id >= threadContexts.size()) { 2152680Sktlim@umich.edu panic("replaceThreadContext: bad id, %d >= %d\n", 2162680Sktlim@umich.edu id, threadContexts.size()); 217180SN/A } 218180SN/A 2192680Sktlim@umich.edu threadContexts[id] = tc; 2204095Sbinkertn@umich.edu if (id < remoteGDB.size()) 2214095Sbinkertn@umich.edu remoteGDB[id]->replaceThreadContext(tc); 2222SN/A} 2232SN/A 2242378SN/A#if !FULL_SYSTEM 2252378SN/AAddr 2262378SN/ASystem::new_page() 2272378SN/A{ 2282378SN/A Addr return_addr = page_ptr << LogVMPageSize; 2292378SN/A ++page_ptr; 2303162Ssaidi@eecs.umich.edu if (return_addr >= physmem->size()) 2313162Ssaidi@eecs.umich.edu fatal("Out of memory, please increase size of physical memory."); 2322378SN/A return return_addr; 2332378SN/A} 2342378SN/A#endif 2352378SN/A 2361070SN/Avoid 2371070SN/ASystem::serialize(ostream &os) 2381070SN/A{ 2392378SN/A#if FULL_SYSTEM 2401984SN/A kernelSymtab->serialize("kernel_symtab", os); 2412378SN/A#endif // FULL_SYSTEM 2421070SN/A} 2431070SN/A 2441070SN/A 2451070SN/Avoid 2461070SN/ASystem::unserialize(Checkpoint *cp, const string §ion) 2471070SN/A{ 2482378SN/A#if FULL_SYSTEM 2491984SN/A kernelSymtab->unserialize("kernel_symtab", cp, section); 2502378SN/A#endif // FULL_SYSTEM 2511070SN/A} 2522SN/A 2532SN/Avoid 2542SN/ASystem::printSystems() 2552SN/A{ 2562SN/A vector<System *>::iterator i = systemList.begin(); 2572SN/A vector<System *>::iterator end = systemList.end(); 2582SN/A for (; i != end; ++i) { 2592SN/A System *sys = *i; 2602SN/A cerr << "System " << sys->name() << ": " << hex << sys << endl; 2612SN/A } 2622SN/A} 2632SN/A 2642SN/Avoid 2652SN/AprintSystems() 2662SN/A{ 2672SN/A System::printSystems(); 2682SN/A} 2692SN/A 2702902Ssaidi@eecs.umich.educonst char *System::MemoryModeStrings[3] = {"invalid", "atomic", 2712902Ssaidi@eecs.umich.edu "timing"}; 2722902Ssaidi@eecs.umich.edu 2734762Snate@binkert.org#if !FULL_SYSTEM 2742424SN/A 2754762Snate@binkert.orgSystem * 2764762Snate@binkert.orgSystemParams::create() 2772424SN/A{ 2782424SN/A System::Params *p = new System::Params; 2794762Snate@binkert.org p->name = name; 2802424SN/A p->physmem = physmem; 2812902Ssaidi@eecs.umich.edu p->mem_mode = mem_mode; 2822424SN/A return new System(p); 2832424SN/A} 2842424SN/A 2852424SN/A#endif 286