BaseCPU.py revision 6691
110249Sstephan.diestelhorst@arm.com# Copyright (c) 2005-2008 The Regents of The University of Michigan
210249Sstephan.diestelhorst@arm.com# All rights reserved.
310249Sstephan.diestelhorst@arm.com#
410249Sstephan.diestelhorst@arm.com# Redistribution and use in source and binary forms, with or without
510249Sstephan.diestelhorst@arm.com# modification, are permitted provided that the following conditions are
610249Sstephan.diestelhorst@arm.com# met: redistributions of source code must retain the above copyright
710249Sstephan.diestelhorst@arm.com# notice, this list of conditions and the following disclaimer;
810249Sstephan.diestelhorst@arm.com# redistributions in binary form must reproduce the above copyright
910249Sstephan.diestelhorst@arm.com# notice, this list of conditions and the following disclaimer in the
1010249Sstephan.diestelhorst@arm.com# documentation and/or other materials provided with the distribution;
1110249Sstephan.diestelhorst@arm.com# neither the name of the copyright holders nor the names of its
1210249Sstephan.diestelhorst@arm.com# contributors may be used to endorse or promote products derived from
1310249Sstephan.diestelhorst@arm.com# this software without specific prior written permission.
1410249Sstephan.diestelhorst@arm.com#
1510249Sstephan.diestelhorst@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1610249Sstephan.diestelhorst@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1710249Sstephan.diestelhorst@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1810249Sstephan.diestelhorst@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1910249Sstephan.diestelhorst@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2010249Sstephan.diestelhorst@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2110249Sstephan.diestelhorst@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2210249Sstephan.diestelhorst@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2310249Sstephan.diestelhorst@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2410249Sstephan.diestelhorst@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2510249Sstephan.diestelhorst@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2610249Sstephan.diestelhorst@arm.com#
2710249Sstephan.diestelhorst@arm.com# Authors: Nathan Binkert
2810249Sstephan.diestelhorst@arm.com
2910249Sstephan.diestelhorst@arm.comimport sys
3010249Sstephan.diestelhorst@arm.com
3110249Sstephan.diestelhorst@arm.comfrom m5.defines import buildEnv
3210249Sstephan.diestelhorst@arm.comfrom m5.params import *
3310249Sstephan.diestelhorst@arm.comfrom m5.proxy import *
3410249Sstephan.diestelhorst@arm.com
3510249Sstephan.diestelhorst@arm.comfrom Bus import Bus
3610249Sstephan.diestelhorst@arm.comfrom InstTracer import InstTracer
3710249Sstephan.diestelhorst@arm.comfrom ExeTracer import ExeTracer
3810249Sstephan.diestelhorst@arm.comfrom MemObject import MemObject
3910249Sstephan.diestelhorst@arm.com
4010249Sstephan.diestelhorst@arm.comdefault_tracer = ExeTracer()
4110249Sstephan.diestelhorst@arm.com
4210249Sstephan.diestelhorst@arm.comif buildEnv['TARGET_ISA'] == 'alpha':
4310249Sstephan.diestelhorst@arm.com    from AlphaTLB import AlphaDTB, AlphaITB
4410249Sstephan.diestelhorst@arm.com    if buildEnv['FULL_SYSTEM']:
4510249Sstephan.diestelhorst@arm.com        from AlphaInterrupts import AlphaInterrupts
4610249Sstephan.diestelhorst@arm.comelif buildEnv['TARGET_ISA'] == 'sparc':
4710249Sstephan.diestelhorst@arm.com    from SparcTLB import SparcTLB
4810249Sstephan.diestelhorst@arm.com    if buildEnv['FULL_SYSTEM']:
4910249Sstephan.diestelhorst@arm.com        from SparcInterrupts import SparcInterrupts
5010249Sstephan.diestelhorst@arm.comelif buildEnv['TARGET_ISA'] == 'x86':
5110249Sstephan.diestelhorst@arm.com    from X86TLB import X86TLB
5210249Sstephan.diestelhorst@arm.com    if buildEnv['FULL_SYSTEM']:
5310249Sstephan.diestelhorst@arm.com        from X86LocalApic import X86LocalApic
5410249Sstephan.diestelhorst@arm.comelif buildEnv['TARGET_ISA'] == 'mips':
5510249Sstephan.diestelhorst@arm.com    from MipsTLB import MipsTLB
5610249Sstephan.diestelhorst@arm.com    if buildEnv['FULL_SYSTEM']:
5710249Sstephan.diestelhorst@arm.com        from MipsInterrupts import MipsInterrupts
5810249Sstephan.diestelhorst@arm.comelif buildEnv['TARGET_ISA'] == 'arm':
5910249Sstephan.diestelhorst@arm.com    from ArmTLB import ArmTLB
6010249Sstephan.diestelhorst@arm.com    if buildEnv['FULL_SYSTEM']:
6110249Sstephan.diestelhorst@arm.com        from ArmInterrupts import ArmInterrupts
6210249Sstephan.diestelhorst@arm.comelif buildEnv['TARGET_ISA'] == 'power':
6310249Sstephan.diestelhorst@arm.com    from PowerTLB import PowerTLB
6410249Sstephan.diestelhorst@arm.com    if buildEnv['FULL_SYSTEM']:
6510249Sstephan.diestelhorst@arm.com        from PowerInterrupts import PowerInterrupts
6610249Sstephan.diestelhorst@arm.com
6710249Sstephan.diestelhorst@arm.comclass BaseCPU(MemObject):
6810249Sstephan.diestelhorst@arm.com    type = 'BaseCPU'
69    abstract = True
70
71    system = Param.System(Parent.any, "system object")
72    cpu_id = Param.Int(-1, "CPU identifier")
73    numThreads = Param.Unsigned(1, "number of HW thread contexts")
74
75    function_trace = Param.Bool(False, "Enable function trace")
76    function_trace_start = Param.Tick(0, "Cycle to start function trace")
77
78    checker = Param.BaseCPU(NULL, "checker CPU")
79
80    do_checkpoint_insts = Param.Bool(True,
81        "enable checkpoint pseudo instructions")
82    do_statistics_insts = Param.Bool(True,
83        "enable statistics pseudo instructions")
84
85    if buildEnv['FULL_SYSTEM']:
86        profile = Param.Latency('0ns', "trace the kernel stack")
87        do_quiesce = Param.Bool(True, "enable quiesce instructions")
88    else:
89        workload = VectorParam.Process("processes to run")
90
91    if buildEnv['TARGET_ISA'] == 'sparc':
92        dtb = Param.SparcTLB(SparcTLB(), "Data TLB")
93        itb = Param.SparcTLB(SparcTLB(), "Instruction TLB")
94        if buildEnv['FULL_SYSTEM']:
95            interrupts = Param.SparcInterrupts(
96                SparcInterrupts(), "Interrupt Controller")
97    elif buildEnv['TARGET_ISA'] == 'alpha':
98        dtb = Param.AlphaTLB(AlphaDTB(), "Data TLB")
99        itb = Param.AlphaTLB(AlphaITB(), "Instruction TLB")
100        if buildEnv['FULL_SYSTEM']:
101            interrupts = Param.AlphaInterrupts(
102                AlphaInterrupts(), "Interrupt Controller")
103    elif buildEnv['TARGET_ISA'] == 'x86':
104        dtb = Param.X86TLB(X86TLB(), "Data TLB")
105        itb = Param.X86TLB(X86TLB(), "Instruction TLB")
106        if buildEnv['FULL_SYSTEM']:
107            _localApic = X86LocalApic(pio_addr=0x2000000000000000)
108            interrupts = \
109                Param.X86LocalApic(_localApic, "Interrupt Controller")
110    elif buildEnv['TARGET_ISA'] == 'mips':
111        dtb = Param.MipsTLB(MipsTLB(), "Data TLB")
112        itb = Param.MipsTLB(MipsTLB(), "Instruction TLB")
113        if buildEnv['FULL_SYSTEM']:
114            interrupts = Param.MipsInterrupts(
115                    MipsInterrupts(), "Interrupt Controller")
116    elif buildEnv['TARGET_ISA'] == 'arm':
117        UnifiedTLB = Param.Bool(True, "Is this a Unified TLB?")
118        dtb = Param.ArmTLB(ArmTLB(), "Data TLB")
119        itb = Param.ArmTLB(ArmTLB(), "Instruction TLB")
120        if buildEnv['FULL_SYSTEM']:
121            interrupts = Param.ArmInterrupts(
122                    ArmInterrupts(), "Interrupt Controller")
123    elif buildEnv['TARGET_ISA'] == 'power':
124        UnifiedTLB = Param.Bool(True, "Is this a Unified TLB?")
125        dtb = Param.PowerTLB(PowerTLB(), "Data TLB")
126        itb = Param.PowerTLB(PowerTLB(), "Instruction TLB")
127        if buildEnv['FULL_SYSTEM']:
128            interrupts = Param.PowerInterrupts(
129                    PowerInterrupts(), "Interrupt Controller")
130    else:
131        print "Don't know what TLB to use for ISA %s" % \
132            buildEnv['TARGET_ISA']
133        sys.exit(1)
134
135    max_insts_all_threads = Param.Counter(0,
136        "terminate when all threads have reached this inst count")
137    max_insts_any_thread = Param.Counter(0,
138        "terminate when any thread reaches this inst count")
139    max_loads_all_threads = Param.Counter(0,
140        "terminate when all threads have reached this load count")
141    max_loads_any_thread = Param.Counter(0,
142        "terminate when any thread reaches this load count")
143    progress_interval = Param.Tick(0,
144        "interval to print out the progress message")
145
146    defer_registration = Param.Bool(False,
147        "defer registration with system (for sampling)")
148
149    clock = Param.Clock('1t', "clock speed")
150    phase = Param.Latency('0ns', "clock phase")
151
152    tracer = Param.InstTracer(default_tracer, "Instruction tracer")
153
154    _mem_ports = []
155    if buildEnv['TARGET_ISA'] == 'x86' and buildEnv['FULL_SYSTEM']:
156        _mem_ports = ["itb.walker.port",
157                      "dtb.walker.port",
158                      "interrupts.pio",
159                      "interrupts.int_port"]
160
161    def connectMemPorts(self, bus):
162        for p in self._mem_ports:
163            if p != 'physmem_port':
164                exec('self.%s = bus.port' % p)
165
166    def addPrivateSplitL1Caches(self, ic, dc):
167        assert(len(self._mem_ports) < 6)
168        self.icache = ic
169        self.dcache = dc
170        self.icache_port = ic.cpu_side
171        self.dcache_port = dc.cpu_side
172        self._mem_ports = ['icache.mem_side', 'dcache.mem_side']
173        if buildEnv['TARGET_ISA'] == 'x86' and buildEnv['FULL_SYSTEM']:
174            self._mem_ports += ["itb.walker_port", "dtb.walker_port"]
175
176    def addTwoLevelCacheHierarchy(self, ic, dc, l2c):
177        self.addPrivateSplitL1Caches(ic, dc)
178        self.toL2Bus = Bus()
179        self.connectMemPorts(self.toL2Bus)
180        self.l2cache = l2c
181        self.l2cache.cpu_side = self.toL2Bus.port
182        self._mem_ports = ['l2cache.mem_side']
183
184    if buildEnv['TARGET_ISA'] == 'mips':
185        CP0_IntCtl_IPTI = Param.Unsigned(0,"No Description")
186        CP0_IntCtl_IPPCI = Param.Unsigned(0,"No Description")
187        CP0_SrsCtl_HSS = Param.Unsigned(0,"No Description")
188        CP0_EBase_CPUNum = Param.Unsigned(0,"No Description")
189        CP0_PRId_CompanyOptions = Param.Unsigned(0,"Company Options in Processor ID Register")
190        CP0_PRId_CompanyID = Param.Unsigned(0,"Company Identifier in Processor ID Register")
191        CP0_PRId_ProcessorID = Param.Unsigned(1,"Processor ID (0=>Not MIPS32/64 Processor, 1=>MIPS, 2-255 => Other Company")
192        CP0_PRId_Revision = Param.Unsigned(0,"Processor Revision Number in Processor ID Register")
193        CP0_Config_BE = Param.Unsigned(0,"Big Endian?")
194        CP0_Config_AT = Param.Unsigned(0,"No Description")
195        CP0_Config_AR = Param.Unsigned(0,"No Description")
196        CP0_Config_MT = Param.Unsigned(0,"No Description")
197        CP0_Config_VI = Param.Unsigned(0,"No Description")
198        CP0_Config1_M = Param.Unsigned(0,"Config2 Implemented?")
199        CP0_Config1_MMU = Param.Unsigned(0,"MMU Type")
200        CP0_Config1_IS = Param.Unsigned(0,"No Description")
201        CP0_Config1_IL = Param.Unsigned(0,"No Description")
202        CP0_Config1_IA = Param.Unsigned(0,"No Description")
203        CP0_Config1_DS = Param.Unsigned(0,"No Description")
204        CP0_Config1_DL = Param.Unsigned(0,"No Description")
205        CP0_Config1_DA = Param.Unsigned(0,"No Description")
206        CP0_Config1_C2 = Param.Bool(False,"No Description")
207        CP0_Config1_MD = Param.Bool(False,"No Description")
208        CP0_Config1_PC = Param.Bool(False,"No Description")
209        CP0_Config1_WR = Param.Bool(False,"No Description")
210        CP0_Config1_CA = Param.Bool(False,"No Description")
211        CP0_Config1_EP = Param.Bool(False,"No Description")
212        CP0_Config1_FP = Param.Bool(False,"FPU Implemented?")
213        CP0_Config2_M = Param.Bool(False,"Config3 Implemented?")
214        CP0_Config2_TU = Param.Unsigned(0,"No Description")
215        CP0_Config2_TS = Param.Unsigned(0,"No Description")
216        CP0_Config2_TL = Param.Unsigned(0,"No Description")
217        CP0_Config2_TA = Param.Unsigned(0,"No Description")
218        CP0_Config2_SU = Param.Unsigned(0,"No Description")
219        CP0_Config2_SS = Param.Unsigned(0,"No Description")
220        CP0_Config2_SL = Param.Unsigned(0,"No Description")
221        CP0_Config2_SA = Param.Unsigned(0,"No Description")
222        CP0_Config3_M = Param.Bool(False,"Config4 Implemented?")
223        CP0_Config3_DSPP = Param.Bool(False,"DSP Extensions Present?")
224        CP0_Config3_LPA = Param.Bool(False,"No Description")
225        CP0_Config3_VEIC = Param.Bool(False,"No Description")
226        CP0_Config3_VInt = Param.Bool(False,"No Description")
227        CP0_Config3_SP = Param.Bool(False,"No Description")
228        CP0_Config3_MT = Param.Bool(False,"Multithreading Extensions Present?")
229        CP0_Config3_SM = Param.Bool(False,"No Description")
230        CP0_Config3_TL = Param.Bool(False,"No Description")
231        CP0_WatchHi_M = Param.Bool(False,"No Description")
232        CP0_PerfCtr_M = Param.Bool(False,"No Description")
233        CP0_PerfCtr_W = Param.Bool(False,"No Description")
234        CP0_PRId = Param.Unsigned(0,"CP0 Status Register")
235        CP0_Config = Param.Unsigned(0,"CP0 Config Register")
236        CP0_Config1 = Param.Unsigned(0,"CP0 Config1 Register")
237        CP0_Config2 = Param.Unsigned(0,"CP0 Config2 Register")
238        CP0_Config3 = Param.Unsigned(0,"CP0 Config3 Register")
239