PlatformConfig.py revision 11889
110399Sstephan.diestelhorst@arm.com# Copyright (c) 2012, 2015 ARM Limited
211128Sali.jafri@arm.com# All rights reserved.
310399Sstephan.diestelhorst@arm.com#
410399Sstephan.diestelhorst@arm.com# Copyright (c) 2017, Centre National de la Recherche Scientifique (CNRS)
510399Sstephan.diestelhorst@arm.com#
610399Sstephan.diestelhorst@arm.com# The license below extends only to copyright in the software and shall
710399Sstephan.diestelhorst@arm.com# not be construed as granting a license to any other intellectual
810399Sstephan.diestelhorst@arm.com# property including but not limited to intellectual property relating
910399Sstephan.diestelhorst@arm.com# to a hardware implementation of the functionality of the software
1010399Sstephan.diestelhorst@arm.com# licensed hereunder.  You may use the software subject to the license
1110399Sstephan.diestelhorst@arm.com# terms below provided that you ensure that this notice is replicated
1210399Sstephan.diestelhorst@arm.com# unmodified and in its entirety in all distributions of the software,
1310399Sstephan.diestelhorst@arm.com# modified or unmodified, in source code or in binary form.
1410399Sstephan.diestelhorst@arm.com#
1510399Sstephan.diestelhorst@arm.com# Redistribution and use in source and binary forms, with or without
1610399Sstephan.diestelhorst@arm.com# modification, are permitted provided that the following conditions are
1710399Sstephan.diestelhorst@arm.com# met: redistributions of source code must retain the above copyright
1810399Sstephan.diestelhorst@arm.com# notice, this list of conditions and the following disclaimer;
1910399Sstephan.diestelhorst@arm.com# redistributions in binary form must reproduce the above copyright
2010399Sstephan.diestelhorst@arm.com# notice, this list of conditions and the following disclaimer in the
2110399Sstephan.diestelhorst@arm.com# documentation and/or other materials provided with the distribution;
2210399Sstephan.diestelhorst@arm.com# neither the name of the copyright holders nor the names of its
2310399Sstephan.diestelhorst@arm.com# contributors may be used to endorse or promote products derived from
2410399Sstephan.diestelhorst@arm.com# this software without specific prior written permission.
2510399Sstephan.diestelhorst@arm.com#
2610399Sstephan.diestelhorst@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2710399Sstephan.diestelhorst@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2810399Sstephan.diestelhorst@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2910399Sstephan.diestelhorst@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3010399Sstephan.diestelhorst@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3110399Sstephan.diestelhorst@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3210399Sstephan.diestelhorst@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3310399Sstephan.diestelhorst@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3410399Sstephan.diestelhorst@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3510399Sstephan.diestelhorst@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3610399Sstephan.diestelhorst@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3711135Sandreas.hansson@arm.com#
3810399Sstephan.diestelhorst@arm.com# Authors: Andreas Sandberg
3910399Sstephan.diestelhorst@arm.com#          Pierre-Yves Peneau
4010399Sstephan.diestelhorst@arm.com
4110399Sstephan.diestelhorst@arm.comimport m5.objects
4211135Sandreas.hansson@arm.comimport inspect
4310399Sstephan.diestelhorst@arm.comimport sys
4410399Sstephan.diestelhorst@arm.comfrom m5.util import fatal
4510399Sstephan.diestelhorst@arm.comfrom textwrap import TextWrapper
4610399Sstephan.diestelhorst@arm.com
4710399Sstephan.diestelhorst@arm.com# Dictionary of mapping names of real CPU models to classes.
4810399Sstephan.diestelhorst@arm.com_platform_classes = {}
4910399Sstephan.diestelhorst@arm.com
5010399Sstephan.diestelhorst@arm.com# Platform aliases. The platforms listed here might not be compiled,
5111129Sali.jafri@arm.com# we make sure they exist before we add them to the platform list.
5211129Sali.jafri@arm.com_platform_aliases_all = [
5311129Sali.jafri@arm.com    ("RealView_EB", "RealViewEB"),
5411129Sali.jafri@arm.com    ("RealView_PBX", "RealViewPBX"),
5511129Sali.jafri@arm.com    ("VExpress_GEM5", "VExpress_GEM5_V1"),
5611129Sali.jafri@arm.com    ]
5711129Sali.jafri@arm.com
5811129Sali.jafri@arm.com# Filtered list of aliases. Only aliases for existing platforms exist
5911129Sali.jafri@arm.com# in this list.
6011129Sali.jafri@arm.com_platform_aliases = {}
6111129Sali.jafri@arm.com
6210399Sstephan.diestelhorst@arm.comdef is_platform_class(cls):
6310399Sstephan.diestelhorst@arm.com    """Determine if a class is a Platform that can be instantiated"""
6410399Sstephan.diestelhorst@arm.com
6510399Sstephan.diestelhorst@arm.com    # We can't use the normal inspect.isclass because the ParamFactory
6610399Sstephan.diestelhorst@arm.com    # and ProxyFactory classes have a tendency to confuse it.
6710399Sstephan.diestelhorst@arm.com    try:
6811128Sali.jafri@arm.com        return issubclass(cls, m5.objects.Platform) and \
6911128Sali.jafri@arm.com            not cls.abstract
7011128Sali.jafri@arm.com    except (TypeError, AttributeError):
7111128Sali.jafri@arm.com        return False
7210399Sstephan.diestelhorst@arm.com
7311131Sandreas.hansson@arm.comdef get(name):
7411131Sandreas.hansson@arm.com    """Get a platform class from a user provided class name."""
7511128Sali.jafri@arm.com
7611128Sali.jafri@arm.com    real_name = _platform_aliases.get(name, name)
7711128Sali.jafri@arm.com
7811128Sali.jafri@arm.com    try:
7911128Sali.jafri@arm.com        return _platform_classes[real_name]
8011128Sali.jafri@arm.com    except KeyError:
8111128Sali.jafri@arm.com        fatal("%s is not a valid Platform model." % (name,))
8211131Sandreas.hansson@arm.com
8311131Sandreas.hansson@arm.comdef print_platform_list():
8411131Sandreas.hansson@arm.com    """Print a list of available Platform classes including their aliases."""
8511131Sandreas.hansson@arm.com
8610403Sstephan.diestelhorst@arm.com    print "Available Platform classes:"
8710403Sstephan.diestelhorst@arm.com    doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
8811129Sali.jafri@arm.com    for name, cls in _platform_classes.items():
8911129Sali.jafri@arm.com        print "\t%s" % name
9011129Sali.jafri@arm.com
9111129Sali.jafri@arm.com        # Try to extract the class documentation from the class help
9211129Sali.jafri@arm.com        # string.
9310403Sstephan.diestelhorst@arm.com        doc = inspect.getdoc(cls)
9410403Sstephan.diestelhorst@arm.com        if doc:
9510403Sstephan.diestelhorst@arm.com            for line in doc_wrapper.wrap(doc):
9610403Sstephan.diestelhorst@arm.com                print line
9710403Sstephan.diestelhorst@arm.com
9810403Sstephan.diestelhorst@arm.com    if _platform_aliases:
9910403Sstephan.diestelhorst@arm.com        print "\Platform aliases:"
10010403Sstephan.diestelhorst@arm.com        for alias, target in _platform_aliases.items():
10110399Sstephan.diestelhorst@arm.com            print "\t%s => %s" % (alias, target)
10210399Sstephan.diestelhorst@arm.com
10310399Sstephan.diestelhorst@arm.comdef platform_names():
10410399Sstephan.diestelhorst@arm.com    """Return a list of valid Platform names."""
10511129Sali.jafri@arm.com    return _platform_classes.keys() + _platform_aliases.keys()
10611129Sali.jafri@arm.com
10711129Sali.jafri@arm.com# Add all Platforms in the object hierarchy.
10811129Sali.jafri@arm.comfor name, cls in inspect.getmembers(m5.objects, is_platform_class):
10911129Sali.jafri@arm.com    _platform_classes[name] = cls
11011129Sali.jafri@arm.com
11111284Sandreas.hansson@arm.comfor alias, target in _platform_aliases_all:
11210399Sstephan.diestelhorst@arm.com    if target in _platform_classes:
11311129Sali.jafri@arm.com        _platform_aliases[alias] = target
11410399Sstephan.diestelhorst@arm.com