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