system.hh revision 1913
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 2002-2005 The Regents of The University of Michigan
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org#ifndef __SYSTEM_HH__
306145Snate@binkert.org#define __SYSTEM_HH__
316145Snate@binkert.org
326145Snate@binkert.org#include <string>
336145Snate@binkert.org#include <vector>
346145Snate@binkert.org
356145Snate@binkert.org#include "base/statistics.hh"
366145Snate@binkert.org#include "base/loader/symtab.hh"
376145Snate@binkert.org#include "cpu/pc_event.hh"
386145Snate@binkert.org#include "kern/system_events.hh"
396145Snate@binkert.org#include "sim/sim_object.hh"
406145Snate@binkert.org
416145Snate@binkert.orgclass BaseCPU;
426145Snate@binkert.orgclass ExecContext;
436145Snate@binkert.orgclass GDBListener;
446145Snate@binkert.orgclass MemoryController;
456145Snate@binkert.orgclass ObjectFile;
466145Snate@binkert.orgclass PhysicalMemory;
476145Snate@binkert.orgclass Platform;
486145Snate@binkert.orgclass RemoteGDB;
496145Snate@binkert.orgnamespace Kernel { class Binning; }
506145Snate@binkert.org
516145Snate@binkert.orgclass System : public SimObject
526145Snate@binkert.org{
536145Snate@binkert.org  public:
546145Snate@binkert.org    MemoryController *memctrl;
556145Snate@binkert.org    PhysicalMemory *physmem;
566145Snate@binkert.org    Platform *platform;
576145Snate@binkert.org    PCEventQueue pcEventQueue;
586145Snate@binkert.org    uint64_t init_param;
596145Snate@binkert.org
606145Snate@binkert.org    std::vector<ExecContext *> execContexts;
616145Snate@binkert.org    int numcpus;
626145Snate@binkert.org
636145Snate@binkert.org    int getNumCPUs()
646145Snate@binkert.org    {
656145Snate@binkert.org        if (numcpus != execContexts.size())
666145Snate@binkert.org            panic("cpu array not fully populated!");
676145Snate@binkert.org
686145Snate@binkert.org        return numcpus;
69    }
70
71    /** kernel symbol table */
72    SymbolTable *kernelSymtab;
73
74    /** console symbol table */
75    SymbolTable *consoleSymtab;
76
77    /** pal symbol table */
78    SymbolTable *palSymtab;
79
80    /** Object pointer for the kernel code */
81    ObjectFile *kernel;
82
83    /** Object pointer for the console code */
84    ObjectFile *console;
85
86    /** Object pointer for the PAL code */
87    ObjectFile *pal;
88
89    /** Begining of kernel code */
90    Addr kernelStart;
91
92    /** End of kernel code */
93    Addr kernelEnd;
94
95    /** Entry point in the kernel to start at */
96    Addr kernelEntry;
97
98    Kernel::Binning *kernelBinning;
99
100#ifdef DEBUG
101    /** Event to halt the simulator if the console calls panic() */
102    BreakPCEvent *consolePanicEvent;
103#endif
104
105  protected:
106
107    /**
108     * Fix up an address used to match PCs for hooking simulator
109     * events on to target function executions.  See comment in
110     * system.cc for details.
111     */
112    Addr fixFuncEventAddr(Addr addr);
113
114    /**
115     * Add a function-based event to the given function, to be looked
116     * up in the specified symbol table.
117     */
118    template <class T>
119    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
120    {
121        Addr addr = 0; // initialize only to avoid compiler warning
122
123        if (symtab->findAddress(lbl, addr)) {
124            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
125            return ev;
126        }
127
128        return NULL;
129    }
130
131    /** Add a function-based event to kernel code. */
132    template <class T>
133    T *System::addKernelFuncEvent(const char *lbl)
134    {
135        return addFuncEvent<T>(kernelSymtab, lbl);
136    }
137
138    /** Add a function-based event to PALcode. */
139    template <class T>
140    T *System::addPalFuncEvent(const char *lbl)
141    {
142        return addFuncEvent<T>(palSymtab, lbl);
143    }
144
145    /** Add a function-based event to the console code. */
146    template <class T>
147    T *System::addConsoleFuncEvent(const char *lbl)
148    {
149        return addFuncEvent<T>(consoleSymtab, lbl);
150    }
151
152  public:
153    std::vector<RemoteGDB *> remoteGDB;
154    std::vector<GDBListener *> gdbListen;
155    bool breakpoint();
156
157  public:
158    struct Params
159    {
160        std::string name;
161        Tick boot_cpu_frequency;
162        MemoryController *memctrl;
163        PhysicalMemory *physmem;
164        uint64_t init_param;
165        bool bin;
166        std::vector<std::string> binned_fns;
167        bool bin_int;
168
169        std::string kernel_path;
170        std::string console_path;
171        std::string palcode;
172        std::string boot_osflags;
173
174        std::string readfile;
175        uint64_t system_type;
176        uint64_t system_rev;
177    };
178    Params *params;
179
180    System(Params *p);
181    ~System();
182
183    void startup();
184
185  public:
186    /**
187     * Set the m5AlphaAccess pointer in the console
188     */
189    void setAlphaAccess(Addr access);
190
191    /**
192     * Returns the addess the kernel starts at.
193     * @return address the kernel starts at
194     */
195    Addr getKernelStart() const { return kernelStart; }
196
197    /**
198     * Returns the addess the kernel ends at.
199     * @return address the kernel ends at
200     */
201    Addr getKernelEnd() const { return kernelEnd; }
202
203    /**
204     * Returns the addess the entry point to the kernel code.
205     * @return entry point of the kernel code
206     */
207    Addr getKernelEntry() const { return kernelEntry; }
208
209    int registerExecContext(ExecContext *xc, int xcIndex);
210    void replaceExecContext(ExecContext *xc, int xcIndex);
211
212    void regStats();
213    void serialize(std::ostream &os);
214    void unserialize(Checkpoint *cp, const std::string &section);
215
216  public:
217    ////////////////////////////////////////////
218    //
219    // STATIC GLOBAL SYSTEM LIST
220    //
221    ////////////////////////////////////////////
222
223    static std::vector<System *> systemList;
224    static int numSystemsRunning;
225
226    static void printSystems();
227};
228
229#endif // __SYSTEM_HH__
230