system.hh revision 2902
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"
42603SN/A#include "cpu/pc_event.hh"
432520SN/A#include "mem/port.hh"
442378SN/A#include "sim/sim_object.hh"
452378SN/A#if FULL_SYSTEM
46722SN/A#include "kern/system_events.hh"
472521SN/A#include "mem/vport.hh"
482378SN/A#endif
49312SN/A
501634SN/Aclass BaseCPU;
512680Sktlim@umich.educlass ThreadContext;
521634SN/Aclass ObjectFile;
532521SN/Aclass PhysicalMemory;
542378SN/A
552378SN/A#if FULL_SYSTEM
56803SN/Aclass Platform;
572378SN/Aclass GDBListener;
582SN/Aclass RemoteGDB;
592378SN/A#endif
602SN/A
612SN/Aclass System : public SimObject
622SN/A{
63603SN/A  public:
642901Ssaidi@eecs.umich.edu    enum MemoryMode {
652901Ssaidi@eecs.umich.edu        Invalid=0,
662901Ssaidi@eecs.umich.edu        Atomic,
672901Ssaidi@eecs.umich.edu        Timing
682901Ssaidi@eecs.umich.edu    };
692901Ssaidi@eecs.umich.edu
702902Ssaidi@eecs.umich.edu    static const char *MemoryModeStrings[3];
712902Ssaidi@eecs.umich.edu
722901Ssaidi@eecs.umich.edu
732901Ssaidi@eecs.umich.edu    MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; }
742901Ssaidi@eecs.umich.edu
752901Ssaidi@eecs.umich.edu    /** Change the memory mode of the system. This should only be called by the
762901Ssaidi@eecs.umich.edu     * python!!
772901Ssaidi@eecs.umich.edu     * @param mode Mode to change to (atomic/timing)
782901Ssaidi@eecs.umich.edu     */
792901Ssaidi@eecs.umich.edu    void setMemoryMode(MemoryMode mode);
802901Ssaidi@eecs.umich.edu
812521SN/A    PhysicalMemory *physmem;
822SN/A    PCEventQueue pcEventQueue;
832SN/A
842680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
851806SN/A    int numcpus;
861806SN/A
871806SN/A    int getNumCPUs()
881806SN/A    {
892680Sktlim@umich.edu        if (numcpus != threadContexts.size())
901806SN/A            panic("cpu array not fully populated!");
911806SN/A
921806SN/A        return numcpus;
931806SN/A    }
94180SN/A
952378SN/A#if FULL_SYSTEM
962378SN/A    Platform *platform;
972378SN/A    uint64_t init_param;
982378SN/A
992520SN/A    /** Port to physical memory used for writing object files into ram at
1002520SN/A     * boot.*/
1012520SN/A    FunctionalPort functionalPort;
1022521SN/A    VirtualPort virtPort;
1032520SN/A
1041885SN/A    /** kernel symbol table */
1051070SN/A    SymbolTable *kernelSymtab;
106954SN/A
1071070SN/A    /** Object pointer for the kernel code */
1081070SN/A    ObjectFile *kernel;
1091070SN/A
1101070SN/A    /** Begining of kernel code */
1111070SN/A    Addr kernelStart;
1121070SN/A
1131070SN/A    /** End of kernel code */
1141070SN/A    Addr kernelEnd;
1151070SN/A
1161070SN/A    /** Entry point in the kernel to start at */
1171070SN/A    Addr kernelEntry;
1181070SN/A
1192378SN/A#else
1202378SN/A
1212378SN/A    int page_ptr;
1222378SN/A
1232378SN/A
1242378SN/A#endif // FULL_SYSTEM
1252378SN/A
1261885SN/A  protected:
1271885SN/A
1282901Ssaidi@eecs.umich.edu    MemoryMode memoryMode;
1292901Ssaidi@eecs.umich.edu
1302424SN/A#if FULL_SYSTEM
1311885SN/A    /**
1321885SN/A     * Fix up an address used to match PCs for hooking simulator
1331885SN/A     * events on to target function executions.  See comment in
1341885SN/A     * system.cc for details.
1351885SN/A     */
1362158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1371885SN/A
1381885SN/A    /**
1391885SN/A     * Add a function-based event to the given function, to be looked
1401885SN/A     * up in the specified symbol table.
1411885SN/A     */
1421885SN/A    template <class T>
1431885SN/A    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
1441885SN/A    {
1451913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1461885SN/A
1471885SN/A        if (symtab->findAddress(lbl, addr)) {
1481885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1491885SN/A            return ev;
1501885SN/A        }
1511885SN/A
1521885SN/A        return NULL;
1531885SN/A    }
1541885SN/A
1551885SN/A    /** Add a function-based event to kernel code. */
1561885SN/A    template <class T>
1571885SN/A    T *System::addKernelFuncEvent(const char *lbl)
1581885SN/A    {
1591885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1601885SN/A    }
1611885SN/A
1622378SN/A#endif
16377SN/A  public:
1642378SN/A#if FULL_SYSTEM
1651070SN/A    std::vector<RemoteGDB *> remoteGDB;
1661070SN/A    std::vector<GDBListener *> gdbListen;
1672158SN/A    virtual bool breakpoint() = 0;
1682378SN/A#endif // FULL_SYSTEM
1691070SN/A
1701070SN/A  public:
1711070SN/A    struct Params
1721070SN/A    {
1731070SN/A        std::string name;
1742521SN/A        PhysicalMemory *physmem;
1752902Ssaidi@eecs.umich.edu        MemoryMode mem_mode;
1762378SN/A
1772378SN/A#if FULL_SYSTEM
1781634SN/A        Tick boot_cpu_frequency;
1792567SN/A        std::string boot_osflags;
1801070SN/A        uint64_t init_param;
1811070SN/A
1821070SN/A        std::string kernel_path;
1832158SN/A        std::string readfile;
1842378SN/A#endif
1852158SN/A    };
1861070SN/A
1872158SN/A  protected:
1882158SN/A    Params *_params;
1891070SN/A
1902158SN/A  public:
1911070SN/A    System(Params *p);
1922SN/A    ~System();
1932SN/A
1941129SN/A    void startup();
1951129SN/A
1962158SN/A    const Params *params() const { return (const Params *)_params; }
1972158SN/A
1981070SN/A  public:
1992378SN/A
2002378SN/A#if FULL_SYSTEM
2011070SN/A    /**
2021070SN/A     * Returns the addess the kernel starts at.
2031070SN/A     * @return address the kernel starts at
2041070SN/A     */
2051070SN/A    Addr getKernelStart() const { return kernelStart; }
2061070SN/A
2071070SN/A    /**
2081070SN/A     * Returns the addess the kernel ends at.
2091070SN/A     * @return address the kernel ends at
2101070SN/A     */
2111070SN/A    Addr getKernelEnd() const { return kernelEnd; }
2121070SN/A
2131070SN/A    /**
2141070SN/A     * Returns the addess the entry point to the kernel code.
2151070SN/A     * @return entry point of the kernel code
2161070SN/A     */
2171070SN/A    Addr getKernelEntry() const { return kernelEntry; }
2181070SN/A
2192378SN/A#else
2202378SN/A
2212378SN/A    Addr new_page();
2222378SN/A
2232378SN/A#endif // FULL_SYSTEM
2242378SN/A
2252680Sktlim@umich.edu    int registerThreadContext(ThreadContext *tc, int tcIndex);
2262680Sktlim@umich.edu    void replaceThreadContext(ThreadContext *tc, int tcIndex);
2271070SN/A
2281070SN/A    void serialize(std::ostream &os);
2291070SN/A    void unserialize(Checkpoint *cp, const std::string &section);
2302SN/A
23177SN/A  public:
2322SN/A    ////////////////////////////////////////////
2332SN/A    //
2342SN/A    // STATIC GLOBAL SYSTEM LIST
2352SN/A    //
2362SN/A    ////////////////////////////////////////////
2372SN/A
2382SN/A    static std::vector<System *> systemList;
2392SN/A    static int numSystemsRunning;
2402SN/A
2412SN/A    static void printSystems();
2422158SN/A
2432158SN/A
2442SN/A};
2452SN/A
2462SN/A#endif // __SYSTEM_HH__
247