system.cc revision 7650
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" 416658Snate@binkert.org#include "config/full_system.hh" 426658Snate@binkert.org#include "config/the_isa.hh" 432521SN/A#include "mem/mem_object.hh" 442522SN/A#include "mem/physical.hh" 452037SN/A#include "sim/byteswap.hh" 4656SN/A#include "sim/system.hh" 475512SMichael.Adler@intel.com#include "sim/debug.hh" 486658Snate@binkert.org 492378SN/A#if FULL_SYSTEM 502521SN/A#include "arch/vtophys.hh" 512378SN/A#include "kern/kernel_stats.hh" 524762Snate@binkert.org#else 534762Snate@binkert.org#include "params/System.hh" 542378SN/A#endif 552SN/A 562SN/Ausing namespace std; 572107SN/Ausing namespace TheISA; 582SN/A 592SN/Avector<System *> System::systemList; 602SN/A 612SN/Aint System::numSystemsRunning = 0; 622SN/A 631070SN/ASystem::System(Params *p) 645714Shsul@eecs.umich.edu : SimObject(p), physmem(p->physmem), _numContexts(0), 652378SN/A#if FULL_SYSTEM 662521SN/A init_param(p->init_param), 672640Sstever@eecs.umich.edu functionalPort(p->name + "-fport"), 682640Sstever@eecs.umich.edu virtPort(p->name + "-vport"), 697580SAli.Saidi@arm.com loadAddrMask(p->load_addr_mask), 702378SN/A#else 712378SN/A page_ptr(0), 724997Sgblack@eecs.umich.edu next_PID(0), 732378SN/A#endif 742902Ssaidi@eecs.umich.edu memoryMode(p->mem_mode), _params(p) 752SN/A{ 761070SN/A // add self to global system list 771070SN/A systemList.push_back(this); 781070SN/A 792378SN/A#if FULL_SYSTEM 801070SN/A kernelSymtab = new SymbolTable; 814838Ssaidi@eecs.umich.edu if (!debugSymbolTable) 824838Ssaidi@eecs.umich.edu debugSymbolTable = new SymbolTable; 831070SN/A 842520SN/A 852520SN/A /** 862520SN/A * Get a functional port to memory 872520SN/A */ 882520SN/A Port *mem_port; 892520SN/A mem_port = physmem->getPort("functional"); 902520SN/A functionalPort.setPeer(mem_port); 912520SN/A mem_port->setPeer(&functionalPort); 922520SN/A 932521SN/A mem_port = physmem->getPort("functional"); 942521SN/A virtPort.setPeer(mem_port); 952521SN/A mem_port->setPeer(&virtPort); 962521SN/A 972520SN/A 981070SN/A /** 992158SN/A * Load the kernel code into memory 1001070SN/A */ 1014762Snate@binkert.org if (params()->kernel == "") { 1025823Ssaidi@eecs.umich.edu inform("No kernel set for full system simulation. Assuming you know what" 1033812Ssaidi@eecs.umich.edu " you're doing...\n"); 1043812Ssaidi@eecs.umich.edu } else { 1053812Ssaidi@eecs.umich.edu // Load kernel code 1064762Snate@binkert.org kernel = createObjectFile(params()->kernel); 1075823Ssaidi@eecs.umich.edu inform("kernel located at: %s", params()->kernel); 1085222Sksewell@umich.edu 1093812Ssaidi@eecs.umich.edu if (kernel == NULL) 1104762Snate@binkert.org fatal("Could not load kernel file %s", params()->kernel); 1111070SN/A 1123812Ssaidi@eecs.umich.edu // Load program sections into memory 1137580SAli.Saidi@arm.com kernel->loadSections(&functionalPort, loadAddrMask); 1141070SN/A 1153812Ssaidi@eecs.umich.edu // setup entry points 1163812Ssaidi@eecs.umich.edu kernelStart = kernel->textBase(); 1173812Ssaidi@eecs.umich.edu kernelEnd = kernel->bssBase() + kernel->bssSize(); 1183812Ssaidi@eecs.umich.edu kernelEntry = kernel->entryPoint(); 1191070SN/A 1203812Ssaidi@eecs.umich.edu // load symbols 1213812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(kernelSymtab)) 1225823Ssaidi@eecs.umich.edu fatal("could not load kernel symbols\n"); 1231070SN/A 1243812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(kernelSymtab)) 1255823Ssaidi@eecs.umich.edu fatal("could not load kernel local symbols\n"); 1261070SN/A 1273812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(debugSymbolTable)) 1285823Ssaidi@eecs.umich.edu fatal("could not load kernel symbols\n"); 1291074SN/A 1303812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(debugSymbolTable)) 1315823Ssaidi@eecs.umich.edu fatal("could not load kernel local symbols\n"); 1321074SN/A 1333812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 1343812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 1353812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 1363812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel loaded...\n"); 1373812Ssaidi@eecs.umich.edu } 1382378SN/A#endif // FULL_SYSTEM 1392378SN/A 1401070SN/A // increment the number of running systms 141878SN/A numSystemsRunning++; 1422SN/A} 1432SN/A 1442SN/ASystem::~System() 1452SN/A{ 1462378SN/A#if FULL_SYSTEM 1471070SN/A delete kernelSymtab; 1481070SN/A delete kernel; 1492378SN/A#else 1502378SN/A panic("System::fixFuncEventAddr needs to be rewritten " 1512378SN/A "to work with syscall emulation"); 1522378SN/A#endif // FULL_SYSTEM} 1532SN/A} 1542SN/A 1552901Ssaidi@eecs.umich.eduvoid 1564762Snate@binkert.orgSystem::setMemoryMode(Enums::MemoryMode mode) 1572901Ssaidi@eecs.umich.edu{ 1582901Ssaidi@eecs.umich.edu assert(getState() == Drained); 1592901Ssaidi@eecs.umich.edu memoryMode = mode; 1602901Ssaidi@eecs.umich.edu} 1612901Ssaidi@eecs.umich.edu 1623960Sgblack@eecs.umich.edubool System::breakpoint() 1633960Sgblack@eecs.umich.edu{ 1644095Sbinkertn@umich.edu if (remoteGDB.size()) 1654095Sbinkertn@umich.edu return remoteGDB[0]->breakpoint(); 1664095Sbinkertn@umich.edu return false; 1673960Sgblack@eecs.umich.edu} 1683960Sgblack@eecs.umich.edu 1697445Ssteve.reinhardt@amd.com/** 1707445Ssteve.reinhardt@amd.com * Setting rgdb_wait to a positive integer waits for a remote debugger to 1717445Ssteve.reinhardt@amd.com * connect to that context ID before continuing. This should really 1727445Ssteve.reinhardt@amd.com be a parameter on the CPU object or something... 1737445Ssteve.reinhardt@amd.com */ 1747445Ssteve.reinhardt@amd.comint rgdb_wait = -1; 1757445Ssteve.reinhardt@amd.com 176180SN/Aint 1775718Shsul@eecs.umich.eduSystem::registerThreadContext(ThreadContext *tc, int assigned) 1782SN/A{ 1795712Shsul@eecs.umich.edu int id; 1805718Shsul@eecs.umich.edu if (assigned == -1) { 1815718Shsul@eecs.umich.edu for (id = 0; id < threadContexts.size(); id++) { 1825718Shsul@eecs.umich.edu if (!threadContexts[id]) 1835718Shsul@eecs.umich.edu break; 1845718Shsul@eecs.umich.edu } 1855718Shsul@eecs.umich.edu 1865718Shsul@eecs.umich.edu if (threadContexts.size() <= id) 1875718Shsul@eecs.umich.edu threadContexts.resize(id + 1); 1885718Shsul@eecs.umich.edu } else { 1895718Shsul@eecs.umich.edu if (threadContexts.size() <= assigned) 1905718Shsul@eecs.umich.edu threadContexts.resize(assigned + 1); 1915718Shsul@eecs.umich.edu id = assigned; 1921806SN/A } 1931806SN/A 1942680Sktlim@umich.edu if (threadContexts[id]) 1955823Ssaidi@eecs.umich.edu fatal("Cannot have two CPUs with the same id (%d)\n", id); 1961806SN/A 1972680Sktlim@umich.edu threadContexts[id] = tc; 1985714Shsul@eecs.umich.edu _numContexts++; 1991070SN/A 2005512SMichael.Adler@intel.com int port = getRemoteGDBPort(); 2017445Ssteve.reinhardt@amd.com if (port) { 2024095Sbinkertn@umich.edu RemoteGDB *rgdb = new RemoteGDB(this, tc); 2035512SMichael.Adler@intel.com GDBListener *gdbl = new GDBListener(rgdb, port + id); 2044095Sbinkertn@umich.edu gdbl->listen(); 2057445Ssteve.reinhardt@amd.com 2064095Sbinkertn@umich.edu if (rgdb_wait != -1 && rgdb_wait == id) 2074095Sbinkertn@umich.edu gdbl->accept(); 2081070SN/A 2094095Sbinkertn@umich.edu if (remoteGDB.size() <= id) { 2104095Sbinkertn@umich.edu remoteGDB.resize(id + 1); 2114095Sbinkertn@umich.edu } 2124095Sbinkertn@umich.edu 2134095Sbinkertn@umich.edu remoteGDB[id] = rgdb; 2141070SN/A } 2151070SN/A 2161806SN/A return id; 217180SN/A} 21875SN/A 2196029Ssteve.reinhardt@amd.comint 2206029Ssteve.reinhardt@amd.comSystem::numRunningContexts() 2216029Ssteve.reinhardt@amd.com{ 2226029Ssteve.reinhardt@amd.com int running = 0; 2236029Ssteve.reinhardt@amd.com for (int i = 0; i < _numContexts; ++i) { 2246029Ssteve.reinhardt@amd.com if (threadContexts[i]->status() != ThreadContext::Halted) 2256029Ssteve.reinhardt@amd.com ++running; 2266029Ssteve.reinhardt@amd.com } 2276029Ssteve.reinhardt@amd.com return running; 2286029Ssteve.reinhardt@amd.com} 2296029Ssteve.reinhardt@amd.com 230180SN/Avoid 2311129SN/ASystem::startup() 2321129SN/A{ 2335713Shsul@eecs.umich.edu#if FULL_SYSTEM 2342114SN/A int i; 2352680Sktlim@umich.edu for (i = 0; i < threadContexts.size(); i++) 2364194Ssaidi@eecs.umich.edu TheISA::startupCPU(threadContexts[i], i); 2375713Shsul@eecs.umich.edu#endif 2381129SN/A} 2391129SN/A 2401129SN/Avoid 2415713Shsul@eecs.umich.eduSystem::replaceThreadContext(ThreadContext *tc, int context_id) 242180SN/A{ 2435713Shsul@eecs.umich.edu if (context_id >= threadContexts.size()) { 2442680Sktlim@umich.edu panic("replaceThreadContext: bad id, %d >= %d\n", 2455713Shsul@eecs.umich.edu context_id, threadContexts.size()); 246180SN/A } 247180SN/A 2485713Shsul@eecs.umich.edu threadContexts[context_id] = tc; 2495713Shsul@eecs.umich.edu if (context_id < remoteGDB.size()) 2505713Shsul@eecs.umich.edu remoteGDB[context_id]->replaceThreadContext(tc); 2512SN/A} 2522SN/A 2532378SN/A#if !FULL_SYSTEM 2542378SN/AAddr 2552378SN/ASystem::new_page() 2562378SN/A{ 2572378SN/A Addr return_addr = page_ptr << LogVMPageSize; 2582378SN/A ++page_ptr; 2593162Ssaidi@eecs.umich.edu if (return_addr >= physmem->size()) 2603162Ssaidi@eecs.umich.edu fatal("Out of memory, please increase size of physical memory."); 2612378SN/A return return_addr; 2622378SN/A} 2635795Ssaidi@eecs.umich.edu 2645795Ssaidi@eecs.umich.eduAddr 2655795Ssaidi@eecs.umich.eduSystem::memSize() 2665795Ssaidi@eecs.umich.edu{ 2675795Ssaidi@eecs.umich.edu return physmem->size(); 2685795Ssaidi@eecs.umich.edu} 2695795Ssaidi@eecs.umich.edu 2705795Ssaidi@eecs.umich.eduAddr 2715795Ssaidi@eecs.umich.eduSystem::freeMemSize() 2725795Ssaidi@eecs.umich.edu{ 2735795Ssaidi@eecs.umich.edu return physmem->size() - (page_ptr << LogVMPageSize); 2745795Ssaidi@eecs.umich.edu} 2755795Ssaidi@eecs.umich.edu 2762378SN/A#endif 2772378SN/A 2781070SN/Avoid 2791070SN/ASystem::serialize(ostream &os) 2801070SN/A{ 2812378SN/A#if FULL_SYSTEM 2821984SN/A kernelSymtab->serialize("kernel_symtab", os); 2835183Ssaidi@eecs.umich.edu#else // !FULL_SYSTEM 2845183Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(page_ptr); 2855183Ssaidi@eecs.umich.edu#endif 2861070SN/A} 2871070SN/A 2881070SN/A 2891070SN/Avoid 2901070SN/ASystem::unserialize(Checkpoint *cp, const string §ion) 2911070SN/A{ 2922378SN/A#if FULL_SYSTEM 2931984SN/A kernelSymtab->unserialize("kernel_symtab", cp, section); 2945183Ssaidi@eecs.umich.edu#else // !FULL_SYSTEM 2955183Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(page_ptr); 2965183Ssaidi@eecs.umich.edu#endif 2971070SN/A} 2982SN/A 2992SN/Avoid 3002SN/ASystem::printSystems() 3012SN/A{ 3022SN/A vector<System *>::iterator i = systemList.begin(); 3032SN/A vector<System *>::iterator end = systemList.end(); 3042SN/A for (; i != end; ++i) { 3052SN/A System *sys = *i; 3062SN/A cerr << "System " << sys->name() << ": " << hex << sys << endl; 3072SN/A } 3082SN/A} 3092SN/A 3102SN/Avoid 3112SN/AprintSystems() 3122SN/A{ 3132SN/A System::printSystems(); 3142SN/A} 3152SN/A 3162902Ssaidi@eecs.umich.educonst char *System::MemoryModeStrings[3] = {"invalid", "atomic", 3172902Ssaidi@eecs.umich.edu "timing"}; 3182902Ssaidi@eecs.umich.edu 3194762Snate@binkert.org#if !FULL_SYSTEM 3202424SN/A 3214762Snate@binkert.orgSystem * 3224762Snate@binkert.orgSystemParams::create() 3232424SN/A{ 3245530Snate@binkert.org return new System(this); 3252424SN/A} 3262424SN/A 3272424SN/A#endif 328