BaseCPU.py revision 9161
18839Sandreas.hansson@arm.com# Copyright (c) 2012 ARM Limited
28839Sandreas.hansson@arm.com# All rights reserved.
38839Sandreas.hansson@arm.com#
48839Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall
58839Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual
68839Sandreas.hansson@arm.com# property including but not limited to intellectual property relating
78839Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software
88839Sandreas.hansson@arm.com# licensed hereunder.  You may use the software subject to the license
98839Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated
108839Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software,
118839Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form.
128839Sandreas.hansson@arm.com#
135335Shines@cs.fsu.edu# Copyright (c) 2005-2008 The Regents of The University of Michigan
147897Shestness@cs.utexas.edu# Copyright (c) 2011 Regents of the University of California
154486Sbinkertn@umich.edu# All rights reserved.
164486Sbinkertn@umich.edu#
174486Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without
184486Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are
194486Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright
204486Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer;
214486Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright
224486Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the
234486Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution;
244486Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its
254486Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from
264486Sbinkertn@umich.edu# this software without specific prior written permission.
274486Sbinkertn@umich.edu#
284486Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
294486Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
304486Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
314486Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
324486Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
334486Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
344486Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
354486Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364486Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
374486Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
384486Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
394486Sbinkertn@umich.edu#
404486Sbinkertn@umich.edu# Authors: Nathan Binkert
417897Shestness@cs.utexas.edu#          Rick Strong
428839Sandreas.hansson@arm.com#          Andreas Hansson
434486Sbinkertn@umich.edu
446654Snate@binkert.orgimport sys
456654Snate@binkert.org
466654Snate@binkert.orgfrom m5.defines import buildEnv
473102SN/Afrom m5.params import *
483102SN/Afrom m5.proxy import *
496654Snate@binkert.org
509036Sandreas.hansson@arm.comfrom Bus import CoherentBus
514776Sgblack@eecs.umich.edufrom InstTracer import InstTracer
524776Sgblack@eecs.umich.edufrom ExeTracer import ExeTracer
536654Snate@binkert.orgfrom MemObject import MemObject
542667SN/A
554776Sgblack@eecs.umich.edudefault_tracer = ExeTracer()
564776Sgblack@eecs.umich.edu
576654Snate@binkert.orgif buildEnv['TARGET_ISA'] == 'alpha':
586023Snate@binkert.org    from AlphaTLB import AlphaDTB, AlphaITB
598745Sgblack@eecs.umich.edu    from AlphaInterrupts import AlphaInterrupts
606654Snate@binkert.orgelif buildEnv['TARGET_ISA'] == 'sparc':
616022Sgblack@eecs.umich.edu    from SparcTLB import SparcTLB
628745Sgblack@eecs.umich.edu    from SparcInterrupts import SparcInterrupts
636654Snate@binkert.orgelif buildEnv['TARGET_ISA'] == 'x86':
646022Sgblack@eecs.umich.edu    from X86TLB import X86TLB
658745Sgblack@eecs.umich.edu    from X86LocalApic import X86LocalApic
666654Snate@binkert.orgelif buildEnv['TARGET_ISA'] == 'mips':
676022Sgblack@eecs.umich.edu    from MipsTLB import MipsTLB
688745Sgblack@eecs.umich.edu    from MipsInterrupts import MipsInterrupts
696654Snate@binkert.orgelif buildEnv['TARGET_ISA'] == 'arm':
706116Snate@binkert.org    from ArmTLB import ArmTLB
718745Sgblack@eecs.umich.edu    from ArmInterrupts import ArmInterrupts
726691Stjones1@inf.ed.ac.ukelif buildEnv['TARGET_ISA'] == 'power':
736691Stjones1@inf.ed.ac.uk    from PowerTLB import PowerTLB
748745Sgblack@eecs.umich.edu    from PowerInterrupts import PowerInterrupts
754486Sbinkertn@umich.edu
765529Snate@binkert.orgclass BaseCPU(MemObject):
771366SN/A    type = 'BaseCPU'
781310SN/A    abstract = True
791310SN/A
802901SN/A    system = Param.System(Parent.any, "system object")
815712Shsul@eecs.umich.edu    cpu_id = Param.Int(-1, "CPU identifier")
825529Snate@binkert.org    numThreads = Param.Unsigned(1, "number of HW thread contexts")
835529Snate@binkert.org
845529Snate@binkert.org    function_trace = Param.Bool(False, "Enable function trace")
859161Sandreas.hansson@arm.com    function_trace_start = Param.Tick(0, "Tick to start function trace")
865529Snate@binkert.org
875821Ssaidi@eecs.umich.edu    checker = Param.BaseCPU(NULL, "checker CPU")
883170SN/A
895780Ssteve.reinhardt@amd.com    do_checkpoint_insts = Param.Bool(True,
905780Ssteve.reinhardt@amd.com        "enable checkpoint pseudo instructions")
915780Ssteve.reinhardt@amd.com    do_statistics_insts = Param.Bool(True,
925780Ssteve.reinhardt@amd.com        "enable statistics pseudo instructions")
935780Ssteve.reinhardt@amd.com
948784Sgblack@eecs.umich.edu    profile = Param.Latency('0ns', "trace the kernel stack")
958784Sgblack@eecs.umich.edu    do_quiesce = Param.Bool(True, "enable quiesce instructions")
968784Sgblack@eecs.umich.edu
978793Sgblack@eecs.umich.edu    workload = VectorParam.Process([], "processes to run")
981310SN/A
996654Snate@binkert.org    if buildEnv['TARGET_ISA'] == 'sparc':
1006022Sgblack@eecs.umich.edu        dtb = Param.SparcTLB(SparcTLB(), "Data TLB")
1016022Sgblack@eecs.umich.edu        itb = Param.SparcTLB(SparcTLB(), "Instruction TLB")
1028745Sgblack@eecs.umich.edu        interrupts = Param.SparcInterrupts(
1038863Snilay@cs.wisc.edu                NULL, "Interrupt Controller")
1046654Snate@binkert.org    elif buildEnv['TARGET_ISA'] == 'alpha':
1056023Snate@binkert.org        dtb = Param.AlphaTLB(AlphaDTB(), "Data TLB")
1066023Snate@binkert.org        itb = Param.AlphaTLB(AlphaITB(), "Instruction TLB")
1078745Sgblack@eecs.umich.edu        interrupts = Param.AlphaInterrupts(
1088863Snilay@cs.wisc.edu                NULL, "Interrupt Controller")
1096654Snate@binkert.org    elif buildEnv['TARGET_ISA'] == 'x86':
1106022Sgblack@eecs.umich.edu        dtb = Param.X86TLB(X86TLB(), "Data TLB")
1116022Sgblack@eecs.umich.edu        itb = Param.X86TLB(X86TLB(), "Instruction TLB")
1128863Snilay@cs.wisc.edu        interrupts = Param.X86LocalApic(NULL, "Interrupt Controller")
1136654Snate@binkert.org    elif buildEnv['TARGET_ISA'] == 'mips':
1146022Sgblack@eecs.umich.edu        dtb = Param.MipsTLB(MipsTLB(), "Data TLB")
1156022Sgblack@eecs.umich.edu        itb = Param.MipsTLB(MipsTLB(), "Instruction TLB")
1168745Sgblack@eecs.umich.edu        interrupts = Param.MipsInterrupts(
1178863Snilay@cs.wisc.edu                NULL, "Interrupt Controller")
1186654Snate@binkert.org    elif buildEnv['TARGET_ISA'] == 'arm':
1196116Snate@binkert.org        dtb = Param.ArmTLB(ArmTLB(), "Data TLB")
1206116Snate@binkert.org        itb = Param.ArmTLB(ArmTLB(), "Instruction TLB")
1218745Sgblack@eecs.umich.edu        interrupts = Param.ArmInterrupts(
1228863Snilay@cs.wisc.edu                NULL, "Interrupt Controller")
1236691Stjones1@inf.ed.ac.uk    elif buildEnv['TARGET_ISA'] == 'power':
1246691Stjones1@inf.ed.ac.uk        UnifiedTLB = Param.Bool(True, "Is this a Unified TLB?")
1256691Stjones1@inf.ed.ac.uk        dtb = Param.PowerTLB(PowerTLB(), "Data TLB")
1266691Stjones1@inf.ed.ac.uk        itb = Param.PowerTLB(PowerTLB(), "Instruction TLB")
1278745Sgblack@eecs.umich.edu        interrupts = Param.PowerInterrupts(
1288863Snilay@cs.wisc.edu                NULL, "Interrupt Controller")
1294997Sgblack@eecs.umich.edu    else:
1304997Sgblack@eecs.umich.edu        print "Don't know what TLB to use for ISA %s" % \
1316654Snate@binkert.org            buildEnv['TARGET_ISA']
1324997Sgblack@eecs.umich.edu        sys.exit(1)
1334997Sgblack@eecs.umich.edu
1341310SN/A    max_insts_all_threads = Param.Counter(0,
1351310SN/A        "terminate when all threads have reached this inst count")
1361310SN/A    max_insts_any_thread = Param.Counter(0,
1371310SN/A        "terminate when any thread reaches this inst count")
1381310SN/A    max_loads_all_threads = Param.Counter(0,
1391310SN/A        "terminate when all threads have reached this load count")
1401310SN/A    max_loads_any_thread = Param.Counter(0,
1411310SN/A        "terminate when any thread reaches this load count")
1423878SN/A    progress_interval = Param.Tick(0,
1433878SN/A        "interval to print out the progress message")
1441310SN/A
1451369SN/A    defer_registration = Param.Bool(False,
1461310SN/A        "defer registration with system (for sampling)")
1471634SN/A
1484776Sgblack@eecs.umich.edu    tracer = Param.InstTracer(default_tracer, "Instruction tracer")
1494776Sgblack@eecs.umich.edu
1508839Sandreas.hansson@arm.com    icache_port = MasterPort("Instruction Port")
1518839Sandreas.hansson@arm.com    dcache_port = MasterPort("Data Port")
1528707Sandreas.hansson@arm.com    _cached_ports = ['icache_port', 'dcache_port']
1538707Sandreas.hansson@arm.com
1548756Sgblack@eecs.umich.edu    if buildEnv['TARGET_ISA'] in ['x86', 'arm']:
1558707Sandreas.hansson@arm.com        _cached_ports += ["itb.walker.port", "dtb.walker.port"]
1567876Sgblack@eecs.umich.edu
1578839Sandreas.hansson@arm.com    _uncached_slave_ports = []
1588839Sandreas.hansson@arm.com    _uncached_master_ports = []
1598745Sgblack@eecs.umich.edu    if buildEnv['TARGET_ISA'] == 'x86':
1608839Sandreas.hansson@arm.com        _uncached_slave_ports += ["interrupts.pio", "interrupts.int_slave"]
1618839Sandreas.hansson@arm.com        _uncached_master_ports += ["interrupts.int_master"]
1622998SN/A
1638863Snilay@cs.wisc.edu    def createInterruptController(self):
1648863Snilay@cs.wisc.edu        if buildEnv['TARGET_ISA'] == 'sparc':
1658863Snilay@cs.wisc.edu            self.interrupts = SparcInterrupts()
1668863Snilay@cs.wisc.edu        elif buildEnv['TARGET_ISA'] == 'alpha':
1678863Snilay@cs.wisc.edu            self.interrupts = AlphaInterrupts()
1688863Snilay@cs.wisc.edu        elif buildEnv['TARGET_ISA'] == 'x86':
1698863Snilay@cs.wisc.edu            _localApic = X86LocalApic(pio_addr=0x2000000000000000)
1708863Snilay@cs.wisc.edu            self.interrupts = _localApic
1718863Snilay@cs.wisc.edu        elif buildEnv['TARGET_ISA'] == 'mips':
1728863Snilay@cs.wisc.edu            self.interrupts = MipsInterrupts()
1738863Snilay@cs.wisc.edu        elif buildEnv['TARGET_ISA'] == 'arm':
1748863Snilay@cs.wisc.edu            self.interrupts = ArmInterrupts()
1758863Snilay@cs.wisc.edu        elif buildEnv['TARGET_ISA'] == 'power':
1768863Snilay@cs.wisc.edu            self.interrupts = PowerInterrupts()
1778863Snilay@cs.wisc.edu        else:
1788863Snilay@cs.wisc.edu            print "Don't know what Interrupt Controller to use for ISA %s" % \
1798863Snilay@cs.wisc.edu                buildEnv['TARGET_ISA']
1808863Snilay@cs.wisc.edu            sys.exit(1)
1818863Snilay@cs.wisc.edu
1827876Sgblack@eecs.umich.edu    def connectCachedPorts(self, bus):
1837876Sgblack@eecs.umich.edu        for p in self._cached_ports:
1848839Sandreas.hansson@arm.com            exec('self.%s = bus.slave' % p)
1857404SAli.Saidi@ARM.com
1867876Sgblack@eecs.umich.edu    def connectUncachedPorts(self, bus):
1878839Sandreas.hansson@arm.com        for p in self._uncached_slave_ports:
1888839Sandreas.hansson@arm.com            exec('self.%s = bus.master' % p)
1898839Sandreas.hansson@arm.com        for p in self._uncached_master_ports:
1908839Sandreas.hansson@arm.com            exec('self.%s = bus.slave' % p)
1917876Sgblack@eecs.umich.edu
1927876Sgblack@eecs.umich.edu    def connectAllPorts(self, cached_bus, uncached_bus = None):
1937876Sgblack@eecs.umich.edu        self.connectCachedPorts(cached_bus)
1947876Sgblack@eecs.umich.edu        if not uncached_bus:
1957876Sgblack@eecs.umich.edu            uncached_bus = cached_bus
1967876Sgblack@eecs.umich.edu        self.connectUncachedPorts(uncached_bus)
1972998SN/A
1987868Sgblack@eecs.umich.edu    def addPrivateSplitL1Caches(self, ic, dc, iwc = None, dwc = None):
1992998SN/A        self.icache = ic
2002998SN/A        self.dcache = dc
2012998SN/A        self.icache_port = ic.cpu_side
2022998SN/A        self.dcache_port = dc.cpu_side
2037876Sgblack@eecs.umich.edu        self._cached_ports = ['icache.mem_side', 'dcache.mem_side']
2048796Sgblack@eecs.umich.edu        if buildEnv['TARGET_ISA'] in ['x86', 'arm']:
2058796Sgblack@eecs.umich.edu            if iwc and dwc:
2068796Sgblack@eecs.umich.edu                self.itb_walker_cache = iwc
2078796Sgblack@eecs.umich.edu                self.dtb_walker_cache = dwc
2088796Sgblack@eecs.umich.edu                self.itb.walker.port = iwc.cpu_side
2098796Sgblack@eecs.umich.edu                self.dtb.walker.port = dwc.cpu_side
2108796Sgblack@eecs.umich.edu                self._cached_ports += ["itb_walker_cache.mem_side", \
2118796Sgblack@eecs.umich.edu                                       "dtb_walker_cache.mem_side"]
2128796Sgblack@eecs.umich.edu            else:
2138796Sgblack@eecs.umich.edu                self._cached_ports += ["itb.walker.port", "dtb.walker.port"]
2148887Sgeoffrey.blake@arm.com
2158809Sgblack@eecs.umich.edu            # Checker doesn't need its own tlb caches because it does
2168809Sgblack@eecs.umich.edu            # functional accesses only
2178887Sgeoffrey.blake@arm.com            if self.checker != NULL:
2188809Sgblack@eecs.umich.edu                self._cached_ports += ["checker.itb.walker.port", \
2198809Sgblack@eecs.umich.edu                                       "checker.dtb.walker.port"]
2202998SN/A
2217868Sgblack@eecs.umich.edu    def addTwoLevelCacheHierarchy(self, ic, dc, l2c, iwc = None, dwc = None):
2227868Sgblack@eecs.umich.edu        self.addPrivateSplitL1Caches(ic, dc, iwc, dwc)
2239036Sandreas.hansson@arm.com        self.toL2Bus = CoherentBus()
2247876Sgblack@eecs.umich.edu        self.connectCachedPorts(self.toL2Bus)
2252998SN/A        self.l2cache = l2c
2268839Sandreas.hansson@arm.com        self.toL2Bus.master = self.l2cache.cpu_side
2277876Sgblack@eecs.umich.edu        self._cached_ports = ['l2cache.mem_side']
2288887Sgeoffrey.blake@arm.com
2298887Sgeoffrey.blake@arm.com    def addCheckerCpu(self):
2308887Sgeoffrey.blake@arm.com        pass
231