system.hh revision 2986:99640058db70
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 * Authors: Steve Reinhardt 29 * Lisa Hsu 30 * Nathan Binkert 31 */ 32 33#ifndef __SYSTEM_HH__ 34#define __SYSTEM_HH__ 35 36#include <string> 37#include <vector> 38 39#include "base/loader/symtab.hh" 40#include "base/misc.hh" 41#include "base/statistics.hh" 42#include "config/full_system.hh" 43#include "cpu/pc_event.hh" 44#include "mem/port.hh" 45#include "sim/sim_object.hh" 46#if FULL_SYSTEM 47#include "kern/system_events.hh" 48#include "mem/vport.hh" 49#endif 50 51class BaseCPU; 52class ThreadContext; 53class ObjectFile; 54class PhysicalMemory; 55 56#if FULL_SYSTEM 57class Platform; 58class GDBListener; 59class RemoteGDB; 60#endif 61 62class System : public SimObject 63{ 64 public: 65 enum MemoryMode { 66 Invalid=0, 67 Atomic, 68 Timing 69 }; 70 71 static const char *MemoryModeStrings[3]; 72 73 74 MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; } 75 76 /** Change the memory mode of the system. This should only be called by the 77 * python!! 78 * @param mode Mode to change to (atomic/timing) 79 */ 80 void setMemoryMode(MemoryMode mode); 81 82 PhysicalMemory *physmem; 83 PCEventQueue pcEventQueue; 84 85 std::vector<ThreadContext *> threadContexts; 86 int numcpus; 87 88 int getNumCPUs() 89 { 90 if (numcpus != threadContexts.size()) 91 panic("cpu array not fully populated!"); 92 93 return numcpus; 94 } 95 96#if FULL_SYSTEM 97 Platform *platform; 98 uint64_t init_param; 99 100 /** Port to physical memory used for writing object files into ram at 101 * boot.*/ 102 FunctionalPort functionalPort; 103 VirtualPort virtPort; 104 105 /** kernel symbol table */ 106 SymbolTable *kernelSymtab; 107 108 /** Object pointer for the kernel code */ 109 ObjectFile *kernel; 110 111 /** Begining of kernel code */ 112 Addr kernelStart; 113 114 /** End of kernel code */ 115 Addr kernelEnd; 116 117 /** Entry point in the kernel to start at */ 118 Addr kernelEntry; 119 120#else 121 122 int page_ptr; 123 124 125#endif // FULL_SYSTEM 126 127 protected: 128 129 MemoryMode memoryMode; 130 131#if FULL_SYSTEM 132 /** 133 * Fix up an address used to match PCs for hooking simulator 134 * events on to target function executions. See comment in 135 * system.cc for details. 136 */ 137 virtual Addr fixFuncEventAddr(Addr addr) = 0; 138 139 /** 140 * Add a function-based event to the given function, to be looked 141 * up in the specified symbol table. 142 */ 143 template <class T> 144 T *System::addFuncEvent(SymbolTable *symtab, const char *lbl) 145 { 146 Addr addr = 0; // initialize only to avoid compiler warning 147 148 if (symtab->findAddress(lbl, addr)) { 149 T *ev = new T(&pcEventQueue, lbl, fixFuncEventAddr(addr)); 150 return ev; 151 } 152 153 return NULL; 154 } 155 156 /** Add a function-based event to kernel code. */ 157 template <class T> 158 T *System::addKernelFuncEvent(const char *lbl) 159 { 160 return addFuncEvent<T>(kernelSymtab, lbl); 161 } 162 163#endif 164 public: 165#if FULL_SYSTEM 166 std::vector<RemoteGDB *> remoteGDB; 167 std::vector<GDBListener *> gdbListen; 168 virtual bool breakpoint() = 0; 169#endif // FULL_SYSTEM 170 171 public: 172 struct Params 173 { 174 std::string name; 175 PhysicalMemory *physmem; 176 MemoryMode mem_mode; 177 178#if FULL_SYSTEM 179 Tick boot_cpu_frequency; 180 std::string boot_osflags; 181 uint64_t init_param; 182 183 std::string kernel_path; 184 std::string readfile; 185#endif 186 }; 187 188 protected: 189 Params *_params; 190 191 public: 192 System(Params *p); 193 ~System(); 194 195 void startup(); 196 197 const Params *params() const { return (const Params *)_params; } 198 199 public: 200 201#if FULL_SYSTEM 202 /** 203 * Returns the addess the kernel starts at. 204 * @return address the kernel starts at 205 */ 206 Addr getKernelStart() const { return kernelStart; } 207 208 /** 209 * Returns the addess the kernel ends at. 210 * @return address the kernel ends at 211 */ 212 Addr getKernelEnd() const { return kernelEnd; } 213 214 /** 215 * Returns the addess the entry point to the kernel code. 216 * @return entry point of the kernel code 217 */ 218 Addr getKernelEntry() const { return kernelEntry; } 219 220#else 221 222 Addr new_page(); 223 224#endif // FULL_SYSTEM 225 226 int registerThreadContext(ThreadContext *tc, int tcIndex); 227 void replaceThreadContext(ThreadContext *tc, int tcIndex); 228 229 void serialize(std::ostream &os); 230 void unserialize(Checkpoint *cp, const std::string §ion); 231 232 public: 233 //////////////////////////////////////////// 234 // 235 // STATIC GLOBAL SYSTEM LIST 236 // 237 //////////////////////////////////////////// 238 239 static std::vector<System *> systemList; 240 static int numSystemsRunning; 241 242 static void printSystems(); 243 244 245}; 246 247#endif // __SYSTEM_HH__ 248