system.hh revision 4997
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;
901806SN/A    int numcpus;
911806SN/A
921806SN/A    int getNumCPUs()
931806SN/A    {
942680Sktlim@umich.edu        if (numcpus != threadContexts.size())
951806SN/A            panic("cpu array not fully populated!");
961806SN/A
971806SN/A        return numcpus;
981806SN/A    }
99180SN/A
1002378SN/A#if FULL_SYSTEM
1012378SN/A    Platform *platform;
1022378SN/A    uint64_t init_param;
1032378SN/A
1042520SN/A    /** Port to physical memory used for writing object files into ram at
1052520SN/A     * boot.*/
1062520SN/A    FunctionalPort functionalPort;
1072521SN/A    VirtualPort virtPort;
1082520SN/A
1091885SN/A    /** kernel symbol table */
1101070SN/A    SymbolTable *kernelSymtab;
111954SN/A
1121070SN/A    /** Object pointer for the kernel code */
1131070SN/A    ObjectFile *kernel;
1141070SN/A
1151070SN/A    /** Begining of kernel code */
1161070SN/A    Addr kernelStart;
1171070SN/A
1181070SN/A    /** End of kernel code */
1191070SN/A    Addr kernelEnd;
1201070SN/A
1211070SN/A    /** Entry point in the kernel to start at */
1221070SN/A    Addr kernelEntry;
1231070SN/A
1242378SN/A#else
1252378SN/A
1262378SN/A    int page_ptr;
1272378SN/A
1284997Sgblack@eecs.umich.edu  protected:
1294997Sgblack@eecs.umich.edu    uint64_t next_PID;
1304997Sgblack@eecs.umich.edu
1314997Sgblack@eecs.umich.edu  public:
1324997Sgblack@eecs.umich.edu    uint64_t allocatePID()
1334997Sgblack@eecs.umich.edu    {
1344997Sgblack@eecs.umich.edu        return next_PID++;
1354997Sgblack@eecs.umich.edu    }
1364997Sgblack@eecs.umich.edu
1372378SN/A
1382378SN/A#endif // FULL_SYSTEM
1392378SN/A
1401885SN/A  protected:
1414762Snate@binkert.org    Enums::MemoryMode memoryMode;
1422901Ssaidi@eecs.umich.edu
1432424SN/A#if FULL_SYSTEM
1441885SN/A    /**
1451885SN/A     * Fix up an address used to match PCs for hooking simulator
1461885SN/A     * events on to target function executions.  See comment in
1471885SN/A     * system.cc for details.
1481885SN/A     */
1492158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1501885SN/A
1511885SN/A    /**
1521885SN/A     * Add a function-based event to the given function, to be looked
1531885SN/A     * up in the specified symbol table.
1541885SN/A     */
1551885SN/A    template <class T>
1562989Ssaidi@eecs.umich.edu    T *addFuncEvent(SymbolTable *symtab, const char *lbl)
1571885SN/A    {
1581913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1591885SN/A
1601885SN/A        if (symtab->findAddress(lbl, addr)) {
1611885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1621885SN/A            return ev;
1631885SN/A        }
1641885SN/A
1651885SN/A        return NULL;
1661885SN/A    }
1671885SN/A
1681885SN/A    /** Add a function-based event to kernel code. */
1691885SN/A    template <class T>
1702989Ssaidi@eecs.umich.edu    T *addKernelFuncEvent(const char *lbl)
1711885SN/A    {
1721885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1731885SN/A    }
1741885SN/A
1752378SN/A#endif
17677SN/A  public:
1773536Sgblack@eecs.umich.edu    std::vector<TheISA::RemoteGDB *> remoteGDB;
1781070SN/A    std::vector<GDBListener *> gdbListen;
1793960Sgblack@eecs.umich.edu    bool breakpoint();
1801070SN/A
1811070SN/A  public:
1824762Snate@binkert.org    typedef SystemParams Params;
1831070SN/A
1842158SN/A  protected:
1852158SN/A    Params *_params;
1861070SN/A
1872158SN/A  public:
1881070SN/A    System(Params *p);
1892SN/A    ~System();
1902SN/A
1911129SN/A    void startup();
1921129SN/A
1932158SN/A    const Params *params() const { return (const Params *)_params; }
1942158SN/A
1951070SN/A  public:
1962378SN/A
1972378SN/A#if FULL_SYSTEM
1981070SN/A    /**
1991070SN/A     * Returns the addess the kernel starts at.
2001070SN/A     * @return address the kernel starts at
2011070SN/A     */
2021070SN/A    Addr getKernelStart() const { return kernelStart; }
2031070SN/A
2041070SN/A    /**
2051070SN/A     * Returns the addess the kernel ends at.
2061070SN/A     * @return address the kernel ends at
2071070SN/A     */
2081070SN/A    Addr getKernelEnd() const { return kernelEnd; }
2091070SN/A
2101070SN/A    /**
2111070SN/A     * Returns the addess the entry point to the kernel code.
2121070SN/A     * @return entry point of the kernel code
2131070SN/A     */
2141070SN/A    Addr getKernelEntry() const { return kernelEntry; }
2151070SN/A
2162378SN/A#else
2172378SN/A
2182378SN/A    Addr new_page();
2192378SN/A
2202378SN/A#endif // FULL_SYSTEM
2212378SN/A
2222680Sktlim@umich.edu    int registerThreadContext(ThreadContext *tc, int tcIndex);
2232680Sktlim@umich.edu    void replaceThreadContext(ThreadContext *tc, int tcIndex);
2241070SN/A
2251070SN/A    void serialize(std::ostream &os);
2261070SN/A    void unserialize(Checkpoint *cp, const std::string &section);
2272SN/A
22877SN/A  public:
2292SN/A    ////////////////////////////////////////////
2302SN/A    //
2312SN/A    // STATIC GLOBAL SYSTEM LIST
2322SN/A    //
2332SN/A    ////////////////////////////////////////////
2342SN/A
2352SN/A    static std::vector<System *> systemList;
2362SN/A    static int numSystemsRunning;
2372SN/A
2382SN/A    static void printSystems();
2392158SN/A
2402158SN/A
2412SN/A};
2422SN/A
2432SN/A#endif // __SYSTEM_HH__
244