BaseCPU.py revision 9338
1695SN/A# Copyright (c) 2012 ARM Limited
29262Ssascha.bischoff@arm.com# All rights reserved.
39262Ssascha.bischoff@arm.com#
49262Ssascha.bischoff@arm.com# The license below extends only to copyright in the software and shall
59262Ssascha.bischoff@arm.com# not be construed as granting a license to any other intellectual
69262Ssascha.bischoff@arm.com# property including but not limited to intellectual property relating
79262Ssascha.bischoff@arm.com# to a hardware implementation of the functionality of the software
89262Ssascha.bischoff@arm.com# licensed hereunder.  You may use the software subject to the license
99262Ssascha.bischoff@arm.com# terms below provided that you ensure that this notice is replicated
109262Ssascha.bischoff@arm.com# unmodified and in its entirety in all distributions of the software,
119262Ssascha.bischoff@arm.com# modified or unmodified, in source code or in binary form.
129262Ssascha.bischoff@arm.com#
139262Ssascha.bischoff@arm.com# Copyright (c) 2005-2008 The Regents of The University of Michigan
141762SN/A# Copyright (c) 2011 Regents of the University of California
15695SN/A# All rights reserved.
16695SN/A#
17695SN/A# Redistribution and use in source and binary forms, with or without
18695SN/A# modification, are permitted provided that the following conditions are
19695SN/A# met: redistributions of source code must retain the above copyright
20695SN/A# notice, this list of conditions and the following disclaimer;
21695SN/A# redistributions in binary form must reproduce the above copyright
22695SN/A# notice, this list of conditions and the following disclaimer in the
23695SN/A# documentation and/or other materials provided with the distribution;
24695SN/A# neither the name of the copyright holders nor the names of its
25695SN/A# contributors may be used to endorse or promote products derived from
26695SN/A# this software without specific prior written permission.
27695SN/A#
28695SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29695SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30695SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31695SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32695SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33695SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34695SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35695SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36695SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37695SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38695SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu#
402665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert
419262Ssascha.bischoff@arm.com#          Rick Strong
42695SN/A#          Andreas Hansson
43695SN/A
44695SN/Aimport sys
45695SN/A
46695SN/Afrom m5.defines import buildEnv
47729SN/Afrom m5.params import *
48695SN/Afrom m5.proxy import *
499554Sandreas.hansson@arm.com
509554Sandreas.hansson@arm.comfrom Bus import CoherentBus
519554Sandreas.hansson@arm.comfrom InstTracer import InstTracer
529554Sandreas.hansson@arm.comfrom ExeTracer import ExeTracer
539554Sandreas.hansson@arm.comfrom MemObject import MemObject
549554Sandreas.hansson@arm.com
554078Sbinkertn@umich.edudefault_tracer = ExeTracer()
569262Ssascha.bischoff@arm.com
579262Ssascha.bischoff@arm.comif buildEnv['TARGET_ISA'] == 'alpha':
589262Ssascha.bischoff@arm.com    from AlphaTLB import AlphaDTB, AlphaITB
599262Ssascha.bischoff@arm.com    from AlphaInterrupts import AlphaInterrupts
609262Ssascha.bischoff@arm.comelif buildEnv['TARGET_ISA'] == 'sparc':
619262Ssascha.bischoff@arm.com    from SparcTLB import SparcTLB
629262Ssascha.bischoff@arm.com    from SparcInterrupts import SparcInterrupts
639262Ssascha.bischoff@arm.comelif buildEnv['TARGET_ISA'] == 'x86':
649262Ssascha.bischoff@arm.com    from X86TLB import X86TLB
659262Ssascha.bischoff@arm.com    from X86LocalApic import X86LocalApic
669262Ssascha.bischoff@arm.comelif buildEnv['TARGET_ISA'] == 'mips':
679262Ssascha.bischoff@arm.com    from MipsTLB import MipsTLB
689262Ssascha.bischoff@arm.com    from MipsInterrupts import MipsInterrupts
699262Ssascha.bischoff@arm.comelif buildEnv['TARGET_ISA'] == 'arm':
709262Ssascha.bischoff@arm.com    from ArmTLB import ArmTLB
719262Ssascha.bischoff@arm.com    from ArmInterrupts import ArmInterrupts
729262Ssascha.bischoff@arm.comelif buildEnv['TARGET_ISA'] == 'power':
739262Ssascha.bischoff@arm.com    from PowerTLB import PowerTLB
747823Ssteve.reinhardt@amd.com    from PowerInterrupts import PowerInterrupts
757822Ssteve.reinhardt@amd.com
76695SN/Aclass BaseCPU(MemObject):
779262Ssascha.bischoff@arm.com    type = 'BaseCPU'
789262Ssascha.bischoff@arm.com    abstract = True
799262Ssascha.bischoff@arm.com    cxx_header = "cpu/base.hh"
809262Ssascha.bischoff@arm.com
819262Ssascha.bischoff@arm.com    @classmethod
829262Ssascha.bischoff@arm.com    def export_methods(cls, code):
839450Ssascha.bischoff@arm.com        code('''
847811Ssteve.reinhardt@amd.com    void switchOut();
85695SN/A    void takeOverFrom(BaseCPU *cpu);
86695SN/A''')
87
88    def takeOverFrom(self, old_cpu):
89        self._ccObject.takeOverFrom(old_cpu._ccObject)
90
91
92    system = Param.System(Parent.any, "system object")
93    cpu_id = Param.Int(-1, "CPU identifier")
94    numThreads = Param.Unsigned(1, "number of HW thread contexts")
95
96    function_trace = Param.Bool(False, "Enable function trace")
97    function_trace_start = Param.Tick(0, "Tick to start function trace")
98
99    checker = Param.BaseCPU(NULL, "checker CPU")
100
101    do_checkpoint_insts = Param.Bool(True,
102        "enable checkpoint pseudo instructions")
103    do_statistics_insts = Param.Bool(True,
104        "enable statistics pseudo instructions")
105
106    profile = Param.Latency('0ns', "trace the kernel stack")
107    do_quiesce = Param.Bool(True, "enable quiesce instructions")
108
109    workload = VectorParam.Process([], "processes to run")
110
111    if buildEnv['TARGET_ISA'] == 'sparc':
112        dtb = Param.SparcTLB(SparcTLB(), "Data TLB")
113        itb = Param.SparcTLB(SparcTLB(), "Instruction TLB")
114        interrupts = Param.SparcInterrupts(
115                NULL, "Interrupt Controller")
116    elif buildEnv['TARGET_ISA'] == 'alpha':
117        dtb = Param.AlphaTLB(AlphaDTB(), "Data TLB")
118        itb = Param.AlphaTLB(AlphaITB(), "Instruction TLB")
119        interrupts = Param.AlphaInterrupts(
120                NULL, "Interrupt Controller")
121    elif buildEnv['TARGET_ISA'] == 'x86':
122        dtb = Param.X86TLB(X86TLB(), "Data TLB")
123        itb = Param.X86TLB(X86TLB(), "Instruction TLB")
124        interrupts = Param.X86LocalApic(NULL, "Interrupt Controller")
125    elif buildEnv['TARGET_ISA'] == 'mips':
126        dtb = Param.MipsTLB(MipsTLB(), "Data TLB")
127        itb = Param.MipsTLB(MipsTLB(), "Instruction TLB")
128        interrupts = Param.MipsInterrupts(
129                NULL, "Interrupt Controller")
130    elif buildEnv['TARGET_ISA'] == 'arm':
131        dtb = Param.ArmTLB(ArmTLB(), "Data TLB")
132        itb = Param.ArmTLB(ArmTLB(), "Instruction TLB")
133        interrupts = Param.ArmInterrupts(
134                NULL, "Interrupt Controller")
135    elif buildEnv['TARGET_ISA'] == 'power':
136        UnifiedTLB = Param.Bool(True, "Is this a Unified TLB?")
137        dtb = Param.PowerTLB(PowerTLB(), "Data TLB")
138        itb = Param.PowerTLB(PowerTLB(), "Instruction TLB")
139        interrupts = Param.PowerInterrupts(
140                NULL, "Interrupt Controller")
141    else:
142        print "Don't know what TLB to use for ISA %s" % \
143            buildEnv['TARGET_ISA']
144        sys.exit(1)
145
146    max_insts_all_threads = Param.Counter(0,
147        "terminate when all threads have reached this inst count")
148    max_insts_any_thread = Param.Counter(0,
149        "terminate when any thread reaches this inst count")
150    max_loads_all_threads = Param.Counter(0,
151        "terminate when all threads have reached this load count")
152    max_loads_any_thread = Param.Counter(0,
153        "terminate when any thread reaches this load count")
154    progress_interval = Param.Frequency('0Hz',
155        "frequency to print out the progress message")
156
157    defer_registration = Param.Bool(False,
158        "defer registration with system (for sampling)")
159
160    tracer = Param.InstTracer(default_tracer, "Instruction tracer")
161
162    icache_port = MasterPort("Instruction Port")
163    dcache_port = MasterPort("Data Port")
164    _cached_ports = ['icache_port', 'dcache_port']
165
166    if buildEnv['TARGET_ISA'] in ['x86', 'arm']:
167        _cached_ports += ["itb.walker.port", "dtb.walker.port"]
168
169    _uncached_slave_ports = []
170    _uncached_master_ports = []
171    if buildEnv['TARGET_ISA'] == 'x86':
172        _uncached_slave_ports += ["interrupts.pio", "interrupts.int_slave"]
173        _uncached_master_ports += ["interrupts.int_master"]
174
175    def createInterruptController(self):
176        if buildEnv['TARGET_ISA'] == 'sparc':
177            self.interrupts = SparcInterrupts()
178        elif buildEnv['TARGET_ISA'] == 'alpha':
179            self.interrupts = AlphaInterrupts()
180        elif buildEnv['TARGET_ISA'] == 'x86':
181            _localApic = X86LocalApic(pio_addr=0x2000000000000000)
182            self.interrupts = _localApic
183        elif buildEnv['TARGET_ISA'] == 'mips':
184            self.interrupts = MipsInterrupts()
185        elif buildEnv['TARGET_ISA'] == 'arm':
186            self.interrupts = ArmInterrupts()
187        elif buildEnv['TARGET_ISA'] == 'power':
188            self.interrupts = PowerInterrupts()
189        else:
190            print "Don't know what Interrupt Controller to use for ISA %s" % \
191                buildEnv['TARGET_ISA']
192            sys.exit(1)
193
194    def connectCachedPorts(self, bus):
195        for p in self._cached_ports:
196            exec('self.%s = bus.slave' % p)
197
198    def connectUncachedPorts(self, bus):
199        for p in self._uncached_slave_ports:
200            exec('self.%s = bus.master' % p)
201        for p in self._uncached_master_ports:
202            exec('self.%s = bus.slave' % p)
203
204    def connectAllPorts(self, cached_bus, uncached_bus = None):
205        self.connectCachedPorts(cached_bus)
206        if not uncached_bus:
207            uncached_bus = cached_bus
208        self.connectUncachedPorts(uncached_bus)
209
210    def addPrivateSplitL1Caches(self, ic, dc, iwc = None, dwc = None):
211        self.icache = ic
212        self.dcache = dc
213        self.icache_port = ic.cpu_side
214        self.dcache_port = dc.cpu_side
215        self._cached_ports = ['icache.mem_side', 'dcache.mem_side']
216        if buildEnv['TARGET_ISA'] in ['x86', 'arm']:
217            if iwc and dwc:
218                self.itb_walker_cache = iwc
219                self.dtb_walker_cache = dwc
220                self.itb.walker.port = iwc.cpu_side
221                self.dtb.walker.port = dwc.cpu_side
222                self._cached_ports += ["itb_walker_cache.mem_side", \
223                                       "dtb_walker_cache.mem_side"]
224            else:
225                self._cached_ports += ["itb.walker.port", "dtb.walker.port"]
226
227            # Checker doesn't need its own tlb caches because it does
228            # functional accesses only
229            if self.checker != NULL:
230                self._cached_ports += ["checker.itb.walker.port", \
231                                       "checker.dtb.walker.port"]
232
233    def addTwoLevelCacheHierarchy(self, ic, dc, l2c, iwc = None, dwc = None):
234        self.addPrivateSplitL1Caches(ic, dc, iwc, dwc)
235        # Override the default bus clock of 1 GHz and uses the CPU
236        # clock for the L1-to-L2 bus, and also set a width of 32 bytes
237        # (256-bits), which is four times that of the default bus.
238        self.toL2Bus = CoherentBus(clock = Parent.clock, width = 32)
239        self.connectCachedPorts(self.toL2Bus)
240        self.l2cache = l2c
241        self.toL2Bus.master = self.l2cache.cpu_side
242        self._cached_ports = ['l2cache.mem_side']
243
244    def addCheckerCpu(self):
245        pass
246