system.hh revision 1885
112841Sgabeblack@google.com/*
212841Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
312841Sgabeblack@google.com * All rights reserved.
412841Sgabeblack@google.com *
512841Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612841Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712841Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912841Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112841Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212841Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312841Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412841Sgabeblack@google.com * this software without specific prior written permission.
1512841Sgabeblack@google.com *
1612841Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712841Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812841Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912841Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012841Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112841Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212841Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312841Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412841Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512841Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612841Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712841Sgabeblack@google.com */
2812841Sgabeblack@google.com
2912841Sgabeblack@google.com#ifndef __SYSTEM_HH__
3012841Sgabeblack@google.com#define __SYSTEM_HH__
3112841Sgabeblack@google.com
3212841Sgabeblack@google.com#include <string>
3312841Sgabeblack@google.com#include <vector>
3412841Sgabeblack@google.com
3513071Sgabeblack@google.com#include "base/statistics.hh"
3613269Sgabeblack@google.com#include "base/loader/symtab.hh"
3712841Sgabeblack@google.com#include "cpu/pc_event.hh"
3813071Sgabeblack@google.com#include "kern/system_events.hh"
3913245Sgabeblack@google.com#include "sim/sim_object.hh"
4012841Sgabeblack@google.com
4112841Sgabeblack@google.comclass BaseCPU;
4212841Sgabeblack@google.comclass ExecContext;
4312841Sgabeblack@google.comclass GDBListener;
4412841Sgabeblack@google.comclass MemoryController;
4512841Sgabeblack@google.comclass ObjectFile;
4612841Sgabeblack@google.comclass PhysicalMemory;
4712841Sgabeblack@google.comclass Platform;
4812841Sgabeblack@google.comclass RemoteGDB;
4912841Sgabeblack@google.comnamespace Kernel { class Binning; }
5012841Sgabeblack@google.com
5112841Sgabeblack@google.comclass System : public SimObject
5212841Sgabeblack@google.com{
5312841Sgabeblack@google.com  public:
5412841Sgabeblack@google.com    MemoryController *memctrl;
5512841Sgabeblack@google.com    PhysicalMemory *physmem;
5612841Sgabeblack@google.com    Platform *platform;
5712841Sgabeblack@google.com    PCEventQueue pcEventQueue;
5812841Sgabeblack@google.com    uint64_t init_param;
5913071Sgabeblack@google.com
6013071Sgabeblack@google.com    std::vector<ExecContext *> execContexts;
6113071Sgabeblack@google.com    int numcpus;
6212841Sgabeblack@google.com
6313071Sgabeblack@google.com    int getNumCPUs()
6413071Sgabeblack@google.com    {
6512841Sgabeblack@google.com        if (numcpus != execContexts.size())
6613071Sgabeblack@google.com            panic("cpu array not fully populated!");
6712841Sgabeblack@google.com
6812868Sgabeblack@google.com        return numcpus;
6912868Sgabeblack@google.com    }
7013071Sgabeblack@google.com
7113071Sgabeblack@google.com    /** kernel symbol table */
7212868Sgabeblack@google.com    SymbolTable *kernelSymtab;
7312868Sgabeblack@google.com
7413071Sgabeblack@google.com    /** console symbol table */
7513071Sgabeblack@google.com    SymbolTable *consoleSymtab;
7612868Sgabeblack@google.com
7712868Sgabeblack@google.com    /** pal symbol table */
7813071Sgabeblack@google.com    SymbolTable *palSymtab;
7913071Sgabeblack@google.com
8012868Sgabeblack@google.com    /** Object pointer for the kernel code */
8112868Sgabeblack@google.com    ObjectFile *kernel;
8213071Sgabeblack@google.com
8313071Sgabeblack@google.com    /** Object pointer for the console code */
8412868Sgabeblack@google.com    ObjectFile *console;
8512868Sgabeblack@google.com
8613071Sgabeblack@google.com    /** Object pointer for the PAL code */
8713071Sgabeblack@google.com    ObjectFile *pal;
8812868Sgabeblack@google.com
8912868Sgabeblack@google.com    /** Begining of kernel code */
9013071Sgabeblack@google.com    Addr kernelStart;
9113071Sgabeblack@google.com
9212868Sgabeblack@google.com    /** End of kernel code */
9312868Sgabeblack@google.com    Addr kernelEnd;
9412841Sgabeblack@google.com
9513071Sgabeblack@google.com    /** Entry point in the kernel to start at */
9612841Sgabeblack@google.com    Addr kernelEntry;
9713071Sgabeblack@google.com
9813071Sgabeblack@google.com    Kernel::Binning *kernelBinning;
9913071Sgabeblack@google.com
10013071Sgabeblack@google.com#ifdef DEBUG
10113071Sgabeblack@google.com    /** Event to halt the simulator if the console calls panic() */
10213071Sgabeblack@google.com    BreakPCEvent *consolePanicEvent;
10313071Sgabeblack@google.com#endif
10412841Sgabeblack@google.com
10513071Sgabeblack@google.com  protected:
10613071Sgabeblack@google.com
10713071Sgabeblack@google.com    /**
10813071Sgabeblack@google.com     * Fix up an address used to match PCs for hooking simulator
10912841Sgabeblack@google.com     * events on to target function executions.  See comment in
11013071Sgabeblack@google.com     * system.cc for details.
11113071Sgabeblack@google.com     */
11213071Sgabeblack@google.com    Addr fixFuncEventAddr(Addr addr);
11313071Sgabeblack@google.com
11413071Sgabeblack@google.com    /**
11513245Sgabeblack@google.com     * Add a function-based event to the given function, to be looked
11613245Sgabeblack@google.com     * up in the specified symbol table.
11713245Sgabeblack@google.com     */
11813245Sgabeblack@google.com    template <class T>
11913245Sgabeblack@google.com    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
12012841Sgabeblack@google.com    {
12112841Sgabeblack@google.com        Addr addr;
12213071Sgabeblack@google.com
12313071Sgabeblack@google.com        if (symtab->findAddress(lbl, addr)) {
12412841Sgabeblack@google.com            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
12513071Sgabeblack@google.com            return ev;
12613071Sgabeblack@google.com        }
12713071Sgabeblack@google.com
12812841Sgabeblack@google.com        return NULL;
12913071Sgabeblack@google.com    }
13013071Sgabeblack@google.com
13112841Sgabeblack@google.com    /** Add a function-based event to kernel code. */
13213071Sgabeblack@google.com    template <class T>
13313071Sgabeblack@google.com    T *System::addKernelFuncEvent(const char *lbl)
13412841Sgabeblack@google.com    {
13513071Sgabeblack@google.com        return addFuncEvent<T>(kernelSymtab, lbl);
13613071Sgabeblack@google.com    }
13713071Sgabeblack@google.com
13813071Sgabeblack@google.com    /** Add a function-based event to PALcode. */
13913071Sgabeblack@google.com    template <class T>
14013071Sgabeblack@google.com    T *System::addPalFuncEvent(const char *lbl)
14113071Sgabeblack@google.com    {
14213071Sgabeblack@google.com        return addFuncEvent<T>(palSymtab, lbl);
14313071Sgabeblack@google.com    }
14413071Sgabeblack@google.com
14513071Sgabeblack@google.com    /** Add a function-based event to the console code. */
14613071Sgabeblack@google.com    template <class T>
14713071Sgabeblack@google.com    T *System::addConsoleFuncEvent(const char *lbl)
14813071Sgabeblack@google.com    {
14913071Sgabeblack@google.com        return addFuncEvent<T>(consoleSymtab, lbl);
15013071Sgabeblack@google.com    }
15113071Sgabeblack@google.com
15213071Sgabeblack@google.com  public:
15313071Sgabeblack@google.com    std::vector<RemoteGDB *> remoteGDB;
15413071Sgabeblack@google.com    std::vector<GDBListener *> gdbListen;
15512841Sgabeblack@google.com    bool breakpoint();
15612841Sgabeblack@google.com
15713071Sgabeblack@google.com  public:
15812841Sgabeblack@google.com    struct Params
15912841Sgabeblack@google.com    {
16012841Sgabeblack@google.com        std::string name;
16113071Sgabeblack@google.com        Tick boot_cpu_frequency;
16212841Sgabeblack@google.com        MemoryController *memctrl;
16313071Sgabeblack@google.com        PhysicalMemory *physmem;
16413071Sgabeblack@google.com        uint64_t init_param;
16512841Sgabeblack@google.com        bool bin;
16612841Sgabeblack@google.com        std::vector<std::string> binned_fns;
16712841Sgabeblack@google.com        bool bin_int;
16813245Sgabeblack@google.com
16913245Sgabeblack@google.com        std::string kernel_path;
17013245Sgabeblack@google.com        std::string console_path;
17113245Sgabeblack@google.com        std::string palcode;
17213245Sgabeblack@google.com        std::string boot_osflags;
17313245Sgabeblack@google.com
17412841Sgabeblack@google.com        std::string readfile;
17513071Sgabeblack@google.com        uint64_t system_type;
17613071Sgabeblack@google.com        uint64_t system_rev;
17713071Sgabeblack@google.com    };
17813245Sgabeblack@google.com    Params *params;
17913245Sgabeblack@google.com
18012841Sgabeblack@google.com    System(Params *p);
18113071Sgabeblack@google.com    ~System();
18212841Sgabeblack@google.com
18312841Sgabeblack@google.com    void startup();
18412841Sgabeblack@google.com
18512841Sgabeblack@google.com  public:
18613245Sgabeblack@google.com    /**
18712841Sgabeblack@google.com     * Set the m5AlphaAccess pointer in the console
18813269Sgabeblack@google.com     */
18913269Sgabeblack@google.com    void setAlphaAccess(Addr access);
19013269Sgabeblack@google.com
19113245Sgabeblack@google.com    /**
19212841Sgabeblack@google.com     * Returns the addess the kernel starts at.
19312841Sgabeblack@google.com     * @return address the kernel starts at
19412841Sgabeblack@google.com     */
19512841Sgabeblack@google.com    Addr getKernelStart() const { return kernelStart; }
19612841Sgabeblack@google.com
19712841Sgabeblack@google.com    /**
19813071Sgabeblack@google.com     * Returns the addess the kernel ends at.
19913071Sgabeblack@google.com     * @return address the kernel ends at
20013071Sgabeblack@google.com     */
20113071Sgabeblack@google.com    Addr getKernelEnd() const { return kernelEnd; }
20213071Sgabeblack@google.com
20313071Sgabeblack@google.com    /**
20412841Sgabeblack@google.com     * Returns the addess the entry point to the kernel code.
20513071Sgabeblack@google.com     * @return entry point of the kernel code
20613071Sgabeblack@google.com     */
20713071Sgabeblack@google.com    Addr getKernelEntry() const { return kernelEntry; }
20813071Sgabeblack@google.com
20913071Sgabeblack@google.com    int registerExecContext(ExecContext *xc, int xcIndex);
21012841Sgabeblack@google.com    void replaceExecContext(ExecContext *xc, int xcIndex);
21113071Sgabeblack@google.com
21212841Sgabeblack@google.com    void regStats();
21312868Sgabeblack@google.com    void serialize(std::ostream &os);
21412868Sgabeblack@google.com    void unserialize(Checkpoint *cp, const std::string &section);
21513071Sgabeblack@google.com
21613071Sgabeblack@google.com  public:
21713071Sgabeblack@google.com    ////////////////////////////////////////////
21813071Sgabeblack@google.com    //
21913071Sgabeblack@google.com    // STATIC GLOBAL SYSTEM LIST
22012868Sgabeblack@google.com    //
22112868Sgabeblack@google.com    ////////////////////////////////////////////
22213071Sgabeblack@google.com
22313071Sgabeblack@google.com    static std::vector<System *> systemList;
22413071Sgabeblack@google.com    static int numSystemsRunning;
22513071Sgabeblack@google.com
22613071Sgabeblack@google.com    static void printSystems();
22713071Sgabeblack@google.com};
22812868Sgabeblack@google.com
22912868Sgabeblack@google.com#endif // __SYSTEM_HH__
23013071Sgabeblack@google.com