system.hh revision 2378
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 "sim/sim_object.hh" 39#if FULL_SYSTEM 40#include "kern/system_events.hh" 41#endif 42 43class BaseCPU; 44class ExecContext; 45class MemoryController; 46class ObjectFile; 47class PhysicalMemory; 48 49#if FULL_SYSTEM 50class Platform; 51class GDBListener; 52class RemoteGDB; 53namespace Kernel { class Binning; } 54#endif 55 56class System : public SimObject 57{ 58 public: 59 PhysicalMemory *physmem; 60 PCEventQueue pcEventQueue; 61 62 std::vector<ExecContext *> execContexts; 63 int numcpus; 64 65 int getNumCPUs() 66 { 67 if (numcpus != execContexts.size()) 68 panic("cpu array not fully populated!"); 69 70 return numcpus; 71 } 72 73#if FULL_SYSTEM 74 MemoryController *memctrl; 75 Platform *platform; 76 uint64_t init_param; 77 78 /** kernel symbol table */ 79 SymbolTable *kernelSymtab; 80 81 /** console symbol table */ 82 SymbolTable *consoleSymtab; 83 84 /** pal symbol table */ 85 SymbolTable *palSymtab; 86 87 /** Object pointer for the kernel code */ 88 ObjectFile *kernel; 89 90 /** Object pointer for the console code */ 91 ObjectFile *console; 92 93 /** Object pointer for the PAL code */ 94 ObjectFile *pal; 95 96 /** Begining of kernel code */ 97 Addr kernelStart; 98 99 /** End of kernel code */ 100 Addr kernelEnd; 101 102 /** Entry point in the kernel to start at */ 103 Addr kernelEntry; 104 105 Kernel::Binning *kernelBinning; 106 107#ifdef DEBUG 108 /** Event to halt the simulator if the console calls panic() */ 109 BreakPCEvent *consolePanicEvent; 110#endif 111 112#else 113 114 int page_ptr; 115 116 117#endif // FULL_SYSTEM 118 119 protected: 120 121 /** 122 * Fix up an address used to match PCs for hooking simulator 123 * events on to target function executions. See comment in 124 * system.cc for details. 125 */ 126 Addr fixFuncEventAddr(Addr addr); 127 128 /** 129 * Add a function-based event to the given function, to be looked 130 * up in the specified symbol table. 131 */ 132 template <class T> 133 T *System::addFuncEvent(SymbolTable *symtab, const char *lbl) 134 { 135 Addr addr = 0; // initialize only to avoid compiler warning 136 137 if (symtab->findAddress(lbl, addr)) { 138 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr)); 139 return ev; 140 } 141 142 return NULL; 143 } 144 145#if FULL_SYSTEM 146 /** Add a function-based event to kernel code. */ 147 template <class T> 148 T *System::addKernelFuncEvent(const char *lbl) 149 { 150 return addFuncEvent<T>(kernelSymtab, lbl); 151 } 152 153 /** Add a function-based event to PALcode. */ 154 template <class T> 155 T *System::addPalFuncEvent(const char *lbl) 156 { 157 return addFuncEvent<T>(palSymtab, lbl); 158 } 159 160 /** Add a function-based event to the console code. */ 161 template <class T> 162 T *System::addConsoleFuncEvent(const char *lbl) 163 { 164 return addFuncEvent<T>(consoleSymtab, lbl); 165 } 166#endif 167 168 public: 169#if FULL_SYSTEM 170 std::vector<RemoteGDB *> remoteGDB; 171 std::vector<GDBListener *> gdbListen; 172 bool breakpoint(); 173#endif // FULL_SYSTEM 174 175 public: 176 struct Params 177 { 178 std::string name; 179 PhysicalMemory *physmem; 180 181#if FULL_SYSTEM 182 Tick boot_cpu_frequency; 183 MemoryController *memctrl; 184 uint64_t init_param; 185 bool bin; 186 std::vector<std::string> binned_fns; 187 bool bin_int; 188 189 std::string kernel_path; 190 std::string console_path; 191 std::string palcode; 192 std::string boot_osflags; 193 194 std::string readfile; 195 uint64_t system_type; 196 uint64_t system_rev; 197#endif 198 }; 199 Params *params; 200 201 System(Params *p); 202 ~System(); 203 204 void startup(); 205 206 public: 207 208#if FULL_SYSTEM 209 /** 210 * Set the m5AlphaAccess pointer in the console 211 */ 212 void setAlphaAccess(Addr access); 213 214 /** 215 * Returns the addess the kernel starts at. 216 * @return address the kernel starts at 217 */ 218 Addr getKernelStart() const { return kernelStart; } 219 220 /** 221 * Returns the addess the kernel ends at. 222 * @return address the kernel ends at 223 */ 224 Addr getKernelEnd() const { return kernelEnd; } 225 226 /** 227 * Returns the addess the entry point to the kernel code. 228 * @return entry point of the kernel code 229 */ 230 Addr getKernelEntry() const { return kernelEntry; } 231 232#else 233 234 Addr new_page(); 235 236#endif // FULL_SYSTEM 237 238 int registerExecContext(ExecContext *xc, int xcIndex); 239 void replaceExecContext(ExecContext *xc, int xcIndex); 240 241 void regStats(); 242 void serialize(std::ostream &os); 243 void unserialize(Checkpoint *cp, const std::string §ion); 244 245 public: 246 //////////////////////////////////////////// 247 // 248 // STATIC GLOBAL SYSTEM LIST 249 // 250 //////////////////////////////////////////// 251 252 static std::vector<System *> systemList; 253 static int numSystemsRunning; 254 255 static void printSystems(); 256}; 257 258#endif // __SYSTEM_HH__ 259