SConscript revision 12109
1545SN/A# -*- mode:python -*- 211193Sandreas.hansson@arm.com 38948Sandreas.hansson@arm.com# Copyright (c) 2016 ARM Limited 48948Sandreas.hansson@arm.com# All rights reserved. 58948Sandreas.hansson@arm.com# 68948Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall 78948Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual 88948Sandreas.hansson@arm.com# property including but not limited to intellectual property relating 98948Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software 108948Sandreas.hansson@arm.com# licensed hereunder. You may use the software subject to the license 118948Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated 128948Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software, 138948Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form. 142512SN/A# 15545SN/A# Copyright (c) 2006 The Regents of The University of Michigan 16545SN/A# All rights reserved. 17545SN/A# 18545SN/A# Redistribution and use in source and binary forms, with or without 19545SN/A# modification, are permitted provided that the following conditions are 20545SN/A# met: redistributions of source code must retain the above copyright 21545SN/A# notice, this list of conditions and the following disclaimer; 22545SN/A# redistributions in binary form must reproduce the above copyright 23545SN/A# notice, this list of conditions and the following disclaimer in the 24545SN/A# documentation and/or other materials provided with the distribution; 25545SN/A# neither the name of the copyright holders nor the names of its 26545SN/A# contributors may be used to endorse or promote products derived from 27545SN/A# this software without specific prior written permission. 28545SN/A# 29545SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30545SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31545SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32545SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33545SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34545SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35545SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36545SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37545SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38545SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu# 412665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 42545SN/A 43545SN/Aimport sys 4411793Sbrandon.potter@amd.comimport os 4511793Sbrandon.potter@amd.comimport re 462657Ssaidi@eecs.umich.edu 4710405Sandreas.hansson@arm.comImport('*') 482901Ssaidi@eecs.umich.edu 49545SN/A################################################################# 504762Snate@binkert.org# 5113892Sgabeblack@google.com# ISA "switch header" generation. 524762Snate@binkert.org# 534762Snate@binkert.org# Auto-generate arch headers that include the right ISA-specific 54545SN/A# header based on the setting of THE_ISA preprocessor variable. 55545SN/A# 56545SN/A################################################################# 57545SN/A 582542SN/Aenv.SwitchingHeaders( 592541SN/A Split(''' 602541SN/A decoder.hh 618851Sandreas.hansson@arm.com interrupts.hh 628674Snilay@cs.wisc.edu isa.hh 638851Sandreas.hansson@arm.com isa_traits.hh 642541SN/A kernel_stats.hh 652541SN/A locked_mem.hh 6613784Sgabeblack@google.com microcode_rom.hh 6713784Sgabeblack@google.com mmapped_ipr.hh 688598Ssteve.reinhardt@amd.com mt.hh 698598Ssteve.reinhardt@amd.com process.hh 708922Swilliam.wang@arm.com pseudo_inst.hh 718598Ssteve.reinhardt@amd.com registers.hh 7213892Sgabeblack@google.com remote_gdb.hh 738598Ssteve.reinhardt@amd.com stacktrace.hh 742901Ssaidi@eecs.umich.edu tlb.hh 759808Sstever@gmail.com types.hh 769808Sstever@gmail.com utility.hh 774762Snate@binkert.org vtophys.hh 784762Snate@binkert.org '''), 794762Snate@binkert.org env.subst('${TARGET_ISA}')) 808711Sandreas.hansson@arm.com 819090Sandreas.hansson@arm.comif env['BUILD_GPU']: 822539SN/A env.SwitchingHeaders( 832539SN/A Split(''' 848711Sandreas.hansson@arm.com gpu_decoder.hh 8510405Sandreas.hansson@arm.com gpu_isa.hh 868711Sandreas.hansson@arm.com gpu_types.hh 878711Sandreas.hansson@arm.com '''), 882539SN/A env.subst('${TARGET_GPU_ISA}')) 89 90################################################################# 91# 92# Include architecture-specific files. 93# 94################################################################# 95 96# 97# Build a SCons scanner for ISA files 98# 99import SCons.Scanner 100 101isa_scanner = SCons.Scanner.Classic("ISAScan", 102 [".isa", ".ISA"], 103 "SRCDIR", 104 r'^\s*##include\s+"([\w/.-]*)"') 105 106env.Append(SCANNERS = isa_scanner) 107 108# 109# Now create a Builder object that uses isa_parser.py to generate C++ 110# output from the ISA description (*.isa) files. 111# 112 113isa_parser = File('isa_parser.py') 114 115# The emitter patches up the sources & targets to include the 116# autogenerated files as targets and isa parser itself as a source. 117def isa_desc_emitter(target, source, env): 118 # List the isa parser as a source. 119 source += [ 120 isa_parser, 121 Value("ExecContext"), 122 ] 123 124 # Specify different targets depending on if we're running the ISA 125 # parser for its dependency information, or for the generated files. 126 # (As an optimization, the ISA parser detects the useless second run 127 # and skips doing any work, if the first run was performed, since it 128 # always generates all its files). The way we track this in SCons is the 129 # <arch>_isa_outputs value in the environment (env). If it's unset, we 130 # don't know what the dependencies are so we ask for generated/inc.d to 131 # be generated so they can be acquired. If we know what they are, then 132 # it's because we've already processed inc.d and then claim that our 133 # outputs (targets) will be thus. 134 isa = env['TARGET_ISA'] 135 key = '%s_isa_outputs' % isa 136 if key in env: 137 targets = [ os.path.join('generated', f) for f in env[key] ] 138 else: 139 targets = [ os.path.join('generated','inc.d') ] 140 141 def prefix(s): 142 return os.path.join(target[0].dir.up().abspath, s) 143 144 return [ prefix(t) for t in targets ], source 145 146ARCH_DIR = Dir('.') 147 148# import ply here because SCons screws with sys.path when performing actions. 149import ply 150 151def isa_desc_action_func(target, source, env): 152 # Add the current directory to the system path so we can import files 153 sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 154 import isa_parser 155 156 # Skip over the ISA description itself and the parser to the CPU models. 157 models = [ s.get_contents() for s in source[2:] ] 158 parser = isa_parser.ISAParser(target[0].dir.abspath) 159 parser.parse_isa_desc(source[0].abspath) 160isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 161 162# Also include the CheckerCPU as one of the models if it is being 163# enabled via command line. 164isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 165 166env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 167 168# The ISA is generated twice: the first time to find out what it generates, 169# and the second time to make scons happy by telling the ISADesc builder 170# what it will make before it builds it. 171def scan_isa_deps(target, source, env): 172 # Process dependency file generated by the ISA parser -- 173 # add the listed files to the dependency tree of the build. 174 source = source[0] 175 archbase = source.dir.up().path 176 177 try: 178 depfile = open(source.abspath, 'r') 179 except: 180 print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 181 (source.path,os.getcwd()) 182 raise 183 184 # Scan through the lines 185 targets = {} 186 for line in depfile: 187 # Read the dependency line with the format 188 # <target file>: [ <dependent file>* ] 189 m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 190 assert(m) 191 targ, extn = m.group(1,2) 192 deps = m.group(3).split() 193 194 files = [ targ ] + deps 195 for f in files: 196 targets[f] = True 197 # Eliminate unnecessary re-generation if we already generated it 198 env.Precious(os.path.join(archbase, 'generated', f)) 199 200 files = [ os.path.join(archbase, 'generated', f) for f in files ] 201 202 if extn == 'cc': 203 Source(os.path.join(archbase,'generated', targ)) 204 depfile.close() 205 env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 206 207 isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 208 for t in targets: 209 env.Depends('#all-isas', isa) 210 211env.Append(BUILDERS = {'ScanISA' : 212 Builder(action=MakeAction(scan_isa_deps, 213 Transform("NEW DEPS", 1)))}) 214 215DebugFlag('IntRegs') 216DebugFlag('FloatRegs') 217DebugFlag('VecRegs') 218DebugFlag('CCRegs') 219DebugFlag('MiscRegs') 220CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 221