arch: Add generic BaseMMU
[gem5.git] / src / arch / SConscript
1 # -*- mode:python -*-
2
3 # Copyright (c) 2016-2017 ARM Limited
4 # All rights reserved.
5 #
6 # The license below extends only to copyright in the software and shall
7 # not be construed as granting a license to any other intellectual
8 # property including but not limited to intellectual property relating
9 # to a hardware implementation of the functionality of the software
10 # licensed hereunder. You may use the software subject to the license
11 # terms below provided that you ensure that this notice is replicated
12 # unmodified and in its entirety in all distributions of the software,
13 # modified or unmodified, in source code or in binary form.
14 #
15 # Copyright (c) 2006 The Regents of The University of Michigan
16 # All rights reserved.
17 #
18 # Redistribution and use in source and binary forms, with or without
19 # modification, are permitted provided that the following conditions are
20 # met: redistributions of source code must retain the above copyright
21 # notice, this list of conditions and the following disclaimer;
22 # redistributions in binary form must reproduce the above copyright
23 # notice, this list of conditions and the following disclaimer in the
24 # documentation and/or other materials provided with the distribution;
25 # neither the name of the copyright holders nor the names of its
26 # contributors may be used to endorse or promote products derived from
27 # this software without specific prior written permission.
28 #
29 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41 import sys
42 import os
43 import re
44
45 from gem5_scons import Transform
46
47 Import('*')
48
49 #################################################################
50 #
51 # ISA "switch header" generation.
52 #
53 # Auto-generate arch headers that include the right ISA-specific
54 # header based on the setting of THE_ISA preprocessor variable.
55 #
56 #################################################################
57
58 env.SwitchingHeaders(
59 Split('''
60 decoder.hh
61 isa.hh
62 isa_traits.hh
63 locked_mem.hh
64 pseudo_inst.hh
65 registers.hh
66 remote_gdb.hh
67 types.hh
68 utility.hh
69 '''),
70 env.subst('${TARGET_ISA}'))
71
72 if env['BUILD_GPU']:
73 env.SwitchingHeaders(
74 Split('''
75 gpu_decoder.hh
76 gpu_isa.hh
77 gpu_types.hh
78 '''),
79 env.subst('${TARGET_GPU_ISA}'))
80
81 #################################################################
82 #
83 # Include architecture-specific files.
84 #
85 #################################################################
86
87 #
88 # Build a SCons scanner for ISA files
89 #
90 import SCons.Scanner
91 import SCons.Tool
92
93 scanner = SCons.Scanner.Classic("ISAScan",
94 [".isa", ".ISA"],
95 "SRCDIR",
96 r'^\s*##include\s+"([\w/.-]*)"')
97
98 env.Append(SCANNERS=scanner)
99
100 # Tell scons that when it sees a cc.inc file, it should scan it for includes.
101 SCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
102
103 #
104 # Now create a Builder object that uses isa_parser.py to generate C++
105 # output from the ISA description (*.isa) files.
106 #
107
108 parser_py = File('isa_parser.py')
109 micro_asm_py = File('micro_asm.py')
110
111 # import ply here because SCons screws with sys.path when performing actions.
112 import ply
113
114 def run_parser(target, source, env):
115 # Add the current directory to the system path so we can import files.
116 sys.path[0:0] = [ parser_py.dir.abspath ]
117 import isa_parser
118
119 parser = isa_parser.ISAParser(target[0].dir.abspath)
120 parser.parse_isa_desc(source[0].abspath)
121
122 desc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
123
124 IsaDescBuilder = Builder(action=desc_action)
125
126
127 # ISAs should use this function to set up an IsaDescBuilder and not try to
128 # set one up manually.
129 def ISADesc(desc, decoder_splits=1, exec_splits=1):
130 '''Set up a builder for an ISA description.
131
132 The decoder_splits and exec_splits parameters let us determine what
133 files the isa parser is actually going to generate. This needs to match
134 what files are actually generated, and there's no specific check for that
135 right now.
136
137 If the parser itself is responsible for generating a list of its products
138 and their dependencies, then using that output to set up the right
139 dependencies. This is what we used to do. The problem is that scons
140 fundamentally doesn't support using a build product to affect its graph
141 of possible products, dependencies, builders, etc. There are a couple ways
142 to work around that limitation.
143
144 One option is to compute dependencies while the build phase of scons is
145 running. That method can be quite complicated and cumbersome, because we
146 have to make sure our modifications are made before scons tries to
147 consume them. There's also no guarantee that this mechanism will work since
148 it subverts scons expectations and changes things behind its back. This
149 was implemented previously and constrained the builds parallelism
150 significantly.
151
152 Another option would be to recursively call scons to have it update the
153 list of products/dependencies during the setup phase of this invocation of
154 scons. The problem with that is that it would be very difficult to make
155 the sub-invocation of scons observe the options passed to the primary one
156 in all possible cases, or to even determine conclusively what the name of
157 the scons executable is in the first place.
158
159 Possible future changes to the isa parser might make it easier to
160 determine what files it would generate, perhaps because there was a more
161 direct correspondence between input files and output files. Or, if the
162 parser could run quickly and determine what its output files would be
163 without having do actually generate those files, then it could be run
164 unconditionally without slowing down all builds or touching the output
165 files unnecessarily.
166 '''
167 generated_dir = File(desc).dir.up().Dir('generated')
168 def gen_file(name):
169 return generated_dir.File(name)
170
171 gen = []
172 def add_gen(name):
173 gen.append(gen_file(name))
174
175 # Tell scons about the various files the ISA parser will generate.
176 add_gen('decoder-g.cc.inc')
177 add_gen('decoder-ns.cc.inc')
178 add_gen('decode-method.cc.inc')
179
180 add_gen('decoder.hh')
181 add_gen('decoder-g.hh.inc')
182 add_gen('decoder-ns.hh.inc')
183
184 add_gen('exec-g.cc.inc')
185 add_gen('exec-ns.cc.inc')
186
187 add_gen('max_inst_regs.hh')
188
189
190 # These generated files are also top level sources.
191 def source_gen(name):
192 add_gen(name)
193 Source(gen_file(name))
194
195 source_gen('decoder.cc')
196
197 if decoder_splits == 1:
198 source_gen('inst-constrs.cc')
199 else:
200 for i in range(1, decoder_splits + 1):
201 source_gen('inst-constrs-%d.cc' % i)
202
203 if exec_splits == 1:
204 source_gen('generic_cpu_exec.cc')
205 else:
206 for i in range(1, exec_splits + 1):
207 source_gen('generic_cpu_exec_%d.cc' % i)
208
209 # Actually create the builder.
210 sources = [desc, parser_py, micro_asm_py]
211 IsaDescBuilder(target=gen, source=sources, env=env)
212 return gen
213
214 Export('ISADesc')
215
216 DebugFlag('IntRegs')
217 DebugFlag('FloatRegs')
218 DebugFlag('VecRegs')
219 DebugFlag('VecPredRegs')
220 DebugFlag('CCRegs')
221 DebugFlag('MiscRegs')
222 CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'VecRegs', 'VecPredRegs',
223 'CCRegs', 'MiscRegs' ])