system.hh revision 8711
12SN/A/* 28703Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited 38703Sandreas.hansson@arm.com * All rights reserved 48703Sandreas.hansson@arm.com * 58703Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68703Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78703Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88703Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98703Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108703Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118703Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128703Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138703Sandreas.hansson@arm.com * 141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 157897Shestness@cs.utexas.edu * Copyright (c) 2011 Regents of the University of California 162SN/A * All rights reserved. 172SN/A * 182SN/A * Redistribution and use in source and binary forms, with or without 192SN/A * modification, are permitted provided that the following conditions are 202SN/A * met: redistributions of source code must retain the above copyright 212SN/A * notice, this list of conditions and the following disclaimer; 222SN/A * redistributions in binary form must reproduce the above copyright 232SN/A * notice, this list of conditions and the following disclaimer in the 242SN/A * documentation and/or other materials provided with the distribution; 252SN/A * neither the name of the copyright holders nor the names of its 262SN/A * contributors may be used to endorse or promote products derived from 272SN/A * this software without specific prior written permission. 282SN/A * 292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 422665Ssaidi@eecs.umich.edu * Lisa Hsu 432665Ssaidi@eecs.umich.edu * Nathan Binkert 447897Shestness@cs.utexas.edu * Rick Strong 452SN/A */ 462SN/A 472SN/A#ifndef __SYSTEM_HH__ 482SN/A#define __SYSTEM_HH__ 492SN/A 502SN/A#include <string> 5175SN/A#include <vector> 522SN/A 532439SN/A#include "base/loader/symtab.hh" 542439SN/A#include "base/misc.hh" 55603SN/A#include "base/statistics.hh" 562986Sgblack@eecs.umich.edu#include "config/full_system.hh" 57603SN/A#include "cpu/pc_event.hh" 584762Snate@binkert.org#include "enums/MemoryMode.hh" 598703Sandreas.hansson@arm.com#include "mem/mem_object.hh" 602520SN/A#include "mem/port.hh" 614762Snate@binkert.org#include "params/System.hh" 626658Snate@binkert.org 632378SN/A#if FULL_SYSTEM 64722SN/A#include "kern/system_events.hh" 652378SN/A#endif 66312SN/A 671634SN/Aclass BaseCPU; 682680Sktlim@umich.educlass ThreadContext; 691634SN/Aclass ObjectFile; 702521SN/Aclass PhysicalMemory; 712378SN/A 722378SN/A#if FULL_SYSTEM 73803SN/Aclass Platform; 748706Sandreas.hansson@arm.comclass PortProxy; 758706Sandreas.hansson@arm.comclass FSTranslatingPortProxy; 763960Sgblack@eecs.umich.edu#endif 772378SN/Aclass GDBListener; 786658Snate@binkert.orgclass BaseRemoteGDB; 792SN/A 808703Sandreas.hansson@arm.comclass System : public MemObject 812SN/A{ 828703Sandreas.hansson@arm.com private: 838703Sandreas.hansson@arm.com 848703Sandreas.hansson@arm.com /** 858703Sandreas.hansson@arm.com * Private class for the system port which is only used as a 868703Sandreas.hansson@arm.com * master for debug access and for non-structural entities that do 878703Sandreas.hansson@arm.com * not have a port of their own. 888703Sandreas.hansson@arm.com */ 898703Sandreas.hansson@arm.com class SystemPort : public Port 908703Sandreas.hansson@arm.com { 918703Sandreas.hansson@arm.com public: 928703Sandreas.hansson@arm.com 938703Sandreas.hansson@arm.com /** 948703Sandreas.hansson@arm.com * Create a system port with a name and an owner. 958703Sandreas.hansson@arm.com */ 968703Sandreas.hansson@arm.com SystemPort(const std::string &_name, MemObject *_owner) 978703Sandreas.hansson@arm.com : Port(_name, _owner) 988703Sandreas.hansson@arm.com { } 998703Sandreas.hansson@arm.com bool recvTiming(PacketPtr pkt) 1008703Sandreas.hansson@arm.com { panic("SystemPort does not receive timing!\n"); return false; } 1018703Sandreas.hansson@arm.com Tick recvAtomic(PacketPtr pkt) 1028703Sandreas.hansson@arm.com { panic("SystemPort does not receive atomic!\n"); return 0; } 1038703Sandreas.hansson@arm.com void recvFunctional(PacketPtr pkt) 1048703Sandreas.hansson@arm.com { panic("SystemPort does not receive functional!\n"); } 1058711Sandreas.hansson@arm.com 1068711Sandreas.hansson@arm.com /** 1078711Sandreas.hansson@arm.com * The system port is a master port connected to a single 1088711Sandreas.hansson@arm.com * slave and thus do not care about what ranges the slave 1098711Sandreas.hansson@arm.com * covers (as there is nothing to choose from). 1108711Sandreas.hansson@arm.com */ 1118711Sandreas.hansson@arm.com void recvRangeChange() { } 1128703Sandreas.hansson@arm.com 1138703Sandreas.hansson@arm.com }; 1148703Sandreas.hansson@arm.com 1158703Sandreas.hansson@arm.com SystemPort _systemPort; 1168703Sandreas.hansson@arm.com 117603SN/A public: 1182901Ssaidi@eecs.umich.edu 1198703Sandreas.hansson@arm.com /** 1208706Sandreas.hansson@arm.com * After all objects have been created and all ports are 1218706Sandreas.hansson@arm.com * connected, check that the system port is connected. 1228706Sandreas.hansson@arm.com */ 1238706Sandreas.hansson@arm.com virtual void init(); 1248706Sandreas.hansson@arm.com 1258706Sandreas.hansson@arm.com /** 1268703Sandreas.hansson@arm.com * Get a pointer to the system port that can be used by 1278703Sandreas.hansson@arm.com * non-structural simulation objects like processes or threads, or 1288703Sandreas.hansson@arm.com * external entities like loaders and debuggers, etc, to access 1298703Sandreas.hansson@arm.com * the memory system. 1308703Sandreas.hansson@arm.com * 1318703Sandreas.hansson@arm.com * @return a pointer to the system port we own 1328703Sandreas.hansson@arm.com */ 1338703Sandreas.hansson@arm.com Port* getSystemPort() { return &_systemPort; } 1348703Sandreas.hansson@arm.com 1358703Sandreas.hansson@arm.com /** 1368703Sandreas.hansson@arm.com * Additional function to return the Port of a memory object. 1378703Sandreas.hansson@arm.com */ 1388703Sandreas.hansson@arm.com Port *getPort(const std::string &if_name, int idx = -1); 1398703Sandreas.hansson@arm.com 1402902Ssaidi@eecs.umich.edu static const char *MemoryModeStrings[3]; 1412902Ssaidi@eecs.umich.edu 1424762Snate@binkert.org Enums::MemoryMode 1434762Snate@binkert.org getMemoryMode() 1444762Snate@binkert.org { 1454762Snate@binkert.org assert(memoryMode); 1464762Snate@binkert.org return memoryMode; 1474762Snate@binkert.org } 1482901Ssaidi@eecs.umich.edu 1492901Ssaidi@eecs.umich.edu /** Change the memory mode of the system. This should only be called by the 1502901Ssaidi@eecs.umich.edu * python!! 1512901Ssaidi@eecs.umich.edu * @param mode Mode to change to (atomic/timing) 1522901Ssaidi@eecs.umich.edu */ 1534762Snate@binkert.org void setMemoryMode(Enums::MemoryMode mode); 1542901Ssaidi@eecs.umich.edu 1552521SN/A PhysicalMemory *physmem; 1562SN/A PCEventQueue pcEventQueue; 1572SN/A 1582680Sktlim@umich.edu std::vector<ThreadContext *> threadContexts; 1595714Shsul@eecs.umich.edu int _numContexts; 1601806SN/A 1616221Snate@binkert.org ThreadContext *getThreadContext(ThreadID tid) 1625713Shsul@eecs.umich.edu { 1635713Shsul@eecs.umich.edu return threadContexts[tid]; 1645713Shsul@eecs.umich.edu } 1655713Shsul@eecs.umich.edu 1665714Shsul@eecs.umich.edu int numContexts() 1671806SN/A { 1686227Snate@binkert.org assert(_numContexts == (int)threadContexts.size()); 1695714Shsul@eecs.umich.edu return _numContexts; 1701806SN/A } 171180SN/A 1726029Ssteve.reinhardt@amd.com /** Return number of running (non-halted) thread contexts in 1736029Ssteve.reinhardt@amd.com * system. These threads could be Active or Suspended. */ 1746029Ssteve.reinhardt@amd.com int numRunningContexts(); 1756029Ssteve.reinhardt@amd.com 1768460SAli.Saidi@ARM.com /** List to store ranges of memories in this system */ 1778460SAli.Saidi@ARM.com AddrRangeList memRanges; 1788460SAli.Saidi@ARM.com 1798460SAli.Saidi@ARM.com /** check if an address points to valid system memory 1808460SAli.Saidi@ARM.com * and thus we can fetch instructions out of it 1818460SAli.Saidi@ARM.com */ 1828460SAli.Saidi@ARM.com bool isMemory(const Addr addr) const; 1838460SAli.Saidi@ARM.com 1842378SN/A#if FULL_SYSTEM 1852378SN/A Platform *platform; 1862378SN/A uint64_t init_param; 1872378SN/A 1882520SN/A /** Port to physical memory used for writing object files into ram at 1892520SN/A * boot.*/ 1908706Sandreas.hansson@arm.com PortProxy* physProxy; 1918706Sandreas.hansson@arm.com FSTranslatingPortProxy* virtProxy; 1922520SN/A 1931885SN/A /** kernel symbol table */ 1941070SN/A SymbolTable *kernelSymtab; 195954SN/A 1961070SN/A /** Object pointer for the kernel code */ 1971070SN/A ObjectFile *kernel; 1981070SN/A 1991070SN/A /** Begining of kernel code */ 2001070SN/A Addr kernelStart; 2011070SN/A 2021070SN/A /** End of kernel code */ 2031070SN/A Addr kernelEnd; 2041070SN/A 2051070SN/A /** Entry point in the kernel to start at */ 2061070SN/A Addr kernelEntry; 2071070SN/A 2087580SAli.Saidi@arm.com /** Mask that should be anded for binary/symbol loading. 2097580SAli.Saidi@arm.com * This allows one two different OS requirements for the same ISA to be 2107580SAli.Saidi@arm.com * handled. Some OSes are compiled for a virtual address and need to be 2117580SAli.Saidi@arm.com * loaded into physical memory that starts at address 0, while other 2127580SAli.Saidi@arm.com * bare metal tools generate images that start at address 0. 2137580SAli.Saidi@arm.com */ 2147580SAli.Saidi@arm.com Addr loadAddrMask; 2157580SAli.Saidi@arm.com 2162378SN/A#else 2172378SN/A 2187770SAli.Saidi@ARM.com Addr pagePtr; 2192378SN/A 2204997Sgblack@eecs.umich.edu protected: 2217770SAli.Saidi@ARM.com uint64_t nextPID; 2224997Sgblack@eecs.umich.edu 2234997Sgblack@eecs.umich.edu public: 2244997Sgblack@eecs.umich.edu uint64_t allocatePID() 2254997Sgblack@eecs.umich.edu { 2267770SAli.Saidi@ARM.com return nextPID++; 2274997Sgblack@eecs.umich.edu } 2284997Sgblack@eecs.umich.edu 2295795Ssaidi@eecs.umich.edu /** Amount of physical memory that is still free */ 2305795Ssaidi@eecs.umich.edu Addr freeMemSize(); 2315795Ssaidi@eecs.umich.edu 2325795Ssaidi@eecs.umich.edu /** Amount of physical memory that exists */ 2335795Ssaidi@eecs.umich.edu Addr memSize(); 2345795Ssaidi@eecs.umich.edu 2352378SN/A 2362378SN/A#endif // FULL_SYSTEM 2372378SN/A 2381885SN/A protected: 2394762Snate@binkert.org Enums::MemoryMode memoryMode; 2407914SBrad.Beckmann@amd.com uint64_t workItemsBegin; 2417914SBrad.Beckmann@amd.com uint64_t workItemsEnd; 2428666SPrakash.Ramrakhyani@arm.com uint32_t numWorkIds; 2437914SBrad.Beckmann@amd.com std::vector<bool> activeCpus; 2447914SBrad.Beckmann@amd.com 2457914SBrad.Beckmann@amd.com public: 2468666SPrakash.Ramrakhyani@arm.com virtual void regStats(); 2477914SBrad.Beckmann@amd.com /** 2487914SBrad.Beckmann@amd.com * Called by pseudo_inst to track the number of work items started by this 2497914SBrad.Beckmann@amd.com * system. 2507914SBrad.Beckmann@amd.com */ 2518666SPrakash.Ramrakhyani@arm.com uint64_t 2527914SBrad.Beckmann@amd.com incWorkItemsBegin() 2537914SBrad.Beckmann@amd.com { 2547914SBrad.Beckmann@amd.com return ++workItemsBegin; 2557914SBrad.Beckmann@amd.com } 2567914SBrad.Beckmann@amd.com 2577914SBrad.Beckmann@amd.com /** 2587914SBrad.Beckmann@amd.com * Called by pseudo_inst to track the number of work items completed by 2597914SBrad.Beckmann@amd.com * this system. 2607914SBrad.Beckmann@amd.com */ 2617914SBrad.Beckmann@amd.com uint64_t 2627914SBrad.Beckmann@amd.com incWorkItemsEnd() 2637914SBrad.Beckmann@amd.com { 2647914SBrad.Beckmann@amd.com return ++workItemsEnd; 2657914SBrad.Beckmann@amd.com } 2667914SBrad.Beckmann@amd.com 2677914SBrad.Beckmann@amd.com /** 2687914SBrad.Beckmann@amd.com * Called by pseudo_inst to mark the cpus actively executing work items. 2697914SBrad.Beckmann@amd.com * Returns the total number of cpus that have executed work item begin or 2707914SBrad.Beckmann@amd.com * ends. 2717914SBrad.Beckmann@amd.com */ 2727914SBrad.Beckmann@amd.com int 2737914SBrad.Beckmann@amd.com markWorkItem(int index) 2747914SBrad.Beckmann@amd.com { 2757914SBrad.Beckmann@amd.com int count = 0; 2767914SBrad.Beckmann@amd.com assert(index < activeCpus.size()); 2777914SBrad.Beckmann@amd.com activeCpus[index] = true; 2787914SBrad.Beckmann@amd.com for (std::vector<bool>::iterator i = activeCpus.begin(); 2797914SBrad.Beckmann@amd.com i < activeCpus.end(); i++) { 2807914SBrad.Beckmann@amd.com if (*i) count++; 2817914SBrad.Beckmann@amd.com } 2827914SBrad.Beckmann@amd.com return count; 2837914SBrad.Beckmann@amd.com } 2842901Ssaidi@eecs.umich.edu 2858666SPrakash.Ramrakhyani@arm.com inline void workItemBegin(uint32_t tid, uint32_t workid) 2868666SPrakash.Ramrakhyani@arm.com { 2878666SPrakash.Ramrakhyani@arm.com std::pair<uint32_t,uint32_t> p(tid, workid); 2888666SPrakash.Ramrakhyani@arm.com lastWorkItemStarted[p] = curTick(); 2898666SPrakash.Ramrakhyani@arm.com } 2908666SPrakash.Ramrakhyani@arm.com 2918666SPrakash.Ramrakhyani@arm.com void workItemEnd(uint32_t tid, uint32_t workid); 2928666SPrakash.Ramrakhyani@arm.com 2932424SN/A#if FULL_SYSTEM 2941885SN/A /** 2951885SN/A * Fix up an address used to match PCs for hooking simulator 2961885SN/A * events on to target function executions. See comment in 2971885SN/A * system.cc for details. 2981885SN/A */ 2992158SN/A virtual Addr fixFuncEventAddr(Addr addr) = 0; 3001885SN/A 3011885SN/A /** 3021885SN/A * Add a function-based event to the given function, to be looked 3031885SN/A * up in the specified symbol table. 3041885SN/A */ 3051885SN/A template <class T> 3062989Ssaidi@eecs.umich.edu T *addFuncEvent(SymbolTable *symtab, const char *lbl) 3071885SN/A { 3081913SN/A Addr addr = 0; // initialize only to avoid compiler warning 3091885SN/A 3101885SN/A if (symtab->findAddress(lbl, addr)) { 3111885SN/A T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr)); 3121885SN/A return ev; 3131885SN/A } 3141885SN/A 3151885SN/A return NULL; 3161885SN/A } 3171885SN/A 3181885SN/A /** Add a function-based event to kernel code. */ 3191885SN/A template <class T> 3202989Ssaidi@eecs.umich.edu T *addKernelFuncEvent(const char *lbl) 3211885SN/A { 3221885SN/A return addFuncEvent<T>(kernelSymtab, lbl); 3231885SN/A } 3241885SN/A 3252378SN/A#endif 32677SN/A public: 3276658Snate@binkert.org std::vector<BaseRemoteGDB *> remoteGDB; 3281070SN/A std::vector<GDBListener *> gdbListen; 3293960Sgblack@eecs.umich.edu bool breakpoint(); 3301070SN/A 3311070SN/A public: 3324762Snate@binkert.org typedef SystemParams Params; 3331070SN/A 3342158SN/A protected: 3352158SN/A Params *_params; 3361070SN/A 3372158SN/A public: 3381070SN/A System(Params *p); 3392SN/A ~System(); 3402SN/A 3417733SAli.Saidi@ARM.com void initState(); 3421129SN/A 3432158SN/A const Params *params() const { return (const Params *)_params; } 3442158SN/A 3451070SN/A public: 3462378SN/A 3472378SN/A#if FULL_SYSTEM 3481070SN/A /** 3491070SN/A * Returns the addess the kernel starts at. 3501070SN/A * @return address the kernel starts at 3511070SN/A */ 3521070SN/A Addr getKernelStart() const { return kernelStart; } 3531070SN/A 3541070SN/A /** 3551070SN/A * Returns the addess the kernel ends at. 3561070SN/A * @return address the kernel ends at 3571070SN/A */ 3581070SN/A Addr getKernelEnd() const { return kernelEnd; } 3591070SN/A 3601070SN/A /** 3611070SN/A * Returns the addess the entry point to the kernel code. 3621070SN/A * @return entry point of the kernel code 3631070SN/A */ 3641070SN/A Addr getKernelEntry() const { return kernelEntry; } 3651070SN/A 3662378SN/A#else 3672378SN/A 3688601Ssteve.reinhardt@amd.com /// Allocate npages contiguous unused physical pages 3698601Ssteve.reinhardt@amd.com /// @return Starting address of first page 3708601Ssteve.reinhardt@amd.com Addr allocPhysPages(int npages); 3712378SN/A 3722378SN/A#endif // FULL_SYSTEM 3732378SN/A 3745718Shsul@eecs.umich.edu int registerThreadContext(ThreadContext *tc, int assigned=-1); 3755713Shsul@eecs.umich.edu void replaceThreadContext(ThreadContext *tc, int context_id); 3761070SN/A 3771070SN/A void serialize(std::ostream &os); 3781070SN/A void unserialize(Checkpoint *cp, const std::string §ion); 3797897Shestness@cs.utexas.edu virtual void resume(); 3802SN/A 38177SN/A public: 3827897Shestness@cs.utexas.edu Counter totalNumInsts; 3837897Shestness@cs.utexas.edu EventQueue instEventQueue; 3848666SPrakash.Ramrakhyani@arm.com std::map<std::pair<uint32_t,uint32_t>, Tick> lastWorkItemStarted; 3858666SPrakash.Ramrakhyani@arm.com std::map<uint32_t, Stats::Histogram*> workItemStats; 3867897Shestness@cs.utexas.edu 3872SN/A //////////////////////////////////////////// 3882SN/A // 3892SN/A // STATIC GLOBAL SYSTEM LIST 3902SN/A // 3912SN/A //////////////////////////////////////////// 3922SN/A 3932SN/A static std::vector<System *> systemList; 3942SN/A static int numSystemsRunning; 3952SN/A 3962SN/A static void printSystems(); 3972158SN/A 3982158SN/A 3992SN/A}; 4002SN/A 4012SN/A#endif // __SYSTEM_HH__ 402