system.hh revision 2358
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu#ifndef __SYSTEM_HH__
302SN/A#define __SYSTEM_HH__
312SN/A
322SN/A#include <string>
332SN/A#include <vector>
342SN/A
3556SN/A#include "base/statistics.hh"
3656SN/A#include "base/loader/symtab.hh"
371954SN/A#include "cpu/pc_event.hh"
382SN/A#include "kern/system_events.hh"
392SN/A#include "sim/sim_object.hh"
402SN/A
412SN/Aclass BaseCPU;
422SN/Aclass ExecContext;
432SN/Aclass GDBListener;
442SN/Aclass MemoryController;
452SN/Aclass ObjectFile;
461296SN/Aclass PhysicalMemory;
472SN/Aclass Platform;
482SN/Aclass RemoteGDB;
492SN/Anamespace Kernel { class Binning; }
502SN/A
512SN/Aclass System : public SimObject
522SN/A{
532SN/A  public:
542SN/A    MemoryController *memctrl;
552SN/A    PhysicalMemory *physmem;
562SN/A    Platform *platform;
572SN/A    PCEventQueue pcEventQueue;
582SN/A    uint64_t init_param;
591954SN/A
602SN/A    std::vector<ExecContext *> execContexts;
612SN/A    int numcpus;
622SN/A
632SN/A    int getNumCPUs()
642SN/A    {
651954SN/A        if (numcpus != execContexts.size())
662SN/A            panic("cpu array not fully populated!");
672SN/A
681954SN/A        return numcpus;
691971SN/A    }
701954SN/A
711954SN/A    /** kernel symbol table */
721971SN/A    SymbolTable *kernelSymtab;
731954SN/A
741954SN/A    /** Object pointer for the kernel code */
751954SN/A    ObjectFile *kernel;
761954SN/A
771971SN/A    /** Begining of kernel code */
781954SN/A    Addr kernelStart;
791954SN/A
801971SN/A    /** End of kernel code */
811954SN/A    Addr kernelEnd;
821954SN/A
831954SN/A    /** Entry point in the kernel to start at */
841954SN/A    Addr kernelEntry;
852SN/A
862SN/A    Kernel::Binning *kernelBinning;
872SN/A
882SN/A  protected:
892SN/A
902SN/A    /**
912SN/A     * Fix up an address used to match PCs for hooking simulator
922SN/A     * events on to target function executions.  See comment in
932SN/A     * system.cc for details.
941954SN/A     */
951954SN/A    virtual Addr fixFuncEventAddr(Addr addr) = 0;
962SN/A
972SN/A    /**
982SN/A     * Add a function-based event to the given function, to be looked
992SN/A     * up in the specified symbol table.
1002SN/A     */
101    template <class T>
102    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
103    {
104        Addr addr = 0; // initialize only to avoid compiler warning
105
106        if (symtab->findAddress(lbl, addr)) {
107            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
108            return ev;
109        }
110
111        return NULL;
112    }
113
114    /** Add a function-based event to kernel code. */
115    template <class T>
116    T *System::addKernelFuncEvent(const char *lbl)
117    {
118        return addFuncEvent<T>(kernelSymtab, lbl);
119    }
120
121  public:
122    std::vector<RemoteGDB *> remoteGDB;
123    std::vector<GDBListener *> gdbListen;
124    virtual bool breakpoint() = 0;
125
126  public:
127    struct Params
128    {
129        std::string name;
130        Tick boot_cpu_frequency;
131        MemoryController *memctrl;
132        PhysicalMemory *physmem;
133        uint64_t init_param;
134        bool bin;
135        std::vector<std::string> binned_fns;
136        bool bin_int;
137
138        std::string kernel_path;
139        std::string readfile;
140        std::string symbolfile;
141    };
142
143  protected:
144    Params *_params;
145
146  public:
147    System(Params *p);
148    ~System();
149
150    void startup();
151
152    const Params *params() const { return (const Params *)_params; }
153
154  public:
155    /**
156     * Returns the addess the kernel starts at.
157     * @return address the kernel starts at
158     */
159    Addr getKernelStart() const { return kernelStart; }
160
161    /**
162     * Returns the addess the kernel ends at.
163     * @return address the kernel ends at
164     */
165    Addr getKernelEnd() const { return kernelEnd; }
166
167    /**
168     * Returns the addess the entry point to the kernel code.
169     * @return entry point of the kernel code
170     */
171    Addr getKernelEntry() const { return kernelEntry; }
172
173    int registerExecContext(ExecContext *xc, int xcIndex);
174    void replaceExecContext(ExecContext *xc, int xcIndex);
175
176    void regStats();
177    void serialize(std::ostream &os);
178    void unserialize(Checkpoint *cp, const std::string &section);
179
180  public:
181    ////////////////////////////////////////////
182    //
183    // STATIC GLOBAL SYSTEM LIST
184    //
185    ////////////////////////////////////////////
186
187    static std::vector<System *> systemList;
188    static int numSystemsRunning;
189
190    static void printSystems();
191
192
193};
194
195#endif // __SYSTEM_HH__
196