SConscript revision 8961
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
322139SN/Aimport os
334202Sbinkertn@umich.edu
342152SN/AImport('*')
352152SN/A
362139SN/A#################################################################
372139SN/A#
382139SN/A# ISA "switch header" generation.
392139SN/A#
402139SN/A# Auto-generate arch headers that include the right ISA-specific
412152SN/A# header based on the setting of THE_ISA preprocessor variable.
422152SN/A#
432139SN/A#################################################################
442139SN/A
452139SN/A# List of headers to generate
462984Sgblack@eecs.umich.eduisa_switch_hdrs = Split('''
472439SN/A        interrupts.hh
483520Sgblack@eecs.umich.edu        isa.hh
492139SN/A        isa_traits.hh
503565Sgblack@eecs.umich.edu        kernel_stats.hh
513170Sstever@eecs.umich.edu        locked_mem.hh
523806Ssaidi@eecs.umich.edu        microcode_rom.hh
532439SN/A        mmapped_ipr.hh
542460SN/A        mt.hh
553536Sgblack@eecs.umich.edu        process.hh
562439SN/A        predecoder.hh
572972Sgblack@eecs.umich.edu        registers.hh
582171SN/A        remote_gdb.hh
592439SN/A        stacktrace.hh
602439SN/A        tlb.hh
612170SN/A        types.hh
622139SN/A        utility.hh
632139SN/A        vtophys.hh
643546Sgblack@eecs.umich.edu        ''')
654202Sbinkertn@umich.edu
662152SN/A# Set up this directory to support switching headers
672152SN/Amake_switching_dir('arch', isa_switch_hdrs, env)
682152SN/A
692152SN/A#################################################################
702152SN/A#
712152SN/A# Include architecture-specific files.
722152SN/A#
732152SN/A#################################################################
742152SN/A
752152SN/A#
762152SN/A# Build a SCons scanner for ISA files
772152SN/A#
782504SN/Aimport SCons.Scanner
792504SN/A
802504SN/Aisa_scanner = SCons.Scanner.Classic("ISAScan",
812504SN/A                                    [".isa", ".ISA"],
822152SN/A                                    "SRCDIR",
832504SN/A                                    r'^\s*##include\s+"([\w/.-]*)"')
842152SN/A
852152SN/Aenv.Append(SCANNERS = isa_scanner)
862152SN/A
872152SN/A#
882152SN/A# Now create a Builder object that uses isa_parser.py to generate C++
892152SN/A# output from the ISA description (*.isa) files.
902152SN/A#
912152SN/A
922632Sstever@eecs.umich.eduisa_parser = File('isa_parser.py')
932155SN/A
942155SN/A# The emitter patches up the sources & targets to include the
952155SN/A# autogenerated files as targets and isa parser itself as a source.
962155SN/Adef isa_desc_emitter(target, source, env):
972155SN/A    cpu_models = list(env['CPU_MODELS'])
982155SN/A    cpu_models.append('CheckerCPU')
994202Sbinkertn@umich.edu
1002155SN/A    # Several files are generated from the ISA description.
1012155SN/A    # We always get the basic decoder and header file.
1022155SN/A    target = [ 'decoder.cc', 'decoder.hh', 'max_inst_regs.hh' ]
1032152SN/A    # We also get an execute file for each selected CPU model.
1042766Sktlim@umich.edu    target += [CpuModel.dict[cpu].filename for cpu in cpu_models]
1052766Sktlim@umich.edu
1062766Sktlim@umich.edu    # List the isa parser as a source.
1072766Sktlim@umich.edu    source += [ isa_parser ]
1082766Sktlim@umich.edu    # Add in the CPU models.
1092152SN/A    source += [ Value(m) for m in cpu_models ]
1102152SN/A
1112152SN/A    return [os.path.join("generated", t) for t in target], source
1122155SN/A
1132152SN/AARCH_DIR = Dir('.')
1142152SN/A
1152718Sstever@eecs.umich.edu# import ply here because SCons screws with sys.path when performing actions.
1162921Sktlim@umich.eduimport ply
1172921Sktlim@umich.edu
1182921Sktlim@umich.edudef isa_desc_action_func(target, source, env):
1192921Sktlim@umich.edu    # Add the current directory to the system path so we can import files
1202921Sktlim@umich.edu    sys.path[0:0] = [ ARCH_DIR.srcnode().abspath ]
1212921Sktlim@umich.edu    import isa_parser
1222921Sktlim@umich.edu
1232921Sktlim@umich.edu    # Skip over the ISA description itself and the parser to the CPU models.
1242921Sktlim@umich.edu    models = [ s.get_contents() for s in source[2:] ]
1252152SN/A    cpu_models = [CpuModel.dict[cpu] for cpu in models]
1262152SN/A    parser = isa_parser.ISAParser(target[0].dir.abspath, cpu_models)
127    parser.parse_isa_desc(source[0].abspath)
128isa_desc_action = MakeAction(isa_desc_action_func, Transform("ISA DESC", 1))
129
130# Also include the CheckerCPU as one of the models if it is being
131# enabled via command line.
132isa_desc_builder = Builder(action=isa_desc_action, emitter=isa_desc_emitter)
133
134env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
135
136DebugFlag('IntRegs')
137DebugFlag('FloatRegs')
138DebugFlag('MiscRegs')
139CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'MiscRegs' ])
140