SConscript revision 12109
12139SN/A# -*- mode:python -*- 22139SN/A 312109SRekai.GonzalezAlberquilla@arm.com# Copyright (c) 2016 ARM Limited 412109SRekai.GonzalezAlberquilla@arm.com# All rights reserved. 512109SRekai.GonzalezAlberquilla@arm.com# 612109SRekai.GonzalezAlberquilla@arm.com# The license below extends only to copyright in the software and shall 712109SRekai.GonzalezAlberquilla@arm.com# not be construed as granting a license to any other intellectual 812109SRekai.GonzalezAlberquilla@arm.com# property including but not limited to intellectual property relating 912109SRekai.GonzalezAlberquilla@arm.com# to a hardware implementation of the functionality of the software 1012109SRekai.GonzalezAlberquilla@arm.com# licensed hereunder. You may use the software subject to the license 1112109SRekai.GonzalezAlberquilla@arm.com# terms below provided that you ensure that this notice is replicated 1212109SRekai.GonzalezAlberquilla@arm.com# unmodified and in its entirety in all distributions of the software, 1312109SRekai.GonzalezAlberquilla@arm.com# modified or unmodified, in source code or in binary form. 1412109SRekai.GonzalezAlberquilla@arm.com# 152139SN/A# Copyright (c) 2006 The Regents of The University of Michigan 162139SN/A# All rights reserved. 172139SN/A# 182139SN/A# Redistribution and use in source and binary forms, with or without 192139SN/A# modification, are permitted provided that the following conditions are 202139SN/A# met: redistributions of source code must retain the above copyright 212139SN/A# notice, this list of conditions and the following disclaimer; 222139SN/A# redistributions in binary form must reproduce the above copyright 232139SN/A# notice, this list of conditions and the following disclaimer in the 242139SN/A# documentation and/or other materials provided with the distribution; 252139SN/A# neither the name of the copyright holders nor the names of its 262139SN/A# contributors may be used to endorse or promote products derived from 272139SN/A# this software without specific prior written permission. 282139SN/A# 292139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu# 412665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 422139SN/A 434202Sbinkertn@umich.eduimport sys 448961Sgblack@eecs.umich.eduimport os 4510196SCurtis.Dunham@arm.comimport re 462139SN/A 474202Sbinkertn@umich.eduImport('*') 482152SN/A 492152SN/A################################################################# 502139SN/A# 512139SN/A# ISA "switch header" generation. 522139SN/A# 532139SN/A# Auto-generate arch headers that include the right ISA-specific 542139SN/A# header based on the setting of THE_ISA preprocessor variable. 552152SN/A# 562152SN/A################################################################# 572139SN/A 5812015Sgabeblack@google.comenv.SwitchingHeaders( 5912015Sgabeblack@google.com Split(''' 609020Sgblack@eecs.umich.edu decoder.hh 614781Snate@binkert.org interrupts.hh 627799Sgblack@eecs.umich.edu isa.hh 634781Snate@binkert.org isa_traits.hh 644781Snate@binkert.org kernel_stats.hh 653170Sstever@eecs.umich.edu locked_mem.hh 665664Sgblack@eecs.umich.edu microcode_rom.hh 678105Sgblack@eecs.umich.edu mmapped_ipr.hh 686179Sksewell@umich.edu mt.hh 694781Snate@binkert.org process.hh 7010553Salexandru.dutu@amd.com pseudo_inst.hh 716329Sgblack@eecs.umich.edu registers.hh 724781Snate@binkert.org remote_gdb.hh 734781Snate@binkert.org stacktrace.hh 744781Snate@binkert.org tlb.hh 754781Snate@binkert.org types.hh 764781Snate@binkert.org utility.hh 774781Snate@binkert.org vtophys.hh 7812015Sgabeblack@google.com '''), 7912015Sgabeblack@google.com env.subst('${TARGET_ISA}')) 802152SN/A 8111308Santhony.gutierrez@amd.comif env['BUILD_GPU']: 8212016Sgabeblack@google.com env.SwitchingHeaders( 8312016Sgabeblack@google.com Split(''' 8411308Santhony.gutierrez@amd.com gpu_decoder.hh 8511696Santhony.gutierrez@amd.com gpu_isa.hh 8611308Santhony.gutierrez@amd.com gpu_types.hh 8712016Sgabeblack@google.com '''), 8812016Sgabeblack@google.com env.subst('${TARGET_GPU_ISA}')) 8911308Santhony.gutierrez@amd.com 902152SN/A################################################################# 912152SN/A# 922152SN/A# Include architecture-specific files. 932152SN/A# 942152SN/A################################################################# 952152SN/A 962152SN/A# 972152SN/A# Build a SCons scanner for ISA files 982152SN/A# 992152SN/Aimport SCons.Scanner 1002152SN/A 1012504SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan", 1022504SN/A [".isa", ".ISA"], 1032504SN/A "SRCDIR", 1042504SN/A r'^\s*##include\s+"([\w/.-]*)"') 1052152SN/A 1062504SN/Aenv.Append(SCANNERS = isa_scanner) 1072152SN/A 1082152SN/A# 1092152SN/A# Now create a Builder object that uses isa_parser.py to generate C++ 1102152SN/A# output from the ISA description (*.isa) files. 1112152SN/A# 1122152SN/A 1138584Sgblack@eecs.umich.eduisa_parser = File('isa_parser.py') 1148584Sgblack@eecs.umich.edu 1156993Snate@binkert.org# The emitter patches up the sources & targets to include the 1166993Snate@binkert.org# autogenerated files as targets and isa parser itself as a source. 1176993Snate@binkert.orgdef isa_desc_emitter(target, source, env): 1188584Sgblack@eecs.umich.edu # List the isa parser as a source. 11910319SAndreas.Sandberg@ARM.com source += [ 12010319SAndreas.Sandberg@ARM.com isa_parser, 12110319SAndreas.Sandberg@ARM.com Value("ExecContext"), 12210319SAndreas.Sandberg@ARM.com ] 1238584Sgblack@eecs.umich.edu 12410196SCurtis.Dunham@arm.com # Specify different targets depending on if we're running the ISA 12510196SCurtis.Dunham@arm.com # parser for its dependency information, or for the generated files. 12610196SCurtis.Dunham@arm.com # (As an optimization, the ISA parser detects the useless second run 12710196SCurtis.Dunham@arm.com # and skips doing any work, if the first run was performed, since it 12810196SCurtis.Dunham@arm.com # always generates all its files). The way we track this in SCons is the 12910196SCurtis.Dunham@arm.com # <arch>_isa_outputs value in the environment (env). If it's unset, we 13010196SCurtis.Dunham@arm.com # don't know what the dependencies are so we ask for generated/inc.d to 13110196SCurtis.Dunham@arm.com # be generated so they can be acquired. If we know what they are, then 13210196SCurtis.Dunham@arm.com # it's because we've already processed inc.d and then claim that our 13310196SCurtis.Dunham@arm.com # outputs (targets) will be thus. 13410196SCurtis.Dunham@arm.com isa = env['TARGET_ISA'] 13510196SCurtis.Dunham@arm.com key = '%s_isa_outputs' % isa 13610196SCurtis.Dunham@arm.com if key in env: 13710196SCurtis.Dunham@arm.com targets = [ os.path.join('generated', f) for f in env[key] ] 13810196SCurtis.Dunham@arm.com else: 13910196SCurtis.Dunham@arm.com targets = [ os.path.join('generated','inc.d') ] 14010196SCurtis.Dunham@arm.com 14110196SCurtis.Dunham@arm.com def prefix(s): 14210196SCurtis.Dunham@arm.com return os.path.join(target[0].dir.up().abspath, s) 14310196SCurtis.Dunham@arm.com 14410196SCurtis.Dunham@arm.com return [ prefix(t) for t in targets ], source 1456993Snate@binkert.org 1466993Snate@binkert.orgARCH_DIR = Dir('.') 1476993Snate@binkert.org 1486998Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions. 1496998Snate@binkert.orgimport ply 1506998Snate@binkert.org 1517756SAli.Saidi@ARM.comdef isa_desc_action_func(target, source, env): 1526993Snate@binkert.org # Add the current directory to the system path so we can import files 1536993Snate@binkert.org sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ] 1546993Snate@binkert.org import isa_parser 1556993Snate@binkert.org 1568585Sgblack@eecs.umich.edu # Skip over the ISA description itself and the parser to the CPU models. 1578584Sgblack@eecs.umich.edu models = [ s.get_contents() for s in source[2:] ] 15810319SAndreas.Sandberg@ARM.com parser = isa_parser.ISAParser(target[0].dir.abspath) 1596993Snate@binkert.org parser.parse_isa_desc(source[0].abspath) 1607816Ssteve.reinhardt@amd.comisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1)) 1612152SN/A 1622766Sktlim@umich.edu# Also include the CheckerCPU as one of the models if it is being 1632766Sktlim@umich.edu# enabled via command line. 1646993Snate@binkert.orgisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter) 1652152SN/A 1662152SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder }) 1675944Sgblack@eecs.umich.edu 16810196SCurtis.Dunham@arm.com# The ISA is generated twice: the first time to find out what it generates, 16910196SCurtis.Dunham@arm.com# and the second time to make scons happy by telling the ISADesc builder 17010196SCurtis.Dunham@arm.com# what it will make before it builds it. 17110196SCurtis.Dunham@arm.comdef scan_isa_deps(target, source, env): 17210196SCurtis.Dunham@arm.com # Process dependency file generated by the ISA parser -- 17310196SCurtis.Dunham@arm.com # add the listed files to the dependency tree of the build. 17410196SCurtis.Dunham@arm.com source = source[0] 17510196SCurtis.Dunham@arm.com archbase = source.dir.up().path 17610196SCurtis.Dunham@arm.com 17710196SCurtis.Dunham@arm.com try: 17810196SCurtis.Dunham@arm.com depfile = open(source.abspath, 'r') 17910196SCurtis.Dunham@arm.com except: 18010196SCurtis.Dunham@arm.com print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \ 18110196SCurtis.Dunham@arm.com (source.path,os.getcwd()) 18210196SCurtis.Dunham@arm.com raise 18310196SCurtis.Dunham@arm.com 18410196SCurtis.Dunham@arm.com # Scan through the lines 18510196SCurtis.Dunham@arm.com targets = {} 18610196SCurtis.Dunham@arm.com for line in depfile: 18710196SCurtis.Dunham@arm.com # Read the dependency line with the format 18810196SCurtis.Dunham@arm.com # <target file>: [ <dependent file>* ] 18910196SCurtis.Dunham@arm.com m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line) 19010196SCurtis.Dunham@arm.com assert(m) 19110196SCurtis.Dunham@arm.com targ, extn = m.group(1,2) 19210196SCurtis.Dunham@arm.com deps = m.group(3).split() 19310196SCurtis.Dunham@arm.com 19410196SCurtis.Dunham@arm.com files = [ targ ] + deps 19510196SCurtis.Dunham@arm.com for f in files: 19610196SCurtis.Dunham@arm.com targets[f] = True 19710196SCurtis.Dunham@arm.com # Eliminate unnecessary re-generation if we already generated it 19810196SCurtis.Dunham@arm.com env.Precious(os.path.join(archbase, 'generated', f)) 19910196SCurtis.Dunham@arm.com 20010196SCurtis.Dunham@arm.com files = [ os.path.join(archbase, 'generated', f) for f in files ] 20110196SCurtis.Dunham@arm.com 20210196SCurtis.Dunham@arm.com if extn == 'cc': 20310196SCurtis.Dunham@arm.com Source(os.path.join(archbase,'generated', targ)) 20410196SCurtis.Dunham@arm.com depfile.close() 20510196SCurtis.Dunham@arm.com env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys() 20610196SCurtis.Dunham@arm.com 20710196SCurtis.Dunham@arm.com isa = env.ISADesc(os.path.join(archbase,'isa','main.isa')) 20810196SCurtis.Dunham@arm.com for t in targets: 20910196SCurtis.Dunham@arm.com env.Depends('#all-isas', isa) 21010196SCurtis.Dunham@arm.com 21110196SCurtis.Dunham@arm.comenv.Append(BUILDERS = {'ScanISA' : 21210196SCurtis.Dunham@arm.com Builder(action=MakeAction(scan_isa_deps, 21310196SCurtis.Dunham@arm.com Transform("NEW DEPS", 1)))}) 21410196SCurtis.Dunham@arm.com 2158335Snate@binkert.orgDebugFlag('IntRegs') 2168335Snate@binkert.orgDebugFlag('FloatRegs') 21712109SRekai.GonzalezAlberquilla@arm.comDebugFlag('VecRegs') 2189920Syasuko.eckert@amd.comDebugFlag('CCRegs') 2198335Snate@binkert.orgDebugFlag('MiscRegs') 22010935Snilay@cs.wisc.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ]) 221