1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2018 The Regents of the University of California
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.
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.
32 from m5
.objects
import *
35 """Simple L1 Cache with default values"""
44 def connectBus(self
, bus
):
45 """Connect this cache to a memory-side bus"""
46 self
.mem_side
= bus
.slave
48 def connectCPU(self
, cpu
):
49 """Connect this cache's port to a CPU-side port
50 This must be defined in a subclass"""
51 raise NotImplementedError
53 class L1ICache(L1Cache
):
54 """Simple L1 instruction cache with default values"""
56 # Set the default size
59 def connectCPU(self
, cpu
):
60 """Connect this cache's port to a CPU icache port"""
61 self
.cpu_side
= cpu
.icache_port
63 class L1DCache(L1Cache
):
64 """Simple L1 data cache with default values"""
66 # Set the default size
69 def connectCPU(self
, cpu
):
70 """Connect this cache's port to a CPU dcache port"""
71 self
.cpu_side
= cpu
.dcache_port
74 """Simple L2 Cache with default values"""
85 def connectCPUSideBus(self
, bus
):
86 self
.cpu_side
= bus
.master
88 def connectMemSideBus(self
, bus
):
89 self
.mem_side
= bus
.slave
92 class MySimpleMemory(SimpleMemory
):
95 if buildEnv
['TARGET_ISA'] == 'x86':
96 valid_cpu
= {'AtomicSimpleCPU': AtomicSimpleCPU
,
97 'TimingSimpleCPU': TimingSimpleCPU
,
98 'DerivO3CPU': DerivO3CPU
101 valid_cpu
= {'AtomicSimpleCPU': AtomicSimpleCPU
,
102 'TimingSimpleCPU': TimingSimpleCPU
,
103 'MinorCPU': MinorCPU
,
104 'DerivO3CPU': DerivO3CPU
,
107 valid_mem
= {'SimpleMemory': MySimpleMemory
,
108 'DDR3_1600_8x8': DDR3_1600_8x8
111 parser
= argparse
.ArgumentParser()
112 parser
.add_argument('binary', type = str)
113 parser
.add_argument('--cpu', choices
= valid_cpu
.keys(),
114 default
= 'TimingSimpleCPU')
115 parser
.add_argument('--mem', choices
= valid_mem
.keys(),
116 default
= 'SimpleMemory')
118 args
= parser
.parse_args()
122 system
.clk_domain
= SrcClockDomain()
123 system
.clk_domain
.clock
= '1GHz'
124 system
.clk_domain
.voltage_domain
= VoltageDomain()
126 if args
.cpu
!= "AtomicSimpleCPU":
127 system
.mem_mode
= 'timing'
129 system
.mem_ranges
= [AddrRange('512MB')]
131 system
.cpu
= valid_cpu
[args
.cpu
]()
133 if args
.cpu
== "AtomicSimpleCPU":
134 system
.membus
= SystemXBar()
135 system
.cpu
.icache_port
= system
.membus
.slave
136 system
.cpu
.dcache_port
= system
.membus
.slave
138 system
.cpu
.l1d
= L1DCache()
139 system
.cpu
.l1i
= L1ICache()
140 system
.l1_to_l2
= L2XBar()
141 system
.l2cache
= L2Cache()
142 system
.membus
= SystemXBar()
143 system
.cpu
.l1d
.connectCPU(system
.cpu
)
144 system
.cpu
.l1d
.connectBus(system
.l1_to_l2
)
145 system
.cpu
.l1i
.connectCPU(system
.cpu
)
146 system
.cpu
.l1i
.connectBus(system
.l1_to_l2
)
147 system
.l2cache
.connectCPUSideBus(system
.l1_to_l2
)
148 system
.l2cache
.connectMemSideBus(system
.membus
)
150 system
.cpu
.createInterruptController()
151 if m5
.defines
.buildEnv
['TARGET_ISA'] == "x86":
152 system
.cpu
.interrupts
[0].pio
= system
.membus
.master
153 system
.cpu
.interrupts
[0].int_master
= system
.membus
.slave
154 system
.cpu
.interrupts
[0].int_slave
= system
.membus
.master
156 system
.mem_ctrl
= valid_mem
[args
.mem
]()
157 system
.mem_ctrl
.range = system
.mem_ranges
[0]
158 system
.mem_ctrl
.port
= system
.membus
.master
159 system
.system_port
= system
.membus
.slave
162 process
.cmd
= [args
.binary
]
163 system
.cpu
.workload
= process
164 system
.cpu
.createThreads()
166 root
= Root(full_system
= False, system
= system
)
169 exit_event
= m5
.simulate()
171 if exit_event
.getCause() != 'exiting with last active thread context':