system.hh revision 2650
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.
272SN/A */
282SN/A
292SN/A#ifndef __SYSTEM_HH__
302SN/A#define __SYSTEM_HH__
312SN/A
322SN/A#include <string>
3375SN/A#include <vector>
342SN/A
352439SN/A#include "base/loader/symtab.hh"
362439SN/A#include "base/misc.hh"
37603SN/A#include "base/statistics.hh"
38603SN/A#include "cpu/pc_event.hh"
392520SN/A#include "mem/port.hh"
402378SN/A#include "sim/sim_object.hh"
412378SN/A#if FULL_SYSTEM
42722SN/A#include "kern/system_events.hh"
432521SN/A#include "mem/vport.hh"
442378SN/A#endif
45312SN/A
461634SN/Aclass BaseCPU;
471634SN/Aclass ExecContext;
481634SN/Aclass ObjectFile;
492521SN/Aclass PhysicalMemory;
502378SN/A
512378SN/A#if FULL_SYSTEM
52803SN/Aclass Platform;
532378SN/Aclass GDBListener;
542SN/Aclass RemoteGDB;
551070SN/Anamespace Kernel { class Binning; }
562378SN/A#endif
572SN/A
582SN/Aclass System : public SimObject
592SN/A{
60603SN/A  public:
612521SN/A    PhysicalMemory *physmem;
622SN/A    PCEventQueue pcEventQueue;
632SN/A
64180SN/A    std::vector<ExecContext *> execContexts;
651806SN/A    int numcpus;
661806SN/A
671806SN/A    int getNumCPUs()
681806SN/A    {
691806SN/A        if (numcpus != execContexts.size())
701806SN/A            panic("cpu array not fully populated!");
711806SN/A
721806SN/A        return numcpus;
731806SN/A    }
74180SN/A
752378SN/A#if FULL_SYSTEM
762378SN/A    Platform *platform;
772378SN/A    uint64_t init_param;
782378SN/A
792520SN/A    /** Port to physical memory used for writing object files into ram at
802520SN/A     * boot.*/
812520SN/A    FunctionalPort functionalPort;
822521SN/A    VirtualPort virtPort;
832520SN/A
841885SN/A    /** kernel symbol table */
851070SN/A    SymbolTable *kernelSymtab;
86954SN/A
871070SN/A    /** Object pointer for the kernel code */
881070SN/A    ObjectFile *kernel;
891070SN/A
901070SN/A    /** Begining of kernel code */
911070SN/A    Addr kernelStart;
921070SN/A
931070SN/A    /** End of kernel code */
941070SN/A    Addr kernelEnd;
951070SN/A
961070SN/A    /** Entry point in the kernel to start at */
971070SN/A    Addr kernelEntry;
981070SN/A
991070SN/A    Kernel::Binning *kernelBinning;
1001070SN/A
1012378SN/A#else
1022378SN/A
1032378SN/A    int page_ptr;
1042378SN/A
1052378SN/A
1062378SN/A#endif // FULL_SYSTEM
1072378SN/A
1081885SN/A  protected:
1091885SN/A
1102424SN/A#if FULL_SYSTEM
1111885SN/A    /**
1121885SN/A     * Fix up an address used to match PCs for hooking simulator
1131885SN/A     * events on to target function executions.  See comment in
1141885SN/A     * system.cc for details.
1151885SN/A     */
1162158SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
1171885SN/A
1181885SN/A    /**
1191885SN/A     * Add a function-based event to the given function, to be looked
1201885SN/A     * up in the specified symbol table.
1211885SN/A     */
1221885SN/A    template <class T>
1231885SN/A    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
1241885SN/A    {
1251913SN/A        Addr addr = 0; // initialize only to avoid compiler warning
1261885SN/A
1271885SN/A        if (symtab->findAddress(lbl, addr)) {
1281885SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1291885SN/A            return ev;
1301885SN/A        }
1311885SN/A
1321885SN/A        return NULL;
1331885SN/A    }
1341885SN/A
1351885SN/A    /** Add a function-based event to kernel code. */
1361885SN/A    template <class T>
1371885SN/A    T *System::addKernelFuncEvent(const char *lbl)
1381885SN/A    {
1391885SN/A        return addFuncEvent<T>(kernelSymtab, lbl);
1401885SN/A    }
1411885SN/A
1422378SN/A#endif
14377SN/A  public:
1442378SN/A#if FULL_SYSTEM
1451070SN/A    std::vector<RemoteGDB *> remoteGDB;
1461070SN/A    std::vector<GDBListener *> gdbListen;
1472158SN/A    virtual bool breakpoint() = 0;
1482378SN/A#endif // FULL_SYSTEM
1491070SN/A
1501070SN/A  public:
1511070SN/A    struct Params
1521070SN/A    {
1531070SN/A        std::string name;
1542521SN/A        PhysicalMemory *physmem;
1552378SN/A
1562378SN/A#if FULL_SYSTEM
1571634SN/A        Tick boot_cpu_frequency;
1582567SN/A        std::string boot_osflags;
1591070SN/A        uint64_t init_param;
1601070SN/A        bool bin;
1611070SN/A        std::vector<std::string> binned_fns;
1621082SN/A        bool bin_int;
1631070SN/A
1641070SN/A        std::string kernel_path;
1652158SN/A        std::string readfile;
1662378SN/A#endif
1672158SN/A    };
1681070SN/A
1692158SN/A  protected:
1702158SN/A    Params *_params;
1711070SN/A
1722158SN/A  public:
1731070SN/A    System(Params *p);
1742SN/A    ~System();
1752SN/A
1761129SN/A    void startup();
1771129SN/A
1782158SN/A    const Params *params() const { return (const Params *)_params; }
1792158SN/A
1801070SN/A  public:
1812378SN/A
1822378SN/A#if FULL_SYSTEM
1831070SN/A    /**
1841070SN/A     * Returns the addess the kernel starts at.
1851070SN/A     * @return address the kernel starts at
1861070SN/A     */
1871070SN/A    Addr getKernelStart() const { return kernelStart; }
1881070SN/A
1891070SN/A    /**
1901070SN/A     * Returns the addess the kernel ends at.
1911070SN/A     * @return address the kernel ends at
1921070SN/A     */
1931070SN/A    Addr getKernelEnd() const { return kernelEnd; }
1941070SN/A
1951070SN/A    /**
1961070SN/A     * Returns the addess the entry point to the kernel code.
1971070SN/A     * @return entry point of the kernel code
1981070SN/A     */
1991070SN/A    Addr getKernelEntry() const { return kernelEntry; }
2001070SN/A
2012378SN/A#else
2022378SN/A
2032378SN/A    Addr new_page();
2042378SN/A
2052378SN/A#endif // FULL_SYSTEM
2062378SN/A
2071806SN/A    int registerExecContext(ExecContext *xc, int xcIndex);
2081070SN/A    void replaceExecContext(ExecContext *xc, int xcIndex);
2091070SN/A
2101070SN/A    void regStats();
2111070SN/A    void serialize(std::ostream &os);
2121070SN/A    void unserialize(Checkpoint *cp, const std::string &section);
2132SN/A
21477SN/A  public:
2152SN/A    ////////////////////////////////////////////
2162SN/A    //
2172SN/A    // STATIC GLOBAL SYSTEM LIST
2182SN/A    //
2192SN/A    ////////////////////////////////////////////
2202SN/A
2212SN/A    static std::vector<System *> systemList;
2222SN/A    static int numSystemsRunning;
2232SN/A
2242SN/A    static void printSystems();
2252158SN/A
2262158SN/A
2272SN/A};
2282SN/A
2292SN/A#endif // __SYSTEM_HH__
230