SConscript revision 11308
12139SN/A# -*- mode:python -*-
22139SN/A
32139SN/A# Copyright (c) 2006 The Regents of The University of Michigan
42139SN/A# All rights reserved.
52139SN/A#
62139SN/A# Redistribution and use in source and binary forms, with or without
72139SN/A# modification, are permitted provided that the following conditions are
82139SN/A# met: redistributions of source code must retain the above copyright
92139SN/A# notice, this list of conditions and the following disclaimer;
102139SN/A# redistributions in binary form must reproduce the above copyright
112139SN/A# notice, this list of conditions and the following disclaimer in the
122139SN/A# documentation and/or other materials provided with the distribution;
132139SN/A# neither the name of the copyright holders nor the names of its
142139SN/A# contributors may be used to endorse or promote products derived from
152139SN/A# this software without specific prior written permission.
162139SN/A#
172139SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182139SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192139SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202139SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212139SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222139SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232139SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242139SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252139SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262139SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272139SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
302139SN/A
314202Sbinkertn@umich.eduimport sys
328961Sgblack@eecs.umich.eduimport os
3310196SCurtis.Dunham@arm.comimport re
342139SN/A
354202Sbinkertn@umich.eduImport('*')
362152SN/A
372152SN/A#################################################################
382139SN/A#
392139SN/A# ISA "switch header" generation.
402139SN/A#
412139SN/A# Auto-generate arch headers that include the right ISA-specific
422139SN/A# header based on the setting of THE_ISA preprocessor variable.
432152SN/A#
442152SN/A#################################################################
452139SN/A
462139SN/A# List of headers to generate
472139SN/Aisa_switch_hdrs = Split('''
489020Sgblack@eecs.umich.edu        decoder.hh
494781Snate@binkert.org        interrupts.hh
507799Sgblack@eecs.umich.edu        isa.hh
514781Snate@binkert.org        isa_traits.hh
524781Snate@binkert.org        kernel_stats.hh
533170Sstever@eecs.umich.edu        locked_mem.hh
545664Sgblack@eecs.umich.edu        microcode_rom.hh
558105Sgblack@eecs.umich.edu        mmapped_ipr.hh
566179Sksewell@umich.edu        mt.hh
574781Snate@binkert.org        process.hh
5810553Salexandru.dutu@amd.com        pseudo_inst.hh
596329Sgblack@eecs.umich.edu        registers.hh
604781Snate@binkert.org        remote_gdb.hh
614781Snate@binkert.org        stacktrace.hh
624781Snate@binkert.org        tlb.hh
634781Snate@binkert.org        types.hh
644781Snate@binkert.org        utility.hh
654781Snate@binkert.org        vtophys.hh
662139SN/A        ''')
672139SN/A
683546Sgblack@eecs.umich.edu# Set up this directory to support switching headers
694202Sbinkertn@umich.edumake_switching_dir('arch', isa_switch_hdrs, env)
702152SN/A
7111308Santhony.gutierrez@amd.comif env['BUILD_GPU']:
7211308Santhony.gutierrez@amd.com    gpu_isa_switch_hdrs = Split('''
7311308Santhony.gutierrez@amd.com            gpu_decoder.hh
7411308Santhony.gutierrez@amd.com            gpu_types.hh
7511308Santhony.gutierrez@amd.com            ''')
7611308Santhony.gutierrez@amd.com
7711308Santhony.gutierrez@amd.com    make_gpu_switching_dir('arch', gpu_isa_switch_hdrs, env)
7811308Santhony.gutierrez@amd.com
792152SN/A#################################################################
802152SN/A#
812152SN/A# Include architecture-specific files.
822152SN/A#
832152SN/A#################################################################
842152SN/A
852152SN/A#
862152SN/A# Build a SCons scanner for ISA files
872152SN/A#
882152SN/Aimport SCons.Scanner
892152SN/A
902504SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan",
912504SN/A                                    [".isa", ".ISA"],
922504SN/A                                    "SRCDIR",
932504SN/A                                    r'^\s*##include\s+"([\w/.-]*)"')
942152SN/A
952504SN/Aenv.Append(SCANNERS = isa_scanner)
962152SN/A
972152SN/A#
982152SN/A# Now create a Builder object that uses isa_parser.py to generate C++
992152SN/A# output from the ISA description (*.isa) files.
1002152SN/A#
1012152SN/A
1028584Sgblack@eecs.umich.eduisa_parser = File('isa_parser.py')
1038584Sgblack@eecs.umich.edu
1046993Snate@binkert.org# The emitter patches up the sources & targets to include the
1056993Snate@binkert.org# autogenerated files as targets and isa parser itself as a source.
1066993Snate@binkert.orgdef isa_desc_emitter(target, source, env):
1078584Sgblack@eecs.umich.edu    # List the isa parser as a source.
10810319SAndreas.Sandberg@ARM.com    source += [
10910319SAndreas.Sandberg@ARM.com        isa_parser,
11010319SAndreas.Sandberg@ARM.com        Value("ExecContext"),
11110319SAndreas.Sandberg@ARM.com        ]
1128584Sgblack@eecs.umich.edu
11310196SCurtis.Dunham@arm.com    # Specify different targets depending on if we're running the ISA
11410196SCurtis.Dunham@arm.com    # parser for its dependency information, or for the generated files.
11510196SCurtis.Dunham@arm.com    # (As an optimization, the ISA parser detects the useless second run
11610196SCurtis.Dunham@arm.com    # and skips doing any work, if the first run was performed, since it
11710196SCurtis.Dunham@arm.com    # always generates all its files). The way we track this in SCons is the
11810196SCurtis.Dunham@arm.com    # <arch>_isa_outputs value in the environment (env). If it's unset, we
11910196SCurtis.Dunham@arm.com    # don't know what the dependencies are so we ask for generated/inc.d to
12010196SCurtis.Dunham@arm.com    # be generated so they can be acquired. If we know what they are, then
12110196SCurtis.Dunham@arm.com    # it's because we've already processed inc.d and then claim that our
12210196SCurtis.Dunham@arm.com    # outputs (targets) will be thus.
12310196SCurtis.Dunham@arm.com    isa = env['TARGET_ISA']
12410196SCurtis.Dunham@arm.com    key = '%s_isa_outputs' % isa
12510196SCurtis.Dunham@arm.com    if key in env:
12610196SCurtis.Dunham@arm.com        targets = [ os.path.join('generated', f) for f in env[key] ]
12710196SCurtis.Dunham@arm.com    else:
12810196SCurtis.Dunham@arm.com        targets = [ os.path.join('generated','inc.d') ]
12910196SCurtis.Dunham@arm.com
13010196SCurtis.Dunham@arm.com    def prefix(s):
13110196SCurtis.Dunham@arm.com        return os.path.join(target[0].dir.up().abspath, s)
13210196SCurtis.Dunham@arm.com
13310196SCurtis.Dunham@arm.com    return [ prefix(t) for t in targets ], source
1346993Snate@binkert.org
1356993Snate@binkert.orgARCH_DIR = Dir('.')
1366993Snate@binkert.org
1376998Snate@binkert.org# import ply here because SCons screws with sys.path when performing actions.
1386998Snate@binkert.orgimport ply
1396998Snate@binkert.org
1407756SAli.Saidi@ARM.comdef isa_desc_action_func(target, source, env):
1416993Snate@binkert.org    # Add the current directory to the system path so we can import files
1426993Snate@binkert.org    sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
1436993Snate@binkert.org    import isa_parser
1446993Snate@binkert.org
1458585Sgblack@eecs.umich.edu    # Skip over the ISA description itself and the parser to the CPU models.
1468584Sgblack@eecs.umich.edu    models = [ s.get_contents() for s in source[2:] ]
14710319SAndreas.Sandberg@ARM.com    parser = isa_parser.ISAParser(target[0].dir.abspath)
1486993Snate@binkert.org    parser.parse_isa_desc(source[0].abspath)
1497816Ssteve.reinhardt@amd.comisa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
1502152SN/A
1512766Sktlim@umich.edu# Also include the CheckerCPU as one of the models if it is being
1522766Sktlim@umich.edu# enabled via command line.
1536993Snate@binkert.orgisa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
1542152SN/A
1552152SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1565944Sgblack@eecs.umich.edu
15710196SCurtis.Dunham@arm.com# The ISA is generated twice: the first time to find out what it generates,
15810196SCurtis.Dunham@arm.com# and the second time to make scons happy by telling the ISADesc builder
15910196SCurtis.Dunham@arm.com# what it will make before it builds it.
16010196SCurtis.Dunham@arm.comdef scan_isa_deps(target, source, env):
16110196SCurtis.Dunham@arm.com    # Process dependency file generated by the ISA parser --
16210196SCurtis.Dunham@arm.com    # add the listed files to the dependency tree of the build.
16310196SCurtis.Dunham@arm.com    source = source[0]
16410196SCurtis.Dunham@arm.com    archbase = source.dir.up().path
16510196SCurtis.Dunham@arm.com
16610196SCurtis.Dunham@arm.com    try:
16710196SCurtis.Dunham@arm.com        depfile = open(source.abspath, 'r')
16810196SCurtis.Dunham@arm.com    except:
16910196SCurtis.Dunham@arm.com        print "scan_isa_deps: Can't open ISA deps file '%s' in %s" % \
17010196SCurtis.Dunham@arm.com              (source.path,os.getcwd())
17110196SCurtis.Dunham@arm.com        raise
17210196SCurtis.Dunham@arm.com
17310196SCurtis.Dunham@arm.com    # Scan through the lines
17410196SCurtis.Dunham@arm.com    targets = {}
17510196SCurtis.Dunham@arm.com    for line in depfile:
17610196SCurtis.Dunham@arm.com        # Read the dependency line with the format
17710196SCurtis.Dunham@arm.com        # <target file>: [ <dependent file>* ]
17810196SCurtis.Dunham@arm.com        m = re.match(r'^\s*([^:]+\.([^\.:]+))\s*:\s*(.*)', line)
17910196SCurtis.Dunham@arm.com        assert(m)
18010196SCurtis.Dunham@arm.com        targ, extn = m.group(1,2)
18110196SCurtis.Dunham@arm.com        deps = m.group(3).split()
18210196SCurtis.Dunham@arm.com
18310196SCurtis.Dunham@arm.com        files = [ targ ] + deps
18410196SCurtis.Dunham@arm.com        for f in files:
18510196SCurtis.Dunham@arm.com            targets[f] = True
18610196SCurtis.Dunham@arm.com            # Eliminate unnecessary re-generation if we already generated it
18710196SCurtis.Dunham@arm.com            env.Precious(os.path.join(archbase, 'generated', f))
18810196SCurtis.Dunham@arm.com
18910196SCurtis.Dunham@arm.com        files = [ os.path.join(archbase, 'generated', f) for f in files ]
19010196SCurtis.Dunham@arm.com
19110196SCurtis.Dunham@arm.com        if extn == 'cc':
19210196SCurtis.Dunham@arm.com            Source(os.path.join(archbase,'generated', targ))
19310196SCurtis.Dunham@arm.com    depfile.close()
19410196SCurtis.Dunham@arm.com    env[env['TARGET_ISA'] + '_isa_outputs'] = targets.keys()
19510196SCurtis.Dunham@arm.com
19610196SCurtis.Dunham@arm.com    isa = env.ISADesc(os.path.join(archbase,'isa','main.isa'))
19710196SCurtis.Dunham@arm.com    for t in targets:
19810196SCurtis.Dunham@arm.com        env.Depends('#all-isas', isa)
19910196SCurtis.Dunham@arm.com
20010196SCurtis.Dunham@arm.comenv.Append(BUILDERS = {'ScanISA' :
20110196SCurtis.Dunham@arm.com                        Builder(action=MakeAction(scan_isa_deps,
20210196SCurtis.Dunham@arm.com                                                  Transform("NEW DEPS", 1)))})
20310196SCurtis.Dunham@arm.com
2048335Snate@binkert.orgDebugFlag('IntRegs')
2058335Snate@binkert.orgDebugFlag('FloatRegs')
2069920Syasuko.eckert@amd.comDebugFlag('CCRegs')
2078335Snate@binkert.orgDebugFlag('MiscRegs')
20810935Snilay@cs.wisc.eduCompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'CCRegs', 'MiscRegs' ])
209