BaseCPU.py revision 7897
1# Copyright (c) 2005-2008 The Regents of The University of Michigan 2# Copyright (c) 2011 Regents of the University of California 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: Nathan Binkert 29# Rick Strong 30 31import sys 32 33from m5.defines import buildEnv 34from m5.params import * 35from m5.proxy import * 36 37from Bus import Bus 38from InstTracer import InstTracer 39from ExeTracer import ExeTracer 40from MemObject import MemObject 41 42default_tracer = ExeTracer() 43 44if buildEnv['TARGET_ISA'] == 'alpha': 45 from AlphaTLB import AlphaDTB, AlphaITB 46 if buildEnv['FULL_SYSTEM']: 47 from AlphaInterrupts import AlphaInterrupts 48elif buildEnv['TARGET_ISA'] == 'sparc': 49 from SparcTLB import SparcTLB 50 if buildEnv['FULL_SYSTEM']: 51 from SparcInterrupts import SparcInterrupts 52elif buildEnv['TARGET_ISA'] == 'x86': 53 from X86TLB import X86TLB 54 if buildEnv['FULL_SYSTEM']: 55 from X86LocalApic import X86LocalApic 56elif buildEnv['TARGET_ISA'] == 'mips': 57 from MipsTLB import MipsTLB 58 if buildEnv['FULL_SYSTEM']: 59 from MipsInterrupts import MipsInterrupts 60elif buildEnv['TARGET_ISA'] == 'arm': 61 from ArmTLB import ArmTLB 62 if buildEnv['FULL_SYSTEM']: 63 from ArmInterrupts import ArmInterrupts 64elif buildEnv['TARGET_ISA'] == 'power': 65 from PowerTLB import PowerTLB 66 if buildEnv['FULL_SYSTEM']: 67 from PowerInterrupts import PowerInterrupts 68 69class BaseCPU(MemObject): 70 type = 'BaseCPU' 71 abstract = True 72 73 system = Param.System(Parent.any, "system object") 74 cpu_id = Param.Int(-1, "CPU identifier") 75 numThreads = Param.Unsigned(1, "number of HW thread contexts") 76 77 function_trace = Param.Bool(False, "Enable function trace") 78 function_trace_start = Param.Tick(0, "Cycle to start function trace") 79 80 checker = Param.BaseCPU(NULL, "checker CPU") 81 82 do_checkpoint_insts = Param.Bool(True, 83 "enable checkpoint pseudo instructions") 84 do_statistics_insts = Param.Bool(True, 85 "enable statistics pseudo instructions") 86 87 if buildEnv['FULL_SYSTEM']: 88 profile = Param.Latency('0ns', "trace the kernel stack") 89 do_quiesce = Param.Bool(True, "enable quiesce instructions") 90 else: 91 workload = VectorParam.Process("processes to run") 92 93 if buildEnv['TARGET_ISA'] == 'sparc': 94 dtb = Param.SparcTLB(SparcTLB(), "Data TLB") 95 itb = Param.SparcTLB(SparcTLB(), "Instruction TLB") 96 if buildEnv['FULL_SYSTEM']: 97 interrupts = Param.SparcInterrupts( 98 SparcInterrupts(), "Interrupt Controller") 99 elif buildEnv['TARGET_ISA'] == 'alpha': 100 dtb = Param.AlphaTLB(AlphaDTB(), "Data TLB") 101 itb = Param.AlphaTLB(AlphaITB(), "Instruction TLB") 102 if buildEnv['FULL_SYSTEM']: 103 interrupts = Param.AlphaInterrupts( 104 AlphaInterrupts(), "Interrupt Controller") 105 elif buildEnv['TARGET_ISA'] == 'x86': 106 dtb = Param.X86TLB(X86TLB(), "Data TLB") 107 itb = Param.X86TLB(X86TLB(), "Instruction TLB") 108 if buildEnv['FULL_SYSTEM']: 109 _localApic = X86LocalApic(pio_addr=0x2000000000000000) 110 interrupts = \ 111 Param.X86LocalApic(_localApic, "Interrupt Controller") 112 elif buildEnv['TARGET_ISA'] == 'mips': 113 dtb = Param.MipsTLB(MipsTLB(), "Data TLB") 114 itb = Param.MipsTLB(MipsTLB(), "Instruction TLB") 115 if buildEnv['FULL_SYSTEM']: 116 interrupts = Param.MipsInterrupts( 117 MipsInterrupts(), "Interrupt Controller") 118 elif buildEnv['TARGET_ISA'] == 'arm': 119 dtb = Param.ArmTLB(ArmTLB(), "Data TLB") 120 itb = Param.ArmTLB(ArmTLB(), "Instruction TLB") 121 if buildEnv['FULL_SYSTEM']: 122 interrupts = Param.ArmInterrupts( 123 ArmInterrupts(), "Interrupt Controller") 124 elif buildEnv['TARGET_ISA'] == 'power': 125 UnifiedTLB = Param.Bool(True, "Is this a Unified TLB?") 126 dtb = Param.PowerTLB(PowerTLB(), "Data TLB") 127 itb = Param.PowerTLB(PowerTLB(), "Instruction TLB") 128 if buildEnv['FULL_SYSTEM']: 129 interrupts = Param.PowerInterrupts( 130 PowerInterrupts(), "Interrupt Controller") 131 else: 132 print "Don't know what TLB to use for ISA %s" % \ 133 buildEnv['TARGET_ISA'] 134 sys.exit(1) 135 136 max_insts_all_threads = Param.Counter(0, 137 "terminate when all threads have reached this inst count") 138 max_insts_any_thread = Param.Counter(0, 139 "terminate when any thread reaches this inst count") 140 max_loads_all_threads = Param.Counter(0, 141 "terminate when all threads have reached this load count") 142 max_loads_any_thread = Param.Counter(0, 143 "terminate when any thread reaches this load count") 144 progress_interval = Param.Tick(0, 145 "interval to print out the progress message") 146 147 defer_registration = Param.Bool(False, 148 "defer registration with system (for sampling)") 149 150 clock = Param.Clock('1t', "clock speed") 151 phase = Param.Latency('0ns', "clock phase") 152 153 tracer = Param.InstTracer(default_tracer, "Instruction tracer") 154 155 _cached_ports = [] 156 if buildEnv['TARGET_ISA'] in ['x86', 'arm'] and buildEnv['FULL_SYSTEM']: 157 _cached_ports = ["itb.walker.port", "dtb.walker.port"] 158 159 _uncached_ports = [] 160 if buildEnv['TARGET_ISA'] == 'x86' and buildEnv['FULL_SYSTEM']: 161 _uncached_ports = ["interrupts.pio", "interrupts.int_port"] 162 163 def connectCachedPorts(self, bus): 164 for p in self._cached_ports: 165 exec('self.%s = bus.port' % p) 166 167 def connectUncachedPorts(self, bus): 168 for p in self._uncached_ports: 169 exec('self.%s = bus.port' % p) 170 171 def connectAllPorts(self, cached_bus, uncached_bus = None): 172 self.connectCachedPorts(cached_bus) 173 if not uncached_bus: 174 uncached_bus = cached_bus 175 self.connectUncachedPorts(uncached_bus) 176 177 def addPrivateSplitL1Caches(self, ic, dc, iwc = None, dwc = None): 178 assert(len(self._cached_ports) < 7) 179 self.icache = ic 180 self.dcache = dc 181 self.icache_port = ic.cpu_side 182 self.dcache_port = dc.cpu_side 183 self._cached_ports = ['icache.mem_side', 'dcache.mem_side'] 184 if buildEnv['FULL_SYSTEM']: 185 if buildEnv['TARGET_ISA'] == 'x86': 186 self.itb_walker_cache = iwc 187 self.dtb_walker_cache = dwc 188 self.itb.walker.port = iwc.cpu_side 189 self.dtb.walker.port = dwc.cpu_side 190 self._cached_ports += ["itb_walker_cache.mem_side", \ 191 "dtb_walker_cache.mem_side"] 192 elif buildEnv['TARGET_ISA'] == 'arm': 193 self._cached_ports += ["itb.walker.port", "dtb.walker.port"] 194 195 def addTwoLevelCacheHierarchy(self, ic, dc, l2c, iwc = None, dwc = None): 196 self.addPrivateSplitL1Caches(ic, dc, iwc, dwc) 197 self.toL2Bus = Bus() 198 self.connectCachedPorts(self.toL2Bus) 199 self.l2cache = l2c 200 self.l2cache.cpu_side = self.toL2Bus.port 201 self._cached_ports = ['l2cache.mem_side'] 202 203 if buildEnv['TARGET_ISA'] == 'mips': 204 CP0_IntCtl_IPTI = Param.Unsigned(0,"No Description") 205 CP0_IntCtl_IPPCI = Param.Unsigned(0,"No Description") 206 CP0_SrsCtl_HSS = Param.Unsigned(0,"No Description") 207 CP0_EBase_CPUNum = Param.Unsigned(0,"No Description") 208 CP0_PRId_CompanyOptions = Param.Unsigned(0,"Company Options in Processor ID Register") 209 CP0_PRId_CompanyID = Param.Unsigned(0,"Company Identifier in Processor ID Register") 210 CP0_PRId_ProcessorID = Param.Unsigned(1,"Processor ID (0=>Not MIPS32/64 Processor, 1=>MIPS, 2-255 => Other Company") 211 CP0_PRId_Revision = Param.Unsigned(0,"Processor Revision Number in Processor ID Register") 212 CP0_Config_BE = Param.Unsigned(0,"Big Endian?") 213 CP0_Config_AT = Param.Unsigned(0,"No Description") 214 CP0_Config_AR = Param.Unsigned(0,"No Description") 215 CP0_Config_MT = Param.Unsigned(0,"No Description") 216 CP0_Config_VI = Param.Unsigned(0,"No Description") 217 CP0_Config1_M = Param.Unsigned(0,"Config2 Implemented?") 218 CP0_Config1_MMU = Param.Unsigned(0,"MMU Type") 219 CP0_Config1_IS = Param.Unsigned(0,"No Description") 220 CP0_Config1_IL = Param.Unsigned(0,"No Description") 221 CP0_Config1_IA = Param.Unsigned(0,"No Description") 222 CP0_Config1_DS = Param.Unsigned(0,"No Description") 223 CP0_Config1_DL = Param.Unsigned(0,"No Description") 224 CP0_Config1_DA = Param.Unsigned(0,"No Description") 225 CP0_Config1_C2 = Param.Bool(False,"No Description") 226 CP0_Config1_MD = Param.Bool(False,"No Description") 227 CP0_Config1_PC = Param.Bool(False,"No Description") 228 CP0_Config1_WR = Param.Bool(False,"No Description") 229 CP0_Config1_CA = Param.Bool(False,"No Description") 230 CP0_Config1_EP = Param.Bool(False,"No Description") 231 CP0_Config1_FP = Param.Bool(False,"FPU Implemented?") 232 CP0_Config2_M = Param.Bool(False,"Config3 Implemented?") 233 CP0_Config2_TU = Param.Unsigned(0,"No Description") 234 CP0_Config2_TS = Param.Unsigned(0,"No Description") 235 CP0_Config2_TL = Param.Unsigned(0,"No Description") 236 CP0_Config2_TA = Param.Unsigned(0,"No Description") 237 CP0_Config2_SU = Param.Unsigned(0,"No Description") 238 CP0_Config2_SS = Param.Unsigned(0,"No Description") 239 CP0_Config2_SL = Param.Unsigned(0,"No Description") 240 CP0_Config2_SA = Param.Unsigned(0,"No Description") 241 CP0_Config3_M = Param.Bool(False,"Config4 Implemented?") 242 CP0_Config3_DSPP = Param.Bool(False,"DSP Extensions Present?") 243 CP0_Config3_LPA = Param.Bool(False,"No Description") 244 CP0_Config3_VEIC = Param.Bool(False,"No Description") 245 CP0_Config3_VInt = Param.Bool(False,"No Description") 246 CP0_Config3_SP = Param.Bool(False,"No Description") 247 CP0_Config3_MT = Param.Bool(False,"Multithreading Extensions Present?") 248 CP0_Config3_SM = Param.Bool(False,"No Description") 249 CP0_Config3_TL = Param.Bool(False,"No Description") 250 CP0_WatchHi_M = Param.Bool(False,"No Description") 251 CP0_PerfCtr_M = Param.Bool(False,"No Description") 252 CP0_PerfCtr_W = Param.Bool(False,"No Description") 253 CP0_PRId = Param.Unsigned(0,"CP0 Status Register") 254 CP0_Config = Param.Unsigned(0,"CP0 Config Register") 255 CP0_Config1 = Param.Unsigned(0,"CP0 Config1 Register") 256 CP0_Config2 = Param.Unsigned(0,"CP0 Config2 Register") 257 CP0_Config3 = Param.Unsigned(0,"CP0 Config3 Register") 258