7d45c787090b37011ac6751b3a300ccab6cc98f4
[gem5.git] / src / cpu / SConscript
1 # -*- mode:python -*-
2
3 # Copyright (c) 2006 The Regents of The University of Michigan
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #
29 # Authors: Steve Reinhardt
30
31 import os
32 import os.path
33
34 # Import build environment variable from SConstruct.
35 Import('env')
36
37 #################################################################
38 #
39 # Generate StaticInst execute() method signatures.
40 #
41 # There must be one signature for each CPU model compiled in.
42 # Since the set of compiled-in models is flexible, we generate a
43 # header containing the appropriate set of signatures on the fly.
44 #
45 #################################################################
46
47 # CPU model-specific data is contained in cpu_models.py
48 # Convert to SCons File node to get path handling
49 models_db = File('cpu_models.py')
50 # slurp in contents of file
51 execfile(models_db.srcnode().abspath)
52
53 # Template for execute() signature.
54 exec_sig_template = '''
55 virtual Fault execute(%s *xc, Trace::InstRecord *traceData) const = 0;
56 virtual Fault initiateAcc(%s *xc, Trace::InstRecord *traceData) const
57 { panic("initiateAcc not defined!"); };
58 virtual Fault completeAcc(Packet *pkt, %s *xc,
59 Trace::InstRecord *traceData) const
60 { panic("completeAcc not defined!"); };
61 '''
62
63 mem_ini_sig_template = '''
64 virtual Fault initiateAcc(%s *xc, Trace::InstRecord *traceData) const { panic("Not defined!"); };
65 '''
66
67 mem_comp_sig_template = '''
68 virtual Fault completeAcc(uint8_t *data, %s *xc, Trace::InstRecord *traceData) const { panic("Not defined!"); return NoFault; };
69 '''
70
71 # Generate a temporary CPU list, including the CheckerCPU if
72 # it's enabled. This isn't used for anything else other than StaticInst
73 # headers.
74 temp_cpu_list = env['CPU_MODELS'][:]
75
76 if env['USE_CHECKER']:
77 temp_cpu_list.append('CheckerCPU')
78
79 # Generate header.
80 def gen_cpu_exec_signatures(target, source, env):
81 f = open(str(target[0]), 'w')
82 print >> f, '''
83 #ifndef __CPU_STATIC_INST_EXEC_SIGS_HH__
84 #define __CPU_STATIC_INST_EXEC_SIGS_HH__
85 '''
86 for cpu in temp_cpu_list:
87 xc_type = CpuModel.dict[cpu].strings['CPU_exec_context']
88 print >> f, exec_sig_template % (xc_type, xc_type, xc_type)
89 print >> f, '''
90 #endif // __CPU_STATIC_INST_EXEC_SIGS_HH__
91 '''
92
93 # Generate string that gets printed when header is rebuilt
94 def gen_sigs_string(target, source, env):
95 return "Generating static_inst_exec_sigs.hh: " \
96 + ', '.join(temp_cpu_list)
97
98 # Add command to generate header to environment.
99 env.Command('static_inst_exec_sigs.hh', models_db,
100 Action(gen_cpu_exec_signatures, gen_sigs_string,
101 varlist = temp_cpu_list))
102
103 env.Depends('static_inst_exec_sigs.hh', Value(env['USE_CHECKER']))
104 env.Depends('static_inst_exec_sigs.hh', Value(env['CPU_MODELS']))
105
106 # List of suppported CPUs by the Checker. Errors out if USE_CHECKER=True
107 # and one of these are not being used.
108 CheckerSupportedCPUList = ['O3CPU', 'OzoneCPU']
109
110 #################################################################
111 #
112 # Include CPU-model-specific files based on set of models
113 # specified in CPU_MODELS build option.
114 #
115 #################################################################
116
117 # Keep a list of CPU models that support SMT
118 env['SMT_CPU_MODELS'] = []
119
120 sources = []
121
122 need_simple_base = False
123 if 'AtomicSimpleCPU' in env['CPU_MODELS']:
124 need_simple_base = True
125 sources += Split('simple/atomic.cc')
126
127 if 'TimingSimpleCPU' in env['CPU_MODELS']:
128 need_simple_base = True
129 sources += Split('simple/timing.cc')
130
131 if need_simple_base:
132 sources += Split('simple/base.cc')
133
134 if 'FastCPU' in env['CPU_MODELS']:
135 sources += Split('fast/cpu.cc')
136
137 need_bp_unit = False
138 if 'O3CPU' in env['CPU_MODELS']:
139 need_bp_unit = True
140 sources += SConscript('o3/SConscript', exports = 'env')
141 sources += Split('''
142 o3/base_dyn_inst.cc
143 o3/bpred_unit.cc
144 o3/commit.cc
145 o3/decode.cc
146 o3/fetch.cc
147 o3/free_list.cc
148 o3/fu_pool.cc
149 o3/cpu.cc
150 o3/iew.cc
151 o3/inst_queue.cc
152 o3/lsq_unit.cc
153 o3/lsq.cc
154 o3/mem_dep_unit.cc
155 o3/rename.cc
156 o3/rename_map.cc
157 o3/rob.cc
158 o3/scoreboard.cc
159 o3/store_set.cc
160 ''')
161 if env['USE_CHECKER']:
162 sources += Split('o3/checker_builder.cc')
163 env['SMT_CPU_MODELS'].append('O3CPU')
164
165 if 'OzoneCPU' in env['CPU_MODELS']:
166 need_bp_unit = True
167 sources += Split('''
168 ozone/base_dyn_inst.cc
169 ozone/bpred_unit.cc
170 ozone/cpu.cc
171 ozone/cpu_builder.cc
172 ozone/dyn_inst.cc
173 ozone/front_end.cc
174 ozone/lw_back_end.cc
175 ozone/lw_lsq.cc
176 ozone/rename_table.cc
177 ''')
178 if env['USE_CHECKER']:
179 sources += Split('ozone/checker_builder.cc')
180
181 if need_bp_unit:
182 sources += Split('''
183 o3/2bit_local_pred.cc
184 o3/btb.cc
185 o3/ras.cc
186 o3/tournament_pred.cc
187 ''')
188
189 if env['USE_CHECKER']:
190 sources += Split('checker/cpu.cc')
191 checker_supports = False
192 for i in CheckerSupportedCPUList:
193 if i in env['CPU_MODELS']:
194 checker_supports = True
195 if not checker_supports:
196 print "Checker only supports CPU models",
197 for i in CheckerSupportedCPUList:
198 print i,
199 print ", please set USE_CHECKER=False or use one of those CPU models"
200 Exit(1)
201
202
203 # FullCPU sources are included from src/SConscript since they're not
204 # below this point in the file hierarchy.
205
206 # Convert file names to SCons File objects. This takes care of the
207 # path relative to the top of the directory tree.
208 sources = [File(s) for s in sources]
209
210 Return('sources')
211