system.hh revision 2439
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>
3313201Sgabeblack@google.com#include <vector>
3413201Sgabeblack@google.com
3512841Sgabeblack@google.com#include "base/loader/symtab.hh"
3612841Sgabeblack@google.com#include "base/misc.hh"
3712841Sgabeblack@google.com#include "base/statistics.hh"
3812841Sgabeblack@google.com#include "cpu/pc_event.hh"
3912841Sgabeblack@google.com#include "sim/sim_object.hh"
4012841Sgabeblack@google.com#if FULL_SYSTEM
4112841Sgabeblack@google.com#include "kern/system_events.hh"
4212841Sgabeblack@google.com#endif
4312841Sgabeblack@google.com
4412841Sgabeblack@google.comclass BaseCPU;
4513201Sgabeblack@google.comclass ExecContext;
4613201Sgabeblack@google.comclass MemoryController;
4713201Sgabeblack@google.comclass ObjectFile;
4813201Sgabeblack@google.comclass Memory;
4913201Sgabeblack@google.com
5013201Sgabeblack@google.com#if FULL_SYSTEM
5113201Sgabeblack@google.comclass Platform;
5212841Sgabeblack@google.comclass GDBListener;
5312841Sgabeblack@google.comclass RemoteGDB;
5412841Sgabeblack@google.comnamespace Kernel { class Binning; }
5512841Sgabeblack@google.com#endif
5612841Sgabeblack@google.com
5712841Sgabeblack@google.comclass System : public SimObject
5812841Sgabeblack@google.com{
5912841Sgabeblack@google.com  public:
6012841Sgabeblack@google.com    Memory *physmem;
6112841Sgabeblack@google.com    PCEventQueue pcEventQueue;
6212841Sgabeblack@google.com
6312841Sgabeblack@google.com    std::vector<ExecContext *> execContexts;
6412841Sgabeblack@google.com    int numcpus;
6512841Sgabeblack@google.com
6612841Sgabeblack@google.com    int getNumCPUs()
6712841Sgabeblack@google.com    {
6812841Sgabeblack@google.com        if (numcpus != execContexts.size())
6912841Sgabeblack@google.com            panic("cpu array not fully populated!");
7013201Sgabeblack@google.com
7112841Sgabeblack@google.com        return numcpus;
7212841Sgabeblack@google.com    }
7312841Sgabeblack@google.com
7412841Sgabeblack@google.com#if FULL_SYSTEM
7512841Sgabeblack@google.com    MemoryController *memctrl;
7612841Sgabeblack@google.com    Platform *platform;
7712841Sgabeblack@google.com    uint64_t init_param;
7812841Sgabeblack@google.com
7912841Sgabeblack@google.com    /** kernel symbol table */
8013201Sgabeblack@google.com    SymbolTable *kernelSymtab;
8113201Sgabeblack@google.com
8212841Sgabeblack@google.com    /** Object pointer for the kernel code */
8312841Sgabeblack@google.com    ObjectFile *kernel;
8412841Sgabeblack@google.com
8512841Sgabeblack@google.com    /** Begining of kernel code */
8612841Sgabeblack@google.com    Addr kernelStart;
87
88    /** End of kernel code */
89    Addr kernelEnd;
90
91    /** Entry point in the kernel to start at */
92    Addr kernelEntry;
93
94    Kernel::Binning *kernelBinning;
95
96#else
97
98    int page_ptr;
99
100
101#endif // FULL_SYSTEM
102
103  protected:
104
105#if FULL_SYSTEM
106    /**
107     * Fix up an address used to match PCs for hooking simulator
108     * events on to target function executions.  See comment in
109     * system.cc for details.
110     */
111    virtual Addr fixFuncEventAddr(Addr addr) = 0;
112
113    /**
114     * Add a function-based event to the given function, to be looked
115     * up in the specified symbol table.
116     */
117    template <class T>
118    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
119    {
120        Addr addr = 0; // initialize only to avoid compiler warning
121
122        if (symtab->findAddress(lbl, addr)) {
123            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
124            return ev;
125        }
126
127        return NULL;
128    }
129
130    /** Add a function-based event to kernel code. */
131    template <class T>
132    T *System::addKernelFuncEvent(const char *lbl)
133    {
134        return addFuncEvent<T>(kernelSymtab, lbl);
135    }
136
137#endif
138  public:
139#if FULL_SYSTEM
140    std::vector<RemoteGDB *> remoteGDB;
141    std::vector<GDBListener *> gdbListen;
142    virtual bool breakpoint() = 0;
143#endif // FULL_SYSTEM
144
145  public:
146    struct Params
147    {
148        std::string name;
149        Memory *physmem;
150
151#if FULL_SYSTEM
152        Tick boot_cpu_frequency;
153        MemoryController *memctrl;
154        uint64_t init_param;
155        bool bin;
156        std::vector<std::string> binned_fns;
157        bool bin_int;
158
159        std::string kernel_path;
160        std::string readfile;
161#endif
162    };
163
164  protected:
165    Params *_params;
166
167  public:
168    System(Params *p);
169    ~System();
170
171    void startup();
172
173    const Params *params() const { return (const Params *)_params; }
174
175  public:
176
177#if FULL_SYSTEM
178    /**
179     * Returns the addess the kernel starts at.
180     * @return address the kernel starts at
181     */
182    Addr getKernelStart() const { return kernelStart; }
183
184    /**
185     * Returns the addess the kernel ends at.
186     * @return address the kernel ends at
187     */
188    Addr getKernelEnd() const { return kernelEnd; }
189
190    /**
191     * Returns the addess the entry point to the kernel code.
192     * @return entry point of the kernel code
193     */
194    Addr getKernelEntry() const { return kernelEntry; }
195
196#else
197
198    Addr new_page();
199
200#endif // FULL_SYSTEM
201
202    int registerExecContext(ExecContext *xc, int xcIndex);
203    void replaceExecContext(ExecContext *xc, int xcIndex);
204
205    void regStats();
206    void serialize(std::ostream &os);
207    void unserialize(Checkpoint *cp, const std::string &section);
208
209  public:
210    ////////////////////////////////////////////
211    //
212    // STATIC GLOBAL SYSTEM LIST
213    //
214    ////////////////////////////////////////////
215
216    static std::vector<System *> systemList;
217    static int numSystemsRunning;
218
219    static void printSystems();
220
221
222};
223
224#endif // __SYSTEM_HH__
225