system.hh revision 2212
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; 49namespace Kernel { class Binning; } 50 51class System : public SimObject 52{ 53 public: 54 MemoryController *memctrl; 55 PhysicalMemory *physmem; 56 Platform *platform; 57 PCEventQueue pcEventQueue; 58 uint64_t init_param; 59 60 std::vector<ExecContext *> execContexts; 61 int numcpus; 62 63 int getNumCPUs() 64 { 65 if (numcpus != execContexts.size()) 66 panic("cpu array not fully populated!"); 67 68 return numcpus; 69 } 70 71 /** kernel symbol table */ 72 SymbolTable *kernelSymtab; 73 74 /** Object pointer for the kernel code */ 75 ObjectFile *kernel; 76 77 /** Begining of kernel code */ 78 Addr kernelStart; 79 80 /** End of kernel code */ 81 Addr kernelEnd; 82 83 /** Entry point in the kernel to start at */ 84 Addr kernelEntry; 85 86 Kernel::Binning *kernelBinning; 87 88 protected: 89 90 /** 91 * Fix up an address used to match PCs for hooking simulator 92 * events on to target function executions. See comment in 93 * system.cc for details. 94 */ 95 virtual Addr fixFuncEventAddr(Addr addr) = 0; 96 97 /** 98 * Add a function-based event to the given function, to be looked 99 * up in the specified symbol table. 100 */ 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 }; 141 142 protected: 143 Params *_params; 144 145 public: 146 System(Params *p); 147 ~System(); 148 149 void startup(); 150 151 const Params *params() const { return (const Params *)_params; } 152 153 public: 154 /** 155 * Returns the addess the kernel starts at. 156 * @return address the kernel starts at 157 */ 158 Addr getKernelStart() const { return kernelStart; } 159 160 /** 161 * Returns the addess the kernel ends at. 162 * @return address the kernel ends at 163 */ 164 Addr getKernelEnd() const { return kernelEnd; } 165 166 /** 167 * Returns the addess the entry point to the kernel code. 168 * @return entry point of the kernel code 169 */ 170 Addr getKernelEntry() const { return kernelEntry; } 171 172 int registerExecContext(ExecContext *xc, int xcIndex); 173 void replaceExecContext(ExecContext *xc, int xcIndex); 174 175 void regStats(); 176 void serialize(std::ostream &os); 177 void unserialize(Checkpoint *cp, const std::string §ion); 178 179 public: 180 //////////////////////////////////////////// 181 // 182 // STATIC GLOBAL SYSTEM LIST 183 // 184 //////////////////////////////////////////// 185 186 static std::vector<System *> systemList; 187 static int numSystemsRunning; 188 189 static void printSystems(); 190 191 192}; 193 194#endif // __SYSTEM_HH__ 195