system.hh revision 4762:c94e103c83ad
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 * Authors: Steve Reinhardt
29 *          Lisa Hsu
30 *          Nathan Binkert
31 */
32
33#ifndef __SYSTEM_HH__
34#define __SYSTEM_HH__
35
36#include <string>
37#include <vector>
38
39#include "base/loader/symtab.hh"
40#include "base/misc.hh"
41#include "base/statistics.hh"
42#include "config/full_system.hh"
43#include "cpu/pc_event.hh"
44#include "enums/MemoryMode.hh"
45#include "mem/port.hh"
46#include "params/System.hh"
47#include "sim/sim_object.hh"
48#if FULL_SYSTEM
49#include "kern/system_events.hh"
50#include "mem/vport.hh"
51#endif
52
53class BaseCPU;
54class ThreadContext;
55class ObjectFile;
56class PhysicalMemory;
57
58#if FULL_SYSTEM
59class Platform;
60#endif
61class GDBListener;
62namespace TheISA
63{
64    class RemoteGDB;
65}
66
67class System : public SimObject
68{
69  public:
70
71    static const char *MemoryModeStrings[3];
72
73    Enums::MemoryMode
74    getMemoryMode()
75    {
76        assert(memoryMode);
77        return memoryMode;
78    }
79
80    /** Change the memory mode of the system. This should only be called by the
81     * python!!
82     * @param mode Mode to change to (atomic/timing)
83     */
84    void setMemoryMode(Enums::MemoryMode mode);
85
86    PhysicalMemory *physmem;
87    PCEventQueue pcEventQueue;
88
89    std::vector<ThreadContext *> threadContexts;
90    int numcpus;
91
92    int getNumCPUs()
93    {
94        if (numcpus != threadContexts.size())
95            panic("cpu array not fully populated!");
96
97        return numcpus;
98    }
99
100#if FULL_SYSTEM
101    Platform *platform;
102    uint64_t init_param;
103
104    /** Port to physical memory used for writing object files into ram at
105     * boot.*/
106    FunctionalPort functionalPort;
107    VirtualPort virtPort;
108
109    /** kernel symbol table */
110    SymbolTable *kernelSymtab;
111
112    /** Object pointer for the kernel code */
113    ObjectFile *kernel;
114
115    /** Begining of kernel code */
116    Addr kernelStart;
117
118    /** End of kernel code */
119    Addr kernelEnd;
120
121    /** Entry point in the kernel to start at */
122    Addr kernelEntry;
123
124#else
125
126    int page_ptr;
127
128
129#endif // FULL_SYSTEM
130
131  protected:
132    Enums::MemoryMode memoryMode;
133
134#if FULL_SYSTEM
135    /**
136     * Fix up an address used to match PCs for hooking simulator
137     * events on to target function executions.  See comment in
138     * system.cc for details.
139     */
140    virtual Addr fixFuncEventAddr(Addr addr) = 0;
141
142    /**
143     * Add a function-based event to the given function, to be looked
144     * up in the specified symbol table.
145     */
146    template <class T>
147    T *addFuncEvent(SymbolTable *symtab, const char *lbl)
148    {
149        Addr addr = 0; // initialize only to avoid compiler warning
150
151        if (symtab->findAddress(lbl, addr)) {
152            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
153            return ev;
154        }
155
156        return NULL;
157    }
158
159    /** Add a function-based event to kernel code. */
160    template <class T>
161    T *addKernelFuncEvent(const char *lbl)
162    {
163        return addFuncEvent<T>(kernelSymtab, lbl);
164    }
165
166#endif
167  public:
168    std::vector<TheISA::RemoteGDB *> remoteGDB;
169    std::vector<GDBListener *> gdbListen;
170    bool breakpoint();
171
172  public:
173    typedef SystemParams Params;
174
175  protected:
176    Params *_params;
177
178  public:
179    System(Params *p);
180    ~System();
181
182    void startup();
183
184    const Params *params() const { return (const Params *)_params; }
185
186  public:
187
188#if FULL_SYSTEM
189    /**
190     * Returns the addess the kernel starts at.
191     * @return address the kernel starts at
192     */
193    Addr getKernelStart() const { return kernelStart; }
194
195    /**
196     * Returns the addess the kernel ends at.
197     * @return address the kernel ends at
198     */
199    Addr getKernelEnd() const { return kernelEnd; }
200
201    /**
202     * Returns the addess the entry point to the kernel code.
203     * @return entry point of the kernel code
204     */
205    Addr getKernelEntry() const { return kernelEntry; }
206
207#else
208
209    Addr new_page();
210
211#endif // FULL_SYSTEM
212
213    int registerThreadContext(ThreadContext *tc, int tcIndex);
214    void replaceThreadContext(ThreadContext *tc, int tcIndex);
215
216    void serialize(std::ostream &os);
217    void unserialize(Checkpoint *cp, const std::string &section);
218
219  public:
220    ////////////////////////////////////////////
221    //
222    // STATIC GLOBAL SYSTEM LIST
223    //
224    ////////////////////////////////////////////
225
226    static std::vector<System *> systemList;
227    static int numSystemsRunning;
228
229    static void printSystems();
230
231
232};
233
234#endif // __SYSTEM_HH__
235