system.hh revision 2343
112841Sgabeblack@google.com/* 212841Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 312841Sgabeblack@google.com * All rights reserved. 412841Sgabeblack@google.com * 512841Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612841Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712841Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912841Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112841Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212841Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312841Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412841Sgabeblack@google.com * this software without specific prior written permission. 1512841Sgabeblack@google.com * 1612841Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712841Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812841Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912841Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012841Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112841Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212841Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312841Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412841Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512841Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612841Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712841Sgabeblack@google.com */ 2812841Sgabeblack@google.com 2912841Sgabeblack@google.com#ifndef __SYSTEM_HH__ 3012841Sgabeblack@google.com#define __SYSTEM_HH__ 3112841Sgabeblack@google.com 3212841Sgabeblack@google.com#include <string> 3313198Sgabeblack@google.com#include <vector> 3412841Sgabeblack@google.com 3512841Sgabeblack@google.com#include "base/statistics.hh" 3612841Sgabeblack@google.com#include "base/loader/symtab.hh" 3712841Sgabeblack@google.com#include "cpu/pc_event.hh" 3812841Sgabeblack@google.com#include "kern/system_events.hh" 3912841Sgabeblack@google.com#include "sim/sim_object.hh" 4012841Sgabeblack@google.com 4112841Sgabeblack@google.comclass BaseCPU; 4212841Sgabeblack@google.comclass ExecContext; 4312841Sgabeblack@google.comclass GDBListener; 4412841Sgabeblack@google.comclass MemoryController; 4512841Sgabeblack@google.comclass ObjectFile; 4612841Sgabeblack@google.comclass PhysicalMemory; 4712841Sgabeblack@google.comclass Platform; 4812841Sgabeblack@google.comclass RemoteGDB; 4912841Sgabeblack@google.com 5012841Sgabeblack@google.comclass System : public SimObject 5113198Sgabeblack@google.com{ 5212841Sgabeblack@google.com public: 5312841Sgabeblack@google.com MemoryController *memctrl; 5412841Sgabeblack@google.com PhysicalMemory *physmem; 5512841Sgabeblack@google.com Platform *platform; 5612841Sgabeblack@google.com PCEventQueue pcEventQueue; 5712841Sgabeblack@google.com uint64_t init_param; 5812841Sgabeblack@google.com 5912841Sgabeblack@google.com std::vector<ExecContext *> execContexts; 6013198Sgabeblack@google.com int numcpus; 6113198Sgabeblack@google.com 6213198Sgabeblack@google.com int getNumCPUs() 6312841Sgabeblack@google.com { 6412841Sgabeblack@google.com if (numcpus != execContexts.size()) 6512841Sgabeblack@google.com panic("cpu array not fully populated!"); 6612841Sgabeblack@google.com 6712841Sgabeblack@google.com 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 §ion); 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