system.hh revision 2424
110923SN/A/*
210923SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
310923SN/A * All rights reserved.
410923SN/A *
510923SN/A * Redistribution and use in source and binary forms, with or without
610923SN/A * modification, are permitted provided that the following conditions are
710923SN/A * met: redistributions of source code must retain the above copyright
810923SN/A * notice, this list of conditions and the following disclaimer;
910923SN/A * redistributions in binary form must reproduce the above copyright
1010923SN/A * notice, this list of conditions and the following disclaimer in the
1110923SN/A * documentation and/or other materials provided with the distribution;
1210923SN/A * neither the name of the copyright holders nor the names of its
1310923SN/A * contributors may be used to endorse or promote products derived from
1410923SN/A * this software without specific prior written permission.
1510923SN/A *
1610923SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710923SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810923SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910923SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010923SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110923SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210923SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310923SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410923SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510923SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610923SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710923SN/A */
2810923SN/A
2910923SN/A#ifndef __SYSTEM_HH__
3010923SN/A#define __SYSTEM_HH__
3110923SN/A
3210923SN/A#include <string>
3310923SN/A#include <vector>
3410923SN/A
3510923SN/A#include "base/statistics.hh"
3610923SN/A#include "base/loader/symtab.hh"
3710923SN/A#include "cpu/pc_event.hh"
3811290Sgabor.dozsa@arm.com#include "sim/sim_object.hh"
3910923SN/A#if FULL_SYSTEM
4010923SN/A#include "kern/system_events.hh"
4110923SN/A#endif
4211290Sgabor.dozsa@arm.com
4310923SN/Aclass BaseCPU;
4410923SN/Aclass ExecContext;
4511263Sandreas.sandberg@arm.comclass MemoryController;
4610923SN/Aclass ObjectFile;
4710923SN/Aclass Memory;
4810923SN/A
4911290Sgabor.dozsa@arm.com#if FULL_SYSTEM
5010923SN/Aclass Platform;
5110923SN/Aclass GDBListener;
5210923SN/Aclass RemoteGDB;
5310923SN/Anamespace Kernel { class Binning; }
5410923SN/A#endif
5510923SN/A
5611290Sgabor.dozsa@arm.comclass System : public SimObject
5710923SN/A{
5810923SN/A  public:
5911290Sgabor.dozsa@arm.com    Memory *physmem;
6011290Sgabor.dozsa@arm.com    PCEventQueue pcEventQueue;
6111290Sgabor.dozsa@arm.com
6211290Sgabor.dozsa@arm.com    std::vector<ExecContext *> execContexts;
6311290Sgabor.dozsa@arm.com    int numcpus;
6411290Sgabor.dozsa@arm.com
6511290Sgabor.dozsa@arm.com    int getNumCPUs()
6611290Sgabor.dozsa@arm.com    {
6710923SN/A        if (numcpus != execContexts.size())
6810923SN/A            panic("cpu array not fully populated!");
6910923SN/A
7010923SN/A        return numcpus;
7110923SN/A    }
7210923SN/A
7310923SN/A#if FULL_SYSTEM
7410923SN/A    MemoryController *memctrl;
7510923SN/A    Platform *platform;
7610923SN/A    uint64_t init_param;
7711290Sgabor.dozsa@arm.com
7810923SN/A    /** kernel symbol table */
7911290Sgabor.dozsa@arm.com    SymbolTable *kernelSymtab;
8011290Sgabor.dozsa@arm.com
8110923SN/A    /** Object pointer for the kernel code */
8210923SN/A    ObjectFile *kernel;
8311290Sgabor.dozsa@arm.com
8411290Sgabor.dozsa@arm.com    /** Begining of kernel code */
8511703Smichael.lebeane@amd.com    Addr kernelStart;
8611703Smichael.lebeane@amd.com
8711703Smichael.lebeane@amd.com    /** End of kernel code */
8811290Sgabor.dozsa@arm.com    Addr kernelEnd;
8911290Sgabor.dozsa@arm.com
9011290Sgabor.dozsa@arm.com    /** Entry point in the kernel to start at */
9111290Sgabor.dozsa@arm.com    Addr kernelEntry;
9211290Sgabor.dozsa@arm.com
9311290Sgabor.dozsa@arm.com    Kernel::Binning *kernelBinning;
9411290Sgabor.dozsa@arm.com
9511290Sgabor.dozsa@arm.com#else
9611290Sgabor.dozsa@arm.com
9711290Sgabor.dozsa@arm.com    int page_ptr;
9811290Sgabor.dozsa@arm.com
9911290Sgabor.dozsa@arm.com
10011290Sgabor.dozsa@arm.com#endif // FULL_SYSTEM
10111290Sgabor.dozsa@arm.com
10211290Sgabor.dozsa@arm.com  protected:
10311290Sgabor.dozsa@arm.com
10411290Sgabor.dozsa@arm.com#if FULL_SYSTEM
10511290Sgabor.dozsa@arm.com    /**
10611290Sgabor.dozsa@arm.com     * Fix up an address used to match PCs for hooking simulator
10711290Sgabor.dozsa@arm.com     * events on to target function executions.  See comment in
10811290Sgabor.dozsa@arm.com     * system.cc for details.
10911290Sgabor.dozsa@arm.com     */
11011290Sgabor.dozsa@arm.com    virtual Addr fixFuncEventAddr(Addr addr) = 0;
11111290Sgabor.dozsa@arm.com
11211290Sgabor.dozsa@arm.com    /**
11311290Sgabor.dozsa@arm.com     * Add a function-based event to the given function, to be looked
11411290Sgabor.dozsa@arm.com     * up in the specified symbol table.
11511290Sgabor.dozsa@arm.com     */
11611290Sgabor.dozsa@arm.com    template <class T>
11711290Sgabor.dozsa@arm.com    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
11811290Sgabor.dozsa@arm.com    {
11911290Sgabor.dozsa@arm.com        Addr addr = 0; // initialize only to avoid compiler warning
12011290Sgabor.dozsa@arm.com
12111290Sgabor.dozsa@arm.com        if (symtab->findAddress(lbl, addr)) {
12211290Sgabor.dozsa@arm.com            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
12311290Sgabor.dozsa@arm.com            return ev;
12411290Sgabor.dozsa@arm.com        }
12511290Sgabor.dozsa@arm.com
12611290Sgabor.dozsa@arm.com        return NULL;
12711290Sgabor.dozsa@arm.com    }
12811290Sgabor.dozsa@arm.com
12911290Sgabor.dozsa@arm.com    /** Add a function-based event to kernel code. */
13011290Sgabor.dozsa@arm.com    template <class T>
13111290Sgabor.dozsa@arm.com    T *System::addKernelFuncEvent(const char *lbl)
13211290Sgabor.dozsa@arm.com    {
13311290Sgabor.dozsa@arm.com        return addFuncEvent<T>(kernelSymtab, lbl);
13411290Sgabor.dozsa@arm.com    }
13511290Sgabor.dozsa@arm.com
13611290Sgabor.dozsa@arm.com#endif
13711290Sgabor.dozsa@arm.com  public:
13811290Sgabor.dozsa@arm.com#if FULL_SYSTEM
13911290Sgabor.dozsa@arm.com    std::vector<RemoteGDB *> remoteGDB;
14011290Sgabor.dozsa@arm.com    std::vector<GDBListener *> gdbListen;
14111290Sgabor.dozsa@arm.com    virtual bool breakpoint() = 0;
14211290Sgabor.dozsa@arm.com#endif // FULL_SYSTEM
14311290Sgabor.dozsa@arm.com
14411290Sgabor.dozsa@arm.com  public:
14511290Sgabor.dozsa@arm.com    struct Params
14611290Sgabor.dozsa@arm.com    {
14711290Sgabor.dozsa@arm.com        std::string name;
14811290Sgabor.dozsa@arm.com        Memory *physmem;
14911290Sgabor.dozsa@arm.com
15011290Sgabor.dozsa@arm.com#if FULL_SYSTEM
15111290Sgabor.dozsa@arm.com        Tick boot_cpu_frequency;
15211290Sgabor.dozsa@arm.com        MemoryController *memctrl;
15311290Sgabor.dozsa@arm.com        uint64_t init_param;
15411290Sgabor.dozsa@arm.com        bool bin;
15511290Sgabor.dozsa@arm.com        std::vector<std::string> binned_fns;
15611290Sgabor.dozsa@arm.com        bool bin_int;
15711290Sgabor.dozsa@arm.com
15811290Sgabor.dozsa@arm.com        std::string kernel_path;
15911290Sgabor.dozsa@arm.com        std::string readfile;
16011290Sgabor.dozsa@arm.com#endif
16111290Sgabor.dozsa@arm.com    };
16211290Sgabor.dozsa@arm.com
16311290Sgabor.dozsa@arm.com  protected:
16411290Sgabor.dozsa@arm.com    Params *_params;
16511290Sgabor.dozsa@arm.com
16611290Sgabor.dozsa@arm.com  public:
16711290Sgabor.dozsa@arm.com    System(Params *p);
16811290Sgabor.dozsa@arm.com    ~System();
16911290Sgabor.dozsa@arm.com
17011290Sgabor.dozsa@arm.com    void startup();
17111290Sgabor.dozsa@arm.com
17211290Sgabor.dozsa@arm.com    const Params *params() const { return (const Params *)_params; }
17311290Sgabor.dozsa@arm.com
17411290Sgabor.dozsa@arm.com  public:
17511290Sgabor.dozsa@arm.com
17611290Sgabor.dozsa@arm.com#if FULL_SYSTEM
17711290Sgabor.dozsa@arm.com    /**
17811290Sgabor.dozsa@arm.com     * Returns the addess the kernel starts at.
17911290Sgabor.dozsa@arm.com     * @return address the kernel starts at
18011290Sgabor.dozsa@arm.com     */
18111290Sgabor.dozsa@arm.com    Addr getKernelStart() const { return kernelStart; }
18211290Sgabor.dozsa@arm.com
18311290Sgabor.dozsa@arm.com    /**
18411290Sgabor.dozsa@arm.com     * Returns the addess the kernel ends at.
18511290Sgabor.dozsa@arm.com     * @return address the kernel ends at
18611290Sgabor.dozsa@arm.com     */
18711290Sgabor.dozsa@arm.com    Addr getKernelEnd() const { return kernelEnd; }
18811290Sgabor.dozsa@arm.com
18911290Sgabor.dozsa@arm.com    /**
19011290Sgabor.dozsa@arm.com     * Returns the addess the entry point to the kernel code.
19111290Sgabor.dozsa@arm.com     * @return entry point of the kernel code
19211290Sgabor.dozsa@arm.com     */
19311290Sgabor.dozsa@arm.com    Addr getKernelEntry() const { return kernelEntry; }
19411290Sgabor.dozsa@arm.com
19511290Sgabor.dozsa@arm.com#else
19611290Sgabor.dozsa@arm.com
19711290Sgabor.dozsa@arm.com    Addr new_page();
19811290Sgabor.dozsa@arm.com
19911290Sgabor.dozsa@arm.com#endif // FULL_SYSTEM
20011290Sgabor.dozsa@arm.com
20111290Sgabor.dozsa@arm.com    int registerExecContext(ExecContext *xc, int xcIndex);
20211290Sgabor.dozsa@arm.com    void replaceExecContext(ExecContext *xc, int xcIndex);
20311290Sgabor.dozsa@arm.com
20411290Sgabor.dozsa@arm.com    void regStats();
20511290Sgabor.dozsa@arm.com    void serialize(std::ostream &os);
20611290Sgabor.dozsa@arm.com    void unserialize(Checkpoint *cp, const std::string &section);
20711290Sgabor.dozsa@arm.com
20811290Sgabor.dozsa@arm.com  public:
20911290Sgabor.dozsa@arm.com    ////////////////////////////////////////////
21011290Sgabor.dozsa@arm.com    //
21111290Sgabor.dozsa@arm.com    // STATIC GLOBAL SYSTEM LIST
21211290Sgabor.dozsa@arm.com    //
21311290Sgabor.dozsa@arm.com    ////////////////////////////////////////////
21411290Sgabor.dozsa@arm.com
21511290Sgabor.dozsa@arm.com    static std::vector<System *> systemList;
21611290Sgabor.dozsa@arm.com    static int numSystemsRunning;
21711290Sgabor.dozsa@arm.com
21811290Sgabor.dozsa@arm.com    static void printSystems();
21911290Sgabor.dozsa@arm.com
22011290Sgabor.dozsa@arm.com
22111290Sgabor.dozsa@arm.com};
22211290Sgabor.dozsa@arm.com
22310923SN/A#endif // __SYSTEM_HH__
22410923SN/A