system.hh revision 2521
16145SN/A/*
26145SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
36145SN/A * All rights reserved.
46145SN/A *
56145SN/A * Redistribution and use in source and binary forms, with or without
66145SN/A * modification, are permitted provided that the following conditions are
76145SN/A * met: redistributions of source code must retain the above copyright
86145SN/A * notice, this list of conditions and the following disclaimer;
96145SN/A * redistributions in binary form must reproduce the above copyright
106145SN/A * notice, this list of conditions and the following disclaimer in the
116145SN/A * documentation and/or other materials provided with the distribution;
126145SN/A * neither the name of the copyright holders nor the names of its
136145SN/A * contributors may be used to endorse or promote products derived from
146145SN/A * this software without specific prior written permission.
156145SN/A *
166145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145SN/A */
286145SN/A
2911793Sbrandon.potter@amd.com#ifndef __SYSTEM_HH__
3011793Sbrandon.potter@amd.com#define __SYSTEM_HH__
317832SN/A
327832SN/A#include <string>
339356Snilay@cs.wisc.edu#include <vector>
348232SN/A
357054SN/A#include "base/loader/symtab.hh"
368257SBrad.Beckmann@amd.com#include "base/misc.hh"
3711793Sbrandon.potter@amd.com#include "base/statistics.hh"
387054SN/A#include "cpu/pc_event.hh"
396145SN/A#include "mem/port.hh"
407055SN/A#include "sim/sim_object.hh"
417055SN/A#if FULL_SYSTEM
427054SN/A#include "kern/system_events.hh"
438257SBrad.Beckmann@amd.com#include "mem/vport.hh"
446145SN/A#endif
456145SN/A
466145SN/Aclass BaseCPU;
476145SN/Aclass ExecContext;
486145SN/Aclass ObjectFile;
496145SN/Aclass PhysicalMemory;
506145SN/A
5111096Snilay@cs.wisc.edu#if FULL_SYSTEM
5211096Snilay@cs.wisc.educlass Platform;
5311096Snilay@cs.wisc.educlass GDBListener;
5413661Spfotouhi@ucdavis.educlass RemoteGDB;
5513661Spfotouhi@ucdavis.edunamespace Kernel { class Binning; }
5611096Snilay@cs.wisc.edu#endif
576145SN/A
586881SN/Aclass System : public SimObject
596881SN/A{
606285SN/A  public:
6111663Stushar@ece.gatech.edu    PhysicalMemory *physmem;
6211663Stushar@ece.gatech.edu    PCEventQueue pcEventQueue;
6311663Stushar@ece.gatech.edu
6411663Stushar@ece.gatech.edu    std::vector<ExecContext *> execContexts;
6511663Stushar@ece.gatech.edu    int numcpus;
6611663Stushar@ece.gatech.edu
6711663Stushar@ece.gatech.edu    int getNumCPUs()
6811663Stushar@ece.gatech.edu    {
699594Snilay@cs.wisc.edu        if (numcpus != execContexts.size())
709594Snilay@cs.wisc.edu            panic("cpu array not fully populated!");
718257SBrad.Beckmann@amd.com
728257SBrad.Beckmann@amd.com        return numcpus;
738257SBrad.Beckmann@amd.com    }
746881SN/A
7510078Snilay@cs.wisc.edu#if FULL_SYSTEM
769869Sjthestness@gmail.com    Platform *platform;
777054SN/A    uint64_t init_param;
788257SBrad.Beckmann@amd.com
796145SN/A    /** Port to physical memory used for writing object files into ram at
808257SBrad.Beckmann@amd.com     * boot.*/
8111663Stushar@ece.gatech.edu    FunctionalPort functionalPort;
8211663Stushar@ece.gatech.edu    VirtualPort virtPort;
8311663Stushar@ece.gatech.edu
8411663Stushar@ece.gatech.edu    /** kernel symbol table */
857054SN/A    SymbolTable *kernelSymtab;
866145SN/A
8711663Stushar@ece.gatech.edu    /** Object pointer for the kernel code */
889594Snilay@cs.wisc.edu    ObjectFile *kernel;
899594Snilay@cs.wisc.edu
908257SBrad.Beckmann@amd.com    /** Begining of kernel code */
9111663Stushar@ece.gatech.edu    Addr kernelStart;
9211663Stushar@ece.gatech.edu
936881SN/A    /** End of kernel code */
9411664Stushar@ece.gatech.edu    Addr kernelEnd;
9511664Stushar@ece.gatech.edu
9611664Stushar@ece.gatech.edu    /** Entry point in the kernel to start at */
978257SBrad.Beckmann@amd.com    Addr kernelEntry;
988257SBrad.Beckmann@amd.com
998257SBrad.Beckmann@amd.com    Kernel::Binning *kernelBinning;
10011663Stushar@ece.gatech.edu
10111663Stushar@ece.gatech.edu#else
1028257SBrad.Beckmann@amd.com
10311663Stushar@ece.gatech.edu    int page_ptr;
10411664Stushar@ece.gatech.edu
1057054SN/A
1066145SN/A#endif // FULL_SYSTEM
1076145SN/A
1088257SBrad.Beckmann@amd.com  protected:
1099799Snilay@cs.wisc.edu
1107054SN/A#if FULL_SYSTEM
1117054SN/A    /**
1127054SN/A     * Fix up an address used to match PCs for hooking simulator
1138257SBrad.Beckmann@amd.com     * events on to target function executions.  See comment in
1148257SBrad.Beckmann@amd.com     * system.cc for details.
11510005Snilay@cs.wisc.edu     */
1168257SBrad.Beckmann@amd.com    virtual Addr fixFuncEventAddr(Addr addr) = 0;
11711320Ssteve.reinhardt@amd.com
1187054SN/A    /**
1196881SN/A     * Add a function-based event to the given function, to be looked
1208257SBrad.Beckmann@amd.com     * up in the specified symbol table.
1217054SN/A     */
12211096Snilay@cs.wisc.edu    template <class T>
12311096Snilay@cs.wisc.edu    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
12411096Snilay@cs.wisc.edu    {
12511096Snilay@cs.wisc.edu        Addr addr = 0; // initialize only to avoid compiler warning
12611096Snilay@cs.wisc.edu
12711096Snilay@cs.wisc.edu        if (symtab->findAddress(lbl, addr)) {
1286145SN/A            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1297054SN/A            return ev;
1307054SN/A        }
1317054SN/A
1327054SN/A        return NULL;
1336145SN/A    }
1347054SN/A
1358257SBrad.Beckmann@amd.com    /** Add a function-based event to kernel code. */
1368257SBrad.Beckmann@amd.com    template <class T>
1378257SBrad.Beckmann@amd.com    T *System::addKernelFuncEvent(const char *lbl)
1388257SBrad.Beckmann@amd.com    {
1398257SBrad.Beckmann@amd.com        return addFuncEvent<T>(kernelSymtab, lbl);
1408257SBrad.Beckmann@amd.com    }
14111096Snilay@cs.wisc.edu
1428257SBrad.Beckmann@amd.com#endif
1437054SN/A  public:
14411320Ssteve.reinhardt@amd.com#if FULL_SYSTEM
1457054SN/A    std::vector<RemoteGDB *> remoteGDB;
14611096Snilay@cs.wisc.edu    std::vector<GDBListener *> gdbListen;
14711096Snilay@cs.wisc.edu    virtual bool breakpoint() = 0;
14811096Snilay@cs.wisc.edu#endif // FULL_SYSTEM
1497054SN/A
1507054SN/A  public:
1517054SN/A    struct Params
1527054SN/A    {
1539799Snilay@cs.wisc.edu        std::string name;
1549799Snilay@cs.wisc.edu        PhysicalMemory *physmem;
1559799Snilay@cs.wisc.edu
1567054SN/A#if FULL_SYSTEM
1577054SN/A        Tick boot_cpu_frequency;
1586895SN/A        uint64_t init_param;
1596895SN/A        bool bin;
1606895SN/A        std::vector<std::string> binned_fns;
1617054SN/A        bool bin_int;
16211664Stushar@ece.gatech.edu
16311664Stushar@ece.gatech.edu        std::string kernel_path;
16411664Stushar@ece.gatech.edu        std::string readfile;
1657054SN/A#endif
1667832SN/A    };
1677832SN/A
16811320Ssteve.reinhardt@amd.com  protected:
1698257SBrad.Beckmann@amd.com    Params *_params;
1708257SBrad.Beckmann@amd.com
1718257SBrad.Beckmann@amd.com  public:
1728257SBrad.Beckmann@amd.com    System(Params *p);
1738257SBrad.Beckmann@amd.com    ~System();
1748257SBrad.Beckmann@amd.com
17511664Stushar@ece.gatech.edu    void startup();
17611664Stushar@ece.gatech.edu
1778257SBrad.Beckmann@amd.com    const Params *params() const { return (const Params *)_params; }
1787054SN/A
1797054SN/A  public:
1807054SN/A
1817054SN/A#if FULL_SYSTEM
1829799Snilay@cs.wisc.edu    /**
1837054SN/A     * Returns the addess the kernel starts at.
1847054SN/A     * @return address the kernel starts at
1857054SN/A     */
1867054SN/A    Addr getKernelStart() const { return kernelStart; }
1877054SN/A
1888257SBrad.Beckmann@amd.com    /**
18911320Ssteve.reinhardt@amd.com     * Returns the addess the kernel ends at.
1908257SBrad.Beckmann@amd.com     * @return address the kernel ends at
1917054SN/A     */
1928257SBrad.Beckmann@amd.com    Addr getKernelEnd() const { return kernelEnd; }
1938257SBrad.Beckmann@amd.com
1948257SBrad.Beckmann@amd.com    /**
19511663Stushar@ece.gatech.edu     * Returns the addess the entry point to the kernel code.
19611663Stushar@ece.gatech.edu     * @return entry point of the kernel code
1977054SN/A     */
1987054SN/A    Addr getKernelEntry() const { return kernelEntry; }
1998257SBrad.Beckmann@amd.com
2008257SBrad.Beckmann@amd.com#else
2018257SBrad.Beckmann@amd.com
2028257SBrad.Beckmann@amd.com    Addr new_page();
20311663Stushar@ece.gatech.edu
20411663Stushar@ece.gatech.edu#endif // FULL_SYSTEM
2057054SN/A
2068257SBrad.Beckmann@amd.com    int registerExecContext(ExecContext *xc, int xcIndex);
2078257SBrad.Beckmann@amd.com    void replaceExecContext(ExecContext *xc, int xcIndex);
2088257SBrad.Beckmann@amd.com
2098257SBrad.Beckmann@amd.com    void regStats();
2108257SBrad.Beckmann@amd.com    void serialize(std::ostream &os);
21111663Stushar@ece.gatech.edu    void unserialize(Checkpoint *cp, const std::string &section);
21211664Stushar@ece.gatech.edu
21311664Stushar@ece.gatech.edu  public:
21411664Stushar@ece.gatech.edu    ////////////////////////////////////////////
2157054SN/A    //
2167054SN/A    // STATIC GLOBAL SYSTEM LIST
2177054SN/A    //
2186145SN/A    ////////////////////////////////////////////
2196145SN/A
2207054SN/A    static std::vector<System *> systemList;
22111096Snilay@cs.wisc.edu    static int numSystemsRunning;
22211096Snilay@cs.wisc.edu
2237054SN/A    static void printSystems();
2247054SN/A
2257054SN/A
2266145SN/A};
2277054SN/A
2287054SN/A#endif // __SYSTEM_HH__
2297054SN/A