SConscript revision 3536
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
312718Sstever@eecs.umich.eduimport os.path, sys
322139SN/A
332139SN/A# Import build environment variable from SConstruct.
342139SN/AImport('env')
352139SN/A
362152SN/A# Right now there are no source files immediately in this directory
372152SN/Asources = []
382152SN/A
392152SN/A#################################################################
402139SN/A#
412139SN/A# ISA "switch header" generation.
422139SN/A#
432139SN/A# Auto-generate arch headers that include the right ISA-specific
442139SN/A# header based on the setting of THE_ISA preprocessor variable.
452152SN/A#
462152SN/A#################################################################
472139SN/A
482139SN/A# List of headers to generate
492139SN/Aisa_switch_hdrs = Split('''
502984Sgblack@eecs.umich.edu	arguments.hh
512439SN/A	faults.hh
523520Sgblack@eecs.umich.edu	interrupts.hh
532139SN/A	isa_traits.hh
543170Sstever@eecs.umich.edu        locked_mem.hh
552439SN/A	process.hh
562460SN/A	regfile.hh
573536Sgblack@eecs.umich.edu	remote_gdb.hh
582439SN/A	stacktrace.hh
592972Sgblack@eecs.umich.edu	syscallreturn.hh
602171SN/A	tlb.hh
612439SN/A	types.hh
622439SN/A	utility.hh
632170SN/A	vtophys.hh
642139SN/A        ''')
652139SN/A
662139SN/A# Generate the header.  target[0] is the full path of the output
672139SN/A# header to generate.  'source' is a dummy variable, since we get the
682139SN/A# list of ISAs from env['ALL_ISA_LIST'].
692139SN/Adef gen_switch_hdr(target, source, env):
702139SN/A    fname = str(target[0])
712139SN/A    basename = os.path.basename(fname)
722139SN/A    f = open(fname, 'w')
732139SN/A    f.write('#include "arch/isa_specific.hh"\n')
742139SN/A    cond = '#if'
752139SN/A    for isa in env['ALL_ISA_LIST']:
762139SN/A        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
772139SN/A                % (cond, isa.upper(), isa, basename))
782139SN/A        cond = '#elif'
792139SN/A    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
802139SN/A    f.close()
812139SN/A    return 0
822139SN/A
832139SN/A# String to print when generating header
842139SN/Adef gen_switch_hdr_string(target, source, env):
852139SN/A    return "Generating ISA switch header " + str(target[0])
862139SN/A
872139SN/A# Build SCons Action object. 'varlist' specifies env vars that this
882178SN/A# action depends on; when env['ALL_ISA_LIST'] changes these actions
892139SN/A# should get re-executed.
902139SN/Aswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
912139SN/A                           varlist=['ALL_ISA_LIST'])
922139SN/A
932139SN/A# Instantiate actions for each header
942139SN/Afor hdr in isa_switch_hdrs:
952139SN/A    env.Command(hdr, [], switch_hdr_action)
962152SN/A
972152SN/A#################################################################
982152SN/A#
992152SN/A# Include architecture-specific files.
1002152SN/A#
1012152SN/A#################################################################
1022152SN/A
1032152SN/A#
1042152SN/A# Build a SCons scanner for ISA files
1052152SN/A#
1062152SN/Aimport SCons.Scanner
1072152SN/A
1082504SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan",
1092504SN/A                                    [".isa", ".ISA"],
1102504SN/A                                    "SRCDIR",
1112504SN/A                                    r'^\s*##include\s+"([\w/.-]*)"')
1122152SN/A
1132504SN/Aenv.Append(SCANNERS = isa_scanner)
1142152SN/A
1152152SN/A#
1162152SN/A# Now create a Builder object that uses isa_parser.py to generate C++
1172152SN/A# output from the ISA description (*.isa) files.
1182152SN/A#
1192152SN/A
1202152SN/A# Convert to File node to fix path
1212152SN/Aisa_parser = File('isa_parser.py')
1222632Sstever@eecs.umich.educpu_models_file = File('../cpu/cpu_models.py')
1232155SN/A
1242155SN/A# This sucks in the defintions of the CpuModel objects.
1252155SN/Aexecfile(cpu_models_file.srcnode().abspath)
1262155SN/A
1272155SN/A# Several files are generated from the ISA description.
1282155SN/A# We always get the basic decoder and header file.
1292155SN/Aisa_desc_gen_files = Split('decoder.cc decoder.hh')
1302155SN/A# We also get an execute file for each selected CPU model.
1312155SN/Aisa_desc_gen_files += [CpuModel.dict[cpu].filename
1322155SN/A                       for cpu in env['CPU_MODELS']]
1332152SN/A
1342766Sktlim@umich.edu# Also include the CheckerCPU as one of the models if it is being
1352766Sktlim@umich.edu# enabled via command line.
1362766Sktlim@umich.eduif env['USE_CHECKER']:
1372766Sktlim@umich.edu    isa_desc_gen_files += [CpuModel.dict['CheckerCPU'].filename]
1382766Sktlim@umich.edu
1392152SN/A# The emitter patches up the sources & targets to include the
1402152SN/A# autogenerated files as targets and isa parser itself as a source.
1412152SN/Adef isa_desc_emitter(target, source, env):
1422155SN/A    return (isa_desc_gen_files, [isa_parser, cpu_models_file] + source)
1432152SN/A
1442152SN/A# Pieces are in place, so create the builder.
1452718Sstever@eecs.umich.edupython = sys.executable  # use same Python binary used to run scons
1462921Sktlim@umich.edu
1472921Sktlim@umich.edu# Also include the CheckerCPU as one of the models if it is being
1482921Sktlim@umich.edu# enabled via command line.
1492921Sktlim@umich.eduif env['USE_CHECKER']:
1502921Sktlim@umich.edu    isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS CheckerCPU',
1512921Sktlim@umich.edu                               emitter = isa_desc_emitter)
1522921Sktlim@umich.eduelse:
1532921Sktlim@umich.edu    isa_desc_builder = Builder(action=python + ' $SOURCES $TARGET.dir $CPU_MODELS',
1542921Sktlim@umich.edu                               emitter = isa_desc_emitter)
1552152SN/A
1562152SN/Aenv.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
1572152SN/A
1582152SN/A#
1592152SN/A# Now include other ISA-specific sources from the ISA subdirectories.
1602152SN/A#
1612152SN/A
1622152SN/Aisa = env['TARGET_ISA'] # someday this may be a list of ISAs
1632152SN/A
1642152SN/A# Let the target architecture define what additional sources it needs
1652667Sstever@eecs.umich.edusources += SConscript(os.path.join(isa, 'SConscript'), exports = 'env')
1662152SN/A
1672152SN/AReturn('sources')
168