system.cc revision 3812
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" 351070SN/A#include "base/loader/object_file.hh" 361070SN/A#include "base/loader/symtab.hh" 372521SN/A#include "base/trace.hh" 382680Sktlim@umich.edu#include "cpu/thread_context.hh" 392521SN/A#include "mem/mem_object.hh" 402522SN/A#include "mem/physical.hh" 411711SN/A#include "sim/builder.hh" 422037SN/A#include "sim/byteswap.hh" 4356SN/A#include "sim/system.hh" 442378SN/A#if FULL_SYSTEM 452521SN/A#include "arch/vtophys.hh" 463536Sgblack@eecs.umich.edu#include "arch/remote_gdb.hh" 472378SN/A#include "kern/kernel_stats.hh" 482378SN/A#endif 492SN/A 502SN/Ausing namespace std; 512107SN/Ausing namespace TheISA; 522SN/A 532SN/Avector<System *> System::systemList; 542SN/A 552SN/Aint System::numSystemsRunning = 0; 562SN/A 571070SN/ASystem::System(Params *p) 582378SN/A : SimObject(p->name), physmem(p->physmem), numcpus(0), 592378SN/A#if FULL_SYSTEM 602521SN/A init_param(p->init_param), 612640Sstever@eecs.umich.edu functionalPort(p->name + "-fport"), 622640Sstever@eecs.umich.edu virtPort(p->name + "-vport"), 632378SN/A#else 642378SN/A page_ptr(0), 652378SN/A#endif 662902Ssaidi@eecs.umich.edu memoryMode(p->mem_mode), _params(p) 672SN/A{ 681070SN/A // add self to global system list 691070SN/A systemList.push_back(this); 701070SN/A 712378SN/A#if FULL_SYSTEM 721070SN/A kernelSymtab = new SymbolTable; 731074SN/A debugSymbolTable = new SymbolTable; 741070SN/A 752520SN/A 762520SN/A /** 772520SN/A * Get a functional port to memory 782520SN/A */ 792520SN/A Port *mem_port; 802520SN/A mem_port = physmem->getPort("functional"); 812520SN/A functionalPort.setPeer(mem_port); 822520SN/A mem_port->setPeer(&functionalPort); 832520SN/A 842521SN/A mem_port = physmem->getPort("functional"); 852521SN/A virtPort.setPeer(mem_port); 862521SN/A mem_port->setPeer(&virtPort); 872521SN/A 882520SN/A 891070SN/A /** 902158SN/A * Load the kernel code into memory 911070SN/A */ 923812Ssaidi@eecs.umich.edu if (params()->kernel_path == "") { 933812Ssaidi@eecs.umich.edu warn("No kernel set for full system simulation. Assuming you know what" 943812Ssaidi@eecs.umich.edu " you're doing...\n"); 953812Ssaidi@eecs.umich.edu } else { 963812Ssaidi@eecs.umich.edu // Load kernel code 973812Ssaidi@eecs.umich.edu kernel = createObjectFile(params()->kernel_path); 983812Ssaidi@eecs.umich.edu if (kernel == NULL) 993812Ssaidi@eecs.umich.edu fatal("Could not load kernel file %s", params()->kernel_path); 1001070SN/A 1013812Ssaidi@eecs.umich.edu // Load program sections into memory 1023812Ssaidi@eecs.umich.edu kernel->loadSections(&functionalPort, LoadAddrMask); 1031070SN/A 1043812Ssaidi@eecs.umich.edu // setup entry points 1053812Ssaidi@eecs.umich.edu kernelStart = kernel->textBase(); 1063812Ssaidi@eecs.umich.edu kernelEnd = kernel->bssBase() + kernel->bssSize(); 1073812Ssaidi@eecs.umich.edu kernelEntry = kernel->entryPoint(); 1081070SN/A 1093812Ssaidi@eecs.umich.edu // load symbols 1103812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(kernelSymtab)) 1113812Ssaidi@eecs.umich.edu panic("could not load kernel symbols\n"); 1121070SN/A 1133812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(kernelSymtab)) 1143812Ssaidi@eecs.umich.edu panic("could not load kernel local symbols\n"); 1151070SN/A 1163812Ssaidi@eecs.umich.edu if (!kernel->loadGlobalSymbols(debugSymbolTable)) 1173812Ssaidi@eecs.umich.edu panic("could not load kernel symbols\n"); 1181074SN/A 1193812Ssaidi@eecs.umich.edu if (!kernel->loadLocalSymbols(debugSymbolTable)) 1203812Ssaidi@eecs.umich.edu panic("could not load kernel local symbols\n"); 1211074SN/A 1223812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel start = %#x\n", kernelStart); 1233812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd); 1243812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); 1253812Ssaidi@eecs.umich.edu DPRINTF(Loader, "Kernel loaded...\n"); 1263812Ssaidi@eecs.umich.edu } 1272378SN/A#endif // FULL_SYSTEM 1282378SN/A 1291070SN/A // increment the number of running systms 130878SN/A numSystemsRunning++; 1312SN/A} 1322SN/A 1332SN/ASystem::~System() 1342SN/A{ 1352378SN/A#if FULL_SYSTEM 1361070SN/A delete kernelSymtab; 1371070SN/A delete kernel; 1382378SN/A#else 1392378SN/A panic("System::fixFuncEventAddr needs to be rewritten " 1402378SN/A "to work with syscall emulation"); 1412378SN/A#endif // FULL_SYSTEM} 1422SN/A} 1432SN/A 1442378SN/A#if FULL_SYSTEM 1451885SN/A 1462SN/A 1471808SN/Aint rgdb_wait = -1; 1481808SN/A 1492378SN/A#endif // FULL_SYSTEM 1502378SN/A 1512901Ssaidi@eecs.umich.edu 1522901Ssaidi@eecs.umich.eduvoid 1532901Ssaidi@eecs.umich.eduSystem::setMemoryMode(MemoryMode mode) 1542901Ssaidi@eecs.umich.edu{ 1552901Ssaidi@eecs.umich.edu assert(getState() == Drained); 1562901Ssaidi@eecs.umich.edu memoryMode = mode; 1572901Ssaidi@eecs.umich.edu} 1582901Ssaidi@eecs.umich.edu 159180SN/Aint 1602680Sktlim@umich.eduSystem::registerThreadContext(ThreadContext *tc, int id) 1612SN/A{ 1621806SN/A if (id == -1) { 1632680Sktlim@umich.edu for (id = 0; id < threadContexts.size(); id++) { 1642680Sktlim@umich.edu if (!threadContexts[id]) 1651806SN/A break; 1661806SN/A } 1671806SN/A } 1681806SN/A 1692680Sktlim@umich.edu if (threadContexts.size() <= id) 1702680Sktlim@umich.edu threadContexts.resize(id + 1); 1711806SN/A 1722680Sktlim@umich.edu if (threadContexts[id]) 1731806SN/A panic("Cannot have two CPUs with the same id (%d)\n", id); 1741806SN/A 1752680Sktlim@umich.edu threadContexts[id] = tc; 1761806SN/A numcpus++; 1771070SN/A 1782378SN/A#if FULL_SYSTEM 1792680Sktlim@umich.edu RemoteGDB *rgdb = new RemoteGDB(this, tc); 1801806SN/A GDBListener *gdbl = new GDBListener(rgdb, 7000 + id); 1811070SN/A gdbl->listen(); 1821070SN/A /** 1831070SN/A * Uncommenting this line waits for a remote debugger to connect 1841070SN/A * to the simulator before continuing. 1851070SN/A */ 1861808SN/A if (rgdb_wait != -1 && rgdb_wait == id) 1871808SN/A gdbl->accept(); 1881070SN/A 1891806SN/A if (remoteGDB.size() <= id) { 1901806SN/A remoteGDB.resize(id + 1); 1911070SN/A } 1921070SN/A 1931806SN/A remoteGDB[id] = rgdb; 1942378SN/A#endif // FULL_SYSTEM 1951070SN/A 1961806SN/A return id; 197180SN/A} 19875SN/A 199180SN/Avoid 2001129SN/ASystem::startup() 2011129SN/A{ 2022114SN/A int i; 2032680Sktlim@umich.edu for (i = 0; i < threadContexts.size(); i++) 2042680Sktlim@umich.edu threadContexts[i]->activate(0); 2051129SN/A} 2061129SN/A 2071129SN/Avoid 2082680Sktlim@umich.eduSystem::replaceThreadContext(ThreadContext *tc, int id) 209180SN/A{ 2102680Sktlim@umich.edu if (id >= threadContexts.size()) { 2112680Sktlim@umich.edu panic("replaceThreadContext: bad id, %d >= %d\n", 2122680Sktlim@umich.edu id, threadContexts.size()); 213180SN/A } 214180SN/A 2152680Sktlim@umich.edu threadContexts[id] = tc; 2162378SN/A#if FULL_SYSTEM 2172680Sktlim@umich.edu remoteGDB[id]->replaceThreadContext(tc); 2182378SN/A#endif // FULL_SYSTEM 2192SN/A} 2202SN/A 2212378SN/A#if !FULL_SYSTEM 2222378SN/AAddr 2232378SN/ASystem::new_page() 2242378SN/A{ 2252378SN/A Addr return_addr = page_ptr << LogVMPageSize; 2262378SN/A ++page_ptr; 2273162Ssaidi@eecs.umich.edu if (return_addr >= physmem->size()) 2283162Ssaidi@eecs.umich.edu fatal("Out of memory, please increase size of physical memory."); 2292378SN/A return return_addr; 2302378SN/A} 2312378SN/A#endif 2322378SN/A 2331070SN/Avoid 2341070SN/ASystem::serialize(ostream &os) 2351070SN/A{ 2362378SN/A#if FULL_SYSTEM 2371984SN/A kernelSymtab->serialize("kernel_symtab", os); 2382378SN/A#endif // FULL_SYSTEM 2391070SN/A} 2401070SN/A 2411070SN/A 2421070SN/Avoid 2431070SN/ASystem::unserialize(Checkpoint *cp, const string §ion) 2441070SN/A{ 2452378SN/A#if FULL_SYSTEM 2461984SN/A kernelSymtab->unserialize("kernel_symtab", cp, section); 2472378SN/A#endif // FULL_SYSTEM 2481070SN/A} 2492SN/A 2502SN/Avoid 2512SN/ASystem::printSystems() 2522SN/A{ 2532SN/A vector<System *>::iterator i = systemList.begin(); 2542SN/A vector<System *>::iterator end = systemList.end(); 2552SN/A for (; i != end; ++i) { 2562SN/A System *sys = *i; 2572SN/A cerr << "System " << sys->name() << ": " << hex << sys << endl; 2582SN/A } 2592SN/A} 2602SN/A 2612SN/Avoid 2622SN/AprintSystems() 2632SN/A{ 2642SN/A System::printSystems(); 2652SN/A} 2662SN/A 2672902Ssaidi@eecs.umich.educonst char *System::MemoryModeStrings[3] = {"invalid", "atomic", 2682902Ssaidi@eecs.umich.edu "timing"}; 2692902Ssaidi@eecs.umich.edu 2702424SN/A#if FULL_SYSTEM 2712424SN/A 2722424SN/A// In full system mode, only derived classes (e.g. AlphaLinuxSystem) 2732424SN/A// can be created directly. 2742424SN/A 2752158SN/ADEFINE_SIM_OBJECT_CLASS_NAME("System", System) 2762SN/A 2772424SN/A#else 2782424SN/A 2792424SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(System) 2802424SN/A 2812522SN/A SimObjectParam<PhysicalMemory *> physmem; 2822902Ssaidi@eecs.umich.edu SimpleEnumParam<System::MemoryMode> mem_mode; 2832424SN/A 2842424SN/AEND_DECLARE_SIM_OBJECT_PARAMS(System) 2852424SN/A 2862424SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(System) 2872424SN/A 2882902Ssaidi@eecs.umich.edu INIT_PARAM(physmem, "physical memory"), 2892902Ssaidi@eecs.umich.edu INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)", 2902902Ssaidi@eecs.umich.edu System::MemoryModeStrings) 2912424SN/A 2922424SN/AEND_INIT_SIM_OBJECT_PARAMS(System) 2932424SN/A 2942424SN/ACREATE_SIM_OBJECT(System) 2952424SN/A{ 2962424SN/A System::Params *p = new System::Params; 2972424SN/A p->name = getInstanceName(); 2982424SN/A p->physmem = physmem; 2992902Ssaidi@eecs.umich.edu p->mem_mode = mem_mode; 3002424SN/A return new System(p); 3012424SN/A} 3022424SN/A 3032424SN/AREGISTER_SIM_OBJECT("System", System) 3042424SN/A 3052424SN/A#endif 306