system.hh revision 2901
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
702901Ssaidi@eecs.umich.edu
712901Ssaidi@eecs.umich.edu    MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; }
722901Ssaidi@eecs.umich.edu
732901Ssaidi@eecs.umich.edu    /** Change the memory mode of the system. This should only be called by the
742901Ssaidi@eecs.umich.edu     * python!!
752901Ssaidi@eecs.umich.edu     * @param mode Mode to change to (atomic/timing)
762901Ssaidi@eecs.umich.edu     */
772901Ssaidi@eecs.umich.edu    void setMemoryMode(MemoryMode mode);
782901Ssaidi@eecs.umich.edu
792521SN/A    PhysicalMemory *physmem;
802SN/A    PCEventQueue pcEventQueue;
812SN/A
822680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
831806SN/A    int numcpus;
841806SN/A
851806SN/A    int getNumCPUs()
861806SN/A    {
872680Sktlim@umich.edu        if (numcpus != threadContexts.size())
881806SN/A            panic("cpu array not fully populated!");
891806SN/A
901806SN/A        return numcpus;
911806SN/A    }
92180SN/A
932378SN/A#if FULL_SYSTEM
942378SN/A    Platform *platform;
952378SN/A    uint64_t init_param;
962378SN/A
972520SN/A    /** Port to physical memory used for writing object files into ram at
982520SN/A     * boot.*/
992520SN/A    FunctionalPort functionalPort;
1002521SN/A    VirtualPort virtPort;
1012520SN/A
1021885SN/A    /** kernel symbol table */
1031070SN/A    SymbolTable *kernelSymtab;
104954SN/A
1051070SN/A    /** Object pointer for the kernel code */
1061070SN/A    ObjectFile *kernel;
1071070SN/A
1081070SN/A    /** Begining of kernel code */
1091070SN/A    Addr kernelStart;
1101070SN/A
1111070SN/A    /** End of kernel code */
1121070SN/A    Addr kernelEnd;
1131070SN/A
1141070SN/A    /** Entry point in the kernel to start at */
1151070SN/A    Addr kernelEntry;
1161070SN/A
1172378SN/A#else
1182378SN/A
1192378SN/A    int page_ptr;
1202378SN/A
1212378SN/A
1222378SN/A#endif // FULL_SYSTEM
1232378SN/A
1241885SN/A  protected:
1251885SN/A
1262901Ssaidi@eecs.umich.edu    MemoryMode memoryMode;
1272901Ssaidi@eecs.umich.edu
1282424SN/A#if FULL_SYSTEM
1291885SN/A    /**
1301885SN/A     * Fix up an address used to match PCs for hooking simulator
1311885SN/A     * events on to target function executions.  See comment in
1321885SN/A     * system.cc for details.
1331885SN/A     */
1342158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1351885SN/A
1361885SN/A    /**
1371885SN/A     * Add a function-based event to the given function, to be looked
1381885SN/A     * up in the specified symbol table.
1391885SN/A     */
1401885SN/A    template <class T>
1411885SN/A    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
1421885SN/A    {
1431913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1441885SN/A
1451885SN/A        if (symtab->findAddress(lbl, addr)) {
1461885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1471885SN/A            return ev;
1481885SN/A        }
1491885SN/A
1501885SN/A        return NULL;
1511885SN/A    }
1521885SN/A
1531885SN/A    /** Add a function-based event to kernel code. */
1541885SN/A    template <class T>
1551885SN/A    T *System::addKernelFuncEvent(const char *lbl)
1561885SN/A    {
1571885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1581885SN/A    }
1591885SN/A
1602378SN/A#endif
16177SN/A  public:
1622378SN/A#if FULL_SYSTEM
1631070SN/A    std::vector<RemoteGDB *> remoteGDB;
1641070SN/A    std::vector<GDBListener *> gdbListen;
1652158SN/A    virtual bool breakpoint() = 0;
1662378SN/A#endif // FULL_SYSTEM
1671070SN/A
1681070SN/A  public:
1691070SN/A    struct Params
1701070SN/A    {
1711070SN/A        std::string name;
1722521SN/A        PhysicalMemory *physmem;
1732378SN/A
1742378SN/A#if FULL_SYSTEM
1751634SN/A        Tick boot_cpu_frequency;
1762567SN/A        std::string boot_osflags;
1771070SN/A        uint64_t init_param;
1781070SN/A
1791070SN/A        std::string kernel_path;
1802158SN/A        std::string readfile;
1812378SN/A#endif
1822158SN/A    };
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