system.hh revision 2158
18512Sgeoffrey.blake@arm.com/*
28512Sgeoffrey.blake@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
38512Sgeoffrey.blake@arm.com * All rights reserved.
48512Sgeoffrey.blake@arm.com *
58512Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without
68512Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are
78512Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright
88512Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer;
98512Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright
108512Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the
118512Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution;
128512Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its
138512Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from
148512Sgeoffrey.blake@arm.com * this software without specific prior written permission.
158512Sgeoffrey.blake@arm.com *
168512Sgeoffrey.blake@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178512Sgeoffrey.blake@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188512Sgeoffrey.blake@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
198512Sgeoffrey.blake@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
208512Sgeoffrey.blake@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
218512Sgeoffrey.blake@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
228512Sgeoffrey.blake@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238512Sgeoffrey.blake@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248512Sgeoffrey.blake@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258512Sgeoffrey.blake@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
268512Sgeoffrey.blake@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278512Sgeoffrey.blake@arm.com */
288512Sgeoffrey.blake@arm.com
298512Sgeoffrey.blake@arm.com#ifndef __SYSTEM_HH__
308512Sgeoffrey.blake@arm.com#define __SYSTEM_HH__
318512Sgeoffrey.blake@arm.com
328512Sgeoffrey.blake@arm.com#include <string>
338512Sgeoffrey.blake@arm.com#include <vector>
348512Sgeoffrey.blake@arm.com
358512Sgeoffrey.blake@arm.com#include "base/statistics.hh"
368512Sgeoffrey.blake@arm.com#include "base/loader/symtab.hh"
378512Sgeoffrey.blake@arm.com#include "cpu/pc_event.hh"
388512Sgeoffrey.blake@arm.com#include "kern/system_events.hh"
398512Sgeoffrey.blake@arm.com#include "sim/sim_object.hh"
408512Sgeoffrey.blake@arm.com
418512Sgeoffrey.blake@arm.comclass BaseCPU;
428512Sgeoffrey.blake@arm.comclass ExecContext;
438512Sgeoffrey.blake@arm.comclass GDBListener;
448512Sgeoffrey.blake@arm.comclass MemoryController;
458512Sgeoffrey.blake@arm.comclass ObjectFile;
468512Sgeoffrey.blake@arm.comclass PhysicalMemory;
478512Sgeoffrey.blake@arm.comclass Platform;
488512Sgeoffrey.blake@arm.comclass RemoteGDB;
498512Sgeoffrey.blake@arm.comnamespace Kernel { class Binning; }
508512Sgeoffrey.blake@arm.com
518512Sgeoffrey.blake@arm.comclass System : public SimObject
528512Sgeoffrey.blake@arm.com{
538512Sgeoffrey.blake@arm.com  public:
548512Sgeoffrey.blake@arm.com    MemoryController *memctrl;
558512Sgeoffrey.blake@arm.com    PhysicalMemory *physmem;
568512Sgeoffrey.blake@arm.com    Platform *platform;
578512Sgeoffrey.blake@arm.com    PCEventQueue pcEventQueue;
588512Sgeoffrey.blake@arm.com    uint64_t init_param;
598512Sgeoffrey.blake@arm.com
608512Sgeoffrey.blake@arm.com    std::vector<ExecContext *> execContexts;
618512Sgeoffrey.blake@arm.com    int numcpus;
628512Sgeoffrey.blake@arm.com
638512Sgeoffrey.blake@arm.com    int getNumCPUs()
648512Sgeoffrey.blake@arm.com    {
658512Sgeoffrey.blake@arm.com        if (numcpus != execContexts.size())
668512Sgeoffrey.blake@arm.com            panic("cpu array not fully populated!");
678512Sgeoffrey.blake@arm.com
688512Sgeoffrey.blake@arm.com        return numcpus;
698512Sgeoffrey.blake@arm.com    }
708512Sgeoffrey.blake@arm.com
718512Sgeoffrey.blake@arm.com    /** kernel symbol table */
728512Sgeoffrey.blake@arm.com    SymbolTable *kernelSymtab;
738512Sgeoffrey.blake@arm.com
748512Sgeoffrey.blake@arm.com    /** Object pointer for the kernel code */
758512Sgeoffrey.blake@arm.com    ObjectFile *kernel;
768512Sgeoffrey.blake@arm.com
778512Sgeoffrey.blake@arm.com    /** Begining of kernel code */
788512Sgeoffrey.blake@arm.com    Addr kernelStart;
798512Sgeoffrey.blake@arm.com
808512Sgeoffrey.blake@arm.com    /** End of kernel code */
818512Sgeoffrey.blake@arm.com    Addr kernelEnd;
828512Sgeoffrey.blake@arm.com
838512Sgeoffrey.blake@arm.com    /** Entry point in the kernel to start at */
848512Sgeoffrey.blake@arm.com    Addr kernelEntry;
858512Sgeoffrey.blake@arm.com
868512Sgeoffrey.blake@arm.com    Kernel::Binning *kernelBinning;
878512Sgeoffrey.blake@arm.com
888512Sgeoffrey.blake@arm.com  protected:
898512Sgeoffrey.blake@arm.com
908512Sgeoffrey.blake@arm.com    /**
918512Sgeoffrey.blake@arm.com     * Fix up an address used to match PCs for hooking simulator
928512Sgeoffrey.blake@arm.com     * events on to target function executions.  See comment in
938512Sgeoffrey.blake@arm.com     * system.cc for details.
948512Sgeoffrey.blake@arm.com     */
958512Sgeoffrey.blake@arm.com    virtual Addr fixFuncEventAddr(Addr addr) = 0;
968512Sgeoffrey.blake@arm.com
978512Sgeoffrey.blake@arm.com    /**
988512Sgeoffrey.blake@arm.com     * Add a function-based event to the given function, to be looked
998512Sgeoffrey.blake@arm.com     * up in the specified symbol table.
1008512Sgeoffrey.blake@arm.com     */
1018512Sgeoffrey.blake@arm.com    template <class T>
1028512Sgeoffrey.blake@arm.com    T *System::addFuncEvent(SymbolTable *symtab, const char *lbl)
1038512Sgeoffrey.blake@arm.com    {
1048512Sgeoffrey.blake@arm.com        Addr addr = 0; // initialize only to avoid compiler warning
1058512Sgeoffrey.blake@arm.com
1068512Sgeoffrey.blake@arm.com        if (symtab->findAddress(lbl, addr)) {
1078512Sgeoffrey.blake@arm.com            T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr));
1088512Sgeoffrey.blake@arm.com            return ev;
1098512Sgeoffrey.blake@arm.com        }
1108512Sgeoffrey.blake@arm.com
1118512Sgeoffrey.blake@arm.com        return NULL;
1128512Sgeoffrey.blake@arm.com    }
1138512Sgeoffrey.blake@arm.com
1148512Sgeoffrey.blake@arm.com    /** Add a function-based event to kernel code. */
1158512Sgeoffrey.blake@arm.com    template <class T>
1168512Sgeoffrey.blake@arm.com    T *System::addKernelFuncEvent(const char *lbl)
1178512Sgeoffrey.blake@arm.com    {
1188512Sgeoffrey.blake@arm.com        return addFuncEvent<T>(kernelSymtab, lbl);
1198512Sgeoffrey.blake@arm.com    }
1208512Sgeoffrey.blake@arm.com
1218512Sgeoffrey.blake@arm.com  public:
1228512Sgeoffrey.blake@arm.com    std::vector<RemoteGDB *> remoteGDB;
1238512Sgeoffrey.blake@arm.com    std::vector<GDBListener *> gdbListen;
1248512Sgeoffrey.blake@arm.com    virtual bool breakpoint() = 0;
1258512Sgeoffrey.blake@arm.com
1268512Sgeoffrey.blake@arm.com  public:
1278512Sgeoffrey.blake@arm.com    struct Params
1288512Sgeoffrey.blake@arm.com    {
1298512Sgeoffrey.blake@arm.com        std::string name;
1308512Sgeoffrey.blake@arm.com        Tick boot_cpu_frequency;
1318512Sgeoffrey.blake@arm.com        MemoryController *memctrl;
1328512Sgeoffrey.blake@arm.com        PhysicalMemory *physmem;
1338512Sgeoffrey.blake@arm.com        uint64_t init_param;
1348512Sgeoffrey.blake@arm.com        bool bin;
1358512Sgeoffrey.blake@arm.com        std::vector<std::string> binned_fns;
1368512Sgeoffrey.blake@arm.com        bool bin_int;
1378512Sgeoffrey.blake@arm.com
1388512Sgeoffrey.blake@arm.com        std::string kernel_path;
1398512Sgeoffrey.blake@arm.com        std::string readfile;
1408512Sgeoffrey.blake@arm.com    };
1418512Sgeoffrey.blake@arm.com
1428512Sgeoffrey.blake@arm.com  protected:
1438512Sgeoffrey.blake@arm.com    Params *_params;
1448512Sgeoffrey.blake@arm.com
1458512Sgeoffrey.blake@arm.com  public:
1468512Sgeoffrey.blake@arm.com    System(Params *p);
1478512Sgeoffrey.blake@arm.com    ~System();
1488512Sgeoffrey.blake@arm.com
1498512Sgeoffrey.blake@arm.com    void startup();
1508512Sgeoffrey.blake@arm.com
1518512Sgeoffrey.blake@arm.com    const Params *params() const { return (const Params *)_params; }
1528512Sgeoffrey.blake@arm.com
1538512Sgeoffrey.blake@arm.com  public:
1548512Sgeoffrey.blake@arm.com    /**
1558512Sgeoffrey.blake@arm.com     * Returns the addess the kernel starts at.
1568512Sgeoffrey.blake@arm.com     * @return address the kernel starts at
1578512Sgeoffrey.blake@arm.com     */
1588512Sgeoffrey.blake@arm.com    Addr getKernelStart() const { return kernelStart; }
1598512Sgeoffrey.blake@arm.com
1608512Sgeoffrey.blake@arm.com    /**
1618512Sgeoffrey.blake@arm.com     * Returns the addess the kernel ends at.
1628512Sgeoffrey.blake@arm.com     * @return address the kernel ends at
1638512Sgeoffrey.blake@arm.com     */
1648512Sgeoffrey.blake@arm.com    Addr getKernelEnd() const { return kernelEnd; }
1658512Sgeoffrey.blake@arm.com
1668512Sgeoffrey.blake@arm.com    /**
1678512Sgeoffrey.blake@arm.com     * Returns the addess the entry point to the kernel code.
1688512Sgeoffrey.blake@arm.com     * @return entry point of the kernel code
1698512Sgeoffrey.blake@arm.com     */
1708512Sgeoffrey.blake@arm.com    Addr getKernelEntry() const { return kernelEntry; }
1718512Sgeoffrey.blake@arm.com
1728512Sgeoffrey.blake@arm.com    int registerExecContext(ExecContext *xc, int xcIndex);
1738512Sgeoffrey.blake@arm.com    void replaceExecContext(ExecContext *xc, int xcIndex);
1748512Sgeoffrey.blake@arm.com
1758512Sgeoffrey.blake@arm.com    void regStats();
1768512Sgeoffrey.blake@arm.com    void serialize(std::ostream &os);
1778512Sgeoffrey.blake@arm.com    void unserialize(Checkpoint *cp, const std::string &section);
1788512Sgeoffrey.blake@arm.com
1798512Sgeoffrey.blake@arm.com  public:
1808512Sgeoffrey.blake@arm.com    ////////////////////////////////////////////
1818512Sgeoffrey.blake@arm.com    //
1828512Sgeoffrey.blake@arm.com    // STATIC GLOBAL SYSTEM LIST
1838512Sgeoffrey.blake@arm.com    //
1848512Sgeoffrey.blake@arm.com    ////////////////////////////////////////////
1858512Sgeoffrey.blake@arm.com
1868512Sgeoffrey.blake@arm.com    static std::vector<System *> systemList;
1878512Sgeoffrey.blake@arm.com    static int numSystemsRunning;
1888512Sgeoffrey.blake@arm.com
1898512Sgeoffrey.blake@arm.com    static void printSystems();
1908512Sgeoffrey.blake@arm.com
1918512Sgeoffrey.blake@arm.com
1928512Sgeoffrey.blake@arm.com};
1938512Sgeoffrey.blake@arm.com
1948512Sgeoffrey.blake@arm.com#endif // __SYSTEM_HH__
1958512Sgeoffrey.blake@arm.com