system.hh revision 3202
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"
442520SN/A#include "mem/port.hh"
452378SN/A#include "sim/sim_object.hh"
462378SN/A#if FULL_SYSTEM
47722SN/A#include "kern/system_events.hh"
482521SN/A#include "mem/vport.hh"
492378SN/A#endif
50312SN/A
511634SN/Aclass BaseCPU;
522680Sktlim@umich.educlass ThreadContext;
531634SN/Aclass ObjectFile;
542521SN/Aclass PhysicalMemory;
552378SN/A
562378SN/A#if FULL_SYSTEM
57803SN/Aclass Platform;
582378SN/Aclass GDBListener;
592SN/Aclass RemoteGDB;
602378SN/A#endif
612SN/A
622SN/Aclass System : public SimObject
632SN/A{
64603SN/A  public:
652901Ssaidi@eecs.umich.edu
662902Ssaidi@eecs.umich.edu    static const char *MemoryModeStrings[3];
672902Ssaidi@eecs.umich.edu
683202Shsul@eecs.umich.edu    SimObject::MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; }
692901Ssaidi@eecs.umich.edu
702901Ssaidi@eecs.umich.edu    /** Change the memory mode of the system. This should only be called by the
712901Ssaidi@eecs.umich.edu     * python!!
722901Ssaidi@eecs.umich.edu     * @param mode Mode to change to (atomic/timing)
732901Ssaidi@eecs.umich.edu     */
743202Shsul@eecs.umich.edu    void setMemoryMode(SimObject::MemoryMode mode);
752901Ssaidi@eecs.umich.edu
762521SN/A    PhysicalMemory *physmem;
772SN/A    PCEventQueue pcEventQueue;
782SN/A
792680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
801806SN/A    int numcpus;
811806SN/A
821806SN/A    int getNumCPUs()
831806SN/A    {
842680Sktlim@umich.edu        if (numcpus != threadContexts.size())
851806SN/A            panic("cpu array not fully populated!");
861806SN/A
871806SN/A        return numcpus;
881806SN/A    }
89180SN/A
902378SN/A#if FULL_SYSTEM
912378SN/A    Platform *platform;
922378SN/A    uint64_t init_param;
932378SN/A
942520SN/A    /** Port to physical memory used for writing object files into ram at
952520SN/A     * boot.*/
962520SN/A    FunctionalPort functionalPort;
972521SN/A    VirtualPort virtPort;
982520SN/A
991885SN/A    /** kernel symbol table */
1001070SN/A    SymbolTable *kernelSymtab;
101954SN/A
1021070SN/A    /** Object pointer for the kernel code */
1031070SN/A    ObjectFile *kernel;
1041070SN/A
1051070SN/A    /** Begining of kernel code */
1061070SN/A    Addr kernelStart;
1071070SN/A
1081070SN/A    /** End of kernel code */
1091070SN/A    Addr kernelEnd;
1101070SN/A
1111070SN/A    /** Entry point in the kernel to start at */
1121070SN/A    Addr kernelEntry;
1131070SN/A
1142378SN/A#else
1152378SN/A
1162378SN/A    int page_ptr;
1172378SN/A
1182378SN/A
1192378SN/A#endif // FULL_SYSTEM
1202378SN/A
1211885SN/A  protected:
1221885SN/A
1233202Shsul@eecs.umich.edu    SimObject::MemoryMode memoryMode;
1242901Ssaidi@eecs.umich.edu
1252424SN/A#if FULL_SYSTEM
1261885SN/A    /**
1271885SN/A     * Fix up an address used to match PCs for hooking simulator
1281885SN/A     * events on to target function executions.  See comment in
1291885SN/A     * system.cc for details.
1301885SN/A     */
1312158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1321885SN/A
1331885SN/A    /**
1341885SN/A     * Add a function-based event to the given function, to be looked
1351885SN/A     * up in the specified symbol table.
1361885SN/A     */
1371885SN/A    template <class T>
1382989Ssaidi@eecs.umich.edu    T *addFuncEvent(SymbolTable *symtab, const char *lbl)
1391885SN/A    {
1401913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1411885SN/A
1421885SN/A        if (symtab->findAddress(lbl, addr)) {
1431885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1441885SN/A            return ev;
1451885SN/A        }
1461885SN/A
1471885SN/A        return NULL;
1481885SN/A    }
1491885SN/A
1501885SN/A    /** Add a function-based event to kernel code. */
1511885SN/A    template <class T>
1522989Ssaidi@eecs.umich.edu    T *addKernelFuncEvent(const char *lbl)
1531885SN/A    {
1541885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1551885SN/A    }
1561885SN/A
1572378SN/A#endif
15877SN/A  public:
1592378SN/A#if FULL_SYSTEM
1601070SN/A    std::vector<RemoteGDB *> remoteGDB;
1611070SN/A    std::vector<GDBListener *> gdbListen;
1622158SN/A    virtual bool breakpoint() = 0;
1632378SN/A#endif // FULL_SYSTEM
1641070SN/A
1651070SN/A  public:
1661070SN/A    struct Params
1671070SN/A    {
1681070SN/A        std::string name;
1692521SN/A        PhysicalMemory *physmem;
1703202Shsul@eecs.umich.edu        SimObject::MemoryMode mem_mode;
1712378SN/A
1722378SN/A#if FULL_SYSTEM
1731634SN/A        Tick boot_cpu_frequency;
1742567SN/A        std::string boot_osflags;
1751070SN/A        uint64_t init_param;
1761070SN/A
1771070SN/A        std::string kernel_path;
1782158SN/A        std::string readfile;
1792358SN/A        std::string symbolfile;
1802378SN/A#endif
1812158SN/A    };
1821070SN/A
1832158SN/A  protected:
1842158SN/A    Params *_params;
1851070SN/A
1862158SN/A  public:
1871070SN/A    System(Params *p);
1882SN/A    ~System();
1892SN/A
1901129SN/A    void startup();
1911129SN/A
1922158SN/A    const Params *params() const { return (const Params *)_params; }
1932158SN/A
1941070SN/A  public:
1952378SN/A
1962378SN/A#if FULL_SYSTEM
1971070SN/A    /**
1981070SN/A     * Returns the addess the kernel starts at.
1991070SN/A     * @return address the kernel starts at
2001070SN/A     */
2011070SN/A    Addr getKernelStart() const { return kernelStart; }
2021070SN/A
2031070SN/A    /**
2041070SN/A     * Returns the addess the kernel ends at.
2051070SN/A     * @return address the kernel ends at
2061070SN/A     */
2071070SN/A    Addr getKernelEnd() const { return kernelEnd; }
2081070SN/A
2091070SN/A    /**
2101070SN/A     * Returns the addess the entry point to the kernel code.
2111070SN/A     * @return entry point of the kernel code
2121070SN/A     */
2131070SN/A    Addr getKernelEntry() const { return kernelEntry; }
2141070SN/A
2152378SN/A#else
2162378SN/A
2172378SN/A    Addr new_page();
2182378SN/A
2192378SN/A#endif // FULL_SYSTEM
2202378SN/A
2212680Sktlim@umich.edu    int registerThreadContext(ThreadContext *tc, int tcIndex);
2222680Sktlim@umich.edu    void replaceThreadContext(ThreadContext *tc, int tcIndex);
2231070SN/A
2241070SN/A    void serialize(std::ostream &os);
2251070SN/A    void unserialize(Checkpoint *cp, const std::string &section);
2262SN/A
22777SN/A  public:
2282SN/A    ////////////////////////////////////////////
2292SN/A    //
2302SN/A    // STATIC GLOBAL SYSTEM LIST
2312SN/A    //
2322SN/A    ////////////////////////////////////////////
2332SN/A
2342SN/A    static std::vector<System *> systemList;
2352SN/A    static int numSystemsRunning;
2362SN/A
2372SN/A    static void printSystems();
2382158SN/A
2392158SN/A
2402SN/A};
2412SN/A
2422SN/A#endif // __SYSTEM_HH__
243