system.hh revision 2989
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    enum MemoryMode {
662901Ssaidi@eecs.umich.edu        Invalid=0,
672901Ssaidi@eecs.umich.edu        Atomic,
682901Ssaidi@eecs.umich.edu        Timing
692901Ssaidi@eecs.umich.edu    };
702901Ssaidi@eecs.umich.edu
712902Ssaidi@eecs.umich.edu    static const char *MemoryModeStrings[3];
722902Ssaidi@eecs.umich.edu
732901Ssaidi@eecs.umich.edu
742901Ssaidi@eecs.umich.edu    MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; }
752901Ssaidi@eecs.umich.edu
762901Ssaidi@eecs.umich.edu    /** Change the memory mode of the system. This should only be called by the
772901Ssaidi@eecs.umich.edu     * python!!
782901Ssaidi@eecs.umich.edu     * @param mode Mode to change to (atomic/timing)
792901Ssaidi@eecs.umich.edu     */
802901Ssaidi@eecs.umich.edu    void setMemoryMode(MemoryMode mode);
812901Ssaidi@eecs.umich.edu
822521SN/A    PhysicalMemory *physmem;
832SN/A    PCEventQueue pcEventQueue;
842SN/A
852680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
861806SN/A    int numcpus;
871806SN/A
881806SN/A    int getNumCPUs()
891806SN/A    {
902680Sktlim@umich.edu        if (numcpus != threadContexts.size())
911806SN/A            panic("cpu array not fully populated!");
921806SN/A
931806SN/A        return numcpus;
941806SN/A    }
95180SN/A
962378SN/A#if FULL_SYSTEM
972378SN/A    Platform *platform;
982378SN/A    uint64_t init_param;
992378SN/A
1002520SN/A    /** Port to physical memory used for writing object files into ram at
1012520SN/A     * boot.*/
1022520SN/A    FunctionalPort functionalPort;
1032521SN/A    VirtualPort virtPort;
1042520SN/A
1051885SN/A    /** kernel symbol table */
1061070SN/A    SymbolTable *kernelSymtab;
107954SN/A
1081070SN/A    /** Object pointer for the kernel code */
1091070SN/A    ObjectFile *kernel;
1101070SN/A
1111070SN/A    /** Begining of kernel code */
1121070SN/A    Addr kernelStart;
1131070SN/A
1141070SN/A    /** End of kernel code */
1151070SN/A    Addr kernelEnd;
1161070SN/A
1171070SN/A    /** Entry point in the kernel to start at */
1181070SN/A    Addr kernelEntry;
1191070SN/A
1202378SN/A#else
1212378SN/A
1222378SN/A    int page_ptr;
1232378SN/A
1242378SN/A
1252378SN/A#endif // FULL_SYSTEM
1262378SN/A
1271885SN/A  protected:
1281885SN/A
1292901Ssaidi@eecs.umich.edu    MemoryMode memoryMode;
1302901Ssaidi@eecs.umich.edu
1312424SN/A#if FULL_SYSTEM
1321885SN/A    /**
1331885SN/A     * Fix up an address used to match PCs for hooking simulator
1341885SN/A     * events on to target function executions.  See comment in
1351885SN/A     * system.cc for details.
1361885SN/A     */
1372158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1381885SN/A
1391885SN/A    /**
1401885SN/A     * Add a function-based event to the given function, to be looked
1411885SN/A     * up in the specified symbol table.
1421885SN/A     */
1431885SN/A    template <class T>
1442989Ssaidi@eecs.umich.edu    T *addFuncEvent(SymbolTable *symtab, const char *lbl)
1451885SN/A    {
1461913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1471885SN/A
1481885SN/A        if (symtab->findAddress(lbl, addr)) {
1491885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1501885SN/A            return ev;
1511885SN/A        }
1521885SN/A
1531885SN/A        return NULL;
1541885SN/A    }
1551885SN/A
1561885SN/A    /** Add a function-based event to kernel code. */
1571885SN/A    template <class T>
1582989Ssaidi@eecs.umich.edu    T *addKernelFuncEvent(const char *lbl)
1591885SN/A    {
1601885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1611885SN/A    }
1621885SN/A
1632378SN/A#endif
16477SN/A  public:
1652378SN/A#if FULL_SYSTEM
1661070SN/A    std::vector<RemoteGDB *> remoteGDB;
1671070SN/A    std::vector<GDBListener *> gdbListen;
1682158SN/A    virtual bool breakpoint() = 0;
1692378SN/A#endif // FULL_SYSTEM
1701070SN/A
1711070SN/A  public:
1721070SN/A    struct Params
1731070SN/A    {
1741070SN/A        std::string name;
1752521SN/A        PhysicalMemory *physmem;
1762902Ssaidi@eecs.umich.edu        MemoryMode mem_mode;
1772378SN/A
1782378SN/A#if FULL_SYSTEM
1791634SN/A        Tick boot_cpu_frequency;
1802567SN/A        std::string boot_osflags;
1811070SN/A        uint64_t init_param;
1821070SN/A
1831070SN/A        std::string kernel_path;
1842158SN/A        std::string readfile;
1852378SN/A#endif
1862158SN/A    };
1871070SN/A
1882158SN/A  protected:
1892158SN/A    Params *_params;
1901070SN/A
1912158SN/A  public:
1921070SN/A    System(Params *p);
1932SN/A    ~System();
1942SN/A
1951129SN/A    void startup();
1961129SN/A
1972158SN/A    const Params *params() const { return (const Params *)_params; }
1982158SN/A
1991070SN/A  public:
2002378SN/A
2012378SN/A#if FULL_SYSTEM
2021070SN/A    /**
2031070SN/A     * Returns the addess the kernel starts at.
2041070SN/A     * @return address the kernel starts at
2051070SN/A     */
2061070SN/A    Addr getKernelStart() const { return kernelStart; }
2071070SN/A
2081070SN/A    /**
2091070SN/A     * Returns the addess the kernel ends at.
2101070SN/A     * @return address the kernel ends at
2111070SN/A     */
2121070SN/A    Addr getKernelEnd() const { return kernelEnd; }
2131070SN/A
2141070SN/A    /**
2151070SN/A     * Returns the addess the entry point to the kernel code.
2161070SN/A     * @return entry point of the kernel code
2171070SN/A     */
2181070SN/A    Addr getKernelEntry() const { return kernelEntry; }
2191070SN/A
2202378SN/A#else
2212378SN/A
2222378SN/A    Addr new_page();
2232378SN/A
2242378SN/A#endif // FULL_SYSTEM
2252378SN/A
2262680Sktlim@umich.edu    int registerThreadContext(ThreadContext *tc, int tcIndex);
2272680Sktlim@umich.edu    void replaceThreadContext(ThreadContext *tc, int tcIndex);
2281070SN/A
2291070SN/A    void serialize(std::ostream &os);
2301070SN/A    void unserialize(Checkpoint *cp, const std::string &section);
2312SN/A
23277SN/A  public:
2332SN/A    ////////////////////////////////////////////
2342SN/A    //
2352SN/A    // STATIC GLOBAL SYSTEM LIST
2362SN/A    //
2372SN/A    ////////////////////////////////////////////
2382SN/A
2392SN/A    static std::vector<System *> systemList;
2402SN/A    static int numSystemsRunning;
2412SN/A
2422SN/A    static void printSystems();
2432158SN/A
2442158SN/A
2452SN/A};
2462SN/A
2472SN/A#endif // __SYSTEM_HH__
248