system.hh revision 2424
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/statistics.hh"
36#include "base/loader/symtab.hh"
37#include "cpu/pc_event.hh"
38#include "sim/sim_object.hh"
39#if FULL_SYSTEM
40#include "kern/system_events.hh"
41#endif
42
43class BaseCPU;
44class ExecContext;
45class MemoryController;
46class ObjectFile;
47class Memory;
48
49#if FULL_SYSTEM
50class Platform;
51class GDBListener;
52class RemoteGDB;
53namespace Kernel { class Binning; }
54#endif
55
56class System : public SimObject
57{
58  public:
59    Memory *physmem;
60    PCEventQueue pcEventQueue;
61
62    std::vector<ExecContext *> execContexts;
63    int numcpus;
64
65    int getNumCPUs()
66    {
67        if (numcpus != execContexts.size())
68            panic("cpu array not fully populated!");
69
70        return numcpus;
71    }
72
73#if FULL_SYSTEM
74    MemoryController *memctrl;
75    Platform *platform;
76    uint64_t init_param;
77
78    /** kernel symbol table */
79    SymbolTable *kernelSymtab;
80
81    /** Object pointer for the kernel code */
82    ObjectFile *kernel;
83
84    /** Begining of kernel code */
85    Addr kernelStart;
86
87    /** End of kernel code */
88    Addr kernelEnd;
89
90    /** Entry point in the kernel to start at */
91    Addr kernelEntry;
92
93    Kernel::Binning *kernelBinning;
94
95#else
96
97    int page_ptr;
98
99
100#endif // FULL_SYSTEM
101
102  protected:
103
104#if FULL_SYSTEM
105    /**
106     * Fix up an address used to match PCs for hooking simulator
107     * events on to target function executions.  See comment in
108     * system.cc for details.
109     */
110    virtual Addr fixFuncEventAddr(Addr addr) = 0;
111
112    /**
113     * Add a function-based event to the given function, to be looked
114     * up in the specified symbol table.
115     */
116    template <class T>
117    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
118    {
119        Addr addr = 0; // initialize only to avoid compiler warning
120
121        if (symtab->findAddress(lbl, addr)) {
122            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
123            return ev;
124        }
125
126        return NULL;
127    }
128
129    /** Add a function-based event to kernel code. */
130    template <class T>
131    T *System::addKernelFuncEvent(const char *lbl)
132    {
133        return addFuncEvent<T>(kernelSymtab, lbl);
134    }
135
136#endif
137  public:
138#if FULL_SYSTEM
139    std::vector<RemoteGDB *> remoteGDB;
140    std::vector<GDBListener *> gdbListen;
141    virtual bool breakpoint() = 0;
142#endif // FULL_SYSTEM
143
144  public:
145    struct Params
146    {
147        std::string name;
148        Memory *physmem;
149
150#if FULL_SYSTEM
151        Tick boot_cpu_frequency;
152        MemoryController *memctrl;
153        uint64_t init_param;
154        bool bin;
155        std::vector<std::string> binned_fns;
156        bool bin_int;
157
158        std::string kernel_path;
159        std::string readfile;
160#endif
161    };
162
163  protected:
164    Params *_params;
165
166  public:
167    System(Params *p);
168    ~System();
169
170    void startup();
171
172    const Params *params() const { return (const Params *)_params; }
173
174  public:
175
176#if FULL_SYSTEM
177    /**
178     * Returns the addess the kernel starts at.
179     * @return address the kernel starts at
180     */
181    Addr getKernelStart() const { return kernelStart; }
182
183    /**
184     * Returns the addess the kernel ends at.
185     * @return address the kernel ends at
186     */
187    Addr getKernelEnd() const { return kernelEnd; }
188
189    /**
190     * Returns the addess the entry point to the kernel code.
191     * @return entry point of the kernel code
192     */
193    Addr getKernelEntry() const { return kernelEntry; }
194
195#else
196
197    Addr new_page();
198
199#endif // FULL_SYSTEM
200
201    int registerExecContext(ExecContext *xc, int xcIndex);
202    void replaceExecContext(ExecContext *xc, int xcIndex);
203
204    void regStats();
205    void serialize(std::ostream &os);
206    void unserialize(Checkpoint *cp, const std::string &section);
207
208  public:
209    ////////////////////////////////////////////
210    //
211    // STATIC GLOBAL SYSTEM LIST
212    //
213    ////////////////////////////////////////////
214
215    static std::vector<System *> systemList;
216    static int numSystemsRunning;
217
218    static void printSystems();
219
220
221};
222
223#endif // __SYSTEM_HH__
224