system.hh revision 7580
14997Sgblack@eecs.umich.edu/* 24997Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 34997Sgblack@eecs.umich.edu * All rights reserved. 44997Sgblack@eecs.umich.edu * 54997Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 64997Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 74997Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 84997Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 94997Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 104997Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 114997Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 124997Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 134997Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 144997Sgblack@eecs.umich.edu * this software without specific prior written permission. 154997Sgblack@eecs.umich.edu * 164997Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174997Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184997Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194997Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204997Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214997Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224997Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234997Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244997Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254997Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264997Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274997Sgblack@eecs.umich.edu * 284997Sgblack@eecs.umich.edu * Authors: Steve Reinhardt 294997Sgblack@eecs.umich.edu * Lisa Hsu 304997Sgblack@eecs.umich.edu * Nathan Binkert 314997Sgblack@eecs.umich.edu */ 324997Sgblack@eecs.umich.edu 334997Sgblack@eecs.umich.edu#ifndef __SYSTEM_HH__ 344997Sgblack@eecs.umich.edu#define __SYSTEM_HH__ 354997Sgblack@eecs.umich.edu 365019Sgblack@eecs.umich.edu#include <string> 375019Sgblack@eecs.umich.edu#include <vector> 385019Sgblack@eecs.umich.edu 395019Sgblack@eecs.umich.edu#include "base/loader/symtab.hh" 405019Sgblack@eecs.umich.edu#include "base/misc.hh" 415019Sgblack@eecs.umich.edu#include "base/statistics.hh" 425019Sgblack@eecs.umich.edu#include "config/full_system.hh" 435019Sgblack@eecs.umich.edu#include "cpu/pc_event.hh" 445019Sgblack@eecs.umich.edu#include "enums/MemoryMode.hh" 455019Sgblack@eecs.umich.edu#include "mem/port.hh" 465019Sgblack@eecs.umich.edu#include "params/System.hh" 475019Sgblack@eecs.umich.edu#include "sim/sim_object.hh" 485019Sgblack@eecs.umich.edu 495019Sgblack@eecs.umich.edu#if FULL_SYSTEM 505019Sgblack@eecs.umich.edu#include "kern/system_events.hh" 515019Sgblack@eecs.umich.edu#include "mem/vport.hh" 525019Sgblack@eecs.umich.edu#endif 535019Sgblack@eecs.umich.edu 545014Sgblack@eecs.umich.educlass BaseCPU; 555014Sgblack@eecs.umich.educlass ThreadContext; 565014Sgblack@eecs.umich.educlass ObjectFile; 575014Sgblack@eecs.umich.educlass PhysicalMemory; 585014Sgblack@eecs.umich.edu 595014Sgblack@eecs.umich.edu#if FULL_SYSTEM 605014Sgblack@eecs.umich.educlass Platform; 615014Sgblack@eecs.umich.edu#endif 625014Sgblack@eecs.umich.educlass GDBListener; 635014Sgblack@eecs.umich.educlass BaseRemoteGDB; 645014Sgblack@eecs.umich.edu 654997Sgblack@eecs.umich.educlass System : public SimObject 664997Sgblack@eecs.umich.edu{ 674997Sgblack@eecs.umich.edu public: 684997Sgblack@eecs.umich.edu 694997Sgblack@eecs.umich.edu static const char *MemoryModeStrings[3]; 705034Smilesck@eecs.umich.edu 714997Sgblack@eecs.umich.edu Enums::MemoryMode 724997Sgblack@eecs.umich.edu getMemoryMode() 734997Sgblack@eecs.umich.edu { 744997Sgblack@eecs.umich.edu assert(memoryMode); 754997Sgblack@eecs.umich.edu return memoryMode; 765034Smilesck@eecs.umich.edu } 774997Sgblack@eecs.umich.edu 78 /** Change the memory mode of the system. This should only be called by the 79 * python!! 80 * @param mode Mode to change to (atomic/timing) 81 */ 82 void setMemoryMode(Enums::MemoryMode mode); 83 84 PhysicalMemory *physmem; 85 PCEventQueue pcEventQueue; 86 87 std::vector<ThreadContext *> threadContexts; 88 int _numContexts; 89 90 ThreadContext *getThreadContext(ThreadID tid) 91 { 92 return threadContexts[tid]; 93 } 94 95 int numContexts() 96 { 97 assert(_numContexts == (int)threadContexts.size()); 98 return _numContexts; 99 } 100 101 /** Return number of running (non-halted) thread contexts in 102 * system. These threads could be Active or Suspended. */ 103 int numRunningContexts(); 104 105#if FULL_SYSTEM 106 Platform *platform; 107 uint64_t init_param; 108 109 /** Port to physical memory used for writing object files into ram at 110 * boot.*/ 111 FunctionalPort functionalPort; 112 VirtualPort virtPort; 113 114 /** kernel symbol table */ 115 SymbolTable *kernelSymtab; 116 117 /** Object pointer for the kernel code */ 118 ObjectFile *kernel; 119 120 /** Begining of kernel code */ 121 Addr kernelStart; 122 123 /** End of kernel code */ 124 Addr kernelEnd; 125 126 /** Entry point in the kernel to start at */ 127 Addr kernelEntry; 128 129 /** Mask that should be anded for binary/symbol loading. 130 * This allows one two different OS requirements for the same ISA to be 131 * handled. Some OSes are compiled for a virtual address and need to be 132 * loaded into physical memory that starts at address 0, while other 133 * bare metal tools generate images that start at address 0. 134 */ 135 Addr loadAddrMask; 136 137#else 138 139 int page_ptr; 140 141 protected: 142 uint64_t next_PID; 143 144 public: 145 uint64_t allocatePID() 146 { 147 return next_PID++; 148 } 149 150 /** Amount of physical memory that is still free */ 151 Addr freeMemSize(); 152 153 /** Amount of physical memory that exists */ 154 Addr memSize(); 155 156 157#endif // FULL_SYSTEM 158 159 protected: 160 Enums::MemoryMode memoryMode; 161 162#if FULL_SYSTEM 163 /** 164 * Fix up an address used to match PCs for hooking simulator 165 * events on to target function executions. See comment in 166 * system.cc for details. 167 */ 168 virtual Addr fixFuncEventAddr(Addr addr) = 0; 169 170 /** 171 * Add a function-based event to the given function, to be looked 172 * up in the specified symbol table. 173 */ 174 template <class T> 175 T *addFuncEvent(SymbolTable *symtab, const char *lbl) 176 { 177 Addr addr = 0; // initialize only to avoid compiler warning 178 179 if (symtab->findAddress(lbl, addr)) { 180 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr)); 181 return ev; 182 } 183 184 return NULL; 185 } 186 187 /** Add a function-based event to kernel code. */ 188 template <class T> 189 T *addKernelFuncEvent(const char *lbl) 190 { 191 return addFuncEvent<T>(kernelSymtab, lbl); 192 } 193 194#endif 195 public: 196 std::vector<BaseRemoteGDB *> remoteGDB; 197 std::vector<GDBListener *> gdbListen; 198 bool breakpoint(); 199 200 public: 201 typedef SystemParams Params; 202 203 protected: 204 Params *_params; 205 206 public: 207 System(Params *p); 208 ~System(); 209 210 void startup(); 211 212 const Params *params() const { return (const Params *)_params; } 213 214 public: 215 216#if FULL_SYSTEM 217 /** 218 * Returns the addess the kernel starts at. 219 * @return address the kernel starts at 220 */ 221 Addr getKernelStart() const { return kernelStart; } 222 223 /** 224 * Returns the addess the kernel ends at. 225 * @return address the kernel ends at 226 */ 227 Addr getKernelEnd() const { return kernelEnd; } 228 229 /** 230 * Returns the addess the entry point to the kernel code. 231 * @return entry point of the kernel code 232 */ 233 Addr getKernelEntry() const { return kernelEntry; } 234 235#else 236 237 Addr new_page(); 238 239#endif // FULL_SYSTEM 240 241 int registerThreadContext(ThreadContext *tc, int assigned=-1); 242 void replaceThreadContext(ThreadContext *tc, int context_id); 243 244 void serialize(std::ostream &os); 245 void unserialize(Checkpoint *cp, const std::string §ion); 246 247 public: 248 //////////////////////////////////////////// 249 // 250 // STATIC GLOBAL SYSTEM LIST 251 // 252 //////////////////////////////////////////// 253 254 static std::vector<System *> systemList; 255 static int numSystemsRunning; 256 257 static void printSystems(); 258 259 260}; 261 262#endif // __SYSTEM_HH__ 263