SConscript revision 12246
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
4712246Sgabeblack@google.comfrom gem5_scons import Transform
4812246Sgabeblack@google.com
494202Sbinkertn@umich.eduImport('*')
502152SN/A
512152SN/A#################################################################
522139SN/A#
532139SN/A# ISA "switch header" generation.
542139SN/A#
552139SN/A# Auto-generate arch headers that include the right ISA-specific
562139SN/A# header based on the setting of THE_ISA preprocessor variable.
572152SN/A#
582152SN/A#################################################################
592139SN/A
6012015Sgabeblack@google.comenv.SwitchingHeaders(
6112015Sgabeblack@google.com    Split('''
629020Sgblack@eecs.umich.edu        decoder.hh
634781Snate@binkert.org        interrupts.hh
647799Sgblack@eecs.umich.edu        isa.hh
654781Snate@binkert.org        isa_traits.hh
664781Snate@binkert.org        kernel_stats.hh
673170Sstever@eecs.umich.edu        locked_mem.hh
685664Sgblack@eecs.umich.edu        microcode_rom.hh
698105Sgblack@eecs.umich.edu        mmapped_ipr.hh
706179Sksewell@umich.edu        mt.hh
714781Snate@binkert.org        process.hh
7210553Salexandru.dutu@amd.com        pseudo_inst.hh
736329Sgblack@eecs.umich.edu        registers.hh
744781Snate@binkert.org        remote_gdb.hh
754781Snate@binkert.org        stacktrace.hh
764781Snate@binkert.org        tlb.hh
774781Snate@binkert.org        types.hh
784781Snate@binkert.org        utility.hh
794781Snate@binkert.org        vtophys.hh
8012015Sgabeblack@google.com        '''),
8112015Sgabeblack@google.com    env.subst('${TARGET_ISA}'))
822152SN/A
8311308Santhony.gutierrez@amd.comif env['BUILD_GPU']:
8412016Sgabeblack@google.com    env.SwitchingHeaders(
8512016Sgabeblack@google.com        Split('''
8611308Santhony.gutierrez@amd.com            gpu_decoder.hh
8711696Santhony.gutierrez@amd.com            gpu_isa.hh
8811308Santhony.gutierrez@amd.com            gpu_types.hh
8912016Sgabeblack@google.com            '''),
9012016Sgabeblack@google.com        env.subst('${TARGET_GPU_ISA}'))
9111308Santhony.gutierrez@amd.com
922152SN/A#################################################################
932152SN/A#
942152SN/A# Include architecture-specific files.
952152SN/A#
962152SN/A#################################################################
972152SN/A
982152SN/A#
992152SN/A# Build a SCons scanner for ISA files
1002152SN/A#
1012152SN/Aimport SCons.Scanner
10212222Sgabeblack@google.comimport SCons.Tool
1032152SN/A
10412222Sgabeblack@google.comscanner = SCons.Scanner.Classic("ISAScan",
10512222Sgabeblack@google.com                                [".isa", ".ISA"],
10612222Sgabeblack@google.com                                 "SRCDIR",
10712222Sgabeblack@google.com                                r'^\s*##include\s+"([\w/.-]*)"')
1082152SN/A
10912222Sgabeblack@google.comenv.Append(SCANNERS=scanner)
11012222Sgabeblack@google.com
11112222Sgabeblack@google.com# Tell scons that when it sees a cc.inc file, it should scan it for includes.
11212222Sgabeblack@google.comSCons.Tool.SourceFileScanner.add_scanner('.cc.inc', SCons.Tool.CScanner)
1132152SN/A
1142152SN/A#
1152152SN/A# Now create a Builder object that uses isa_parser.py to generate C++
1162152SN/A# output from the ISA description (*.isa) files.
1172152SN/A#
1182152SN/A
11912222Sgabeblack@google.comparser_py = File('isa_parser.py')
12012222Sgabeblack@google.commicro_asm_py = File('micro_asm.py')
1216993Snate@binkert.org
1226998Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions.
1236998Snate@binkert.orgimport ply
1246998Snate@binkert.org
12512222Sgabeblack@google.comdef run_parser(target, source, env):
12612222Sgabeblack@google.com    # Add the current directory to the system path so we can import files.
12712222Sgabeblack@google.com    sys.path[0:0] = [ parser_py.dir.abspath ]
1286993Snate@binkert.org    import isa_parser
1296993Snate@binkert.org
13010319SAndreas.Sandberg@ARM.com    parser = isa_parser.ISAParser(target[0].dir.abspath)
1316993Snate@binkert.org    parser.parse_isa_desc(source[0].abspath)
1322152SN/A
13312222Sgabeblack@google.comdesc_action = MakeAction(run_parser, Transform("ISA DESC", 1))
1342152SN/A
13512222Sgabeblack@google.comIsaDescBuilder = Builder(action=desc_action)
1365944Sgblack@eecs.umich.edu
13710196SCurtis.Dunham@arm.com
13812222Sgabeblack@google.com# ISAs should use this function to set up an IsaDescBuilder and not try to
13912222Sgabeblack@google.com# set one up manually.
14012222Sgabeblack@google.comdef ISADesc(desc, decoder_splits=1, exec_splits=1):
14112222Sgabeblack@google.com    '''Set up a builder for an ISA description.
14210196SCurtis.Dunham@arm.com
14312222Sgabeblack@google.com    The decoder_splits and exec_splits parameters let us determine what
14412222Sgabeblack@google.com    files the isa parser is actually going to generate. This needs to match
14512222Sgabeblack@google.com    what files are actually generated, and there's no specific check for that
14612222Sgabeblack@google.com    right now.
14710196SCurtis.Dunham@arm.com
14812222Sgabeblack@google.com    If the parser itself is responsible for generating a list of its products
14912222Sgabeblack@google.com    and their dependencies, then using that output to set up the right
15012222Sgabeblack@google.com    dependencies. This is what we used to do. The problem is that scons
15112222Sgabeblack@google.com    fundamentally doesn't support using a build product to affect its graph
15212222Sgabeblack@google.com    of possible products, dependencies, builders, etc. There are a couple ways
15312222Sgabeblack@google.com    to work around that limitation.
15410196SCurtis.Dunham@arm.com
15512222Sgabeblack@google.com    One option is to compute dependencies while the build phase of scons is
15612222Sgabeblack@google.com    running. That method can be quite complicated and cumbersome, because we
15712222Sgabeblack@google.com    have to make sure our modifications are made before scons tries to
15812222Sgabeblack@google.com    consume them. There's also no guarantee that this mechanism will work since
15912222Sgabeblack@google.com    it subverts scons expectations and changes things behind its back. This
16012222Sgabeblack@google.com    was implemented previously and constrained the builds parallelism
16112222Sgabeblack@google.com    significantly.
16210196SCurtis.Dunham@arm.com
16312222Sgabeblack@google.com    Another option would be to recursively call scons to have it update the
16412222Sgabeblack@google.com    list of products/dependencies during the setup phase of this invocation of
16512222Sgabeblack@google.com    scons. The problem with that is that it would be very difficult to make
16612222Sgabeblack@google.com    the sub-invocation of scons observe the options passed to the primary one
16712222Sgabeblack@google.com    in all possible cases, or to even determine conclusively what the name of
16812222Sgabeblack@google.com    the scons executable is in the first place.
16910196SCurtis.Dunham@arm.com
17012222Sgabeblack@google.com    Possible future changes to the isa parser might make it easier to
17112222Sgabeblack@google.com    determine what files it would generate, perhaps because there was a more
17212222Sgabeblack@google.com    direct correspondence between input files and output files. Or, if the
17312222Sgabeblack@google.com    parser could run quickly and determine what its output files would be
17412222Sgabeblack@google.com    without having do actually generate those files, then it could be run
17512222Sgabeblack@google.com    unconditionally without slowing down all builds or touching the output
17612222Sgabeblack@google.com    files unnecessarily.
17712222Sgabeblack@google.com    '''
17812222Sgabeblack@google.com    generated_dir = File(desc).dir.up().Dir('generated')
17912222Sgabeblack@google.com    def gen_file(name):
18012222Sgabeblack@google.com        return generated_dir.File(name)
18110196SCurtis.Dunham@arm.com
18212222Sgabeblack@google.com    gen = []
18312222Sgabeblack@google.com    def add_gen(name):
18412222Sgabeblack@google.com        gen.append(gen_file(name))
18512222Sgabeblack@google.com
18612222Sgabeblack@google.com    # Tell scons about the various files the ISA parser will generate.
18712222Sgabeblack@google.com    add_gen('decoder-g.cc.inc')
18812222Sgabeblack@google.com    add_gen('decoder-ns.cc.inc')
18912222Sgabeblack@google.com    add_gen('decode-method.cc.inc')
19012222Sgabeblack@google.com
19112222Sgabeblack@google.com    add_gen('decoder.hh')
19212222Sgabeblack@google.com    add_gen('decoder-g.hh.inc')
19312222Sgabeblack@google.com    add_gen('decoder-ns.hh.inc')
19412222Sgabeblack@google.com
19512222Sgabeblack@google.com    add_gen('exec-g.cc.inc')
19612222Sgabeblack@google.com    add_gen('exec-ns.cc.inc')
19712222Sgabeblack@google.com
19812222Sgabeblack@google.com    add_gen('max_inst_regs.hh')
19912222Sgabeblack@google.com
20012222Sgabeblack@google.com
20112222Sgabeblack@google.com    # These generated files are also top level sources.
20212222Sgabeblack@google.com    def source_gen(name):
20312222Sgabeblack@google.com        add_gen(name)
20412222Sgabeblack@google.com        Source(gen_file(name))
20512222Sgabeblack@google.com
20612222Sgabeblack@google.com    source_gen('decoder.cc')
20712222Sgabeblack@google.com
20812222Sgabeblack@google.com    if decoder_splits == 1:
20912222Sgabeblack@google.com        source_gen('inst-constrs.cc')
21012222Sgabeblack@google.com    else:
21112222Sgabeblack@google.com        for i in range(1, decoder_splits + 1):
21212222Sgabeblack@google.com            source_gen('inst-constrs-%d.cc' % i)
21312222Sgabeblack@google.com
21412222Sgabeblack@google.com    if exec_splits == 1:
21512222Sgabeblack@google.com        source_gen('generic_cpu_exec.cc')
21612222Sgabeblack@google.com    else:
21712222Sgabeblack@google.com        for i in range(1, exec_splits + 1):
21812222Sgabeblack@google.com            source_gen('generic_cpu_exec_%d.cc' % i)
21912222Sgabeblack@google.com
22012222Sgabeblack@google.com    # Actually create the builder.
22112222Sgabeblack@google.com    sources = [desc, parser_py, micro_asm_py]
22212222Sgabeblack@google.com    IsaDescBuilder(target=gen, source=sources, env=env)
22312222Sgabeblack@google.com    return gen
22412222Sgabeblack@google.com
22512222Sgabeblack@google.comExport('ISADesc')
22610196SCurtis.Dunham@arm.com
2278335Snate@binkert.orgDebugFlag('IntRegs')
2288335Snate@binkert.orgDebugFlag('FloatRegs')
22912109SRekai.GonzalezAlberquilla@arm.comDebugFlag('VecRegs')
2309920Syasuko.eckert@amd.comDebugFlag('CCRegs')
2318335Snate@binkert.orgDebugFlag('MiscRegs')
23210935Snilay@cs.wisc.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
233