BaseCPU.py revision 9849:603e2ed487f3
15217Ssaidi@eecs.umich.edu# Copyright (c) 2012 ARM Limited
25217Ssaidi@eecs.umich.edu# All rights reserved.
35217Ssaidi@eecs.umich.edu#
45217Ssaidi@eecs.umich.edu# The license below extends only to copyright in the software and shall
55217Ssaidi@eecs.umich.edu# not be construed as granting a license to any other intellectual
65217Ssaidi@eecs.umich.edu# property including but not limited to intellectual property relating
75217Ssaidi@eecs.umich.edu# to a hardware implementation of the functionality of the software
85217Ssaidi@eecs.umich.edu# licensed hereunder.  You may use the software subject to the license
95217Ssaidi@eecs.umich.edu# terms below provided that you ensure that this notice is replicated
105217Ssaidi@eecs.umich.edu# unmodified and in its entirety in all distributions of the software,
115217Ssaidi@eecs.umich.edu# modified or unmodified, in source code or in binary form.
125217Ssaidi@eecs.umich.edu#
135217Ssaidi@eecs.umich.edu# Copyright (c) 2005-2008 The Regents of The University of Michigan
145217Ssaidi@eecs.umich.edu# Copyright (c) 2011 Regents of the University of California
155217Ssaidi@eecs.umich.edu# All rights reserved.
165217Ssaidi@eecs.umich.edu#
175217Ssaidi@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
185217Ssaidi@eecs.umich.edu# modification, are permitted provided that the following conditions are
195217Ssaidi@eecs.umich.edu# met: redistributions of source code must retain the above copyright
205217Ssaidi@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
215217Ssaidi@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
225217Ssaidi@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
235217Ssaidi@eecs.umich.edu# documentation and/or other materials provided with the distribution;
245217Ssaidi@eecs.umich.edu# neither the name of the copyright holders nor the names of its
255217Ssaidi@eecs.umich.edu# contributors may be used to endorse or promote products derived from
265217Ssaidi@eecs.umich.edu# this software without specific prior written permission.
275217Ssaidi@eecs.umich.edu#
285217Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295217Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305217Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
315217Ssaidi@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
325217Ssaidi@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336658Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
345217Ssaidi@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
358232Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
365217Ssaidi@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
375217Ssaidi@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
385217Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395217Ssaidi@eecs.umich.edu#
405217Ssaidi@eecs.umich.edu# Authors: Nathan Binkert
415217Ssaidi@eecs.umich.edu#          Rick Strong
425217Ssaidi@eecs.umich.edu#          Andreas Hansson
435217Ssaidi@eecs.umich.edu
445217Ssaidi@eecs.umich.eduimport sys
455217Ssaidi@eecs.umich.edu
465217Ssaidi@eecs.umich.edufrom m5.defines import buildEnv
475217Ssaidi@eecs.umich.edufrom m5.params import *
485217Ssaidi@eecs.umich.edufrom m5.proxy import *
495217Ssaidi@eecs.umich.edu
505217Ssaidi@eecs.umich.edufrom Bus import CoherentBus
515217Ssaidi@eecs.umich.edufrom InstTracer import InstTracer
525217Ssaidi@eecs.umich.edufrom ExeTracer import ExeTracer
535217Ssaidi@eecs.umich.edufrom MemObject import MemObject
545217Ssaidi@eecs.umich.edufrom ClockDomain import *
555217Ssaidi@eecs.umich.edu
565217Ssaidi@eecs.umich.edudefault_tracer = ExeTracer()
575217Ssaidi@eecs.umich.edu
585217Ssaidi@eecs.umich.eduif buildEnv['TARGET_ISA'] == 'alpha':
595217Ssaidi@eecs.umich.edu    from AlphaTLB import AlphaDTB, AlphaITB
605217Ssaidi@eecs.umich.edu    from AlphaInterrupts import AlphaInterrupts
615217Ssaidi@eecs.umich.edu    from AlphaISA import AlphaISA
625217Ssaidi@eecs.umich.edu    isa_class = AlphaISA
635217Ssaidi@eecs.umich.eduelif buildEnv['TARGET_ISA'] == 'sparc':
645217Ssaidi@eecs.umich.edu    from SparcTLB import SparcTLB
655217Ssaidi@eecs.umich.edu    from SparcInterrupts import SparcInterrupts
665217Ssaidi@eecs.umich.edu    from SparcISA import SparcISA
675217Ssaidi@eecs.umich.edu    isa_class = SparcISA
685217Ssaidi@eecs.umich.eduelif buildEnv['TARGET_ISA'] == 'x86':
697720Sgblack@eecs.umich.edu    from X86TLB import X86TLB
707720Sgblack@eecs.umich.edu    from X86LocalApic import X86LocalApic
715712Shsul@eecs.umich.edu    from X86ISA import X86ISA
725712Shsul@eecs.umich.edu    isa_class = X86ISA
735217Ssaidi@eecs.umich.eduelif buildEnv['TARGET_ISA'] == 'mips':
745217Ssaidi@eecs.umich.edu    from MipsTLB import MipsTLB
755714Shsul@eecs.umich.edu    from MipsInterrupts import MipsInterrupts
765714Shsul@eecs.umich.edu    from MipsISA import MipsISA
775714Shsul@eecs.umich.edu    isa_class = MipsISA
785714Shsul@eecs.umich.eduelif buildEnv['TARGET_ISA'] == 'arm':
795714Shsul@eecs.umich.edu    from ArmTLB import ArmTLB
805714Shsul@eecs.umich.edu    from ArmInterrupts import ArmInterrupts
815714Shsul@eecs.umich.edu    from ArmISA import ArmISA
825217Ssaidi@eecs.umich.edu    isa_class = ArmISA
83elif buildEnv['TARGET_ISA'] == 'power':
84    from PowerTLB import PowerTLB
85    from PowerInterrupts import PowerInterrupts
86    from PowerISA import PowerISA
87    isa_class = PowerISA
88
89class BaseCPU(MemObject):
90    type = 'BaseCPU'
91    abstract = True
92    cxx_header = "cpu/base.hh"
93
94    @classmethod
95    def export_methods(cls, code):
96        code('''
97    void switchOut();
98    void takeOverFrom(BaseCPU *cpu);
99    bool switchedOut();
100    void flushTLBs();
101    Counter totalInsts();
102    void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
103    void scheduleLoadStop(ThreadID tid, Counter loads, const char *cause);
104''')
105
106    @classmethod
107    def memory_mode(cls):
108        """Which memory mode does this CPU require?"""
109        return 'invalid'
110
111    @classmethod
112    def require_caches(cls):
113        """Does the CPU model require caches?
114
115        Some CPU models might make assumptions that require them to
116        have caches.
117        """
118        return False
119
120    @classmethod
121    def support_take_over(cls):
122        """Does the CPU model support CPU takeOverFrom?"""
123        return False
124
125    def takeOverFrom(self, old_cpu):
126        self._ccObject.takeOverFrom(old_cpu._ccObject)
127
128
129    system = Param.System(Parent.any, "system object")
130    cpu_id = Param.Int(-1, "CPU identifier")
131    numThreads = Param.Unsigned(1, "number of HW thread contexts")
132
133    function_trace = Param.Bool(False, "Enable function trace")
134    function_trace_start = Param.Tick(0, "Tick to start function trace")
135
136    checker = Param.BaseCPU(NULL, "checker CPU")
137
138    do_checkpoint_insts = Param.Bool(True,
139        "enable checkpoint pseudo instructions")
140    do_statistics_insts = Param.Bool(True,
141        "enable statistics pseudo instructions")
142
143    profile = Param.Latency('0ns', "trace the kernel stack")
144    do_quiesce = Param.Bool(True, "enable quiesce instructions")
145
146    workload = VectorParam.Process([], "processes to run")
147
148    if buildEnv['TARGET_ISA'] == 'sparc':
149        dtb = Param.SparcTLB(SparcTLB(), "Data TLB")
150        itb = Param.SparcTLB(SparcTLB(), "Instruction TLB")
151        interrupts = Param.SparcInterrupts(
152                NULL, "Interrupt Controller")
153        isa = VectorParam.SparcISA([ isa_class() ], "ISA instance")
154    elif buildEnv['TARGET_ISA'] == 'alpha':
155        dtb = Param.AlphaTLB(AlphaDTB(), "Data TLB")
156        itb = Param.AlphaTLB(AlphaITB(), "Instruction TLB")
157        interrupts = Param.AlphaInterrupts(
158                NULL, "Interrupt Controller")
159        isa = VectorParam.AlphaISA([ isa_class() ], "ISA instance")
160    elif buildEnv['TARGET_ISA'] == 'x86':
161        dtb = Param.X86TLB(X86TLB(), "Data TLB")
162        itb = Param.X86TLB(X86TLB(), "Instruction TLB")
163        interrupts = Param.X86LocalApic(NULL, "Interrupt Controller")
164        isa = VectorParam.X86ISA([ isa_class() ], "ISA instance")
165    elif buildEnv['TARGET_ISA'] == 'mips':
166        dtb = Param.MipsTLB(MipsTLB(), "Data TLB")
167        itb = Param.MipsTLB(MipsTLB(), "Instruction TLB")
168        interrupts = Param.MipsInterrupts(
169                NULL, "Interrupt Controller")
170        isa = VectorParam.MipsISA([ isa_class() ], "ISA instance")
171    elif buildEnv['TARGET_ISA'] == 'arm':
172        dtb = Param.ArmTLB(ArmTLB(), "Data TLB")
173        itb = Param.ArmTLB(ArmTLB(), "Instruction TLB")
174        interrupts = Param.ArmInterrupts(
175                NULL, "Interrupt Controller")
176        isa = VectorParam.ArmISA([ isa_class() ], "ISA instance")
177    elif buildEnv['TARGET_ISA'] == 'power':
178        UnifiedTLB = Param.Bool(True, "Is this a Unified TLB?")
179        dtb = Param.PowerTLB(PowerTLB(), "Data TLB")
180        itb = Param.PowerTLB(PowerTLB(), "Instruction TLB")
181        interrupts = Param.PowerInterrupts(
182                NULL, "Interrupt Controller")
183        isa = VectorParam.PowerISA([ isa_class() ], "ISA instance")
184    else:
185        print "Don't know what TLB to use for ISA %s" % \
186            buildEnv['TARGET_ISA']
187        sys.exit(1)
188
189    max_insts_all_threads = Param.Counter(0,
190        "terminate when all threads have reached this inst count")
191    max_insts_any_thread = Param.Counter(0,
192        "terminate when any thread reaches this inst count")
193    simpoint_start_insts = VectorParam.Counter([],
194        "starting instruction counts of simpoints")
195    max_loads_all_threads = Param.Counter(0,
196        "terminate when all threads have reached this load count")
197    max_loads_any_thread = Param.Counter(0,
198        "terminate when any thread reaches this load count")
199    progress_interval = Param.Frequency('0Hz',
200        "frequency to print out the progress message")
201
202    switched_out = Param.Bool(False,
203        "Leave the CPU switched out after startup (used when switching " \
204        "between CPU models)")
205
206    tracer = Param.InstTracer(default_tracer, "Instruction tracer")
207
208    icache_port = MasterPort("Instruction Port")
209    dcache_port = MasterPort("Data Port")
210    _cached_ports = ['icache_port', 'dcache_port']
211
212    if buildEnv['TARGET_ISA'] in ['x86', 'arm']:
213        _cached_ports += ["itb.walker.port", "dtb.walker.port"]
214
215    _uncached_slave_ports = []
216    _uncached_master_ports = []
217    if buildEnv['TARGET_ISA'] == 'x86':
218        _uncached_slave_ports += ["interrupts.pio", "interrupts.int_slave"]
219        _uncached_master_ports += ["interrupts.int_master"]
220
221    def createInterruptController(self):
222        if buildEnv['TARGET_ISA'] == 'sparc':
223            self.interrupts = SparcInterrupts()
224        elif buildEnv['TARGET_ISA'] == 'alpha':
225            self.interrupts = AlphaInterrupts()
226        elif buildEnv['TARGET_ISA'] == 'x86':
227            self.apic_clk_domain = DerivedClockDomain(clk_domain =
228                                                      Parent.clk_domain,
229                                                      clk_divider = 16)
230            self.interrupts = X86LocalApic(clk_domain = self.apic_clk_domain,
231                                           pio_addr=0x2000000000000000)
232            _localApic = self.interrupts
233        elif buildEnv['TARGET_ISA'] == 'mips':
234            self.interrupts = MipsInterrupts()
235        elif buildEnv['TARGET_ISA'] == 'arm':
236            self.interrupts = ArmInterrupts()
237        elif buildEnv['TARGET_ISA'] == 'power':
238            self.interrupts = PowerInterrupts()
239        else:
240            print "Don't know what Interrupt Controller to use for ISA %s" % \
241                buildEnv['TARGET_ISA']
242            sys.exit(1)
243
244    def connectCachedPorts(self, bus):
245        for p in self._cached_ports:
246            exec('self.%s = bus.slave' % p)
247
248    def connectUncachedPorts(self, bus):
249        for p in self._uncached_slave_ports:
250            exec('self.%s = bus.master' % p)
251        for p in self._uncached_master_ports:
252            exec('self.%s = bus.slave' % p)
253
254    def connectAllPorts(self, cached_bus, uncached_bus = None):
255        self.connectCachedPorts(cached_bus)
256        if not uncached_bus:
257            uncached_bus = cached_bus
258        self.connectUncachedPorts(uncached_bus)
259
260    def addPrivateSplitL1Caches(self, ic, dc, iwc = None, dwc = None):
261        self.icache = ic
262        self.dcache = dc
263        self.icache_port = ic.cpu_side
264        self.dcache_port = dc.cpu_side
265        self._cached_ports = ['icache.mem_side', 'dcache.mem_side']
266        if buildEnv['TARGET_ISA'] in ['x86', 'arm']:
267            if iwc and dwc:
268                self.itb_walker_cache = iwc
269                self.dtb_walker_cache = dwc
270                self.itb.walker.port = iwc.cpu_side
271                self.dtb.walker.port = dwc.cpu_side
272                self._cached_ports += ["itb_walker_cache.mem_side", \
273                                       "dtb_walker_cache.mem_side"]
274            else:
275                self._cached_ports += ["itb.walker.port", "dtb.walker.port"]
276
277            # Checker doesn't need its own tlb caches because it does
278            # functional accesses only
279            if self.checker != NULL:
280                self._cached_ports += ["checker.itb.walker.port", \
281                                       "checker.dtb.walker.port"]
282
283    def addTwoLevelCacheHierarchy(self, ic, dc, l2c, iwc = None, dwc = None):
284        self.addPrivateSplitL1Caches(ic, dc, iwc, dwc)
285        # Set a width of 32 bytes (256-bits), which is four times that
286        # of the default bus. The clock of the CPU is inherited by
287        # default.
288        self.toL2Bus = CoherentBus(width = 32)
289        self.connectCachedPorts(self.toL2Bus)
290        self.l2cache = l2c
291        self.toL2Bus.master = self.l2cache.cpu_side
292        self._cached_ports = ['l2cache.mem_side']
293
294    def createThreads(self):
295        self.isa = [ isa_class() for i in xrange(self.numThreads) ]
296        if self.checker != NULL:
297            self.checker.createThreads()
298
299    def addCheckerCpu(self):
300        pass
301