PlatformConfig.py revision 11297
113669Sjavier.bueno@metempsy.com# Copyright (c) 2012, 2015 ARM Limited
213669Sjavier.bueno@metempsy.com# All rights reserved.
313669Sjavier.bueno@metempsy.com#
413669Sjavier.bueno@metempsy.com# The license below extends only to copyright in the software and shall
513669Sjavier.bueno@metempsy.com# not be construed as granting a license to any other intellectual
613669Sjavier.bueno@metempsy.com# property including but not limited to intellectual property relating
713669Sjavier.bueno@metempsy.com# to a hardware implementation of the functionality of the software
813669Sjavier.bueno@metempsy.com# licensed hereunder.  You may use the software subject to the license
913669Sjavier.bueno@metempsy.com# terms below provided that you ensure that this notice is replicated
1013669Sjavier.bueno@metempsy.com# unmodified and in its entirety in all distributions of the software,
1113669Sjavier.bueno@metempsy.com# modified or unmodified, in source code or in binary form.
1213669Sjavier.bueno@metempsy.com#
1313669Sjavier.bueno@metempsy.com# Redistribution and use in source and binary forms, with or without
1413669Sjavier.bueno@metempsy.com# modification, are permitted provided that the following conditions are
1513669Sjavier.bueno@metempsy.com# met: redistributions of source code must retain the above copyright
1613669Sjavier.bueno@metempsy.com# notice, this list of conditions and the following disclaimer;
1713669Sjavier.bueno@metempsy.com# redistributions in binary form must reproduce the above copyright
1813669Sjavier.bueno@metempsy.com# notice, this list of conditions and the following disclaimer in the
1913669Sjavier.bueno@metempsy.com# documentation and/or other materials provided with the distribution;
2013669Sjavier.bueno@metempsy.com# neither the name of the copyright holders nor the names of its
2113669Sjavier.bueno@metempsy.com# contributors may be used to endorse or promote products derived from
2213669Sjavier.bueno@metempsy.com# this software without specific prior written permission.
2313669Sjavier.bueno@metempsy.com#
2413669Sjavier.bueno@metempsy.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2513669Sjavier.bueno@metempsy.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2613669Sjavier.bueno@metempsy.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2713669Sjavier.bueno@metempsy.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2813669Sjavier.bueno@metempsy.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2913669Sjavier.bueno@metempsy.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3013669Sjavier.bueno@metempsy.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3113669Sjavier.bueno@metempsy.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3213669Sjavier.bueno@metempsy.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3313669Sjavier.bueno@metempsy.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3413669Sjavier.bueno@metempsy.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3513669Sjavier.bueno@metempsy.com#
3613669Sjavier.bueno@metempsy.com# Authors: Andreas Sandberg
3713669Sjavier.bueno@metempsy.com
3813669Sjavier.bueno@metempsy.comimport m5.objects
3913669Sjavier.bueno@metempsy.comimport inspect
4013669Sjavier.bueno@metempsy.comimport sys
4113669Sjavier.bueno@metempsy.comfrom textwrap import TextWrapper
4213669Sjavier.bueno@metempsy.com
4313669Sjavier.bueno@metempsy.com# Dictionary of mapping names of real CPU models to classes.
4413963Sodanrc@yahoo.com.br_platform_classes = {}
4513669Sjavier.bueno@metempsy.com
4613669Sjavier.bueno@metempsy.com# Platform aliases. The platforms listed here might not be compiled,
4713669Sjavier.bueno@metempsy.com# we make sure they exist before we add them to the platform list.
4813669Sjavier.bueno@metempsy.com_platform_aliases_all = [
4913669Sjavier.bueno@metempsy.com    ("RealView_EB", "RealViewEB"),
5013669Sjavier.bueno@metempsy.com    ("RealView_PBX", "RealViewPBX"),
5113669Sjavier.bueno@metempsy.com    ("VExpress_GEM5", "VExpress_GEM5_V1"),
5213669Sjavier.bueno@metempsy.com    ]
5313669Sjavier.bueno@metempsy.com
5413669Sjavier.bueno@metempsy.com# Filtered list of aliases. Only aliases for existing platforms exist
5513669Sjavier.bueno@metempsy.com# in this list.
5613669Sjavier.bueno@metempsy.com_platform_aliases = {}
5713669Sjavier.bueno@metempsy.com
5813669Sjavier.bueno@metempsy.comdef is_platform_class(cls):
5913669Sjavier.bueno@metempsy.com    """Determine if a class is a Platform that can be instantiated"""
6013669Sjavier.bueno@metempsy.com
6113669Sjavier.bueno@metempsy.com    # We can't use the normal inspect.isclass because the ParamFactory
6213669Sjavier.bueno@metempsy.com    # and ProxyFactory classes have a tendency to confuse it.
6313669Sjavier.bueno@metempsy.com    try:
6413669Sjavier.bueno@metempsy.com        return issubclass(cls, m5.objects.Platform) and \
6513669Sjavier.bueno@metempsy.com            not cls.abstract
6613669Sjavier.bueno@metempsy.com    except TypeError:
6713669Sjavier.bueno@metempsy.com        return False
6813669Sjavier.bueno@metempsy.com
6913669Sjavier.bueno@metempsy.comdef get(name):
7013669Sjavier.bueno@metempsy.com    """Get a platform class from a user provided class name."""
7113669Sjavier.bueno@metempsy.com
7213669Sjavier.bueno@metempsy.com    real_name = _platform_aliases.get(name, name)
7313963Sodanrc@yahoo.com.br
7413963Sodanrc@yahoo.com.br    try:
7513669Sjavier.bueno@metempsy.com        return _platform_classes[real_name]
7613669Sjavier.bueno@metempsy.com    except KeyError:
7713669Sjavier.bueno@metempsy.com        print "%s is not a valid Platform model." % (name,)
7813669Sjavier.bueno@metempsy.com        sys.exit(1)
7913669Sjavier.bueno@metempsy.com
8013669Sjavier.bueno@metempsy.comdef print_platform_list():
8113669Sjavier.bueno@metempsy.com    """Print a list of available Platform classes including their aliases."""
8213669Sjavier.bueno@metempsy.com
8313669Sjavier.bueno@metempsy.com    print "Available Platform classes:"
8413963Sodanrc@yahoo.com.br    doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
8513963Sodanrc@yahoo.com.br    for name, cls in _platform_classes.items():
8613669Sjavier.bueno@metempsy.com        print "\t%s" % name
8713669Sjavier.bueno@metempsy.com
8813669Sjavier.bueno@metempsy.com        # Try to extract the class documentation from the class help
8913669Sjavier.bueno@metempsy.com        # string.
9013669Sjavier.bueno@metempsy.com        doc = inspect.getdoc(cls)
9113963Sodanrc@yahoo.com.br        if doc:
9213669Sjavier.bueno@metempsy.com            for line in doc_wrapper.wrap(doc):
9313669Sjavier.bueno@metempsy.com                print line
9413669Sjavier.bueno@metempsy.com
9513669Sjavier.bueno@metempsy.com    if _platform_aliases:
9613669Sjavier.bueno@metempsy.com        print "\Platform aliases:"
9713669Sjavier.bueno@metempsy.com        for alias, target in _platform_aliases.items():
9813669Sjavier.bueno@metempsy.com            print "\t%s => %s" % (alias, target)
9913669Sjavier.bueno@metempsy.com
10013669Sjavier.bueno@metempsy.comdef platform_names():
10113669Sjavier.bueno@metempsy.com    """Return a list of valid Platform names."""
10213669Sjavier.bueno@metempsy.com    return _platform_classes.keys() + _platform_aliases.keys()
10313669Sjavier.bueno@metempsy.com
10413669Sjavier.bueno@metempsy.com# Add all Platforms in the object hierarchy.
10513669Sjavier.bueno@metempsy.comfor name, cls in inspect.getmembers(m5.objects, is_platform_class):
10613669Sjavier.bueno@metempsy.com    _platform_classes[name] = cls
10713669Sjavier.bueno@metempsy.com
10813669Sjavier.bueno@metempsy.comfor alias, target in _platform_aliases_all:
10913669Sjavier.bueno@metempsy.com    if target in _platform_classes:
11013669Sjavier.bueno@metempsy.com        _platform_aliases[alias] = target
11113669Sjavier.bueno@metempsy.com