system.hh revision 6029
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292665Ssaidi@eecs.umich.edu *          Lisa Hsu
302665Ssaidi@eecs.umich.edu *          Nathan Binkert
312SN/A */
322SN/A
332SN/A#ifndef __SYSTEM_HH__
342SN/A#define __SYSTEM_HH__
352SN/A
362SN/A#include <string>
3775SN/A#include <vector>
382SN/A
392439SN/A#include "base/loader/symtab.hh"
402439SN/A#include "base/misc.hh"
41603SN/A#include "base/statistics.hh"
422986Sgblack@eecs.umich.edu#include "config/full_system.hh"
43603SN/A#include "cpu/pc_event.hh"
444762Snate@binkert.org#include "enums/MemoryMode.hh"
452520SN/A#include "mem/port.hh"
464762Snate@binkert.org#include "params/System.hh"
472378SN/A#include "sim/sim_object.hh"
482378SN/A#if FULL_SYSTEM
49722SN/A#include "kern/system_events.hh"
502521SN/A#include "mem/vport.hh"
512378SN/A#endif
52312SN/A
531634SN/Aclass BaseCPU;
542680Sktlim@umich.educlass ThreadContext;
551634SN/Aclass ObjectFile;
562521SN/Aclass PhysicalMemory;
572378SN/A
582378SN/A#if FULL_SYSTEM
59803SN/Aclass Platform;
603960Sgblack@eecs.umich.edu#endif
612378SN/Aclass GDBListener;
623536Sgblack@eecs.umich.edunamespace TheISA
633536Sgblack@eecs.umich.edu{
643536Sgblack@eecs.umich.edu    class RemoteGDB;
653536Sgblack@eecs.umich.edu}
662SN/A
672SN/Aclass System : public SimObject
682SN/A{
69603SN/A  public:
702901Ssaidi@eecs.umich.edu
712902Ssaidi@eecs.umich.edu    static const char *MemoryModeStrings[3];
722902Ssaidi@eecs.umich.edu
734762Snate@binkert.org    Enums::MemoryMode
744762Snate@binkert.org    getMemoryMode()
754762Snate@binkert.org    {
764762Snate@binkert.org        assert(memoryMode);
774762Snate@binkert.org        return memoryMode;
784762Snate@binkert.org    }
792901Ssaidi@eecs.umich.edu
802901Ssaidi@eecs.umich.edu    /** Change the memory mode of the system. This should only be called by the
812901Ssaidi@eecs.umich.edu     * python!!
822901Ssaidi@eecs.umich.edu     * @param mode Mode to change to (atomic/timing)
832901Ssaidi@eecs.umich.edu     */
844762Snate@binkert.org    void setMemoryMode(Enums::MemoryMode mode);
852901Ssaidi@eecs.umich.edu
862521SN/A    PhysicalMemory *physmem;
872SN/A    PCEventQueue pcEventQueue;
882SN/A
892680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
905714Shsul@eecs.umich.edu    int _numContexts;
911806SN/A
926029Ssteve.reinhardt@amd.com    ThreadContext *getThreadContext(int tid)
935713Shsul@eecs.umich.edu    {
945713Shsul@eecs.umich.edu        return threadContexts[tid];
955713Shsul@eecs.umich.edu    }
965713Shsul@eecs.umich.edu
975714Shsul@eecs.umich.edu    int numContexts()
981806SN/A    {
996029Ssteve.reinhardt@amd.com        assert(_numContexts == threadContexts.size());
1005714Shsul@eecs.umich.edu        return _numContexts;
1011806SN/A    }
102180SN/A
1036029Ssteve.reinhardt@amd.com    /** Return number of running (non-halted) thread contexts in
1046029Ssteve.reinhardt@amd.com     * system.  These threads could be Active or Suspended. */
1056029Ssteve.reinhardt@amd.com    int numRunningContexts();
1066029Ssteve.reinhardt@amd.com
1072378SN/A#if FULL_SYSTEM
1082378SN/A    Platform *platform;
1092378SN/A    uint64_t init_param;
1102378SN/A
1112520SN/A    /** Port to physical memory used for writing object files into ram at
1122520SN/A     * boot.*/
1132520SN/A    FunctionalPort functionalPort;
1142521SN/A    VirtualPort virtPort;
1152520SN/A
1161885SN/A    /** kernel symbol table */
1171070SN/A    SymbolTable *kernelSymtab;
118954SN/A
1191070SN/A    /** Object pointer for the kernel code */
1201070SN/A    ObjectFile *kernel;
1211070SN/A
1221070SN/A    /** Begining of kernel code */
1231070SN/A    Addr kernelStart;
1241070SN/A
1251070SN/A    /** End of kernel code */
1261070SN/A    Addr kernelEnd;
1271070SN/A
1281070SN/A    /** Entry point in the kernel to start at */
1291070SN/A    Addr kernelEntry;
1301070SN/A
1312378SN/A#else
1322378SN/A
1332378SN/A    int page_ptr;
1342378SN/A
1354997Sgblack@eecs.umich.edu  protected:
1364997Sgblack@eecs.umich.edu    uint64_t next_PID;
1374997Sgblack@eecs.umich.edu
1384997Sgblack@eecs.umich.edu  public:
1394997Sgblack@eecs.umich.edu    uint64_t allocatePID()
1404997Sgblack@eecs.umich.edu    {
1414997Sgblack@eecs.umich.edu        return next_PID++;
1424997Sgblack@eecs.umich.edu    }
1434997Sgblack@eecs.umich.edu
1445795Ssaidi@eecs.umich.edu    /** Amount of physical memory that is still free */
1455795Ssaidi@eecs.umich.edu    Addr freeMemSize();
1465795Ssaidi@eecs.umich.edu
1475795Ssaidi@eecs.umich.edu    /** Amount of physical memory that exists */
1485795Ssaidi@eecs.umich.edu    Addr memSize();
1495795Ssaidi@eecs.umich.edu
1502378SN/A
1512378SN/A#endif // FULL_SYSTEM
1522378SN/A
1531885SN/A  protected:
1544762Snate@binkert.org    Enums::MemoryMode memoryMode;
1552901Ssaidi@eecs.umich.edu
1562424SN/A#if FULL_SYSTEM
1571885SN/A    /**
1581885SN/A     * Fix up an address used to match PCs for hooking simulator
1591885SN/A     * events on to target function executions.  See comment in
1601885SN/A     * system.cc for details.
1611885SN/A     */
1622158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1631885SN/A
1641885SN/A    /**
1651885SN/A     * Add a function-based event to the given function, to be looked
1661885SN/A     * up in the specified symbol table.
1671885SN/A     */
1681885SN/A    template <class T>
1692989Ssaidi@eecs.umich.edu    T *addFuncEvent(SymbolTable *symtab, const char *lbl)
1701885SN/A    {
1711913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1721885SN/A
1731885SN/A        if (symtab->findAddress(lbl, addr)) {
1741885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1751885SN/A            return ev;
1761885SN/A        }
1771885SN/A
1781885SN/A        return NULL;
1791885SN/A    }
1801885SN/A
1811885SN/A    /** Add a function-based event to kernel code. */
1821885SN/A    template <class T>
1832989Ssaidi@eecs.umich.edu    T *addKernelFuncEvent(const char *lbl)
1841885SN/A    {
1851885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1861885SN/A    }
1871885SN/A
1882378SN/A#endif
18977SN/A  public:
1903536Sgblack@eecs.umich.edu    std::vector<TheISA::RemoteGDB *> remoteGDB;
1911070SN/A    std::vector<GDBListener *> gdbListen;
1923960Sgblack@eecs.umich.edu    bool breakpoint();
1931070SN/A
1941070SN/A  public:
1954762Snate@binkert.org    typedef SystemParams Params;
1961070SN/A
1972158SN/A  protected:
1982158SN/A    Params *_params;
1991070SN/A
2002158SN/A  public:
2011070SN/A    System(Params *p);
2022SN/A    ~System();
2032SN/A
2041129SN/A    void startup();
2051129SN/A
2062158SN/A    const Params *params() const { return (const Params *)_params; }
2072158SN/A
2081070SN/A  public:
2092378SN/A
2102378SN/A#if FULL_SYSTEM
2111070SN/A    /**
2121070SN/A     * Returns the addess the kernel starts at.
2131070SN/A     * @return address the kernel starts at
2141070SN/A     */
2151070SN/A    Addr getKernelStart() const { return kernelStart; }
2161070SN/A
2171070SN/A    /**
2181070SN/A     * Returns the addess the kernel ends at.
2191070SN/A     * @return address the kernel ends at
2201070SN/A     */
2211070SN/A    Addr getKernelEnd() const { return kernelEnd; }
2221070SN/A
2231070SN/A    /**
2241070SN/A     * Returns the addess the entry point to the kernel code.
2251070SN/A     * @return entry point of the kernel code
2261070SN/A     */
2271070SN/A    Addr getKernelEntry() const { return kernelEntry; }
2281070SN/A
2292378SN/A#else
2302378SN/A
2312378SN/A    Addr new_page();
2322378SN/A
2332378SN/A#endif // FULL_SYSTEM
2342378SN/A
2355718Shsul@eecs.umich.edu    int registerThreadContext(ThreadContext *tc, int assigned=-1);
2365713Shsul@eecs.umich.edu    void replaceThreadContext(ThreadContext *tc, int context_id);
2371070SN/A
2381070SN/A    void serialize(std::ostream &os);
2391070SN/A    void unserialize(Checkpoint *cp, const std::string &section);
2402SN/A
24177SN/A  public:
2422SN/A    ////////////////////////////////////////////
2432SN/A    //
2442SN/A    // STATIC GLOBAL SYSTEM LIST
2452SN/A    //
2462SN/A    ////////////////////////////////////////////
2472SN/A
2482SN/A    static std::vector<System *> systemList;
2492SN/A    static int numSystemsRunning;
2502SN/A
2512SN/A    static void printSystems();
2522158SN/A
2532158SN/A
2542SN/A};
2552SN/A
2562SN/A#endif // __SYSTEM_HH__
257