system.hh revision 8765:659670964330
1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * Copyright (c) 2011 Regents of the University of California 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Steve Reinhardt 30 * Lisa Hsu 31 * Nathan Binkert 32 * Rick Strong 33 */ 34 35#ifndef __SYSTEM_HH__ 36#define __SYSTEM_HH__ 37 38#include <string> 39#include <vector> 40 41#include "base/loader/symtab.hh" 42#include "base/misc.hh" 43#include "base/statistics.hh" 44#include "config/full_system.hh" 45#include "cpu/pc_event.hh" 46#include "enums/MemoryMode.hh" 47#include "mem/port.hh" 48#include "params/System.hh" 49#include "sim/sim_object.hh" 50 51#if FULL_SYSTEM 52#include "kern/system_events.hh" 53#endif 54 55class BaseCPU; 56class ThreadContext; 57class ObjectFile; 58class PhysicalMemory; 59 60#if FULL_SYSTEM 61class Platform; 62class FunctionalPort; 63class VirtualPort; 64#endif 65class GDBListener; 66class BaseRemoteGDB; 67 68class System : public SimObject 69{ 70 public: 71 72 static const char *MemoryModeStrings[3]; 73 74 Enums::MemoryMode 75 getMemoryMode() 76 { 77 assert(memoryMode); 78 return memoryMode; 79 } 80 81 /** Change the memory mode of the system. This should only be called by the 82 * python!! 83 * @param mode Mode to change to (atomic/timing) 84 */ 85 void setMemoryMode(Enums::MemoryMode mode); 86 87 PhysicalMemory *physmem; 88 PCEventQueue pcEventQueue; 89 90 std::vector<ThreadContext *> threadContexts; 91 int _numContexts; 92 93 ThreadContext *getThreadContext(ThreadID tid) 94 { 95 return threadContexts[tid]; 96 } 97 98 int numContexts() 99 { 100 assert(_numContexts == (int)threadContexts.size()); 101 return _numContexts; 102 } 103 104 /** Return number of running (non-halted) thread contexts in 105 * system. These threads could be Active or Suspended. */ 106 int numRunningContexts(); 107 108 /** List to store ranges of memories in this system */ 109 AddrRangeList memRanges; 110 111 /** check if an address points to valid system memory 112 * and thus we can fetch instructions out of it 113 */ 114 bool isMemory(const Addr addr) const; 115 116 Addr pagePtr; 117 118#if FULL_SYSTEM 119 uint64_t init_param; 120 121 /** Port to physical memory used for writing object files into ram at 122 * boot.*/ 123 FunctionalPort *functionalPort; 124 VirtualPort *virtPort; 125 126 /** kernel symbol table */ 127 SymbolTable *kernelSymtab; 128 129 /** Object pointer for the kernel code */ 130 ObjectFile *kernel; 131 132 /** Begining of kernel code */ 133 Addr kernelStart; 134 135 /** End of kernel code */ 136 Addr kernelEnd; 137 138 /** Entry point in the kernel to start at */ 139 Addr kernelEntry; 140 141 /** Mask that should be anded for binary/symbol loading. 142 * This allows one two different OS requirements for the same ISA to be 143 * handled. Some OSes are compiled for a virtual address and need to be 144 * loaded into physical memory that starts at address 0, while other 145 * bare metal tools generate images that start at address 0. 146 */ 147 Addr loadAddrMask; 148 149#endif // FULL_SYSTEM 150 151 protected: 152 uint64_t nextPID; 153 154 public: 155 uint64_t allocatePID() 156 { 157 return nextPID++; 158 } 159 160 /** Amount of physical memory that is still free */ 161 Addr freeMemSize(); 162 163 /** Amount of physical memory that exists */ 164 Addr memSize(); 165 166 protected: 167 Enums::MemoryMode memoryMode; 168 uint64_t workItemsBegin; 169 uint64_t workItemsEnd; 170 std::vector<bool> activeCpus; 171 172 public: 173 /** 174 * Called by pseudo_inst to track the number of work items started by this 175 * system. 176 */ 177 uint64_t 178 incWorkItemsBegin() 179 { 180 return ++workItemsBegin; 181 } 182 183 /** 184 * Called by pseudo_inst to track the number of work items completed by 185 * this system. 186 */ 187 uint64_t 188 incWorkItemsEnd() 189 { 190 return ++workItemsEnd; 191 } 192 193 /** 194 * Called by pseudo_inst to mark the cpus actively executing work items. 195 * Returns the total number of cpus that have executed work item begin or 196 * ends. 197 */ 198 int 199 markWorkItem(int index) 200 { 201 int count = 0; 202 assert(index < activeCpus.size()); 203 activeCpus[index] = true; 204 for (std::vector<bool>::iterator i = activeCpus.begin(); 205 i < activeCpus.end(); i++) { 206 if (*i) count++; 207 } 208 return count; 209 } 210 211#if FULL_SYSTEM 212 /** 213 * Fix up an address used to match PCs for hooking simulator 214 * events on to target function executions. See comment in 215 * system.cc for details. 216 */ 217 virtual Addr fixFuncEventAddr(Addr addr) = 0; 218 219 /** 220 * Add a function-based event to the given function, to be looked 221 * up in the specified symbol table. 222 */ 223 template <class T> 224 T *addFuncEvent(SymbolTable *symtab, const char *lbl) 225 { 226 Addr addr = 0; // initialize only to avoid compiler warning 227 228 if (symtab->findAddress(lbl, addr)) { 229 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr)); 230 return ev; 231 } 232 233 return NULL; 234 } 235 236 /** Add a function-based event to kernel code. */ 237 template <class T> 238 T *addKernelFuncEvent(const char *lbl) 239 { 240 return addFuncEvent<T>(kernelSymtab, lbl); 241 } 242 243#endif 244 public: 245 std::vector<BaseRemoteGDB *> remoteGDB; 246 std::vector<GDBListener *> gdbListen; 247 bool breakpoint(); 248 249 public: 250 typedef SystemParams Params; 251 252 protected: 253 Params *_params; 254 255 public: 256 System(Params *p); 257 ~System(); 258 259 void initState(); 260 261 const Params *params() const { return (const Params *)_params; } 262 263 public: 264 265#if FULL_SYSTEM 266 /** 267 * Returns the addess the kernel starts at. 268 * @return address the kernel starts at 269 */ 270 Addr getKernelStart() const { return kernelStart; } 271 272 /** 273 * Returns the addess the kernel ends at. 274 * @return address the kernel ends at 275 */ 276 Addr getKernelEnd() const { return kernelEnd; } 277 278 /** 279 * Returns the addess the entry point to the kernel code. 280 * @return entry point of the kernel code 281 */ 282 Addr getKernelEntry() const { return kernelEntry; } 283 284#endif 285 286 Addr new_page(); 287 288 int registerThreadContext(ThreadContext *tc, int assigned=-1); 289 void replaceThreadContext(ThreadContext *tc, int context_id); 290 291 void serialize(std::ostream &os); 292 void unserialize(Checkpoint *cp, const std::string §ion); 293 virtual void resume(); 294 295 public: 296 Counter totalNumInsts; 297 EventQueue instEventQueue; 298 299 //////////////////////////////////////////// 300 // 301 // STATIC GLOBAL SYSTEM LIST 302 // 303 //////////////////////////////////////////// 304 305 static std::vector<System *> systemList; 306 static int numSystemsRunning; 307 308 static void printSystems(); 309 310 311}; 312 313#endif // __SYSTEM_HH__ 314