system.hh revision 2439
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __SYSTEM_HH__
30#define __SYSTEM_HH__
31
32#include <string>
33#include <vector>
34
35#include "base/loader/symtab.hh"
36#include "base/misc.hh"
37#include "base/statistics.hh"
38#include "cpu/pc_event.hh"
39#include "sim/sim_object.hh"
40#if FULL_SYSTEM
41#include "kern/system_events.hh"
42#endif
43
44class BaseCPU;
45class ExecContext;
46class MemoryController;
47class ObjectFile;
48class Memory;
49
50#if FULL_SYSTEM
51class Platform;
52class GDBListener;
53class RemoteGDB;
54namespace Kernel { class Binning; }
55#endif
56
57class System : public SimObject
58{
59  public:
60    Memory *physmem;
61    PCEventQueue pcEventQueue;
62
63    std::vector<ExecContext *> execContexts;
64    int numcpus;
65
66    int getNumCPUs()
67    {
68        if (numcpus != execContexts.size())
69            panic("cpu array not fully populated!");
70
71        return numcpus;
72    }
73
74#if FULL_SYSTEM
75    MemoryController *memctrl;
76    Platform *platform;
77    uint64_t init_param;
78
79    /** kernel symbol table */
80    SymbolTable *kernelSymtab;
81
82    /** Object pointer for the kernel code */
83    ObjectFile *kernel;
84
85    /** Begining of kernel code */
86    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