111238Sandreas.sandberg@arm.com# Copyright (c) 2012, 2015 ARM Limited
211238Sandreas.sandberg@arm.com# All rights reserved.
311238Sandreas.sandberg@arm.com#
411889Spierre-yves.peneau@lirmm.fr# Copyright (c) 2017, Centre National de la Recherche Scientifique (CNRS)
511889Spierre-yves.peneau@lirmm.fr#
611238Sandreas.sandberg@arm.com# The license below extends only to copyright in the software and shall
711238Sandreas.sandberg@arm.com# not be construed as granting a license to any other intellectual
811238Sandreas.sandberg@arm.com# property including but not limited to intellectual property relating
911238Sandreas.sandberg@arm.com# to a hardware implementation of the functionality of the software
1011238Sandreas.sandberg@arm.com# licensed hereunder.  You may use the software subject to the license
1111238Sandreas.sandberg@arm.com# terms below provided that you ensure that this notice is replicated
1211238Sandreas.sandberg@arm.com# unmodified and in its entirety in all distributions of the software,
1311238Sandreas.sandberg@arm.com# modified or unmodified, in source code or in binary form.
1411238Sandreas.sandberg@arm.com#
1511238Sandreas.sandberg@arm.com# Redistribution and use in source and binary forms, with or without
1611238Sandreas.sandberg@arm.com# modification, are permitted provided that the following conditions are
1711238Sandreas.sandberg@arm.com# met: redistributions of source code must retain the above copyright
1811238Sandreas.sandberg@arm.com# notice, this list of conditions and the following disclaimer;
1911238Sandreas.sandberg@arm.com# redistributions in binary form must reproduce the above copyright
2011238Sandreas.sandberg@arm.com# notice, this list of conditions and the following disclaimer in the
2111238Sandreas.sandberg@arm.com# documentation and/or other materials provided with the distribution;
2211238Sandreas.sandberg@arm.com# neither the name of the copyright holders nor the names of its
2311238Sandreas.sandberg@arm.com# contributors may be used to endorse or promote products derived from
2411238Sandreas.sandberg@arm.com# this software without specific prior written permission.
2511238Sandreas.sandberg@arm.com#
2611238Sandreas.sandberg@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2711238Sandreas.sandberg@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2811238Sandreas.sandberg@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2911238Sandreas.sandberg@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3011238Sandreas.sandberg@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3111238Sandreas.sandberg@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3211238Sandreas.sandberg@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3311238Sandreas.sandberg@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3411238Sandreas.sandberg@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3511238Sandreas.sandberg@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3611238Sandreas.sandberg@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3711238Sandreas.sandberg@arm.com#
3811238Sandreas.sandberg@arm.com# Authors: Andreas Sandberg
3911889Spierre-yves.peneau@lirmm.fr#          Pierre-Yves Peneau
4011238Sandreas.sandberg@arm.com
4112564Sgabeblack@google.comfrom __future__ import print_function
4213774Sandreas.sandberg@arm.comfrom __future__ import absolute_import
4312564Sgabeblack@google.com
4411238Sandreas.sandberg@arm.comimport m5.objects
4511238Sandreas.sandberg@arm.comimport inspect
4611238Sandreas.sandberg@arm.comimport sys
4711889Spierre-yves.peneau@lirmm.frfrom m5.util import fatal
4811238Sandreas.sandberg@arm.comfrom textwrap import TextWrapper
4911238Sandreas.sandberg@arm.com
5011238Sandreas.sandberg@arm.com# Dictionary of mapping names of real CPU models to classes.
5111238Sandreas.sandberg@arm.com_platform_classes = {}
5211238Sandreas.sandberg@arm.com
5311238Sandreas.sandberg@arm.com# Platform aliases. The platforms listed here might not be compiled,
5411238Sandreas.sandberg@arm.com# we make sure they exist before we add them to the platform list.
5511238Sandreas.sandberg@arm.com_platform_aliases_all = [
5611238Sandreas.sandberg@arm.com    ("RealView_PBX", "RealViewPBX"),
5711297Sandreas.sandberg@arm.com    ("VExpress_GEM5", "VExpress_GEM5_V1"),
5811238Sandreas.sandberg@arm.com    ]
5911238Sandreas.sandberg@arm.com
6011238Sandreas.sandberg@arm.com# Filtered list of aliases. Only aliases for existing platforms exist
6111238Sandreas.sandberg@arm.com# in this list.
6211238Sandreas.sandberg@arm.com_platform_aliases = {}
6311238Sandreas.sandberg@arm.com
6411238Sandreas.sandberg@arm.comdef is_platform_class(cls):
6511238Sandreas.sandberg@arm.com    """Determine if a class is a Platform that can be instantiated"""
6611238Sandreas.sandberg@arm.com
6711238Sandreas.sandberg@arm.com    # We can't use the normal inspect.isclass because the ParamFactory
6811238Sandreas.sandberg@arm.com    # and ProxyFactory classes have a tendency to confuse it.
6911238Sandreas.sandberg@arm.com    try:
7011238Sandreas.sandberg@arm.com        return issubclass(cls, m5.objects.Platform) and \
7111238Sandreas.sandberg@arm.com            not cls.abstract
7211688Sandreas.hansson@arm.com    except (TypeError, AttributeError):
7311238Sandreas.sandberg@arm.com        return False
7411238Sandreas.sandberg@arm.com
7511238Sandreas.sandberg@arm.comdef get(name):
7611238Sandreas.sandberg@arm.com    """Get a platform class from a user provided class name."""
7711238Sandreas.sandberg@arm.com
7811238Sandreas.sandberg@arm.com    real_name = _platform_aliases.get(name, name)
7911238Sandreas.sandberg@arm.com
8011238Sandreas.sandberg@arm.com    try:
8111238Sandreas.sandberg@arm.com        return _platform_classes[real_name]
8211238Sandreas.sandberg@arm.com    except KeyError:
8311889Spierre-yves.peneau@lirmm.fr        fatal("%s is not a valid Platform model." % (name,))
8411238Sandreas.sandberg@arm.com
8511238Sandreas.sandberg@arm.comdef print_platform_list():
8611238Sandreas.sandberg@arm.com    """Print a list of available Platform classes including their aliases."""
8711238Sandreas.sandberg@arm.com
8812564Sgabeblack@google.com    print("Available Platform classes:")
8911238Sandreas.sandberg@arm.com    doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
9011238Sandreas.sandberg@arm.com    for name, cls in _platform_classes.items():
9112564Sgabeblack@google.com        print("\t%s" % name)
9211238Sandreas.sandberg@arm.com
9311238Sandreas.sandberg@arm.com        # Try to extract the class documentation from the class help
9411238Sandreas.sandberg@arm.com        # string.
9511238Sandreas.sandberg@arm.com        doc = inspect.getdoc(cls)
9611238Sandreas.sandberg@arm.com        if doc:
9711238Sandreas.sandberg@arm.com            for line in doc_wrapper.wrap(doc):
9812564Sgabeblack@google.com                print(line)
9911238Sandreas.sandberg@arm.com
10011238Sandreas.sandberg@arm.com    if _platform_aliases:
10112564Sgabeblack@google.com        print("\Platform aliases:")
10211238Sandreas.sandberg@arm.com        for alias, target in _platform_aliases.items():
10312564Sgabeblack@google.com            print("\t%s => %s" % (alias, target))
10411238Sandreas.sandberg@arm.com
10511238Sandreas.sandberg@arm.comdef platform_names():
10611238Sandreas.sandberg@arm.com    """Return a list of valid Platform names."""
10713731Sandreas.sandberg@arm.com    return list(_platform_classes.keys()) + list(_platform_aliases.keys())
10811238Sandreas.sandberg@arm.com
10911238Sandreas.sandberg@arm.com# Add all Platforms in the object hierarchy.
11011238Sandreas.sandberg@arm.comfor name, cls in inspect.getmembers(m5.objects, is_platform_class):
11111238Sandreas.sandberg@arm.com    _platform_classes[name] = cls
11211238Sandreas.sandberg@arm.com
11311238Sandreas.sandberg@arm.comfor alias, target in _platform_aliases_all:
11411238Sandreas.sandberg@arm.com    if target in _platform_classes:
11511238Sandreas.sandberg@arm.com        _platform_aliases[alias] = target
116