system.cc revision 4194
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" 431711SN/A#include "sim/builder.hh" 442037SN/A#include "sim/byteswap.hh" 4556SN/A#include "sim/system.hh" 462378SN/A#if FULL_SYSTEM 472521SN/A#include "arch/vtophys.hh" 482378SN/A#include "kern/kernel_stats.hh" 492378SN/A#endif 502SN/A 512SN/Ausing namespace std; 522107SN/Ausing namespace TheISA; 532SN/A 542SN/Avector<System *> System::systemList; 552SN/A 562SN/Aint System::numSystemsRunning = 0; 572SN/A 581070SN/ASystem::System(Params *p) 592378SN/A : SimObject(p->name), physmem(p->physmem), numcpus(0), 602378SN/A#if FULL_SYSTEM 612521SN/A init_param(p->init_param), 622640Sstever@eecs.umich.edu functionalPort(p->name + "-fport"), 632640Sstever@eecs.umich.edu virtPort(p->name + "-vport"), 642378SN/A#else 652378SN/A page_ptr(0), 662378SN/A#endif 672902Ssaidi@eecs.umich.edu memoryMode(p->mem_mode), _params(p) 682SN/A{ 691070SN/A // add self to global system list 701070SN/A systemList.push_back(this); 711070SN/A 722378SN/A#if FULL_SYSTEM 731070SN/A kernelSymtab = new SymbolTable; 741074SN/A debugSymbolTable = new SymbolTable; 751070SN/A 762520SN/A 772520SN/A /** 782520SN/A * Get a functional port to memory 792520SN/A */ 802520SN/A Port *mem_port; 812520SN/A mem_port = physmem->getPort("functional"); 822520SN/A functionalPort.setPeer(mem_port); 832520SN/A mem_port->setPeer(&functionalPort); 842520SN/A 852521SN/A mem_port = physmem->getPort("functional"); 862521SN/A virtPort.setPeer(mem_port); 872521SN/A mem_port->setPeer(&virtPort); 882521SN/A 892520SN/A 901070SN/A /** 912158SN/A * Load the kernel code into memory 921070SN/A */ 933812Ssaidi@eecs.umich.edu if (params()->kernel_path == "") { 943812Ssaidi@eecs.umich.edu warn("No kernel set for full system simulation. Assuming you know what" 953812Ssaidi@eecs.umich.edu " you're doing...\n"); 963812Ssaidi@eecs.umich.edu } else { 973812Ssaidi@eecs.umich.edu // Load kernel code 983812Ssaidi@eecs.umich.edu kernel = createObjectFile(params()->kernel_path); 993812Ssaidi@eecs.umich.edu if (kernel == NULL) 1003812Ssaidi@eecs.umich.edu fatal("Could not load kernel file %s", params()->kernel_path); 1011070SN/A 1023812Ssaidi@eecs.umich.edu // Load program sections into memory 1033812Ssaidi@eecs.umich.edu kernel->loadSections(&functionalPort, LoadAddrMask); 1041070SN/A 1053812Ssaidi@eecs.umich.edu // setup entry points 1063812Ssaidi@eecs.umich.edu kernelStart = kernel->textBase(); 1073812Ssaidi@eecs.umich.edu kernelEnd = kernel->bssBase() + kernel->bssSize(); 1083812Ssaidi@eecs.umich.edu kernelEntry = kernel->entryPoint(); 1091070SN/A 1103812Ssaidi@eecs.umich.edu // load symbols 1113812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(kernelSymtab)) 1123812Ssaidi@eecs.umich.edu panic("could not load kernel symbols\n"); 1131070SN/A 1143812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(kernelSymtab)) 1153812Ssaidi@eecs.umich.edu panic("could not load kernel local symbols\n"); 1161070SN/A 1173812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(debugSymbolTable)) 1183812Ssaidi@eecs.umich.edu panic("could not load kernel symbols\n"); 1191074SN/A 1203812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(debugSymbolTable)) 1213812Ssaidi@eecs.umich.edu panic("could not load kernel local symbols\n"); 1221074SN/A 1233812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 1243812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 1253812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 1263812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel loaded...\n"); 1273812Ssaidi@eecs.umich.edu } 1282378SN/A#endif // FULL_SYSTEM 1292378SN/A 1301070SN/A // increment the number of running systms 131878SN/A numSystemsRunning++; 1322SN/A} 1332SN/A 1342SN/ASystem::~System() 1352SN/A{ 1362378SN/A#if FULL_SYSTEM 1371070SN/A delete kernelSymtab; 1381070SN/A delete kernel; 1392378SN/A#else 1402378SN/A panic("System::fixFuncEventAddr needs to be rewritten " 1412378SN/A "to work with syscall emulation"); 1422378SN/A#endif // FULL_SYSTEM} 1432SN/A} 1442SN/A 1451808SN/Aint rgdb_wait = -1; 1464095Sbinkertn@umich.eduint rgdb_enable = true; 1471808SN/A 1482901Ssaidi@eecs.umich.eduvoid 1492901Ssaidi@eecs.umich.eduSystem::setMemoryMode(MemoryMode mode) 1502901Ssaidi@eecs.umich.edu{ 1512901Ssaidi@eecs.umich.edu assert(getState() == Drained); 1522901Ssaidi@eecs.umich.edu memoryMode = mode; 1532901Ssaidi@eecs.umich.edu} 1542901Ssaidi@eecs.umich.edu 1553960Sgblack@eecs.umich.edubool System::breakpoint() 1563960Sgblack@eecs.umich.edu{ 1574095Sbinkertn@umich.edu if (remoteGDB.size()) 1584095Sbinkertn@umich.edu return remoteGDB[0]->breakpoint(); 1594095Sbinkertn@umich.edu return false; 1603960Sgblack@eecs.umich.edu} 1613960Sgblack@eecs.umich.edu 162180SN/Aint 1632680Sktlim@umich.eduSystem::registerThreadContext(ThreadContext *tc, int id) 1642SN/A{ 1651806SN/A if (id == -1) { 1662680Sktlim@umich.edu for (id = 0; id < threadContexts.size(); id++) { 1672680Sktlim@umich.edu if (!threadContexts[id]) 1681806SN/A break; 1691806SN/A } 1701806SN/A } 1711806SN/A 1722680Sktlim@umich.edu if (threadContexts.size() <= id) 1732680Sktlim@umich.edu threadContexts.resize(id + 1); 1741806SN/A 1752680Sktlim@umich.edu if (threadContexts[id]) 1761806SN/A panic("Cannot have two CPUs with the same id (%d)\n", id); 1771806SN/A 1782680Sktlim@umich.edu threadContexts[id] = tc; 1791806SN/A numcpus++; 1801070SN/A 1814095Sbinkertn@umich.edu if (rgdb_enable) { 1824095Sbinkertn@umich.edu RemoteGDB *rgdb = new RemoteGDB(this, tc); 1834095Sbinkertn@umich.edu GDBListener *gdbl = new GDBListener(rgdb, 7000 + id); 1844095Sbinkertn@umich.edu gdbl->listen(); 1854095Sbinkertn@umich.edu /** 1864095Sbinkertn@umich.edu * Uncommenting this line waits for a remote debugger to 1874095Sbinkertn@umich.edu * connect to the simulator before continuing. 1884095Sbinkertn@umich.edu */ 1894095Sbinkertn@umich.edu if (rgdb_wait != -1 && rgdb_wait == id) 1904095Sbinkertn@umich.edu gdbl->accept(); 1911070SN/A 1924095Sbinkertn@umich.edu if (remoteGDB.size() <= id) { 1934095Sbinkertn@umich.edu remoteGDB.resize(id + 1); 1944095Sbinkertn@umich.edu } 1954095Sbinkertn@umich.edu 1964095Sbinkertn@umich.edu remoteGDB[id] = rgdb; 1971070SN/A } 1981070SN/A 1991806SN/A return id; 200180SN/A} 20175SN/A 202180SN/Avoid 2031129SN/ASystem::startup() 2041129SN/A{ 2052114SN/A int i; 2062680Sktlim@umich.edu for (i = 0; i < threadContexts.size(); i++) 2074194Ssaidi@eecs.umich.edu TheISA::startupCPU(threadContexts[i], i); 2081129SN/A} 2091129SN/A 2101129SN/Avoid 2112680Sktlim@umich.eduSystem::replaceThreadContext(ThreadContext *tc, int id) 212180SN/A{ 2132680Sktlim@umich.edu if (id >= threadContexts.size()) { 2142680Sktlim@umich.edu panic("replaceThreadContext: bad id, %d >= %d\n", 2152680Sktlim@umich.edu id, threadContexts.size()); 216180SN/A } 217180SN/A 2182680Sktlim@umich.edu threadContexts[id] = tc; 2194095Sbinkertn@umich.edu if (id < remoteGDB.size()) 2204095Sbinkertn@umich.edu remoteGDB[id]->replaceThreadContext(tc); 2212SN/A} 2222SN/A 2232378SN/A#if !FULL_SYSTEM 2242378SN/AAddr 2252378SN/ASystem::new_page() 2262378SN/A{ 2272378SN/A Addr return_addr = page_ptr << LogVMPageSize; 2282378SN/A ++page_ptr; 2293162Ssaidi@eecs.umich.edu if (return_addr >= physmem->size()) 2303162Ssaidi@eecs.umich.edu fatal("Out of memory, please increase size of physical memory."); 2312378SN/A return return_addr; 2322378SN/A} 2332378SN/A#endif 2342378SN/A 2351070SN/Avoid 2361070SN/ASystem::serialize(ostream &os) 2371070SN/A{ 2382378SN/A#if FULL_SYSTEM 2391984SN/A kernelSymtab->serialize("kernel_symtab", os); 2402378SN/A#endif // FULL_SYSTEM 2411070SN/A} 2421070SN/A 2431070SN/A 2441070SN/Avoid 2451070SN/ASystem::unserialize(Checkpoint *cp, const string §ion) 2461070SN/A{ 2472378SN/A#if FULL_SYSTEM 2481984SN/A kernelSymtab->unserialize("kernel_symtab", cp, section); 2492378SN/A#endif // FULL_SYSTEM 2501070SN/A} 2512SN/A 2522SN/Avoid 2532SN/ASystem::printSystems() 2542SN/A{ 2552SN/A vector<System *>::iterator i = systemList.begin(); 2562SN/A vector<System *>::iterator end = systemList.end(); 2572SN/A for (; i != end; ++i) { 2582SN/A System *sys = *i; 2592SN/A cerr << "System " << sys->name() << ": " << hex << sys << endl; 2602SN/A } 2612SN/A} 2622SN/A 2632SN/Avoid 2642SN/AprintSystems() 2652SN/A{ 2662SN/A System::printSystems(); 2672SN/A} 2682SN/A 2692902Ssaidi@eecs.umich.educonst char *System::MemoryModeStrings[3] = {"invalid", "atomic", 2702902Ssaidi@eecs.umich.edu "timing"}; 2712902Ssaidi@eecs.umich.edu 2722424SN/A#if FULL_SYSTEM 2732424SN/A 2742424SN/A// In full system mode, only derived classes (e.g. AlphaLinuxSystem) 2752424SN/A// can be created directly. 2762424SN/A 2772158SN/ADEFINE_SIM_OBJECT_CLASS_NAME("System", System) 2782SN/A 2792424SN/A#else 2802424SN/A 2812424SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(System) 2822424SN/A 2832522SN/A SimObjectParam<PhysicalMemory *> physmem; 2842902Ssaidi@eecs.umich.edu SimpleEnumParam<System::MemoryMode> mem_mode; 2852424SN/A 2862424SN/AEND_DECLARE_SIM_OBJECT_PARAMS(System) 2872424SN/A 2882424SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(System) 2892424SN/A 2902902Ssaidi@eecs.umich.edu INIT_PARAM(physmem, "physical memory"), 2912902Ssaidi@eecs.umich.edu INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)", 2922902Ssaidi@eecs.umich.edu System::MemoryModeStrings) 2932424SN/A 2942424SN/AEND_INIT_SIM_OBJECT_PARAMS(System) 2952424SN/A 2962424SN/ACREATE_SIM_OBJECT(System) 2972424SN/A{ 2982424SN/A System::Params *p = new System::Params; 2992424SN/A p->name = getInstanceName(); 3002424SN/A p->physmem = physmem; 3012902Ssaidi@eecs.umich.edu p->mem_mode = mem_mode; 3022424SN/A return new System(p); 3032424SN/A} 3042424SN/A 3052424SN/AREGISTER_SIM_OBJECT("System", System) 3062424SN/A 3072424SN/A#endif 308